indicator: if { for loop-if(statement); } }

 

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

 

Use the Code button to insert your code.



 
user003:

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

  1. you can't start names of variables with a number!
  2. Use the code button Alt+S (or the icon </> from the top) to post code
  3. To use indentions or the "Styler" (Ctrl+,) in the Editor.
  4. 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!

 
Thanks for the tip, I was only using those as an example. I posted the code. Any tips?
Carl Schreiber:

Hi and prosperous trading .. :)

But :(

  1. you can't start names of variables with a number!
  2. Use the code button Alt+S (or the icon </> from the top) to post code
  3. To use indentions or the "Styler" (Ctrl+,) in the Editor.
  4. 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!

 
Got it.  
Eleni Anna Branou:

Use the Code button to insert your code.



 
  1. 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

  2. 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).

  3. You can't start names of variables with a number! You can't use +/- in variable names. Does not compile.
  4. No terminating semicolon. Does not compile.
  5. user003: I'd like to note again that the code works 
    Code does not work, it doesn't even compile. Don't post code that doesn't compile.
 
I was looking for logic more than syntax.
William Roeder:
  1. 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

  2. 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).

  3. You can't start names of variables with a number! You can't use +/- in variable names. Does not compile.
  4. No terminating semicolon. Does not compile.
  5. Code does not work, it doesn't even compile. Don't post code that doesn't compile.
Reason: