Is it possible to iterate a for loop in both directions from a certain point in it until certain criteria is met?
For example, lets say that I have a condition inside a for loop where a Moving Average meets criteria at bar 16. At this moment, I assign the value of the Moving Average to a variable (i_val[i] = MA_Value[i]). After this, I need to go back and forth from this point inside the loop subtracting i_val[i] - the Moving Average value of every bar until criteria is met.
Here is what I have so far:
for ( i = 0; i < limit; i++ )
{
MA_Value[i] = iMA( NULL, 0, MA_1_Period, MA_1_Shift, MA_1_Method, MA_1_Price, i );
}
for ( i = 2; i < limit - 1; i++ )
{
if ( MA_Condition )
{
i_val[i] = MA_Value[i];
i_ma = i;
count++;
}
if ( count > loop_limit - 1 ) break;
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello forum, good day.
Is it possible to iterate a for loop in both directions from a certain point in it until certain criteria is met?
For example, lets say that I have a condition inside a for loop where a Moving Average meets criteria at bar 16. At this moment, I assign the value of the Moving Average to a variable (i_val[i] = MA_Value[i]). After this, I need to go back and forth from this point inside the loop subtracting i_val[i] - the Moving Average value of every bar until criteria is met.
Here is what I have so far:
Your help will be much appreciated.
Best regards and thank you in advance,
Gerardo