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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ursavent, Today, 12:54 PM
        0 responses
        1 view
        0 likes
        Last Post ursavent  
        Started by Mizzouman1, Today, 07:35 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by RubenCazorla, Today, 09:07 AM
        2 responses
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by i019945nj, 12-14-2023, 06:41 AM
        7 responses
        82 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by timmbbo, 07-05-2023, 10:21 PM
        4 responses
        158 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X