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 SuneSorgenfrei, Today, 09:56 AM
        2 responses
        10 views
        0 likes
        Last Post SuneSorgenfrei  
        Started by samish18, Today, 11:44 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by _Zero_, 01-06-2020, 01:16 PM
        66 responses
        1,622 views
        5 likes
        Last Post NinjaTrader_ChelseaB  
        Started by RedDuke, 10-31-2023, 11:18 PM
        42 responses
        823 views
        2 likes
        Last Post NinjaTrader_Emily  
        Started by blar58, Today, 10:37 AM
        11 responses
        30 views
        0 likes
        Last Post blar58
        by blar58
         
        Working...
        X