Error Order Send 138.
Maybe some refs below sort you out...
references:
A. Terminal Help: Managing of Trade Positions — Placing of Pending Orders
B. Terminal Help: Trading -- Order Types
B. Editor Help: Standard constants - Trade operations
C. Editor Help: Trading functions - OrderSend
D. Not forgetting THE BOOK... see top of topics list
1. are you using one of:
MQL4 Reference - Standard constants - Trade operations
| OP_BUYLIMIT | 2 | Buy limit pending position. |
| OP_SELLLIMIT | 3 | Sell limit pending position. |
| OP_BUYSTOP | 4 | Buy stop pending position. |
| OP_SELLSTOP | 5 | Sell stop pending position. |
2. using: Ask [+/-] N*Point ?
must be normalized (via Point)
3. what SLIPPAGE using ?
Please show code - unknown how you calculate OrderSend() inputs, unknown OrderSend() call....
Maybe some refs below sort you out...
references:
A. Terminal Help: Managing of Trade Positions — Placing of Pending Orders
B. Terminal Help: Trading -- Order Types
B. Editor Help: Standard constants - Trade operations
C. Editor Help: Trading functions - OrderSend
D. Not forgetting THE BOOK... see top of topics list
1. are you using one of:
MQL4 Reference - Standard constants - Trade operations
| OP_BUYLIMIT | 2 | Buy limit pending position. |
| OP_SELLLIMIT | 3 | Sell limit pending position. |
| OP_BUYSTOP | 4 | Buy stop pending position. |
| OP_SELLSTOP | 5 | Sell stop pending position. |
2. using: Ask [+/-] N*Point ?
must be normalized (via Point)
3. what SLIPPAGE using ?
Please show code - unknown how you calculate OrderSend() inputs, unknown OrderSend() call....
I'd use a slippage of 3
I use Ask-(NormalizeDouble(20*Point),2)
I didn't refer to the right trade operation code...
After that. I need/It would be better to refresh quotes in a loop?
Thanks
Hi Simon,
"I use Ask-(NormalizeDouble(20*Point),2)" ---> Ask-(NormalizeDouble(20*Point,2)) ---> Ask-NormalizeDouble(20*Point,2)
| double NormalizeDouble( | double value, int digits) |
may I point out syntax issue - see above - compiler would shout but....
I trust below does not offend - but seems that some background may be of interest (hahaaa, always helps me get things better in head if go through examples etc. :)
Long time ago I made function to dump MarketInfo() - if no actual param then use Symbol()
I made function to help me 'see' all marketInfo data for a symbol pair - I've got to see else just not make sense...
Please notice colored lines in the logged marketInfo Print()'s at end.
Reason I did this is your code produces double value rounded to fixed two decimal point digit precision, yes?
ref: MQL4 Reference - Conversion functions - NormalizeDouble
IF did this for let's say, gbpusd which has 4 decimal point digits the result would be
eg, let gbpusd/Ask = 1.9812 and Point = 0.0001, so using your code:
1.9812 - {(20*0.0001) to two digits} = 1.9812 - {0.0020 to two digits} = 1.9812 - 0.00 = 1.9812
If use: Ask - NormalizeDouble(20*Point,MarketInfo("GBPUSD",MODE_DIGITS))
you get eg, 1.1234 and not 1.12
See how the MarketInfo(..) frees code from being specific for just one decimal point precision? (kinda same idea as using #define's instead of constants...)
Consider using:
let: sym = "GBPUSD"; //or whatever symbol EA may be using at that moment (or just use Symbol() instead of sym if only ever using EA's chart symbol pair)
then finally we get: NormalizeDouble(20*Point,MarketInfo(sym,MODE_DIGITS))
which will work for any symbol pair.
GBPUSD,M15: end-->>>>> printMarketInfo(GBPUSD)
GBPUSD,M15: MODE_FREEZELEVEL=0
GBPUSD,M15: MODE_MARGINREQUIRED=1982.4
GBPUSD,M15: MODE_MARGINHEDGED=50000
GBPUSD,M15: MODE_MARGINMAINTENANCE=0
GBPUSD,M15: MODE_MARGININIT=0
GBPUSD,M15: MODE_MARGINCALC=0
GBPUSD,M15: MODE_PROFITCALC=0
GBPUSD,M15: MODE_SWAPTYPE=0
GBPUSD,M15: MODE_MAXLOT=99999
GBPUSD,M15: MODE_LOTSTEP=0.01
GBPUSD,M15: MODE_MINLOT=0.01
GBPUSD,M15: MODE_TRADEALLOWED=1
GBPUSD,M15: MODE_EXPIRATION=0
GBPUSD,M15: MODE_STARTING=0
GBPUSD,M15: MODE_SWAPSHORT=-1.63
GBPUSD,M15: MODE_SWAPLONG=1
GBPUSD,M15: MODE_TICKSIZE=0.0001
GBPUSD,M15: MODE_TICKVALUE=10
GBPUSD,M15: MODE_LOTSIZE=100000
GBPUSD,M15: MODE_STOPLEVEL=3
GBPUSD,M15: MODE_SPREAD=3
GBPUSD,M15: MODE_DIGITS=4
GBPUSD,M15: MODE_POINT=0.0001
GBPUSD,M15: MODE_ASK=1.9824
GBPUSD,M15: MODE_BID=1.9821
GBPUSD,M15: MODE_LOW=1.9747
GBPUSD,M15: MODE_LOW=1.9747
GBPUSD,M15: MODE_LOW=1.9747
GBPUSD,M15: start-->>>>> printMarketInfo(GBPUSD)
USDJPY,H1: end-->>>>> printMarketInfo(USDJPY)
USDJPY,H1: MODE_FREEZELEVEL=0
USDJPY,H1: MODE_MARGINREQUIRED=1000
USDJPY,H1: MODE_MARGINHEDGED=50000
USDJPY,H1: MODE_MARGINMAINTENANCE=0
USDJPY,H1: MODE_MARGININIT=0
USDJPY,H1: MODE_MARGINCALC=0
USDJPY,H1: MODE_PROFITCALC=0
USDJPY,H1: MODE_SWAPTYPE=0
USDJPY,H1: MODE_MAXLOT=99999
USDJPY,H1: MODE_LOTSTEP=0.01
USDJPY,H1: MODE_MINLOT=0.01
USDJPY,H1: MODE_TRADEALLOWED=1
USDJPY,H1: MODE_EXPIRATION=0
USDJPY,H1: MODE_STARTING=0
USDJPY,H1: MODE_SWAPSHORT=-0.87
USDJPY,H1: MODE_SWAPLONG=0.42
USDJPY,H1: MODE_TICKSIZE=0.01
USDJPY,H1: MODE_TICKVALUE=9.78
USDJPY,H1: MODE_LOTSIZE=100000
USDJPY,H1: MODE_STOPLEVEL=3
USDJPY,H1: MODE_SPREAD=3
USDJPY,H1: MODE_DIGITS=2
USDJPY,H1: MODE_POINT=0.01
USDJPY,H1: MODE_ASK=102.28
USDJPY,H1: MODE_BID=102.25
USDJPY,H1: MODE_LOW=101.51
USDJPY,H1: MODE_LOW=101.51
USDJPY,H1: MODE_LOW=101.51
USDJPY,H1: start-->>>>> printMarketInfo(USDJPY)
Hope not mind: I attach this just because maybe is useful for you [or other readers of course ;]
#define EMPTYSTRING "" //I use this generic in my eaDefines.mqh header file because [for me] I am positive I got an empty string - call it paranoia!
void printMarketInfo (string sym=EMPTYSTRING)
{
if( sym==EMPTYSTRING ) sym = Symbol();
Print("start-->>>>> printMarketInfo(",sym,")");
Print("MODE_LOW=",MarketInfo(sym,MODE_LOW));
Print("MODE_LOW=",MarketInfo(sym,MODE_LOW));
Print("MODE_LOW=",MarketInfo(sym,MODE_LOW));
Print("MODE_BID=",MarketInfo(sym,MODE_BID));
Print("MODE_ASK=",MarketInfo(sym,MODE_ASK));
Print("MODE_POINT=",MarketInfo(sym,MODE_POINT));
Print("MODE_DIGITS=",MarketInfo(sym,MODE_DIGITS));
Print("MODE_SPREAD=",MarketInfo(sym,MODE_SPREAD));
Print("MODE_STOPLEVEL=",MarketInfo(sym,MODE_STOPLEVEL));
Print("MODE_LOTSIZE=",MarketInfo(sym,MODE_LOTSIZE));
Print("MODE_TICKVALUE=",MarketInfo(sym,MODE_TICKVALUE));
Print("MODE_TICKSIZE=",MarketInfo(sym,MODE_TICKSIZE));
Print("MODE_SWAPLONG=",MarketInfo(sym,MODE_SWAPLONG));
Print("MODE_SWAPSHORT=",MarketInfo(sym,MODE_SWAPSHORT));
Print("MODE_STARTING=",MarketInfo(sym,MODE_STARTING));
Print("MODE_EXPIRATION=",MarketInfo(sym,MODE_EXPIRATION));
Print("MODE_TRADEALLOWED=",MarketInfo(sym,MODE_TRADEALLOWED));
Print("MODE_MINLOT=",MarketInfo(sym,MODE_MINLOT));
Print("MODE_LOTSTEP=",MarketInfo(sym,MODE_LOTSTEP));
Print("MODE_MAXLOT=",MarketInfo(sym,MODE_MAXLOT));
Print("MODE_SWAPTYPE=",MarketInfo(sym,MODE_SWAPTYPE));
Print("MODE_PROFITCALC=",MarketInfo(sym,MODE_PROFITCALCMODE));
Print("MODE_MARGINCALC=",MarketInfo(sym,MODE_MARGINCALCMODE));
Print("MODE_MARGININIT=",MarketInfo(sym,MODE_MARGININIT));
Print("MODE_MARGINMAINTENANCE=",MarketInfo(sym,MODE_MARGINMAINTENANCE));
Print("MODE_MARGINHEDGED=",MarketInfo(sym,MODE_MARGINHEDGED));
Print("MODE_MARGINREQUIRED=",MarketInfo(sym,MODE_MARGINREQUIRED));
Print("MODE_FREEZELEVEL=",MarketInfo(sym,MODE_FREEZELEVEL));
Print("end-->>>>> printMarketInfo(",sym,")");
}
MQL4 Reference - Window functions - RefreshRates
Not sure really needed unless computing for long period - the EA gets latest tick data when called.
I believe that this function is best used when you have used Sleep() due to say a retry loop - it could be that Terminal gets 1 or more ticks while EA sleeping and in this case is vital to call refreshRates else ea will not 'see' this latest server data...
Regards
That is to say my EA doesn't want to send a pending order. Pending Order aims - e.g. - at buying at (Ask - N ticks). If N==3 then it works, whereas N>3 it possibly returns err 138. The error is ERR_REQUOTE (I presume) and I don't know how/where and what function to add.
What is the most effective CODE to obtein, keep and control pending orders processing? I've already looked at https://docs.mql4.com/trading/errors, https://www.mql5.com/en/forum/107374...
Thanks a lot!
SA