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

Multi-Series Strategies - Live vs. Historical

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

    Multi-Series Strategies - Live vs. Historical

    I have a price pattern based strategy that runs on a 60-min chart right now. It's coded to be running in COBC=false mode. And that has caused it to be difficult to back test as intra-candle price level breaches cannot be emulated. So I finally relented and rewrote it to execute based on single ticks and that seems to work fine when it's running live.

    However, I'm still facing one problem I'm seeing to alleviate - please see the enclosed screen grab as an example.



    So what you see on the chart is the 60-min feed. The blue outlined candle is the one that concludes the price pattern setup. The yellow outlined candles are the ones during which the strategy is allowed to entry. Now, the actual trigger was the low of the blue outlined candle, and it's clear that the first yellow one dropped below that mark.

    However, due to the nature of how historic data is run by Ninja the first 60-min candle at 18:00:00 is COMPLETED before the strategy runs through the second tick series (i.e. series 1). This seems to shift the entry into the second hourly candle (19:00:00) as the entry per the historical data happens after 18:00:00:

    4/22/2013 6:02:05 PM Entered internal PlaceOrder() method at 4/22/2013 6:02:05 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short Position' FromEntrySignal=''

    As you can see it entered at 18:02:05. Now in live tape it would have probably opened the first yellow candle at 18:00:00 and then taken an entry DURING the 18:00 candle. My problem is that the hourly candles DRIVE the tick based entry logic. Basically the hourly price pattern logic analyses the prior candles based on rules and then triggers a 'longTrigger' or 'shortTrigger' flag globally. That one is then picked up the next time the strategy runs through the tick based series (1) - all that's left then is for the tick series to wait for a push above/below the respective price triggers and to take an entry.

    Again, all that works fine in live tape but during historical testing I'm seeing a shift on both the entry and exit side by one candle. The core of the problem appears to be that in live trading it would call the 18:00:00 hourly candle for the first time (FirstTickOfBar) and then call the 17:00:01 candle on the tick side, right? In historic trading it apparently (maybe I'm doing something wrong here) calls the 18:00:00 candle on series 0 only once after calling 17:59:59 on series 1. IF I'm not mistaken this is causing those shifted entries in historical simulation.

    Confusing matters is that it sometimes takes it correctly. See here:



    As you can see the entry is taken on the first candle as it should have. I looked at the tick data on the first chart and based on what I'm seeing it should have done the same. There clearly was a drop through the trigger price. Perhaps this is happening because I'm using single ticks and not seconds. Either way it's confusing ;-)

    Is there any way to fix this? Is this a commonly known problem or did I perhaps screw things up somewhere? ANY input would be much very much appreciated
    Last edited by molecool; 05-03-2013, 06:59 AM.

    #2
    The time shouldn't be changing on backtest vs real-time. The time will always represent the end of the bar time.

    What bars series are you submitting your orders to? Are you doing this on the 60 minute bar, or the 1 tick bar?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Hey Matt - I just added another chart to show that it's intermittent. To answer your question - I did cover this in my write up but I am executing only on the [1] tick series. All entry calls are on [1][0]:

      entryOrder = EnterLong(1, DefaultQuantity, LONG_POSITION);

      Comment


        #4
        More info

        Here I'm logging out my 60-min candle based global triggers:

        4/30/2013 4:00:00 AM: MINUTE...
        Long trigger: False, Short trigger: False
        4/30/2013 5:00:00 AM: MINUTE...
        Long trigger: False, Short trigger: True
        ####### RTV-S triggered #######



        And as you can see the tick series picks it up and enters properly.

        Here's the same on the first chart:

        4/22/2013 5:00:00 PM: MINUTE...
        Long trigger: True, Short trigger: False
        4/22/2013 6:00:00 PM: MINUTE...
        Long trigger: False, Short trigger: True
        ####### RTV-S triggered #######



        And although the short trigger is clearly present at 18:00:00 (the first yellow candle) it does not take the entry when it should. instead it enters a candle too late.
        Last edited by molecool; 05-03-2013, 07:16 AM.

        Comment


          #5
          More details

          Okay, here on the working chart - a bit more log detail:

          4/30/2013 4:00:00 AM: MINUTE...
          Long trigger: False, Short trigger: False
          4/30/2013 5:00:00 AM: MINUTE...
          Long trigger: False, Short trigger: True
          ####### RTV-S triggered #######
          4/30/2013 5:00:00 AM
          Waiting for breach Below: 1.04717 to enter short position.
          Calculating Initial Stop Loss at: 4/30/2013 5:00:00 AM
          Using candle at 4/30/2013 4:00:00 AM
          Tick Size: 0.00001
          Tick Size Multiplier set to: 10
          Wick of previous candle: 0.00092
          Wick of previous candle in full ticks: 9.2
          ISL in full ticks = 11.2
          Initial GainR% target in full ticks = 11.2
          4/30/2013 5:00:00 AM Entered internal PlaceOrder() method at 4/30/2013 5:00:00 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short Position' FromEntrySignal=''
          And here's the chart showing some ticks - clearly it took it DURING the 5:00:00am candle:



          Here's the same on the scenario where it does not work:

          4/22/2013 5:00:00 PM: MINUTE...
          Long trigger: True, Short trigger: False
          4/22/2013 6:00:00 PM: MINUTE...
          Long trigger: False, Short trigger: True
          ####### RTV-S triggered #######
          4/22/2013 6:02:05 PM
          Waiting for breach Below: 1.05319 to enter short position.
          Calculating Initial Stop Loss at: 4/22/2013 6:02:05 PM
          Using candle at 4/22/2013 5:00:00 PM
          Tick Size: 0.00001
          Tick Size Multiplier set to: 10
          Wick of previous candle: 0.00063
          Wick of previous candle in full ticks: 6.3
          ISL in full ticks = 8.3
          Initial GainR% target in full ticks = 8.3
          4/22/2013 6:02:05 PM Entered internal PlaceOrder() method at 4/22/2013 6:02:05 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short Position' FromEntrySignal=''
          And the chart that goes with that log:



          So could it be that Ninja often times paints the entry on the wrong candle during historical testing? Or does the tick data suggest that it wasn't able to grab an entry?

          Also note that it works on the scenario where the trace log shows an even hourly time:

          4/30/2013 5:00:00 AM Entered internal PlaceOrder() method at 4/30/2013 5:00:00 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short Position' FromEntrySignal=''
          And that it does NOT work when it shows an uneven time:

          4/22/2013 6:02:05 PM Entered internal PlaceOrder() method at 4/22/2013 6:02:05 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short Position' FromEntrySignal=''
          Which is strange as it's the very same code - both are short trades via the same entry rule.

          I hope this isn't all confusing - my apologies for the flood of data, I'm simply trying to provide context so you guys can help me sort out what's going on.
          Last edited by molecool; 05-03-2013, 07:37 AM.

          Comment


            #6
            Originally posted by molecool View Post
            Okay, here on the working chart - a bit more log detail:



            And here's the chart showing some ticks - clearly it took it DURING the 5:00:00am candle:



            Here's the same on the scenario where it does not work:



            And the chart that goes with that log:



            So could it be that Ninja often times paints the entry on the wrong candle during historical testing? Or does the tick data suggest that it wasn't able to grab an entry?

            Also note that it works on the scenario where the trace log shows an even hourly time:



            And that it does NOT work when it shows an uneven time:



            Which is strange as it's the very same code - both are short trades via the same entry rule.

            I hope this isn't all confusing - my apologies for the flood of data, I'm simply trying to provide context so you guys can help me sort out what's going on.
            On what tick trigger are you executing the orders? Not the bar series: you already told us that one is BarsArray[1], per index [1][0].

            Comment


              #7
              Originally posted by koganam View Post
              On what tick trigger are you executing the orders? Not the bar series: you already told us that one is BarsArray[1], per index [1][0].
              I'm not sure I understand your question koganam. The way the strategy is structured is explained in my first comment. The 60-min series flips the triggers based on candle patterns and the tick series executes.

              Comment


                #8
                Originally posted by molecool View Post
                I'm not sure I understand your question koganam. The way the strategy is structured is explained in my first comment. The 60-min series flips the triggers based on candle patterns and the tick series executes.
                Do you have a BarsInProgress filter?

                Comment


                  #9
                  Originally posted by koganam View Post
                  Do you have a BarsInProgress filter?
                  Yes, I have it separated between BIP = 0 and BIP = 1. All the 60-min candle pattern code is contained by if(BarsInProgress == 0) and the tick stuff is contained by if(BarsInProgress == 1).
                  Last edited by molecool; 05-03-2013, 03:53 PM.

                  Comment


                    #10
                    Originally posted by molecool View Post
                    Yes, I have it separated between BIP = 0 and BIP = 1. All the 60-min candle pattern code is contained by if(BarsInProgress == 0) and the tick stuff is contained by if(BarsInProgress == 1).
                    Hm. that certainly does not compute then. Time to bring out the old Print() statement, to check if the trade flag is really being set and trapped at the correct time.

                    Comment


                      #11
                      Originally posted by koganam View Post
                      Hm. that certainly does not compute then. Time to bring out the old Print() statement, to check if the trade flag is really being set and trapped at the correct time.
                      That's exactly what I have been doing. Please see the comments below - it's all there in painstaking detail.

                      BTW, sad to see that NT support remains MIA on this one.

                      Comment


                        #12
                        Hello Molecool,

                        We are trying to replicate this scenario. Once we have some more information we will let you know.
                        JCNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_JC View Post
                          Hello Molecool,

                          We are trying to replicate this scenario. Once we have some more information we will let you know.
                          Thanks, I realize that it's difficult without my code but it's > 1000 lines and I wouldn't feel comfortable sharing it. What I'm figuring it out however is that NT is doing what I thought it was doing in historic mode. It does not flip my short trigger flag until AFTER the first yellow candle (at 18:00) has completed:

                          4/22/2013 2:00:00 PM: MINUTE...
                          4/22/2013 2:00:00 PM: Long trigger: False, Short trigger: False
                          4/22/2013 3:00:00 PM: MINUTE...
                          4/22/2013 3:00:00 PM: Long trigger: False, Short trigger: False
                          4/22/2013 4:00:00 PM: MINUTE...
                          4/22/2013 4:00:00 PM: Long trigger: False, Short trigger: False
                          4/22/2013 5:00:00 PM: MINUTE...
                          4/22/2013 4:59:13 PM: Long trigger: True, Short trigger: False
                          ####### RTV-L triggered #######
                          4/22/2013 5:01:04 PM
                          Close currently at: 1.05373
                          Waiting for breach above: 1.05419 to enter long position.
                          ####### RTV-L triggered #######
                          4/22/2013 5:01:04 PM
                          Close currently at: 1.05373
                          Waiting for breach above: 1.05419 to enter long position.
                          ####### RTV-L triggered #######
                          4/22/2013 5:01:04 PM
                          Close currently at: 1.05332
                          Waiting for breach above: 1.05419 to enter long position.
                          ####### RTV-L triggered #######

                          .... etc....

                          ####### RTV-L triggered #######
                          4/22/2013 5:59:53 PM
                          Close currently at: 1.05374
                          Waiting for breach above: 1.05419 to enter long position.
                          ####### RTV-L triggered #######
                          4/22/2013 5:59:54 PM
                          Close currently at: 1.05373
                          Waiting for breach above: 1.05419 to enter long position.

                          Now here comes the roll-over to 18:00:00 which concludes this candle:

                          4/22/2013 6:00:00 PM: MINUTE...
                          4/22/2013 6:00:00 PM: Long trigger: False, Short trigger: True
                          ####### RTV-S triggered #######
                          4/22/2013 6:00:00 PM
                          Close currently at: 1.05375
                          Waiting for breach below: 1.05319 to enter short position.
                          Last edited by molecool; 05-04-2013, 07:44 AM.

                          Comment


                            #14
                            Figured out a bit more.

                            The issue is related to how NT treats historic candles. For example if I'm looking back at the past few 60-min candles and it's 17:05 right now then the 0 series is at 17:05 in live mode (i.e. inside the 18:00 hour candle) but at 17:00 in historic mode. In other words at 17:05 the 18:00 candle DOES NOT EXIST in historic mode. It makes sense if you think about it.

                            Now when taking tick based entries on that 60-min chart this causes problems with how I trace my prior candles - everything gets shifted. I am aware of the problem now and am attempting to find a good fix. Currently I'm using the 'historical' flag to shift my candle pattern parser by one position so that it works both in live and historical mode. Not sure if it'll work and I'm open to any other ideas.

                            Comment


                              #15
                              molecool, to clarify better what you're running into -

                              'For example if I'm looking back at the past few 60-min candles and it's 17:05 right now'

                              So you would be comparing MultiSeries access results here realtime vs historical?

                              The difference would be descriebed in our MultiSeries environment docs under 'how bar data is referenced' - http://www.ninjatrader.com/support/h...nstruments.htm

                              Summing this up - 'The point is if you have a multi-time frame script in real-time and it is processing tick by tick instead of on the close of each bar, understand that the OHLCV data you access in real-time is different than on historical data.'

                              If you're seeing cases where an incorrect event sequence / bar data reference is used in historical mode only, then we would need a simplified and reproducible code example to look into matters.

                              Thanks,
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AaronKoRn, Today, 09:49 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Today, 08:42 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Today, 07:51 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,980 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Today, 06:48 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post rbeckmann05  
                              Working...
                              X