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 rhyminkevin, Today, 04:58 PM
    1 response
    34 views
    0 likes
    Last Post Anfedport  
    Started by iceman2018, Today, 05:07 PM
    0 responses
    4 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    7 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    14 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    49 views
    0 likes
    Last Post futtrader  
    Working...
    X