BcLib further corrections needed
It seems when I inserted the MaxPasses parameter in ReliableOrderSend and ReliableOrderClose they became really broken. Last correction solves the issue, however there is still a bug:
Examining the corrected codes of the functions: copy from here and replace in BcLib.mq4!
int ReliableOrderSend(string symbol,int cmd,double volume,double price,int slippage,double stoploss,double takeprofit, string comment="",int magic=0,datetime expiration=0,color arrow_color=CLR_NONE,int MaxPasses=0) { int Gle=ERR_TRADE_CONTEXT_BUSY; string ErrType=""; string ErrText=""; string ErrExplanation=""; int passes=0; int res=-1; while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES) { if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES||passes==0) { if (passes!=0) RefreshRates(); if (price==0.0) //if (passes!=0||price==0) price=MarketInfo(symbol,PriceOpenMode(cmd)); }//if (Gle==ERR_REQUOTE) res=OrderSend(symbol,cmd,volume,price,slippage,stoploss,takeprofit,comment,magic,expiration,arrow_color); Gle=GetLastError(); TranslateError(Gle,ErrType,ErrText,ErrExplanation); if (Gle!=ERR_NO_ERROR) Print("ReliableOrderSend error : ",Gle," : ",ErrText); passes=passes+1; if (MaxPasses!=0) { if (passes>=MaxPasses) break; } //ADD ONLY THIS LINE if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES) { price=0.0; } }//while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE) return(res); } bool ReliableOrderClose(int ticket, double lots, double price, int slippage, color Color=CLR_NONE,int MaxPasses=0) { int Gle=ERR_TRADE_CONTEXT_BUSY; string ErrType=""; string ErrText=""; string ErrExplanation=""; int passes=0; bool res; int otype; double olots; string osymbol; res=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); osymbol=OrderSymbol(); otype=OrderType(); olots=OrderLots(); if (lots==0) lots=olots; if (res==True) { while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES) { if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES||passes==0) { if (passes!=0) RefreshRates(); if (price==0.0) //if (passes!=0||price==0) price=MarketInfo(osymbol,PriceCloseMode(otype)); }//if (Gle==ERR_REQUOTE) res=OrderClose(ticket,lots,price,slippage,Color); Gle=GetLastError(); TranslateError(Gle,ErrType,ErrText,ErrExplanation); if (Gle!=ERR_NO_ERROR) Print("ReliableOrderClose error : ",Gle," : ",ErrText); passes=passes+1; if (MaxPasses!=0) { if (passes>=MaxPasses) break; } //ADD ONLY THIS LINE if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES) { price=0.0; } }//while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE) } return(res); }
As you can see, the 0 for entry price is correctly handled. As long as a bad error occurs (such as ERR_OFF_QUOTES occurs) and there is no price sent to OrderSend() the price is reread by MarketInfo. However, if a regular error comes (such as ERR_PRICE_CHANGED) then function enters a possible endless loop, as the MarketInfo price inquiry will not be executed. This is why, before while cycle ends, price will be reset in both ReliableOrderSend() and ReliableOrderClose(), making possible its read in the next cycle execution. This is the only modification to be done. In the same time, given the fact we reset the price before the while ends, the first execution is ok in both cases with a 0 price and a non-zero given price. (Don't look at the old closing while comments, they are really old, when functions didn't handle all these errors!)
Later edit: price must be reset only in some error conditions, not in all!
P.S.
I need some input folks! Can't see all the bugs lurking the shadows! At least for BcLib core modules...
P.S. no 2
My trading account floats around 3% ROE (started from late Aug. 27).
10 Comentarii
Comentarii Recomandate