• 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

  • 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:


  • 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

Latest Posts

Collapse

Topics Statistics Last Post
Started by ballboy11, Today, 04:29 PM
0 responses
6 views
0 likes
Last Post ballboy11  
Started by zacharydw00, Today, 02:29 PM
2 responses
23 views
0 likes
Last Post zacharydw00  
Started by timcjpfx, Today, 06:22 AM
4 responses
27 views
0 likes
Last Post timcjpfx  
Started by welson, Today, 08:26 AM
2 responses
18 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by brucerobinson, Today, 08:27 AM
3 responses
17 views
0 likes
Last Post NinjaTrader_Kate  
Working...
X