No announcement yet.

Partner 728x90


trailing stop and stop loss

  • Filter
  • Time
  • Show
Clear All
new posts

    trailing stop and stop loss


    Im testing the trailing stop

    At some point i have just exited at a point where i believe it could continune.

    But while testing i have good results using just pure exit - but im trying to use settrailstop - but it does not work/give me correct results:
    So in my mind - it should give me same result if run these two lines:

    ExitLong(Convert.ToInt32(DefaultQuantity), "Long", "Long");
    SetTrailStop("Long", CalculationMode.Ticks, 0, false);

    It does not.

    Then the other thing is that i see that i need to reset a trailing stop - which i dont understand how i do.

    Because i also use a stoploss that is calculated just before the buy - until i set the trailing stop later.

    As far as i can understand it is not possisble to have both. And is it true that setStoploss - overwrites set SetTrailStop() .
    Then what happens if i start it with setStoploss - but at some point i wish to switch to setTrailStop - is that not possible? - because when i do it - it does not produce "same" reulst - as the two lines above.

    I read that you need to reset on flat market - so right now i try to set another "unuseable" stoploss - when position is flat. But i still wish to set a useable stoploss - when i start a buy -

    I hope anyone can help and explain a bit.

    Best regards

    Hello Karsten,

    ExitLong() sends a market order at the time the code is called. This would be different than a working stop market order submitted by SetTrailStop().

    The trail stop will trail tick for tick from the initial distance in real-time data. In historical data the trail will update when the bar closes.

    SetTrailStop() and other set methods cannot be unset, but you can call these again to adjust the distance before placing a new entry. Or you can use unique signal names.

    Below are links to some examples of custom exit behavior.
    Chelsea B.NinjaTrader Customer Service


      Thanks Chelsea

      OK - then am i correct in the following assumptiins?

      I understand the difference in trail stop and exit.

      But is it true that the trail stop as written below
      SetTrailStop("Long", CalculationMode.Ticks, 0, false); - with 0 as tick value - can only be the same or "better" than pure exit = it will exit at same time - or if price is even better - than the pure exit order - is that true?

      Then i understand that you write that the update - when simulating - will only update on bar close? - so this means that i can never see how it really behaves in the strategy analyzer?

      Then i dont think you replied to the questions about using setStoploss followed by SetTrailStop - is that possible? because as far as im reading on the documentation - the trailstop is overwritten with a setstoploss?

      Best reagrds


        and also - i try the following just for testing
        SetProfitTarget("Long", CalculationMode.Percent, 0);

        And again - i assume that theoretically this would be exactly the same price as just a clean exit (but it is not here)?
        And again is the only reason it is not the same that it now have to wait for the bar to close?


          Hello Karsten,

          Using 0 ticks would place the order at the market price. Likely this either have an error from being on the wrong side of the market or will fill instantly.

          When you mention: "can only be the same or "better" than pure exit = it will exit at same time - or if price is even better - than the pure exit order - is that true?"
          I am not understanding what this means.
          A stop order placed at that number of ticks is where the stop order will be working until it is touched and fills.

          In historical data, set methods update when the primary series updates. Use Calculate.OnPriceChange with TickReplay to have the primary series update for every price change.

          No, SetTrailStop() and SetStopLoss() cannot be used on the same order. From the help guide:
          "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."

          Setting a profit target at 0 distance would likely fill immediately (or cause an error).

          What do you mean by "just a clean exit"? What is the different between a clean exit and a not clean exit?
          Do mean a position that has not been exited and is still open?

          When you mention: "And again is the only reason it is not the same that it now have to wait for the bar to close?"
          Are you waiting for a bar to close before calling a set method?
          Chelsea B.NinjaTrader Customer Service


          Latest Posts


          Topics Statistics Last Post
          Started by chartchartchart, Today, 08:08 AM
          1 response
          Last Post NinjaTrader_Emily  
          Started by andreslazor7, Today, 08:08 AM
          2 responses
          Last Post andreslazor7  
          Started by FatCanary, Today, 08:09 AM
          0 responses
          Last Post FatCanary  
          Started by vantojo, 01-12-2021, 02:13 PM
          15 responses
          Last Post FatCanary  
          Started by nailui, Today, 07:26 AM
          0 responses
          Last Post nailui
          by nailui