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 ZenCortexCLICK, Today, 04:58 AM
      0 responses
      2 views
      0 likes
      Last Post ZenCortexCLICK  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      172 responses
      2,280 views
      0 likes
      Last Post sidlercom80  
      Started by Irukandji, Yesterday, 02:53 AM
      2 responses
      17 views
      0 likes
      Last Post Irukandji  
      Started by adeelshahzad, Today, 03:54 AM
      0 responses
      4 views
      0 likes
      Last Post adeelshahzad  
      Started by Barry Milan, Yesterday, 10:35 PM
      3 responses
      13 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X