• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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
            }
        }    
    }
    JoshNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Dan_D_Trader, Today, 03:49 PM
    0 responses
    4 views
    0 likes
    Last Post Dan_D_Trader  
    Started by JohnAymin, Today, 02:38 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Tyler  
    Started by Rmos22, Today, 02:20 PM
    2 responses
    23 views
    0 likes
    Last Post Rmos22
    by Rmos22
     
    Started by sawtooth500, Today, 12:59 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Spencer  
    Started by Steve L, Yesterday, 09:36 PM
    1 response
    23 views
    0 likes
    Last Post NinjaTrader_Kate  
    Working...
    X