Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using trail stop and stop loss

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

    Using trail stop and stop loss

    I have written a strategy that determines the type of trade to do (if any) once per day. Most of the trades use SetStopLoss and work fine, however two of the trades within the strategy use SetTrailStop. I can't figure out how to make them execute properly with out the SetStopLoss some how overriding it.

    Code:
    if (CrossBelow(Open, SMA(50), 1) && gap >= 20){
          profitTarget = 110;
          trailStop = gap/.25;
          SetProfitTarget("SE", CalculationMode.Ticks,profitTarget+tickChange);
          SetTrailStop("SE",CalculationMode.Ticks, trailStop, false);
          EnterShort(Quantity, "SE");
          }
    else if(gap < 7){
          SetStopLoss("", CalculationMode.Ticks, stopLoss, false);//Even though this never gets called when it's performing the trade above, it will mess up the trailing stop
    }                    
    }
    Even though SetStopLoss never gets called when it's performing the trade above, it will mess up the trailing stop on any backtesting I do

    #2
    Hello Shazzmoe,

    SetStopLoss() can't be used concurrently with SetTrailStop() unless your signal names are unique. The SetStopLoss() method is called the first time the condition is true (else if(gap < 7)), and will be used instead of the trail stop for the remainder of the strategy instance.

    To resolve, try providing your SetStopLoss() with a unique fromEntrySignal value.

    More information on this can be found at the links for these methods below.



    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      thank you very much I was under the assumption that only the trailstop needed a signal name, but it works now.

      One more question this has brought up though, I want to make sure that calling

      ExitShort();

      will exit any short position I am in regardless of the signals name.

      Comment


        #4
        Yes, that will exit all short positions regardless of signal name.
        ExitShort();
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thank you for all the previous help. I didn't want to start a new thread but I have a question about SetStopLoss

          what will happen if i call the following in the ES

          SetStopLoss("someTrade", CalculationMode.Ticks, 28.5, false);

          28.5 ticks is not a valid tick amount for the ES. Will the trade throw an error in real time or will it round one way or the other?

          Comment


            #6
            shazzmoe, it would be rounded and should still work - however due to rounding effect it would not be the exact stop you might wish, so you should take proper care.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            16 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            0 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,785 views
            0 likes
            Last Post Leafcutter  
            Started by poplagelu, Today, 05:00 AM
            0 responses
            3 views
            0 likes
            Last Post poplagelu  
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,407 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Working...
            X