• 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 Atilla, Today, 04:05 PM
    0 responses
    8 views
    0 likes
    Last Post Atilla
    by Atilla
     
    Started by Displacer, Today, 02:57 PM
    2 responses
    13 views
    0 likes
    Last Post Displacer  
    Started by SAILIKITY, 05-22-2019, 05:41 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by rmillar, 01-09-2019, 06:02 PM
    6 responses
    71 views
    1 like
    Last Post eDanny
    by eDanny
     
    Started by mlarocco, Today, 11:39 AM
    4 responses
    23 views
    0 likes
    Last Post mlarocco  
    Working...
    X