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 NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 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