Download MetaTrader 5

is there a faster way than this to get the bar number of lower low 100k bars back?

To add comments, please log in or register
Brian Kester
823
Brian Kester  

if the next lower bar is 100,000 bars back, is there a faster way than this to get the bar number?

 


//--- starting with last closed bar, find next lower low


int next_lower_low()

 {

  for(int i=2;i<Bars;i++)

   { 


    if(Low[i]<Low[1])  

      return(i);  

   }

  

 return(0);   

 }

 

whroeder1
17084
whroeder1  
What do you think this statement does? It compares i <= Bars, which is always true, then assigns one (true) to i. You're comparing Low[i] < Low[1] with i being one always. Infinite loop.
i=i<=Bars;
 If i equals Bars, the Low[i] is an array exceeded error, and your program dies.
 
i<=Bars;
You said you want "to get the bar number", then why are you returning true?
     return(true); 
Brian Kester
823
Brian Kester  

sorry, thanks for the reply,  that was typo. i fixed it. could you please check again?

whroeder1
17084
whroeder1  
Brian Kester: is there a faster way than this to get the bar number?
if(Low[i]<Low[1]) 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Array accesses are 10x slower than variables. Put the Low[1] in one since it isn't changing.
Keith Watford
Moderator
10533
Keith Watford  

Brian, please do not modify the code in the first post. It makes WHRoeder's reply seem nonsense because we don't realise that you have edited the code.

If you change the code, put it in a new post.

Brian Kester
823
Brian Kester  
Keith Watford:

Brian, please do not modify the code in the first post. It makes WHRoeder's reply seem nonsense because we don't realise that you have edited the code.

If you change the code, put it in a new post.

 

Keith Watford: OK I will remember this from now on

 

whroeder1  Big thanks sir.   

To add comments, please log in or register