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

SetTrailStop with SetStopLoss One Cancels The Other

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

    SetTrailStop with SetStopLoss One Cancels The Other

    I'm working on a strategy that requires the use of both SetTrailStop and SetStopLoss but according to the docs (see line below) SetStopLoss has precedence unless using different signal names. I don't think i can use different signal names since i'm trading 1 instrument and 1 contract. What i'm trying to accomplish is have a fixed stop (SetStopLoss) for the x number of profit ticks and then cancel the SetStopLoss and move to a SetTrailStop. Any ideas? See pseudo code below:

    PSEUDO CODE:
    IF 8 TICK PROFIT - MOVE UP STOP LOSS TO BREAK EVEN
    THEN TRAIL THE REST OF THE MOVE.

    I can accomplish a trail using SetStopLoss but it's not as elegant as the one liner SetTrailStop.


    DOCUMENTATION:
    The SetTrailStop() method can NOT be used concurrently with the SetStopLoss() or SetParabolicStop() method for the same position, if any of methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use all three methods in the same strategy if they reference different signal names.

    #2
    Hello bc24fl,

    In this situation you would likely be best off just using SetStopLoss or an exit method and then adding logic to make that trail. As you noted you cannot use both types of orders at once so logic would be the next best solution.

    We have a sample that shows how to move a stop to breakeven, so that part can be used for this purpose: https://ninjatrader.com/support/help...and_onexec.htm

    A secondary condition could be placed after the break even condition to check if the stop should trail from that point. Calling SetStopLoss again will just update it so you can make it trail by calling it again for each OnBarUpdate where it should be trailing. Keep in mind if you control this with logic, you need to make that logic only work in one direction. What I mean is that if the price moved back down, you want the condition to recognize this so it does not adjust the stop back down in the opposite direction.

    You can find an example of trailing logic in the following post, this uses exit orders however the concept is generally the same. Using a condition you would trail the price yourself by calling the order method again with a new price: https://ninjatrader.com/support/foru...654#post785654


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I have done something similar with help from Jim. To trail it you check for the profit above average entry price and move the Stop accordingly. So it moves on each tick of profit as in the ATM.

      Comment


        #4
        I have used this from the start to trail a position.

        if (Close[0] >= Position.AveragePrice + (11 * TickSize))

        SetStopLoss(CalculationMode.Price, Close[0] - (10 * TickSize));

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ghoul, Today, 06:02 PM
        0 responses
        4 views
        0 likes
        Last Post ghoul
        by ghoul
         
        Started by Barry Milan, Yesterday, 10:35 PM
        6 responses
        18 views
        0 likes
        Last Post Barry Milan  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        13 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        12 views
        0 likes
        Last Post terofs
        by terofs
         
        Working...
        X