Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

For() loops in IsFirstTickOfBar

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

    For() loops in IsFirstTickOfBar

    It seems to me that the for() loops that are part of statement blocks within IsFirstTickOfBar conditions behave as if IsFirstTickOfBar was not there to begin with, but for IsFirstTickOfBar to be observed, IsFirstTickOfBar must be included in for() loop test expression, something like that:

    Code:
    IsFirstTickOfBar
    {
         if(!LSwDMIbool)
                        {                          
                            for (int  LastBar = CurrentBar - 1; IsFirstTickOfBar && LastBar <= lastLSwDMIbar + 5; LastBar++)
                            {
                                LastLSwDMIpriceBar[k - 1] = CurrentBar - LowestBar(Lows[2], 5);
                                if (PrintDmiSwing)
                                    Print ("LSwDMIbool = " + LSwDMIbool + " | IsFirstTickOfBar = " + IsFirstTickOfBar + " | LastLSwDMIpriceBar[k-1] = " + LastLSwDMIpriceBar[k-1] +
                                    " | Last Bar = " + LastBar + " | lastLSwDMIbar = " + lastLSwDMIbar + " | k = " + k);
                            }                        
                        }
    }
    If the for() loop test expression wouldn't include IsFirstTickOfBar, the Prints of LastBar would be coming all in the same time pass, rather than say LastBar = 890, then LastBar = 891 at the start of the next bar and so on.
    Can someone please explain why is that?

    #2
    Hello itrader46,

    Thanks for your post.

    IsFirstTickOf bar will be true when a tick that is processing in OnBarUpdate is the first tick of a new bar, or if the script is set to Calculate.OnBarClose. It is dependent on the processing bar data only, and will not be true when looping over past bars. (Past bars also only include the OHLC oh that bar. Calculate.OnEachTick and Calculate.OnPriceChange processes OnBarUpdate for the developing bar to update it with each tick or price change. Previous ticks would not be referenced with historical data.) In your code, you are looping through bars when OnBarUpdate is processing a bar whose tick is IsFirstTickOfBar.

    Please let me know if I can be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X