Ask not working

 

Hello everyone,

I'm learning MQL4 (already know programming) and I'm trying some logic, loops and price levels.

I'm trying to check the high of the previous candle and display an alert at that level.

Example:

previous_candle = (symbol,0,1)

if (Ask = previous_candle)

alert(hello world)

Not working. So then I tried comparing the previous high level to the pre-previous high level and if the levels are the same => diplay an alert and it works.

if candle2_high == candle1_high

alert("hello world")

This works perfectly BUT if I do:

if candle2_high == candle1_high

and if Ask == candle1_high

alert("hello world")

It doesn't work. I'm guessing there's problem with the "Ask" command. I also tried "double ask2 = MarketInfo(Symbol(),MODE_ASK);" and then comparing the high to ask2 and it also doesn't work. How can I fix the problem? Is there another way to check the current price level?

 
It may well be a double precision issue. What are you using to get the high ? iHigh ?
 

Yes.

This is my complete code.

int start()
  {
   double high2 = iHigh(Symbol(),0,2);
   double high1 = iHigh(Symbol(),0,1);

   if(high2 == high1)
   {
     Alert("this works");
     if(Ask == high1+10*Point)
     {
        Alert("this doesn't work");
     }
   }

  return(0);
  }


APP:

double ask2 = MarketInfo(Symbol(),MODE_ASK);

if (ask2 == high1+10*Point)

Also doesn't work.
 
  1. double high2 = iHigh(Symbol(),0,2);
                 = iHigh(NULL,0, 2);
                 = High[2];
    
    double ask2 = MarketInfo(Symbol(),MODE_ASK);
                = MarketInfo(NULL,MODE_ASK);
                = Ask;
    All the same
  2.    if(high2 == high1)
    Doubles rarely compare equal.
       if(MathAbs(high2 - high1) < Point)

  3. Why do you think the high of two candles will be equal?
 

Thanks.

Doesn't matter if the operator is ==, < or >. I'm just trying to test MQL4 commands and I'm using the IF statement to see if the condition gets met. I'm testing it on M1 so I get a lot of equal highs. Not relevant, I'll use < and > to see better result.

I can't get the condition to meet and that is " IF the current price level (Ask) == previous bar high+2pips above THEN send me a message". I'm obviously missing something but I don't know what it is.

EDIT: The thing is if I test "Ask" in a different condition it works, but it doesn't work here.

 

Try replacing . . .

if(Ask == high1+10*Point)

with . . . .

if(MathAbs(Ask - (high1+10*Point)) < Point)

and read this thread : https://www.mql5.com/en/forum/136997

 
joskojoras:
Doesn't matter if the operator is ==, < or >. I'm just trying to test MQL4 commands and I'm using the IF statement to see if the condition gets met.
  1. It does matter, doubles rarely compare equal, so your IFs will never be true.
  2. Print out the values of your variables before the IF
    double high2 = iHigh(Symbol(),0,2);
    double high1 = iHigh(Symbol(),0,1);
    Print("high2=", PriceToStr(high2)," high1=",PriceToStr(high1));
       if(high2 == high1) ..
    :
    string  PriceToStr(double p){ return( DoubleToStr(p, Digits) ); }

 

My problem shows you are correct, but if I send an alert at the 1.12345 price level and the price is at 1.12330 and goes up until 1.12360, then at some point it will reach the 1.12345 level so the alert should have released. Why is that not so?

I've tried replacing

if(Ask == high1+10*Point)

with

if(MathAbs(Ask - (high1+10*Point)) < Point)

and

if ((Ask - High[1]) > 10*Point)

but it doesn't work. Too bad MetaEditor doen't have a debugger so I could follow the code step-by-step to see where exactly lies my problem. It could be that MQL is skipping increments therefore the Ask cannot be equal to High[1] but in that case no price would be equal to any at all. Sometimes the condition is TRUE but mostly not, so I can only conclude that real time price level is too fast for the code? How do I get around it? Is there maybe a way I can check for a price range say 1.12340 - 1.12380 in a condition instead of a defined price level?


EDIT2: I've put /2 at the end of the line like this:

if (Ask == High[1]+20*Point/2)
I thought it works, but it doesn't.
 
joskojoras:

My problem shows you are correct, but if I send an alert at the 1.12345 price level and the price is at 1.12330 and goes up until 1.12360, then at some point it will reach the 1.12345 level so the alert should have released. Why is that not so?

On the way from 1.12330 to 1.12360 you cannot guarantee that price will visit every 1/10th of a pip in between . . . . sometimes price moves in pips, sometimes it moves in 1/10ths of a pip sometimes it moves in multiple pips
 
That's right, is there a way to get around this? I'm willing to pay for a solution that works.
 
joskojoras:
That's right, is there a way to get around this? I'm willing to pay for a solution that works.

" I'm learning MQL4 (already know programming) and I'm trying some logic, loops and price levels. "

If you already know programming you will know it's a simple task . . . monitor price, when it moves from one side of your alert level to the other then your alert should be activated.

Reason: