Help newbie in AO

 

 Hi everyone.

I'm learning code and i need help wiht AO. 

I want check when  AO valeu = 0. and before that AO is red bar or greenbar

I write this 

double val1= iAO(NULL,0, i); double val2= iAO(NULL,0, i+1); if ( val1 == 0)  if (val1>val2) ....... is that right ? or something wrong. Please help me. I learn myself and i have a lot of classic problem. Sorry because my poor Enghlish

 
When you compiled the code, any error?

For 

If(val ==0) and if(val1>val2) 

Would never work, cause if value 1 is 0, then val2 must be less for that section to run. Try,

if(val1 !=0)
  if(val1>val2)
     {
      ...
     }

// Or
if(val1 <=0)
  return;
if(val1>val2)
  {
   ...
  }
 
It is Mr B57: I want check when  AO valeu = 0. and before that AO is red bar or greenbar
  1. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 (2013)

  2. Look for a cross.

    double aPrev = …(i+1), aCurr = …(i);
    bool   wasUp = aPrev > 0.0,
            isUp = aCurr > 0.0,
         isCross = isUp != wasUp;

 
William Roeder #:
  1. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 (2013)

  2. Look for a cross.

 I write this but i don't work, i try another way but it not. i don't understand why


if ( val2 <0.0 && val1 > 0.0 )

                 {


                 Print( "AO move to green");
                 Alert(" AO  move to green ");
                  

                 } 

if ( val2 >0.0 && val1 < 0.0 )

                 {


                  Print( "AO  move to red");
                  Alert(" AO  move to red ");
                      

                 } 

can you help me fix it or find another way to do it

 
It is Mr B57 # I write this but i don't work,
  1. Please edit your 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 (2019)
              Messages Editor

  2. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  3. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    Do you expect us to know what val1 and val2 are?

 
William Roeder #:
  1. Please edit your 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 (2019)
              Messages Editor

  2. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  3. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    Do you expect us to know what val1 and val2 are?

I'm so sorry. that my mistake. I "m newbie try to code so I have a lot of thing that I don't know.

this is my problem

I want to know when AO from minus to positive and opposite .I try this but when i test it in MT4 not thing happen. I don't know anh why

  double val1 = iAO(NULL,0, 0);
  double val2 = iAO(NULL, 0, 1);
if ( val2 <0.0 && val1 > 0.0 )

      {
                 Print( "AO move to green");
                 Alert(" AO  move to green ");
                  
      } 

if ( val2 >0.0 && val1 < 0.0 )

      {

                  Print( "AO  move to red");
                  Alert(" AO  move to red ");
                      
      }