So I am trying to code pivot points. The idea I have is to check for a high/low of let's say the last 5 bars. Then what I would like to do is check to see if the previous 5 bar before that beat said high/low and continue checking that until the answer is false. I figure I would need a for loop but am having no luck. None of my code will compile and I am probably way off. Anyone have any pointers on how to create a for loop that goes forever until the statement reads false?
Nothing changes between ticks. So you only need to do anything on a new tick. Ie price change. At which point you can check your conditions. This is better than Constantly checking in a loop when nothing has changed
I have the for loop in the On tick function which should take care of this right?
The For loop is to change the int value of the high/low value if the previous 5 bars are beat. At least that is what I am trying to achieve. If the statement is false and the previous 5 bars are not beating my high/low then I want my code to use this int. I am just not quite sure how to do this, or if the for loop is even a good idea for this. How would you go about this?
The For loop is to change the int value of the high/low value if the previous 5 bars are beat. At least that is what I am trying to achieve. If the statement is false and the previous 5 bars are not beating my high/low then I want my code to use this int. I am just not quite sure how to do this, or if the for loop is even a good idea for this. How would you go about this?
No! You don't seem to understand, that if you loop inside a tick event, nothing changes. You have to return from the OnTick() function in order for the new values to be generated on the next tick event.
So don't loop. Check it on the next tick event. However, even that is inefficient. Instead wait for a new candle to form before checking again.
Remember that all this is an event driven architecture. So learn to write code that reacts to those events and not by continuously polling data.
No! You don't seem to understand, that if you loop inside a tick event, nothing changes. You have to return from the OnTick() function in order for the new values to be generated on the next tick event.
So don't loop. Check it on the next tick event. However, even that is inefficient. Instead wait for a new candle to form before checking again.
Remember that all this is an event driven architecture. So learn to write code that reacts to those events and not by continuously polling data.
I am confused here. I am actually looking for the value of something that has already happened. Not sure why I would need new tick values to be generated for value that already exist on my chart. I am looking for the previous high/low to determine what to do with it. For example:
If I check the high of the last 5 bars and its bar#3, I would like to check and see if Bars # 4,5,6,7, and 8 highs are less than Bar#3. If its not and lets say Bar #7 is the new High check Bars 8,9,10,11 and 12. If this time Bar 7 is still the Highest I would like a way to get this Bar#7 value so I can plot and calculate the High of Bar #7.
If the for loop is not the proper way to do this can somebody tell me what I should be looking to do. What kind of functions should I be looking for to achieve this?
I am confused here. I am actually looking for the value of something that has already happened. Not sure why I would need new tick values to be generated for value that already exist on my chart. I am looking for the previous high/low to determine what to do with it. For example:
If I check the high of the last 5 bars and its bar#3, I would like to check and see if Bars # 4,5,6,7, and 8 highs are less than Bar#3. If its not and lets say Bar #7 is the new High check Bars 8,9,10,11 and 12. If this time Bar 7 is still the Highest I would like a way to get this Bar#7 value so I can plot and calculate the High of Bar #7.
If the for loop is not the proper way to do this can somebody tell me what I should be looking to do. What kind of functions should I be looking for to achieve this?
There is nothing wrong with using a loop inside the tick event. The problem is that your loop can become never ending, because you don't do proper checks and can easily lock up the handler. Plus it is also inefficient because it repeats searches every time you run the loop.
Try to draw inspiration from how the OnCalculate() event handler works in an Indicator. Try to do things in smaller more logical steps and iteratively as each new candle is formed. Not only will it be more efficient but your code will be more structured and easier to read.
There is nothing wrong with using a loop inside the tick event. The problem is that your loop can become never ending, because you don't do proper checks and can easily lock up the handler. Plus it is also inefficient because it repeats searches every time you run the loop.
Try to draw inspiration from how the OnCalculate() event handler works in an Indicator. Try to do things in smaller more logical steps and iteratively as each new candle is formed. Not only will it be more efficient but your code will be more structured and easier to read.
Thank you Fernando, I will see what kind of inspiration I can get from the OnCalculate () event handler.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So I am trying to code pivot points. The idea I have is to check for a high/low of let's say the last 5 bars. Then what I would like to do is check to see if the previous 5 bar before that beat said high/low and continue checking that until the answer is false. I figure I would need a for loop but am having no luck. None of my code will compile and I am probably way off. Anyone have any pointers on how to create a for loop that goes forever until the statement reads false?
Currently this is what I am working with.
int Low_Candle = iLowest(_Symbol,_Period,MODE_LOW,5,0);
for (int i=Low_Candle;Low[Low_Candle] > Low[Low_Candle + 1]||Low[Low_Candle + 2]||Low[Low_Candle + 3]||Low[Low_Candle + 4]||Low[Low_Candle + 5];i++)
{
double Low_Pivot = Low[i];
}