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

Changing Trailing Stop

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

    Changing Trailing Stop

    Hello,

    I have this piece of code in my strategy, in order to change my trailing stop when price goes in my favour.

    // Resets the trail stop to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetTrailStop(CalculationMode.Ticks, trailstop);
    }
    // Condition set 2
    if (Position.MarketPosition == MarketPosition.Long
    && Close[0] > Position.AvgPrice + 50 * TickSize)
    {
    SetTrailStop(CalculationMode.Ticks, trailstop + 10);
    }
    // Condition set 4
    if (Position.MarketPosition == MarketPosition.Short
    && Close[0] < Position.AvgPrice - 50 * TickSize)
    {
    SetTrailStop(CalculationMode.Ticks, trailstop + 10);
    }


    This seems to work fine in backtests. But it's not working when running the strategy on real time, the trailing stop do not change. Any ideas why this is happening?

    Thanks!












    #2
    What is the EntrySignalName for your long and short entry orders?

    Comment


      #3
      Hi,
      I don't use EntrySignalName, i have:

      EnterLong(DefaultQuantity, "");

      EnterShort(DefaultQuantity, "");

      Comment


        #4
        Hello mastercillo,

        If you add prints to the action block of the condition in question, are you seeing the prints appear when you are expecting the set method to be called?

        (edited, forgot the link)
        Below is a link to a forum post that demonstrates using prints to understand behavior.


        What is the amount of ticks the trailing stop is being set to? (i.e. what is the value of trailstop?)
        Last edited by NinjaTrader_ChelseaB; 04-01-2019, 12:32 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ChelseaB,

          I've tried a strategy with simpler entry conditions just to make tests. I have added print():

          // Condition set 2
          if (Position.MarketPosition == MarketPosition.Long
          && Close[0] > Position.AvgPrice + ticksinyourfavour * TickSize)
          {
          SetTrailStop(CalculationMode.Ticks, trailstop + widetrail);
          Print("we change trailstop");
          }



          trailstop is 10, if price moves 5 ticks in your favour (ticksinyourfavour), then trailstop is changed adding 40 ticks (widetrail).

          Nothing is printed in the output window "we change trailstop", but I see a line changing trailstop to 50 (this is correct), then to 36 (?ż), then to 10 (this is correct as the trade is closed and trail returns to original value)... so I'm very confused:

          01/04/2019 19:54:00 Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False
          01/04/2019 19:54:00 Entered internal PlaceOrder() method at 01/04/2019 19:54:00: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
          01/04/2019 19:57:00 Entered internal PlaceOrder() method at 01/04/2019 19:57:00: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
          01/04/2019 19:57:00 Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Ticks Value=50 Currency=0 Simulated=False
          01/04/2019 20:00:00 Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Ticks Value=50 Currency=0 Simulated=False
          01/04/2019 20:02:20 Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Ticks Value=36 Currency=0 Simulated=False
          01/04/2019 20:03:00 Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False

          Comment


            #6
            Hello mastercillo,

            The out appears to show the orders are being placed.

            In real-time are you seeing the trailing stop appear on the chart?

            Trail stop orders trail tick for tick after being initially placed at a price.

            If you use the Simulated data feed and slide the market up while in a long position, are you not seeing the trailing stop trail tick for tick as the as the price increases?

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello ChelseaB,
              I don't know how to see trailing stop (or target) on the chart, can you help me with that?
              I see the "chart trader" button but it is disabled.

              Comment


                #8
                Hello mastercillo,

                You will need to enable Chart Trader.

                You can either:

                Right-click the chart > select Properties.. > and in the General section set Chart Trader to Chart Trader > click OK.

                Or

                Click the Chart Trader icon on the chart toolbar and select Chart Trader.




                If you are using the Free License key Chart Trader will not be available.
                You would need to either monitor the Orders tab of the Control Center or open a SuperDOM or Basic Entry window.
                (But NinjaScript Strategies would also not be available so you would not be able to run a NinjaScript Strategy)
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ChelseaB,

                  I think Chart Trader and strategies cannot be enabled at the same time in NinjaTrader 7.

                  However I have been doing tests with Simulated data feed and now seems to be working properly. I think I can go on my own now.

                  Thanks for your help.

                  Comment


                    #10
                    Hello mastercillo,

                    I overlooked this is a NinjaTrader 7 question. You are correct, with NinjaTrader 7 the same chart cannot have a strategy enabled and Chart Trader.

                    Instead, open up a new chart to the same instrument and enable Chart Trader on the other chart to view active orders. This would give you a chance to watch the movement of the trailing stop and ensure this is behaving as you are expecting.

                    The Simulated Data Feed can also be very useful for testing real-time behavior. You can control the direction of the market to trigger behavior and movement faster without having to wait for the natural markets to make movement.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks ChelseaB,

                      This information has been very useful.

                      Comment


                        #12
                        Hello bandass,

                        Welcome to the NinjaTrader forums!

                        Are you inquiring about using SetTrailStop()?

                        Is the stop loss not being placed or is the trailing action not occurring?
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by algospoke, Yesterday, 06:40 PM
                        2 responses
                        19 views
                        0 likes
                        Last Post algospoke  
                        Started by ghoul, Today, 06:02 PM
                        3 responses
                        14 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        45 views
                        0 likes
                        Last Post jeronymite  
                        Started by Barry Milan, Yesterday, 10:35 PM
                        7 responses
                        20 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by AttiM, 02-14-2024, 05:20 PM
                        10 responses
                        181 views
                        0 likes
                        Last Post jeronymite  
                        Working...
                        X