Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Higher Time Frame Indicator in the Strategy

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

    Higher Time Frame Indicator in the Strategy

    Hi,

    I'm trying out a new strategy that checks on MACD average differences between 2 bars from a higher time frame chart before entering a trade. However, the values that the MACD avg produces are the same as the ones from the lower time frame.

    For example, my strategy enters a trade on the 2-min /CL chart based on 5-min /CL chart MACD avg differences between bar[0] and bar[14]. When I print the values, for the MACD Avg values from 2-min and 5-min, they are exactly the same.

    What might I be doing wrong?

    Thanks in advance for your help.

    Here's a snippet of the code that relates to the higher time frame check:

    // HTF Indicator
    private MACD MACD2;
    ......

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 5);
    MACD2 = MACD(Closes[1], 21, 29, 9);
    ​
    // Condition check
    if (MACD2.Avg[0] > MACD2.Avg[14])
    ......

    #2
    Hello givemefood,

    The indicators need to be moved to State.DataLoaded where that secondary series would be available.

    I would also suggest to use the strategy builder to add the secondary series and then create conditions using the indicator/series. That will let you click View Code to see the correct placement for making/using the indicators.

    Comment


      #3
      Can you please clarify which chart/timeframe you mean by secondary series? I've built the code using Strategy Builder and inserted my own code into it.
      In my code, this is how State.Dataloaded is currently used. It's used to set the stop loss order.


      else if (State == State.DataLoaded)
      {
      SetStopLoss(CalculationMode.Ticks, Stop);
      ​}

      Originally posted by NinjaTrader_Jesse View Post
      Hello givemefood,

      The indicators need to be moved to State.DataLoaded where that secondary series would be available.

      I would also suggest to use the strategy builder to add the secondary series and then create conditions using the indicator/series. That will let you click View Code to see the correct placement for making/using the indicators.

      Comment


        #4
        Hello givemefood,

        The secondary series would mean the extra data series that you added and passed to the indicator. The code you have shown for the indicator is in the wrong state, it needs to be in DataLoaded. You also didn't include any code to compare the two timeframes, you only used the 1 macd indicator which is using Closes[1] or the second series.

        You can use the strategy builder to generate the correct code for using indicators with another data series. I would suggest to re generate the strategy using the strategy builder and do all of the steps using the builder meaning add the timeframes you wanted to use and form conditions with the indicators you plan to use. After doing that if you wanted to unlock it to make changes you can but that process will put the indicator code in the correct state which is State.DataLoaded.





        Comment


          #5
          When i generate the code using the strategy builder, it adds the secondary data series here. It does not add it under State.DataLoaded(). Is this a bug? Should I manually move that piece of code to the suggested DataLoaded?

          }
          else if (State == State.Configure)
          {
          AddDataSeries(Data.BarsPeriodType.Range, 72);
          }
          else if (State == State.DataLoaded)
          {​

          Comment


            #6
            Hello givemefood,

            No that would be correct, you can read about using AddDataSeries here: https://ninjatrader.com/support/help...=AddDataSeries
            There are samples shown near the bottom of the page.

            Comment


              #7
              Thank you.
              To confirm this is how the code should look like?

              // HTF Indicator
              private MACD MACD2;
              ......

              else if (State == State.Configure)
              {
              AddDataSeries(Data.BarsPeriodType.Minute, 5);
              }
              else if (State == State.DataLoaded)
              {​
              MACD2 = MACD(Closes[1], 21, 29, 9);

              // Condition check
              if (MACD2.Avg[0] > MACD2.Avg[14])
              .

              Comment


                #8
                Hello givemefood,

                Correct, if you use the strategy builder to create these conditions it would generate the code that looks like that.

                Comment


                  #9
                  Thanks, Jesse. That fixed the problem!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  62 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  134 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  75 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  50 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X