Download MetaTrader 5

Tracking price movement every 10 pips

To add comments, please log in or register
secrettrader100@abv.bg
13
secrettrader100@abv.bg  

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 ? 

Carl Schreiber
7089
Carl Schreiber  
Please use the SRC-button - beside the camera!
whroeder1
15567
whroeder1  

  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.
Carl Schreiber
7089
Carl Schreiber  
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 ;)
Carl Schreiber
7089
Carl Schreiber  
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(..)

Keith Watford
Moderator
10566
Keith Watford  
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
secrettrader100@abv.bg
13
secrettrader100@abv.bg  
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 < :)
whroeder1
15567
whroeder1  
gooly: WHRoeder you picture is out of date, the SRC-button has moved ;)
Is that better? (Wasn't my picture to begin with.)
Carl Schreiber
7089
Carl Schreiber  
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 ;)
To add comments, please log in or register