Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Virtual trailing stop

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

    Virtual trailing stop

    I’m trying to write a strategy in NinjaScript that creates a virtual trailing stop by modifying the stop price. Here’s what I want it to do:

    Upon entry, set the initial stop to 12 cents with no trailing stop.
    When the high-water mark is 6 cents, initiate the trailing stop to 6 cents (break-even).
    When the high-water mark is 14 cents, set the trailing stop to 7 cents. Then, for each 2-cent increase in high-water mark, increase the trailing stop one cent.
    When the high-water mark is 50 cents, set the trailing stop to one-third of the high-water mark.

    This strategy only goes long and only gets into one position per symbol.

    #2
    Hello egan857,
    Welcome to the NinjaTrader forum and I am happy to assist you.

    You can create virtual trailing stop and modify the same as per your need. Please refer to the SetStopLoss method for the same. You can get more info regarding the same from this page http://www.ninjatrader.com/support/h...etstoploss.htm

    basically you have to check the current price and reassign the SetStopLoss accordingly. For Example,

    Code:
    if (Position.MarketPosition == MarketPosition.Long)
    {
    	if (Close[0] > Position.AvgPrice + 20 * TickSize)
    	{
    		SetStopLoss(CalculationMode.Ticks, -8);
    	}
    	else if (Close[0] > Position.AvgPrice + 6 * TickSize)
    	{
    		SetStopLoss(CalculationMode.Ticks, 6);
    	}
    }

    The above is only a reference code.

    In this context let me say, that you might be also be interested int the SetTrialStop Method. You can get more info regarding the same from here http://www.ninjatrader.com/support/h...ttrailstop.htm

    Let me know if I can assist you any further.

    Regards,
    Joydeep.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hi Joydeep,

      I don't think that solution will work. What that does is change the stop based on the current price, and I need to change the stop only when the high-water mark has changed. In that example, when the position is up 20 cents the stop is changed to -8, which captures a 12-cent win, which is correct. But, as soon as the position drops one penny and is up only 19 cents, the stop is changed to 6, which allows a 6-cent loss.

      That code would work if we replaced all occurrences of "Close[0]" with the position's high-water mark. How would I get that value?

      Comment


        #4
        Hello egan857,
        The code was only for reference, and you could do what you want through custom coding.

        Unfortunately we cannot offer you full coding snippet, however you can contact one of our NinjaScript consultants for the job. You can get the list of our NinjaScript consultants from here http://www.ninjatrader.com/partners#...pt-Consultants

        Please do let me know if I can assist you any further.

        Regards,
        Joydeep.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by WHICKED, Today, 12:45 PM
        2 responses
        19 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by GussJ, 03-04-2020, 03:11 PM
        15 responses
        3,276 views
        0 likes
        Last Post xiinteractive  
        Started by Tim-c, Today, 02:10 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        5 views
        0 likes
        Last Post Taddypole  
        Started by chbruno, 04-24-2024, 04:10 PM
        4 responses
        51 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Working...
        X