Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

reset the trail stop on strategy

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

    reset the trail stop on strategy

    Dear all.
    in the help guide appears:
    Should you call this method to dynamically change the trail stop price in the strategy OnBarUpdate() method, you should always reset the trail stop price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your trail stop order on your next open position.

    In my strategy, the trailing stop is on bar uptade. I do not understand this tip.

    - For example. I have used
    SetTrailStop (CalculationMode.Percent, 0.01);

    The value of 0.01 can be modified? one example:

    In NQ instrument. Long Order filled at 10000
    Trail stop offset 9900
    Next order Long Order filled at 9900
    Trail stop offset 9801

    This is the scheme?

    Regards

    #2
    Hello memonic,

    Thanks for your post.

    This tip from the SetTrailStop() help guide page means that in your strategy you would need to check if you are in a flat position (Position.MarketPosition == MarketPosition.Flat) and call SetTrailStop() to reset the stop loss to the original value when all positions are closed

    See the SamplePriceModification example script in the help guide documentation below for an example of modifying the price of stop loss and profit target orders.

    SamplePriceModification: https://ninjatrader.com/support/help...of_stop_lo.htm

    SetTrailStop(): https://ninjatrader.com/support/help...ttrailstop.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Brandon.
      In the case of use train stop in flat position, the value of the offset is at triggered?. For example:

      if ((ToTime(Time[0]) > 230000 && ToTime(Time[0]) < 150000))
      SetTrailStop(CalculationMode.Percent, 0.001);

      The value of trail stop from 23.00 to 15.00 will be:
      Position.AveragePrice - Position.AveragePrice*0.001
      in the time window described above.

      Thanks in advance

      Comment


        #4
        Hello memonic,

        Thank you for your reply.

        Brandon is currently out of the office, however, I'm happy to answer.

        SetTrailStop would only be triggered if there is a position open for it to be protecting - if you are in a flat position it would not be active since there would be no position to protect.

        Please note in percentage calculation mode a value of 1 is equal to 100%, a value of 0.1 is equal to 10%, and a value of 0.01 will be 1%, so using 0.001 as the percent value would calculate a starting trail position of 0.1% of the average entry price.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks kate for your answer.
          In this case trail stops works exactly with this two sentences:
          Case 1
          if ((ToTime(Time[0]) > 230000 && ToTime(Time[0]) < 150000))
          {
          if(Position.MarketPosition == MarketPosition.Long)
          {
          SetTrailStop(CalculationMode.Percent, stp2);
          }
          }

          case 2
          if ((ToTime(Time[0]) > 230000 && ToTime(Time[0]) < 150000))
          {
          SetTrailStop(CalculationMode.Percent, stp2);
          }
          In the backtest, on bar close, 12 minute bars. Case 1 and case 2 shows different results.

          Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by inanazsocial, Today, 01:15 AM
          0 responses
          2 views
          0 likes
          Last Post inanazsocial  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          22 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Started by guillembm, Yesterday, 11:25 AM
          2 responses
          9 views
          0 likes
          Last Post guillembm  
          Started by junkone, 04-21-2024, 07:17 AM
          9 responses
          70 views
          0 likes
          Last Post jeronymite  
          Working...
          X