• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intrabar Trading using Tick timeframes

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

    Intrabar Trading using Tick timeframes

    Josh gave a great example of how to trigger trades intrabar in his reference section post: Strategy: Backtesting NinjaScript Strategies with an intrabar granularity

    If I use his example strategy with the example timeframe of a 5 minute chart, I can see that trades are taken intrabar. However if I use a Tick based timeframe (e.g. 500t) with a smaller Tick based timeframe (e.g. 50t) coded in the example strategy, trades will not trigger intrabar.

    In Josh's example code, I modified one line of code:

    Add(PeriodType.Minute, 1);

    to

    Add(PeriodType.Tick, 50);

    I then setup a backtest in the Strategy Analyzer with a timeframe of 500 ticks and executed a backtest using the Josh's example code. Using Tick charts, no intrabar trades were initiated. Attached is a snapshot of the Strategy Analyzer output chart.

    Thus my question is: Can NinjaTrader Strategy Analyzer trigger trades intrabar as described in the reference code using Tick timeframes instead of minute timeframes? If so, how?

    Thanks,

    David
    Attached Files

    #2
    Should work as expected. Will have Josh take a look into this.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi David,

      Are there any errors in your logs? I was able to get it working on my end. Please try the attached strategy on AAPL from 6/29/08 to 7/2/08. Run on a 500tick primary bar series.

      I suspect a possible reason on your end is that you do not have a 50tick chart? Before backtesting please try this. Open a 500tick chart of AAPL for the dates 6/29 - 7/2. Confirm data population on that. Then open a 50tick chart of AAPL for the same dates. Confirm data population on that chart too. To speed things up you may also try disconnecting from your data provider when you run the backtest.
      Attached Files
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Hi Josh,

        I guess what I expect to see is different than what I'm seeing. With the 5-minute / 1-minute intrabar example I saw trades intrabar (see attachment below for an example). However after examining the 5-minute example output this morning using 20 days of historical data for the Sep 08 ES, I could only find 2 trades out of 116 that were initiatiated intrabar. Every other trade is initiated at the open of the bar after the bar that causes the an MA cross. This is exactly what I'm also seeing with the 500t/50t charts. Upon close examination, I did find 5 trades out of 199 that executed intrabar. Every other trade executed at a bar open. I guess with a 1/10th timeframe like 50t vs. 500t, I expected a much larger percentage of the trades to be executed intrabar on the 500t.

        Also, the example snapshot you provided shows only trades initiated at a bar open.

        I looked through my log files and did not see anything that would indicate that I have problems or errors.

        The example code supports what I am seeing. It has:

        CalculateOnBarClose = true;

        So this tells me the OnBarUpdate() method gets called everytime a 500t or 50t bar closes. Then in the OnBarUpdate() method, the logic that checks the MA cross is inside the condition:

        if (BarsInProgress == 0) // 500t bar close

        This tells me that the MA cross is only checked when the 500t bar closes. So I don't understand how a trade can be initiated intrabar. It seems like the MA cross should be checked with every 50t bar closing. I would think this means the MA cross code should be in the condition:

        if (BarsInProgress == 1) // 50t bar close

        I'm guessing that by checking each MA cross when the 50t bar closes will generate more 500t intrabar trades (maybe too many as the MAs cross and uncross).

        Regards,

        David
        Attached Files

        Comment


          #5
          Hi David,

          I think we are not on the same page. The behavior you are experiencing is the expected behavior.

          In the sample the goal of it was to be able to submit orders immediately once you got a trade signal. Since the trade signal is coming from the 5min bar series at bar close it is natural that we cannot submit a trade anywhere within that bar (The only reason we got that trade signal is because that bar already closed). The logical location to place the next trade would now be in the next 5min bar, but normally this would cause that trade to be timestamped 5mins later at the end of that bar. The sample demonstrates how to get it timestamped earlier.

          If you run a strategy without intrabar granularity you might get a trade signal at 10:00. Your trade will occur at 10:05. With intrabar granularity you get your signal at 10:00. You trade at 10:01. Now the sample may not seem like it makes much difference since both versions will take a trade at the opening price of the 10:05 5min bar which is also the opening price of the 10:01 1min bar, but the functionality is there for you to be able to manage your order and do other more advanced strategic things within the 1min bar series that was not available to you if you only had a 5min bar series.

          Hope that makes sense.

          Notice the attached trade log. All the trades are occuring 1min after the 5min signal bar.
          Last edited by NinjaTrader_JoshP; 07-03-2008, 12:12 PM.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Hi Josh,

            You are right, we were not on the same page. I was confused since I couldn't see a difference between entering on the chart timeframe or the intrabar timeframe because both entry prices would be the same: the open price of the bar after the EnterLong() or EnterShort() method call. I understand now that you were just demonstrating a way to program logic intrabar.

            Thanks,

            David

            Comment


              #7
              Question about the secondary timeframe

              I know this is an older thread but I've been playing with the sample strategy and have some questions about what a backtest of this strategy is really telling me.

              1) Is the primary purpose of submitting the order on the secondary timeframe to produce a more realistic result in a backtest?

              2) Why is it when I change the secondary period from 1 to 4 minutes the results of the backtest get so much better. I can't seem to get my arms around the dynamic that is occurring and changing the backtest. Seems as though the closer the secondary timeframe is to the primary, the (apparently) better the backtest.

              Thanks,
              Eric

              Comment


                #8
                Hi Eric,

                Yes, it's designed to submit an order to the smaller series. This provides increased granularity for the trade sequence. You get to "look within" the bars that generate the signals.

                There's not really an answer to your second question. Results are as they are and there's no reason why you wouldn't see the reverse take place either. If you're looking for the most realistic representation of your strategies performance on live data, consider running it against a market replay connection. You can adjust the playback speed to 500x, making it pretty quick to run it against a single day.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks

                  Thanks for the info. Based on a quick optimization of the smaller timeframe length i was having trouble making sense of the results. Does submitting the order on the smaller timeframe have any effect on the real-time performance of the strategy?

                  Comment


                    #10
                    Yes, it could change performance, but you wouldn't necessarily want to use the same principles in a real time strategy. It's designed to solve a problem in backtesting that isn't really there in real time autotrading. With real time trading, your working orders are filled according to market dynamics and you can get the complete tick-by-tick sequence just by setting CalculateOnBarClose = false.

                    http://www.ninjatrader.com/support/h...ime_vs_bac.htm
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok. It's becoming clear to me now. Thanks for your time.
                      Eric

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by tvaughan4, Today, 01:02 PM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_PaulH  
                      Started by RtelTrade, Today, 01:27 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post RtelTrade  
                      Started by NinjaTrader_Brandon, Today, 01:19 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post NinjaTrader_Brandon  
                      Started by nedstrader, Today, 01:01 PM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_PaulH  
                      Started by RolloHarper, Today, 12:59 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post RolloHarper  
                      Working...
                      X