• 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

  • Domek_69
    started a topic Checking indicator result in X number of bars back

    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

  • NinjaTrader_JoshG
    replied
    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
            }
        }    
    }

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by Vincere, Yesterday, 11:20 PM
0 responses
4 views
0 likes
Last Post Vincere
by Vincere
 
Started by lMagi, 05-18-2019, 09:34 AM
1 response
4 views
0 likes
Last Post NinjaTrader_ChrisSch  
Started by uday12, Yesterday, 10:26 PM
0 responses
3 views
0 likes
Last Post uday12
by uday12
 
Started by uday12, Yesterday, 10:07 PM
0 responses
0 views
0 likes
Last Post uday12
by uday12
 
Started by Nabil, Yesterday, 07:46 PM
1 response
5 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X