Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Timeframe Indicators/Strategies

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

    Multi Timeframe Indicators/Strategies

    Greetings,

    I've only started using NT in the last 3 days, so apologies if this is an obvious question. I'm trying to develop a strategy that will look at the values of multiple timeframes of pre-defined indicators (like macd). I've created (via copy) new macd indicators for each of the desired timeframes. In each of these, I've added a new Bar via the Add method in the initialize method; i.e.
    Add(PeriodType.Minute, 5). Then, in the OnBarUpdate method, I've added an if statement => if (BarsInProgress == 1) and left the rest of the code alone. I though this would do the trick, but the plots are very sporadic. Appreciate any and all assistance!
    Ultimately, I'd like to be able to compare values across each of these as signals.
    Thank you,
    hbmiles2000



    #2
    Hello,

    Thanks for the post and welcome to the NinjaTrader support forum.

    There are some key elements to understand about multi time frame strategies or indicators.

    That is that OnBarUpdate() runs on every series.

    For example.

    OnBarUpdate(5 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(5 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)
    OnBarUpdate(1 min bar)

    Therefor you need to filter which ones you want your code to run on.

    If you want your code to run on the 5 min bar but pull values from the 1 min bar or vice versa.

    You would put all your code if(BarsInProgress == 0)
    {
    //Then reference the value from the secondary series. You do this with Bars Array
    SMA(BarsArray[1], Period);
    }
    BrettNinjaTrader Product Management

    Comment


      #3
      Thanks Brett - can I do this on individual indicators instead of strategies? My current OnBarUpate is below; but when added to a chart what should be a continuous lines only appear every now and again :
      if (BarsInProgress == 1)
      {
      if (CurrentBar == 0)
      {
      fastEma.Set(Input[
      0]);
      slowEma.Set(Input[
      0]);
      Value.Set(
      0);
      Avg.Set(
      0);
      Diff.Set(
      0);
      }
      else
      {
      fastEma.Set((
      2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
      slowEma.Set((
      2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
      double macd = fastEma[0] - slowEma[0];
      double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];

      Value.Set(macd);
      Avg.Set(macdAvg);
      Diff.Set(macd - macdAvg);
      Value.Set(macd - macdAvg);

      Comment


        #4
        Hello,

        These values will only set to be displayed when BarsInProgress 1 runs. Is this what you want?

        What is the time frame of the primary series. What is the time frame of the secondary?

        I look forward to assisting you further.
        BrettNinjaTrader Product Management

        Comment


          #5
          Brett-I'm trying to use a 1-min chart (primary) with 5, 15, 60 as the second, third, and 4th timeframes; so a 1-min chart with 4 indicators (1-min macd, 5-min macd, 15-min macd, and 60-min macd).

          Comment


            #6
            So, if you set a data series to plot on a 1 min chart. But your only setting it inside of BarsInProgress == 1 which is the 5 minute chart. This means that the value for Value will be set once every 5 minutes.

            This is what you would see with this code.

            However, did you rename the variables? As if you then run in BarsInProgress == 2 and re use Value again this will set it again and give you some strange values. You would need a plot for each time frame if you did this all in one indicator.

            Let me know if I can be of further assistance.
            BrettNinjaTrader Product Management

            Comment


              #7
              Thanks for all the help - I'll give that a shot.

              Comment


                #8
                Brett - apologies for what I'm sure are rudimentary questions, but where & how would I create variables for 5-min, 10-min, etc macd? Would it be macd(barsarray[1]...), etc?

                Comment


                  #9
                  Hello,

                  You would need to create a new MACD plot for each time frame.

                  To do this please see this sample:



                  This is how you add new Plots, easiest way however is to create a new strategy and then in the new strategy wizard plug in the plots you want to create and then copy and paste the code it generated into your already created script.

                  Theres the sction in Initialize(), and also a section in the properties for each plot.

                  Let me know if I can be of further assistance.
                  BrettNinjaTrader Product Management

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  589 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  342 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  103 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  555 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  552 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X