Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Minimum bars/multi timeframe & different results

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

    Minimum bars/multi timeframe & different results

    Hi. I have three questions:

    1) I have a strategy that calls one indicator that has two different time frames. Within the indicator, I "return" if "CurrentBars[0] < BarsRequired || Current[1] < BarsRequired." When using the backtest on strategy analyzer there is a field called "minimum bars required." Does this number only ensure the minimum bars required for the default/main timeframe? So for instance, if I am using 1-second intervals but my second timeframe is 1-hour, but I am calling the function to compute the 50-period simple moving average for the 1-hour bars, do I need to enter 50 for the minimum bars required or 50 * 60 * 60 = 180000 (so that 180,000 seconds would be 50 hours)?

    I know this has been asked before (for instance, see http://www.ninjatrader.com/support/f...ad.php?t=62161, but the answer was not clear to me).

    2) If I pick the dates to run the backtest on Strategy Analyzer in the time frame subsection, will the only bars that load come from within this time frame? For instance, if I am testing from 1/1/2014 to 1/10/2014 but my strategy needs to compute the 50 1-hour-period simple moving average, will any trades/computation done on 1/1/2014 not be accurate because it will not load 50 hours prior to 1/1/2014? So if I wanted to do an accurate test on 1/1/2014, would I have to push back the start date to sometime in December to ensure that it's calculating the 50 1-hour-period correctly starting for 1/1/2014?

    3) How come when I change the minimum bars required this DRASTICALLY changes the results? I understand if I am not loading enough bars, but I thought that adding the "if(CurrentBars[0]< BarsRequired..." statement in my indicator would catch this, so it wouldn't matter. Even from 50 to 51 bars required the results from the back test are extremely different. Moreover, after some point (like 60 bars), I end up getting no trades, whereas 59 bars will show me trades. I use kinetick for my data feed. Also, when I changed the 1-hour data to 1-day data, all of a sudden the only way backtesting would work is if I put a minimum of 1 bar required. I don't believe I am going outside of the 120 days of backtesting data with Kinetick.

    By the way, I have tested my strategy in market analyzer, and it seems to work. When the backtesting results give me trades (when I use 59 instead of 60 minimum required bars), I don't see any false-positives, so the code seems to be working.

    #2
    Originally posted by TheDarg View Post
    Hi. I have three questions:

    1) I have a strategy that calls one indicator that has two different time frames. Within the indicator, I "return" if "CurrentBars[0] < BarsRequired || Current[1] < BarsRequired." When using the backtest on strategy analyzer there is a field called "minimum bars required." Does this number only ensure the minimum bars required for the default/main timeframe? So for instance, if I am using 1-second intervals but my second timeframe is 1-hour, but I am calling the function to compute the 50-period simple moving average for the 1-hour bars, do I need to enter 50 for the minimum bars required or 50 * 60 * 60 = 180000 (so that 180,000 seconds would be 50 hours)?

    I know this has been asked before (for instance, see http://www.ninjatrader.com/support/f...ad.php?t=62161, but the answer was not clear to me).
    The bars requried on the strategy analyzer only directly impacts the strategy. Indicators are not affected in this way. However if you reference an indicator from the strategy it will not begin processing until that many bars have passed since the strategy will not start until that point.

    There are two versions of bars required
    In regards to strategies: http://www.ninjatrader.com/support/h...srequired2.htm
    In regards to indicators (purely for display purposes): http://www.ninjatrader.com/support/h...rsrequired.htm


    2) If I pick the dates to run the backtest on Strategy Analyzer in the time frame subsection, will the only bars that load come from within this time frame? For instance, if I am testing from 1/1/2014 to 1/10/2014 but my strategy needs to compute the 50 1-hour-period simple moving average, will any trades/computation done on 1/1/2014 not be accurate because it will not load 50 hours prior to 1/1/2014? So if I wanted to do an accurate test on 1/1/2014, would I have to push back the start date to sometime in December to ensure that it's calculating the 50 1-hour-period correctly starting for 1/1/2014?
    Yes this is correct, you would have to adjust your start date further back in order to get the trades to start on the desired date, otherwise there would not be enough data loaded and the trades will begin later.


    3) How come when I change the minimum bars required this DRASTICALLY changes the results? I understand if I am not loading enough bars, but I thought that adding the "if(CurrentBars[0]< BarsRequired..." statement in my indicator would catch this, so it wouldn't matter. Even from 50 to 51 bars required the results from the back test are extremely different. Moreover, after some point (like 60 bars), I end up getting no trades, whereas 59 bars will show me trades. I use kinetick for my data feed. Also, when I changed the 1-hour data to 1-day data, all of a sudden the only way backtesting would work is if I put a minimum of 1 bar required. I don't believe I am going outside of the 120 days of backtesting data with Kinetick.

    By the way, I have tested my strategy in market analyzer, and it seems to work. When the backtesting results give me trades (when I use 59 instead of 60 minimum required bars), I don't see any false-positives, so the code seems to be working.
    Much of this can be attributed to what you noticed in question two. The complexity of tracking and managing backtest results gets more difficult when you have a multi series indicator. You will want to ensure the strategy has a way of knowing if the indicator it calls has enough data loaded.

    Ultimately it comes down to preference on how to manage this but it might be easier to make the strategy multi series while calling the indicators in a single series manor.

    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thank you. However, I am still a little confused about the answer to my first question. So does the minimum bars required that comes up in the strategy analyzer refer to the primary time frame only or if i have a "CurrentBars[0] < BarsRequired || CurrentBars[1]< BarsRequired" condiation in an indicator that the strategy calls ensure that both time frames will have the minimum bars required I specified in the strategy analyzer?

      More specifically, if I assume that

      1) I did that I entered the start date and end date correctly to ensure there is potentially enough data accessible for the dates want to test on (by the way, I hope this date issue gets fixed in Ninjatrader 8 because it is quite inconvenient and makes things more complicated than they have to be especially when you have to factor in weekends/days the stock market isn't open)
      2) the primary data series are 1-second intervals
      3) the strategy calls an indicator that has an additional time frame of 1-hour and I am calculating the 50 period 1-hour simple moving average in this indicator

      do I enter 50 in the minimum bars required in the strategy analyzer or 50*60*60=180000 (so 180000 seconds = 50 hours) so that I can correctly calculate the 50 period 1-hour simple moving average?
      Last edited by TheDarg; 01-16-2014, 10:33 AM.

      Comment


        #4
        Originally posted by TheDarg View Post
        Thank you. However, I am still a little confused about the answer to my first question. So does the minimum bars required that comes up in the strategy analyzer refer to the primary time frame only or if i have a "CurrentBars[0] < BarsRequired || CurrentBars[1]< BarsRequired" condiation in an indicator that the strategy calls ensure that both time frames will have the minimum bars required I specified in the strategy analyzer?
        It determines how long the Strategy will wait before OnBarUpdate() is called. BarsRequired in the indicator will be handled separately.

        More specifically, if I assume that

        1) I did that I entered the start date and end date correctly to ensure there is potentially enough data accessible for the dates want to test on (by the way, I hope this date issue gets fixed in Ninjatrader 8 because it is quite inconvenient and makes things more complicated than they have to be especially when you have to factor in weekends/days the stock market isn't open)
        Thank you for the note, I have submitted this as a feature request
        2) the primary data series are 1-second intervals
        3) the strategy calls an indicator that has an additional time frame of 1-hour and I am calculating the 50 period 1-hour simple moving average in this indicator

        do I enter 50 in the minimum bars required in the strategy analyzer or 50*60*60=180000 (so 180000 seconds = 50 hours) so that I can correctly calculate the 50 period 1-hour simple moving average?
        Yes it sounds like you understand this correctly. You would need about 50 hours to be loaded before processing your logic in order to ensure trades were accurate in this situation.

        Let me know if I can further assist.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Okay. Thanks. But I feel like I still don't understand if in the strategy analyzer I need to enter 50 minimum bars or 180,000 minimum bars in this case because I don't know if it refers to JUST the primary data series?

          Comment


            #6
            BarsRequired will refer to each series separately within the Strategy.

            If it's calling a multi series indicator but the Strategy is a single series you would want to use

            BarsRequired 180,000

            If the Strategy is multi series with primary second and secondary hourly you could use
            BarsRequired 50 and place an || check at the start of your OnBarUpdate() like this

            if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired) return;


            Let me know if I can further assist.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Okay. Thank you. I will try to make my strategy a multi time frame because when I try inputting 180000 it comes up with no trades.

              Comment


                #8
                It could also be that not enough historical data is available. Who is your data provider and which instrument are you trying to test?
                LanceNinjaTrader Customer Service

                Comment


                  #9
                  Kinetick is my data provider. And I am testing it on 100 S&P stocks such as AAPL, AMZN, etc.

                  Comment


                    #10
                    One thing to keep in mind with Kinetick is that during regular trading hours 9:30am to 4:30pm EST the historical tick data (used to make second charts) is restricted to about 7 days.

                    If you try to run the script after 4:30pm you will be able to obtain much more historical tick data.
                    LanceNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by TraderBCL, Today, 04:38 AM
                    2 responses
                    7 views
                    0 likes
                    Last Post TraderBCL  
                    Started by martin70, 03-24-2023, 04:58 AM
                    14 responses
                    105 views
                    0 likes
                    Last Post martin70  
                    Started by Radano, 06-10-2021, 01:40 AM
                    19 responses
                    606 views
                    0 likes
                    Last Post Radano
                    by Radano
                     
                    Started by KenneGaray, Today, 03:48 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post KenneGaray  
                    Started by thanajo, 05-04-2021, 02:11 AM
                    4 responses
                    471 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Working...
                    X