Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

profit within days

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    profit within days

    Hi Guys,

    In the backtesting strategy wizard is it possible to have a condition where if the stock is not in profit within 2 weeks then the stock will be stopped out at that days close.

    I've also added the conditions of profit and loss on percentage that I want to keep as well.

    Any help would be great thanks!

    #2
    Hello NZJim,

    Using the condition builder, you can access the value RealizedPnL. It's under the strategy category. The "two week part" is challenging to do in the strategy wizard only. You can write in a specific date check for with Time > Time series == Time > Date value. Anything more involved with date / time requires working with code directly.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      Thanks for the quick response

      How would I do this in the code?

      cheers
      Jim

      Comment


        #4
        In programming there are usually multiple ways to do things, so following is only provided as an example to get you started on an approach. General help for working with DateTime objects is available here.

        You can capture the DateTime of the first bar and then compare this value + 14 days to the bars's time stamp. Consider the Minimum bars required you're using for your strategy and maybe capture according to this instead of 0.

        //variables region
        private DateTime = myDateTime;


        if (CurrentBar == 0)
        myDateTime = Time[0];


        if (ToDay(Time[0]) <= ToDay(myDateTime.AddDays(14)))
        {
        }
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks Ryan,

          I'll go and have a go at it!

          cheers
          Jim

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          27 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          117 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          69 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          226 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          417 views
          0 likes
          Last Post CaptainJack  
          Working...
          X