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

Checking indicator result in X number of bars back

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

    Checking indicator result in X number of bars back

    Hi,
    I would like to check whether an indicator met certain criteria any given day within the past X bars.

    For example: If Highest High for 500 days was met any day in the past 10 days, than do something...

    I know I can use MAX() for HighestHigh. But I am not sure how to handle those 10 days. Is there any simple way? Should I use some kind of LOOP for it?

    Some kind of:
    For n from 1 to 10
    if Close [1 to n] > MAX(Close, 500) then
    ...

    Thank you

    Petr

    #2
    Hello Domek_69,
    Thanks for your post.

    You could use a loop. In some cases that is the only way to go about something like this. In the case of your example however, I might start with something like the following to check if a bar in the last 10 is the highest in the past 500. You could expand on this in multiple different ways.

    Code:
    private double last500bars;
    protected override void OnBarUpdate()
    {
        if(CurrentBar<500) return;
    
        last500bars = MAX(Close,500)[0];
    
        for( int i=0; i<10 ; i++ )
        {
            if( High[i] >= last500bars )
            {
                //Do something
            }
        }    
    }
    Josh G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    6 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    9 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    20 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X