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 Sparkyboy, Today, 10:57 AM
          0 responses
          0 views
          0 likes
          Last Post Sparkyboy  
          Started by TheMarlin801, 10-13-2020, 01:40 AM
          21 responses
          3,916 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by timmbbo, 07-05-2023, 10:21 PM
          3 responses
          152 views
          0 likes
          Last Post grayfrog  
          Started by Lumbeezl, 01-11-2022, 06:50 PM
          30 responses
          808 views
          1 like
          Last Post grayfrog  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X