Need help fixing my points/pips/digits problem in my mql4 EA. Any help would be really appreciated. - page 2

 
Another probable reason =>

Also => usually Stop Loss for BUY order is set from the Bid price and for SELL order from the Ask price respectively

Check => MQL4 Reference => OrderModify () + OrderSend ()

In any case it is useful to use GetLastError ()

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products. If any errors are identified by the Market...
 
Fabio Cavalloni:

You need to check distance from current price that need to be grater than STOP_LEVEL allowed by your broker.

I suggest to use bigger values for make a try. Use 100 and 100 for SL and TP. That are 10 pips (if you don't multiply *10)  or 100 pips in the other case.

Yes, I figured it out. I already solved this problem. Thank you! Do you want a copy of my EA?

 
Airat Safin:
Another probable reason =>

Also => usually Stop Loss for BUY order is set from the Bid price and for SELL order from the Ask price respectively

Check => MQL4 Reference => OrderModify () + OrderSend ()

In any case it is useful to use GetLastError ()

Yeah, I read this article after I solved this problem. Thank you!

 
Daniel Sastraamidjaja:

Yes, I figured it out. I already solved this problem. Thank you! Do you want a copy of my EA?

If you have solved it, then please post what you did to solve it.

It may help others.

 
Keith Watford:

If you have solved it, then please post what you did to solve it.

It may help others.


It was like this:

if(TakeProfit > 0) TheTakeProfit = Ask + TakeProfit * MyPoint;
if(StopLoss > 0)   TheStopLoss   = Ask - StopLoss * MyPoint;


Then I changed it into:

if(TakeProfit > 0) TheTakeProfit = NormalizeDouble(MathMax(Ask + TakeProfit * MyPoint, MarketInfo(Symbol(), MODE_BID) + MarketInfo(Symbol(), MODE_STOPLEVEL) * MyPoint), 
                                   (int)MarketInfo(Symbol(), MODE_DIGITS));    
if(StopLoss > 0) TheStopLoss = NormalizeDouble(MathMin(Ask - StopLoss * MyPoint, MarketInfo(Symbol(), MODE_BID) - MarketInfo(Symbol(), MODE_STOPLEVEL) * MyPoint), 
                               (int)MarketInfo(Symbol(), MODE_DIGITS));


Also, I write this in Init():

int OnInit()
  {
   MyPoint     = MarketInfo(Symbol(), MODE_POINT);
   return(INIT_SUCCEEDED);
  }


And it worked like charm!

 
You can simply use _Digits and _Points without using other variables.
 
Daniel Sastraamidjaja:

Also, I write this in Init():

int OnInit()
  {
   MyPoint     = MarketInfo(Symbol(), MODE_POINT);
   return(INIT_SUCCEEDED);
  }

And it worked like charm!

That won't work unless you remove

if(Digits==2 || Digits==3 || Digits ==5) MyPoint=Point*10;

from OnTick()

This was pointed out to you in the first 2 replies

 
Keith Watford:

That won't work unless you remove

from OnTick()

This was pointed out to you in the first 2 replies

Already removed it. Sorry I was forgot to mentioned it.

Fabio Cavalloni:
You can simply use _Digits and _Points without using other variables.

Okay. thank you for your help!

Reason: