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 judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      53 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      32 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      5 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      19 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      6 views
      0 likes
      Last Post cre8able  
      Working...
      X