I'm writing an indicator that for example asks to check for several conditions, then using a for-loop looks back (10 bars) to see if an event occurred after these events x & y have been verified. It in EA but I'm not sure why. Could anyone explain what it's actually doing? or is it the correct logic?
if(fastEMA < slowEMA)
{
if( macd_signal_1 > macd_main_1 && macd_signal_0 < macd_main_0)
//then check to see if the ADX+ crossed over ADX- in the last (10) bars
{
for(int i=10; i>=0;i--)
double 1adx+ = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_PLUSDI,i)
double 1adx- = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_MINUS,i)
double 2adx+ = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_PLUSDI,i+1)
double 2adx- = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_MINUS,i+1)
//insert expression for crossover
if((1adx+) > (1iadx-) && (2adx+) < (2adx-))
//insert execute order
statement
}
}
I'd like to note again that the code works and im under the impression that its checking for the adx to have occurred within the last 10 bars. If more clarity is necessary don't hesitate to ask. Thank you!
-003
Hi and prosperous trading .. :)
But :(
- you can't start names of variables with a number!
- Use the code button Alt+S (or the icon </> from the top) to post code
- To use indentions or the "Styler" (Ctrl+,) in the Editor.
- The Editor has a debugger where you can control the changing values of every variable you want - this is perfect to find out what a code is doing!
Hi and prosperous trading .. :)
But :(
- you can't start names of variables with a number!
- Use the code button Alt+S (or the icon </> from the top) to post code
- To use indentions or the "Styler" (Ctrl+,) in the Editor.
- The Editor has a debugger where you can control the changing values of every variable you want - this is perfect to find out what a code is doing!
Use the Code button to insert your code.
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor -
for(int i=10; i>=0;i--) double 1adx+ = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_PLUSDI,i) double 1adx- = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_MINUS,i) double 2adx+ = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_PLUSDI,i+1) double 2adx- = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_MINUS,i+1)
The for loop is only operating on the first iADX. Result is ADX(0).
The second ADX is after the loop terminates. Result is ADX(-1). - You can't start names of variables with a number! You can't use +/- in variable names. Does not compile.
- No terminating semicolon. Does not compile.
- user003: I'd like to note again that the code worksCode does not work, it doesn't even compile. Don't post code that doesn't compile.
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - The for loop is only operating on the first iADX. Result is ADX(0).
The second ADX is after the loop terminates. Result is ADX(-1). - You can't start names of variables with a number! You can't use +/- in variable names. Does not compile.
- No terminating semicolon. Does not compile.
- Code does not work, it doesn't even compile. Don't post code that doesn't compile.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm writing an indicator that for example asks to check for several conditions, then using a for-loop looks back (10 bars) to see if an event occurred after these events x & y have been verified. It in EA but I'm not sure why. Could anyone explain what it's actually doing? or is it the correct logic?
if(fastEMA < slowEMA)
{
if( macd_signal_1 > macd_main_1 && macd_signal_0 < macd_main_0)
//then check to see if the ADX+ crossed over ADX- in the last (10) bars
{
for(int i=10; i>=0;i--)
double 1adx+ = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_PLUSDI,i)
double 1adx- = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_MINUS,i)
double 2adx+ = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_PLUSDI,i+1)
double 2adx- = iADX(NULL,0,ADX_period,PRICE_CLOSE,MODE_MINUS,i+1)
//insert expression for crossover
if((1adx+) > (1iadx-) && (2adx+) < (2adx-))
//insert execute order statement
}
}
I'd like to note again that the code works and im under the impression that its checking for the adx to have occurred within the last 10 bars. If more clarity is necessary don't hesitate to ask. Thank you!
-003