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

Historical Testing - Managed Stop Ignored

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

    Historical Testing - Managed Stop Ignored

    Hi,

    I have searched a lot via Google and these forums to try to understand how to resolve this type of situation in historical backtesting. I will describe the process of my indicator and strategy, and then the error that occurs.

    1) Indicator generates signals with OnBarClose = true
    2) Strategy checks indicator signals and open positions OnBarClose = false
    3) If signal is valid on the last bar close, the strategy enters the next bar @market which is marked as the Open if historical testing. I am using all managed order methods for stops and targets, so ExitShortStop, ExitLongStop, ExitLongLimit, and ExitShortLimit.

    My issue is as follows and would occur for a long or short trade that would be in this situation in historical testing, my guess it would be fine in live trading.

    My strategies' output window shows I have entered a Long trade at the Open after a closed bar with a valid signal on it. In live trading the next tick would be processed by my strategy and place the stop order (ExitLongStop), however using the strategy analyzer in historical testing this stop order is shown to be "ignored" because the stop price is greater than or equal to the close of the current bar. This is because the event goes from open to close bar as there aren't any ticks coming in. Because of this my position stays open and the strategy cannot proceed with any new trades and then just closes at the end of the data date range I supplied to the analyzer.

    How can I work around this issue and make sure my stop order gets accepted by the historical analyzer to test my strategy properly?

    I have included a screenshot of the chart tab from the strategy analyzer and the issue in question is outlined there as well.

    Thanks,
    Charles
    Attached Files

    #2
    Hello Charles,

    Thank you for your post.

    You would want to incorporate an Intrabar granularity to your script.
    This would be adding an additional small dataseries such as 1 tick to the script.
    This would allow you have the strategy calculate on a tick by tick basis and use that to submit orders.

    Here is a reference sample on how to write this -
    http://www.ninjatrader.com/support/f...ead.php?t=6652

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi Cal,

      For others that may encounter this I will describe what I did below, and report that this reference you gave worked perfectly!

      I added the smaller data series to my initialize method, using the 1 minute series. Then I included my "closed" bar indicator signal checking for my primary strategy series (60M) in the "BarsInProgress == 0" IF-Statement code bracket and then added my order/position checking for the "else" of BarsInProgress statement; which I wanted to be simulated in historical testing as tick-by-tick, so that my stop order is not "ignored" as before. This worked out perfectly - Thank you!

      An additional question regarding this type of situation, but in live/demo trading; I want to change this code to something different for live trading rather than adding a secondary data series, as it wouldn't be necessary if using the "CalculateOnBarClose = false" in my strategies' initialize method. What IF-Statements can I use in my "OnBarUpdate" method (instead of this second data series option) to segregate my closed bar code from my tick-by-tick code? - I have found this before and tried some statements with the CurrentBars array, but I can't seem to find it or remember how to do it.

      Thanks again!
      -Charles

      Comment


        #4
        Just thought I would - *BUMP* this thread from my last post and question.

        Comment


          #5
          Charles, thanks for ringing our bell, I think you refer to this sample here showing a dual COBC use basically?

          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hi Bertrand!

            That works, I looked this up before - I don't know, guess I was making it all more complicated than necessary. This should work perfectly when I go into "live/demo" forward testing.

            So far the previous solution posted by Cal is working perfectly.

            I may have some other questions about handling broker events; like disconnects and session closes in FX, and re-initializing strategies with active positions. I'll poke around the NT help and Google and the Forums here - If I can't find what I need or get stuck I'll post a new thread

            Thank you all for your assistance - You guys and NT Rock!

            Best,
            Charles

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DawnTreader, Yesterday, 05:58 PM
            2 responses
            12 views
            0 likes
            Last Post DawnTreader  
            Started by quicksandatl, Today, 11:11 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by OllieFeraher, Today, 11:14 AM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by aman jain, 10-01-2020, 09:25 PM
            3 responses
            293 views
            0 likes
            Last Post Legiboka  
            Started by reynoldsn, Today, 07:23 AM
            5 responses
            12 views
            1 like
            Last Post NinjaTrader_Gaby  
            Working...
            X