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

Not accessing the correct bar

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

    Not accessing the correct bar

    Hello,
    I've got a weird problem (at least I think it's weird).
    In a separate file I have:
    Code:
    //beginBluePeriod
            if(CrossAbove(stoch.K, 50, 1)){
                beginBluePeriod        = CurrentBar;
            }
            //Set IntSeries
            beginUpPeriod.Set(beginBluePeriod);
    In my indicator file I have:
    Code:
    if(stochDirection.DownPeriod[0]){
                //Find highest value of blue period    
                sd_HighestHigh_Bar       = HighestBar(High, (CurrentBar - stochDirection.BeginUpPeriod[0]));    
                sd_HighestHigh_Value    = High[sd_HighestHigh_Bar];     
                }
    Everything works fine except when the "beginBluePeriod" condition is only true for one bar. When this happens
    Code:
    sd_HighestHigh_Bar        = HighestBar(High, (CurrentBar - stochDirection.BeginUpPeriod[0]));
    will return 0 instead of 1. So I get the wrong High.
    When I Print();
    Code:
    Print("BarNumber = " + (CurrentBar - stochDirection.BeginUpPeriod[0]));
    BarNumber returns 1.
    I have verified that stochDirection.BeginUpPeriod[0] is starting on the proper bar.
    Again this ONLY happens when the beginBluePeriod condition is only true for one bar.
    Any help would be much appreciated!

    #2
    Hello CaptainAmericaXX,

    Thanks for your post.

    Keep in mind that

    Code:
     
     (CurrentBar - stochDirection.BeginUpPeriod[0])
    is not the same thing as

    Code:
     
     HighestBar(High, (CurrentBar - stochDirection.BeginUpPeriod[0]));
    If you print HighestBar(High, 1) you will always get 0. You could branch your logic when (CurrentBar - stochDirection.BeginUpPeriod[0]) == 1 as a way to move forward so the logic you are using does not skew your calculation.

    Lets us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you Jim,
      I've had this issue a lot. I needed to read the documentation more clearly. It says,
      period: Number of bars to include in the calculation
      So obviously 1 is going to return the current bar. I was figuring a return value of 0 would return the current bar.
      Just to restate so I'm clear. So when
      Code:
      CurrentBar - stochDirection.BeginUpPeriod[0]
      returns 1 then
      Code:
      HighestBar(High, (CurrentBar - stochDirection.BeginUpPeriod[0]))
      will return the current bar since there is 1 bar to consider in the period.
      Thanks for the clarification! Thank you also for the fix suggestion.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DJ888, Today, 10:57 PM
      0 responses
      5 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      158 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Today, 09:29 PM
      0 responses
      7 views
      0 likes
      Last Post Belfortbucks  
      Started by zstheorist, Today, 07:52 PM
      0 responses
      7 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      151 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Working...
      X