Tracking price movement every 10 pips

 

Hello everyone I've been hard at work developing an EA these last few days that price movement be synthesized into 10 pip steps. I believe Ive narrowed down the cause of my troubles to this :

double current_ask;

double startprice = MarketInfo(OrderSymbol(),MODE_ASK);


void OnTick()

  {

  current_ask = MarketInfo(OrderSymbol(),MODE_ASK);

  if(current_ask == startprice + NormalizeDouble(100*Point,Digits))

  {

   Print("Price has moved up 10 pips to ",current_ask," from ", startprice);

  }

  

  if(current_ask == startprice - NormalizeDouble(100*Point,Digits))

  {

   Print("Price has moved down 10 pips to ", current_ask, " from ", startprice);

  }

   

  } 

 

This code only print this in the log :

2014.10.21 05:24  m4 EURUSD,H1: Price has moved up 10 pips to 1.28061 from 1.27961

0 19:11:26 2014.10.21 05:24  m4 EURUSD,H1: Price has moved up 10 pips to 1.28061 from 1.27961

0 19:11:26 2014.10.21 05:24  m4 EURUSD,H1: Price has moved up 10 pips to 1.28061 from 1.27961

0 19:11:26 2014.10.21 05:26  m4 EURUSD,H1: Price has moved up 10 pips to 1.28061 from 1.27961

0 19:11:26 2014.10.21 05:46  m4 EURUSD,H1: Price has moved up 10 pips to 1.28061 from 1.27961 

 ... and so on. I.e. when it gets to the +10 pip level it spams for a bit until price moves away from that level. The problem is that the EA only print messages for the first up/down level it reaches and then ignores the other one even if it is reached. No "Price has moved down 10 pips" message gets printed if a "Price has moved up 10 pips" one has already been printed.

Now I am no pro mql4 coder but shouldnt the OnTick function run both if statement on every tick. Could anyone please explain why this code produces this result ? 

 
Please use the SRC-button - beside the camera!
 

  current_ask = MarketInfo(OrderSymbol(),MODE_ASK);

  if(current_ask == startprice + NormalizeDouble(100*Point,Digits))

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Why are you using a function call in stead of the predefined variable Ask?
  3. Your if statement will never/randomally work. Learn why.
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Why are you using a function call in stead of the predefined variable Ask?
  3. Your if statement will never/randomally work. Learn why.
WHRoeder you picture is out of date, the SRC-button has moved ;)
 
if(current_ask == startprice + NormalizeDouble(100*Point,Digits))

What if the the Asks did not hit exactly:

            startprice + NormalizeDouble(100*Point,Digits)

?

You won't get your print(..)

 
if(current_ask >= startprice + NormalizeDouble(100*Point,Digits))

  {

   Print("Price has moved up 10 pips to ",current_ask," from ", startprice);
   startprice+=100*Point;
   //OR
   startprice=current_ask;

  }
you didn't update the new value for startprice
 
Thanks to everyone who replied ! To anyone reading this in the future - always try to find a way to avoid comparing for price equality and redefine your expressions with > or < :)
 
gooly: WHRoeder you picture is out of date, the SRC-button has moved ;)
Is that better? (Wasn't my picture to begin with.)
 
WHRoeder:
gooly: WHRoeder you picture is out of date, the SRC-button has moved ;)
Is that better? (Wasn't my picture to begin with.)

Yes ;)
Reason: