inquiry about pending orders

 

in case of pending orders
open price must differ from market price by at least unknown pips
how can i calculate this unknown variable ?

for example to calculate Last incoming ask price

double ask =MarketInfo(Symbol(),MODE_ASK);

Thank You in Advance

 

It's in the documentation:

At placing of a pending order, the open price cannot be too close to the market. The minimal distance of the pending price from the current market one in points can be obtained using the MarketInfo() function with the MODE_STOPLEVEL parameter. In case of false open price of a pending order, the error 130 (ERR_INVALID_STOPS) will be generated.

Source: https://docs.mql4.com/trading/OrderSend

So you would use the 2 in combination though you'll need to account for some slippage as well

double minDistance = ((MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD)*MarketInfo(Symbol(),MODE_POINT));
//If pending above market price
double price = MarketInfo(Symbol(),MODE_ASK)+minDistance;
//Else pending below market price
double price = MarketInfo(Symbol(),MODE_BID)-minDistance;

That should work though I've not compiled it yet.

 
asta:

in case of pending orders
open price must differ from market price by at least unknown pips
how can i calculate this unknown variable ?

for example to calculate Last incoming ask price

Thank You in Advance


Well you don't have to calculate the last incoming ask price because it is in the special variable Ask. The difference to the pending level will be MarketInfo(Symbol(), MODE_STOPLEVEL) but that is generally too close, especially in fast markets. If the price moves even a fraction of a pip the pending order can be too close to the market price and may fail.
 

Dear heelflip thank you so much

Dear dabbler I get your meaning thank you so much

 
asta:

in case of pending orders
open price must differ from market price by at least unknown pips
how can i calculate this unknown variable ?

for example to calculate Last incoming ask price

Thank You in Advance


Read and get a grasp on this, it will help you: Making Trades
 

Dear RaptorkUK it's helpful for me Thank you very much

Reason: