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

Stop-Loss not Trailing in SIM

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

    Stop-Loss not Trailing in SIM

    Hi guys,

    So I coded a strategy and ran it through vigorous backtesting and it's working half decent. So the next step in my plan is to SIM test it to see if there are differences in the results before I consider going Live with it.

    When I place it in SIM, the Stop-Loss doesn't trail. In my backtesting the stop-loss trails just fine.

    I have the stop-loss coded where each time a new bar opens in a 5-min HeikenAshi Chart, the Stop-loss is placed at 2 ticks worse than the previous bar (Low or High depending on a sell or buy trade). So:
    - In a sell trade the stop-loss would be placed at High[1] + 2 ticks.
    - In a buy trade the stop-loss would be placed at Low[1] - 2 ticks.

    It works beautifully.

    I call the stop-loss using the SetStopLoss method using CalculationMode.Price. I call this each time the Stop-Loss needs to be moved to the new bar and NinjaTrader seems to handle the removal of the original position of the stop-loss. i.e. I don't have to remove it from what is now High[2] + 2 Ticks. I simply just Set it to High[1] + 2 ticks and it's done.

    I am wondering if I have to set up a feature or option for this to work in a SIM situation. I am SIMming using a demo NinjaTrader account with that GQG feed that comes free for 2 weeks.

    Do I have to set my ATM a specific way to allow my strategy to control the stop-loss?

    Is there an Option in NinjaTrader that needs to be actiavted/deactivated to allow a strategy to control the stop-loss?

    Why does the exact same stop-loss code work in Backtesting and not in SIM?

    My backtest method was to download the individual NRD replay files from a provider and simply load the strategy in the chart and hit play. Then record the results in super detail. Then tweak and do it all over again until I felt I had something worthwhile which was not curve fitted. Which was a serious balancing act BTW lol

    I didn't use the backtest tool built into NinjaTrader coz it only deals with OHLC data or some algorithmic variation which is not good enough for my needs. I wanted exact. So I hit play and watched the strategy trade the market for 3 years worth of data.

    So I'm quite confident the stop-loss works in backtest. Just not in SIM. Maybe I'm doing something else wrong. Any ideas will be very appreciated.

    Thanks!

    #2
    Hello Bluebeep,

    Thanks for your post.

    Please clarify what you are seeing when testing with live data:

    Is the stop not moving at all?

    Is the strategy being disabled?

    Do you see any error messages in the "log" tab of the control center, related to the strategy, while running the strategy on live data?

    What calculate mode is the strategy run on? (Calculate.OnBarClose, Calculate.OnPriceChange, Calculate.OnEachTick)




    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      The stop isn't moving at all. It does get created but doesn't move subsequently. While in backtesting it does move.

      The strategy is active and doesn't get disabled.

      I'll have no error messages in the log file. It has my order and execution info for entering the trade, then it has entry information about the initial stop and finally a close at the end of the day.

      CalculateMode is OnEachTick

      Each time the strategy moves the stop I send a Print to the Output Window. No prints either.

      When I disabled and enabled the strategy the prints from my strategy showed all the stops in the output Window and drew the line for the trade on the chart. Obviously its now calculating what it may have done with the historical data present on my chart.

      So by disabling and enabling it may move the stop now but I may not know for a bit coz the strategy takes a specific condition that arises about once a week. Regardless - something isn't right. Hmmm
      Last edited by Bluebeep; 10-11-2018, 08:07 AM.

      Comment


        #4
        Hello Bluebeep,

        Thanks for your reply.

        I recommend that you debug the strategy using print statements to see what is happening. The place to start would be to add a print statement to the block of code where you are moving the stop. You can use the print statement to advise, in the New>Ninjascript output window, that the stop is being moved along with the Time[0].TimeofDay and the new stop price itself. For example:

        Print ("Time: "+Time[0].TimeOfDay+" Stop Moved to: "+(your stop price variable here));

        Here is a link to our debugging tips for further reference.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          I thought I just mentioned that. I am using Prints. When the stop is moved, a print is sent to the output Window. The stop never gets moved and obviously the Print never gets sent to the Output. It's like the block of code never get touched.

          However when I disabled and enabled the strategy the stops and prints showed up.

          What gives?

          The attached image is for my print AFTER I disabled and enabled the strategy.

          So now that I have disabled and enabled and the prints show up, will the strategy work? Given that it takes around 1 trade a week it this may be a loooooong conversation.

          Comment


            #6
            Hello Bluebeep,

            Thanks for your reply.

            Yes, 1 trade per week would take a long time. Is it possible to test on a shorter time frame just for debugging purposes?

            You would need to add one or more Print statements prior to the block of code that moves the stop. It sounds like a condition that says to move the stop is not in the state expected. You will need to keep moving the prints in your code to find where the print is not executing and where it is and go from there.

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              lol yes that would work if the condition would existed long enough for the stop to be moved at least once.

              I'll make it more reactive and hopefully we have a condition occur soon.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by guillembm, Yesterday, 11:25 AM
              2 responses
              9 views
              0 likes
              Last Post guillembm  
              Started by junkone, 04-21-2024, 07:17 AM
              9 responses
              68 views
              0 likes
              Last Post jeronymite  
              Started by trilliantrader, 04-18-2024, 08:16 AM
              4 responses
              18 views
              0 likes
              Last Post trilliantrader  
              Started by mgco4you, Yesterday, 09:46 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by wzgy0920, Yesterday, 09:53 PM
              0 responses
              10 views
              0 likes
              Last Post wzgy0920  
              Working...
              X