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

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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mmenigma, Today, 02:22 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frankthearm, Today, 09:08 AM
    9 responses
    35 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by NRITV, Today, 01:15 PM
    2 responses
    9 views
    0 likes
    Last Post NRITV
    by NRITV
     
    Started by maybeimnotrader, Yesterday, 05:46 PM
    5 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by quantismo, Yesterday, 05:13 PM
    2 responses
    21 views
    0 likes
    Last Post quantismo  
    Working...
    X