Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multitime frequency system

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

    Multitime frequency system

    Hi

    I developed a system on 1min bars, I want to put a condition on the 5min bars.
    I did so:

    protected override void Initialize()
    {
    Add(PeriodType.Minute, 5);

    Add(EMA(20));

    CalculateOnBarClose = true;
    }

    // Condition set 1

    if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])


    {
    ...
    }


    Then I run it on 1m data. Is it correct? I'm asking because, when I watch the 1m chart of the back test, I see plotted the two EMAs (but they're supposed to be calculated on 5m!).
    Does BarsArray[1] automatically refers to the 5m data only, or I should use another BarsArray[2] for the 1m data (which I don't think makes sense anyway).

    Thank you a lot

    #2
    BarsArray[0] = 1 minute
    BarsArray[1] = 5 minute

    In C#, indexes are zero based.

    You also have to fitler OnBarUpdate() events by BarsInProgress

    if (BarsInProgress == 0)
    // Process my 1 minute bars
    else if (BarsInProgress == 1)
    // Process my 5 minute bars
    RayNinjaTrader Customer Service

    Comment


      #3
      Thank you, Ray.
      I want to use just the 1min bars (using the 5min just to calculate the averages). So I added:
      if (BarsInProgress != 0)
      return;
      as in the SampleMultiframe.

      Now it looks like:

      protected override void Initialize()
      {
      Add(PeriodType.Minute, 5);

      Add(EMA(20));

      CalculateOnBarClose = true;
      }

      if (BarsInProgress != 0)
      return;

      // Condition set 1

      if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])


      {
      ...
      }


      Is that correct now?

      Thank you

      Comment


        #4
        I had some problems with this last year when I was trying to do this.

        If memory serves me, there's a basic problem with checking bars on a DataSeries from another timeframe.

        The problem stems from the fact that there will be a different number of bars for the 1-Min and 5-Min timeframes, and I don't think the indicators (such as EMA that you're trying to use) are written to take this into account.

        Therefore, I don't think the calculations will work correctly when you're running in the 1-Min (primary) timeframe and you try to invoke EMA for the 5-Min timeframe DataSeries.

        The solution I used at the time was to re-code the logic of the indicator within my strategy being sure to take this into account.

        Comment


          #5
          Originally posted by stefy View Post
          Thank you, Ray.
          I want to use just the 1min bars (using the 5min just to calculate the averages). So I added:
          if (BarsInProgress != 0)
          return;
          as in the SampleMultiframe.

          Now it looks like:

          protected override void Initialize()
          {
          Add(PeriodType.Minute, 5);

          Add(EMA(20));

          CalculateOnBarClose = true;
          }

          if (BarsInProgress != 0)
          return;

          // Condition set 1

          if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])


          {
          ...
          }


          Is that correct now?

          Thank you
          Incorrect.

          if (BarsInProgress == 1) return;

          is what you want.

          Now this method is called only on the 1 minute chart.

          Then your code

          if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])

          is saying

          if (2 period ema on 5 minute is greater than 20 period ema on 5 minute) do something..
          RayNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X