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

Limit trail stop

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

    Limit trail stop

    While trading forex I want to set a trailing stop with a specific amount of ticks. However, it cannot pass a specific price.
    For example, suppose I'm entering long at current price of 1.50000 with a trailing stop of 100 ticks which will set the first S.L to 1.49900. However, although I want the trailing stop to be 100 ticks (for example, if the price changes to 1.50200, the S.L will be 1.50100), I don't want the S.L ever to be below 1.49950. As seen above, the first S.L will be 1.49900 which is below 1.49950.
    Is there a way to have a trail stop loss which never cross a specific price?

    Thanks

    #2
    Hello kiss987,

    Thank you for your post.

    Yes, this is possible by checking the current price level of the market and then checking that against the specific price level you do not wish to cross below with your trailing stop. This requires placing the SetTrailStop() command in the OnBarUpdate() method. For example:
    Code:
    			if (Position.MarketPosition == MarketPosition.Flat)
    				SetTrailStop(CalculationMode.Ticks, 500); // reset trailing stop when flat
    			
    			if (Close[0] - 500*TickSize <= 1.49950)
    			{
    				int tStop = Convert.ToInt32(Math.Abs((1.49950 - Close[0])/(Instrument.MasterInstrument.PointValue * TickSize)));
    				SetTrailStop(CalculationMode.Ticks, tStop);
    			}
    Please let me know if you have any questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    1 response
    17 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by benmarkal, Yesterday, 12:52 PM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by helpwanted, Today, 03:06 AM
    1 response
    20 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Working...
    X