Sporadic Pending Order function | MQL4
Sporadic Pending Order function | MQL4
Loading saved threads...
Hunktydunkaty · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Hunktydunkaty
Original post: https://stackoverflow.com/questions/75438913
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
So I have an EA which places a Pending Order at the opening price of the current candle, and expires at the end of the current candle.
My code is below, I have even printed an error function in order to diagnose any errors that may occur, however, according to the EA, a pending order is placed so no error appears.
Sometimes a pending order is actually successfully executed, and other times, it tells me a pending order has been placed successfully, but no pending order appears on the chart.
There are no error messages.
Clearly there are no errors, so it must be something to do with my coding. What am I missing here? Why does it sometimes placed a pending order on the chart, and others times it decided not to?
Many thanks.
if(<Conditions are met>){
int pendingExpiration = Period() * 60;
double candleOpenPrice = iOpen(Symbol(),0,0);
double pendingOrderExecPrice = NormalizeDouble(candleOpenPrice,Digits);
if(!OrderSend(Symbol(),OP_BUYSTOP,3,pendingOrderExecPrice,100,<sl>,<tp>,0,1,Time[0] + pendingExpiration,0)){
RefreshRates();
Print("Error on pending order "+IntegerToString(GetLastError(),0));
}
else {
<confirmaion email function>
}
}
Quote
Report
Mark SdS · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Mark SdS
Original post: https://stackoverflow.com/a/75451713
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Only thing I see is the Digits thing:
Yours:
NormalizeDouble(candleOpenPrice,Digits);
What I know:
NormalizeDouble(candleOpenPrice,_Digits);
Notice the underscore.
Although not sure whether this causes the errors.
Your call to
candleOpenPrice
just might sometimes return too many (or few) digits that can not be casted by the erratic call to _Digits.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Mark SdS Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/75451713 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Only thing I see is the Digits thing: Yours: NormalizeDouble(candleOpenPrice,Digits); What I know: NormalizeDouble(candleOpenPrice,_Digits); Notice the underscore. Although not sure whether this causes the errors. Your call to candleOpenPrice just might sometimes return too many (or few) digits that can not be casted by the erratic call to _Digits.
Checking account access…