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 date range for multi-time frame strategy

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

    Historical date range for multi-time frame strategy

    Hi there,

    This feels trivial but it's taken some time so apologies in advance for the post. I am running a strategy on a 5 second chart that has additional bars for tick & daily data. The Daily data is so I can create a simple moving average over the last say 20 days - with there being logic that says "don't go long if the current close price is below the 20 day SMA":

    Code:
    else if (State == State.Configure) //Add additional data series via AddDataSeries(). •Declare custom resources. •Override and configure values set by the UI
    {
    AddDataSeries(Data.BarsPeriodType.Tick, period:1); //needed in order for the order flow vwap to work
    AddDataSeries(Data.BarsPeriodType.Day, period:1); //needed to create a Daily Close Price SMA
    When I run the strategy over the last two days, it fails because two days isn't enough to form a 20 day SMA (obviously) so instead I select a longer, 22 day timeframe on my chart and this now works, however the system processed 20 days of tick data that was unnecessary in order to get to the last 2 days that actually mattered. Question: is there a better way I should be doing this? I'd prefer to avoid hardcoding specific dates and imagine there may be a rule akin to the following in OnBarUpdate:

    Code:
    if (DayOfTest <= 20DayVariable) return;
    {
    //my code here
    }
    Before chasing this down I thought it may be better to ask for directional guidance/best practice on how to do this please

    Thank you

    ChainsawDR

    #2
    Apologies I missed the most important piece. When I select the 22 period range of the test on my chart, the system is contacting my data provider (iqfeed) and pulling 22 days worth of granular tick data, which is time consuming and not required. Is there a smart way of doing this that pulls 22 days worth of daily data but only 2 days of tick data?

    Thanks again

    ChainsawDR

    Comment


      #3
      Hello ChainsawDR,

      Thanks for your post.

      We will leave this thread open for any forum member to contribute their thoughts and workarounds for this.

      Using daily data and tick data does offer the difficulty of providing sufficient historical data of each to support the needed daily-based indicators.

      Daily bar based indicators do not change their values during the intraday period. So for day x the value of the indicator will be y. With that in mind, an option would be to run the daily indicator on a separate chart and have the indicator write its daily value to a file. You can then code your intraday indicator open that file and read the value for the day under test. This would allow you to run a proper number of days for a moving average to stabilize and reduce your tick data needs.

      Here are links to examples of writing and reading data from a file using the C# streamwriter/reader:


      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by ChainsawDR View Post
        Apologies I missed the most important piece. When I select the 22 period range of the test on my chart, the system is contacting my data provider (iqfeed) and pulling 22 days worth of granular tick data, which is time consuming and not required. Is there a smart way of doing this that pulls 22 days worth of daily data but only 2 days of tick data?
        Yes.

        Idea #1:
        Load 2 days (not 22) into the chart/backtester.
        Remove the secondary data series for Day data.
        Use BarsRequest to get N days of Day data (where 'N' = 22).
        Using this Day data, build a List<double> of Close prices.
        Using this List<double>, build your own SMA calculation.

        Idea #2:
        Load 2 days (not 22) into the chart/backtester.
        Remove the secondary data series for Day data.
        On a separate daily chart, calculate the daily SMA.
        Enter daily SMA value into your strategy as a parameter.

        Idea #3:
        Load 2 days (not 22) into the chart/backtester.
        Remove the secondary data series for Day data.
        Create a special indicator that writes the daily SMA value to a file.
        On a separate daily chart, run this special indicator.
        Have your strategy read this file to get the daily SMA value.

        But first, try this idea #4:
        (for backtest only)
        Make no code changes.
        Manually download all historical data yourself, ahead of time.
        Why? So you can run backtests with your IQfeed disconnected.
        Continue loading 22 days into the backtester.
        Is this is fast enough?
        If yes, you're done.
        If not, start with Idea #2 above, which is easiest to try.
        Compare speeds between Idea #4 and Idea #2.
        Automate Idea #2 (if truly faster) by using Idea #3.

        Idea #1 is your ultimate hands-off automation solution.

        Comment


          #5
          Thank you both, this is really helpful. I will explore Idea #4 first, then if no joy will take a closer look into Idea #1 (feels more self contained and workable across a basket of instruments). Thanks again, really appreciate the inputs!

          ChainsawDR

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by futtrader, Today, 01:16 PM
          0 responses
          4 views
          0 likes
          Last Post futtrader  
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,789 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          838 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,294 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          13 views
          0 likes
          Last Post Touch-Ups  
          Working...
          X