Download MetaTrader 5
To add comments, please log in or register
Publish your trading signal. Gain access to millions of traders!
secrettrader100@abv.bg
13
secrettrader100@abv.bg 2014.10.30 17:27 

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
5965
Carl Schreiber 2014.10.30 18:35  
Please use the SRC-button - beside the camera!
whroeder1
13656
whroeder1 2014.10.30 19:48  

  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
5965
Carl Schreiber 2014.10.30 20:45  
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
5965
Carl Schreiber 2014.10.30 20:48  
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
8016
Keith Watford 2014.10.30 21:05  
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 2014.10.31 11:41  
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
13656
whroeder1 2014.10.31 13:10  
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
5965
Carl Schreiber 2014.10.31 13:35  
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