Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Process multi-time within one if condition

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

    Process multi-time within one if condition

    Hi,

    I'm trying to compare values from different time frame under one if condition. How do I set BarsInProgress properly, in order for this to work?

    Code:
    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 5);
                    AddDataSeries(Data.BarsPeriodType.Minute, 30);
                }
                else if (State == State.DataLoaded)
                {
                    EMA30min21 = EMA(Closes[2], 21);
                    EMA30min60 = EMA(Closes[2], 60);
                    EMA5min60 = EMA(Closes[1], 60);
                    EMA5min100 = EMA(Closes[1], 100);
                }
    
    protected override void OnBarUpdate()
            {
                // how to set BarsInProgress for below if condition to work?
    [COLOR=#FF0000] if (BarsInProgress != 0)
                    return;[/COLOR]
    
                if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < (BarsRequiredToTrade / 5f) || CurrentBars[2] < (BarsRequiredToTrade / 30f))
                    return;
    
    [COLOR=#FF0000]if ((EMA5min60[0] > EMA30min21[0]
                    && (EMA5min100[0] > EMA30min60[0])[/COLOR]
                ........
            }
    Thank you for your help!

    #2
    Hello HiddenPhilosopher,

    Thank you for your post.

    This looks exactly right, you're looking at what the values calculated for those other time frames are at the time you run OnBarUpdate(), but you're only wanting to look at them when the first time frame updates. So your BIP check there looks good.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello HiddenPhilosopher,

      Thank you for your post.

      This looks exactly right, you're looking at what the values calculated for those other time frames are at the time you run OnBarUpdate(), but you're only wanting to look at them when the first time frame updates. So your BIP check there looks good.

      Please let us know if we may be of further assistance to you.
      When live tick comes in, bars on different timeframes are updating simultanenously right? When it processes my additional 5min and 30min data series, BarsInProgress are not 0. Then won't "if BarsInProgress != 0; return;" cause additional data series not being processed?

      Comment


        #4
        Hello HiddenPhilosopher,

        Thank you for your note.

        No, the information in your series will still be calculated even if the additional bars don't do anything in OnBarUpdate, because that information is still available and you've told it what data series to use to calculate the EMAs. Basically, you're just telling it to ignore the logic after the BIP check if you're not on the correct bar series.

        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        41 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X