BuyLimit gives invalid price error - page 2

 
SULAIMAN LALANI:

This didn't work.  Bid and ask price still return as 0.00.  Expert tab file attached.


The bid and ask returns 0 because the wrong variable is called. To get bid price use SymbolInfoDouble
 
Chidera Anakpe:
The bid and ask returns 0 because the wrong variable is called. To get bid price use SymbolInfoDouble

Why the same EA then gets the correct bid and ask price on same symbol, same specifications, same broker's demo account?  See Expert Tab from demo account.

Thanks for helping out


 
jadoon88 :


You are making the same mistake: in MQL5, the indicator handle must be RECEIVED ONCE, AND NOT AT THE TICK !!!

Algorithm:

Forum on trading, automated trading systems and testing trading strategies

How to start with MQL5

Vladimir Karputov, 2020.11.13 06:01

Receiving data from an indicator in an MQL5.

Scheme:

Getting data from indicators in an MQL5 Expert Advisor

An example for the iMA indicator:


 
Donald Reeves Sihombing:

Hi,

as you can see that the trade was successful, and the Result RetCode was 10009.

So, even if we use your code, it will not avoid the trade done at 0.00, right?

Please correct me if I am wrong. 

It will not prevent that, because that's a different problem. If you want to get the price sent to the trade server, you should analyze the request struct instead.
 
jadoon88:

Dear Members,

I am trying to write an Expert Advisor with MQL5 that initiates buy limits based on certain EMA values. Here is the code that I have written in OnTick() function.

When I run it it strategy testing with EURUSD on H1 timeline, I get the following error most of the times:

Can you please tell me what I might be doing wrong?

Apologies in advance if this is a very basic question for your precious time, I am new into MQL5 coding and it is hard for me to understand many things. I have read the existing material as much as I can but I still do not understand why I am getting this error. Please help and thank you.

EURUSD at 1.05342

Hi,

You need to enter into your order a price which is competent with the tick size of your symbol. Copy the code below:

double tick_size = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);

double corrected_price = MathRound(price/tick_size)*tick_size;

Use this corrected_price  in your order.