I get this error: failed instant buy 0.05 AUDCAD at 0.97083, close #2 sell 0.05 AUDCAD 0.97620111 [Invalid volume] I do not understand if the invalid volume error is related to opening the position or with closing the position. Before opening positions, I do the following checks to avoid using an invalid volume:
Is this not sufficient to check for invalid volume? If the error is related to closing of the position, how is the EA allowed to open a 0.5 lot position but not close a 0.5 lot position and how can I check for that?I suggest you print the values to expert journal, to check what you are actually passing in. > the error is received i the automatic validation process on mql5, so I cant read print statements related to the error.
Also, I would first check for lot step, then for max and min values boundaries. > tried that, still get the same errorI see the code for ronding the postion size is Ok. Check the code for closing the position. I think the fault is there.
I do check if there is enough margin to open positions:
// check if enough free margin double margin; double bid = SymbolInfoDouble(inpSymbol,SYMBOL_BID); if(OrderCalcMargin(ORDER_TYPE_SELL,inpSymbol,lot,bid,margin)&& margin > AccountInfoDouble(ACCOUNT_MARGIN_FREE)) { Print("Not enough margin to open buy position"); return; }
I am not aware of any checks that needs to run before being able to close a position. Could you please clarify?
Use this extra code for debugging to print to the log
if((direction>0) && (ask >= tp)) { for(int i=ArraySize(arr)-1; i>=0; i--) { ulong posTicket = arr[i]; if(PositionSelectByTicket(posTicket)) { trade.SetTypeFillingBySymbol( PositionGetString(POSITION_SYMBOL) ); if(trade.PositionClose(posTicket)) { } else { Print("---===Request===---"); string desc="Action: "+EnumToString(trade.RequestAction())+"\n"; desc += "Symbol: " + trade.RequestSymbol() + "\n"; desc += "Magic Number: " + (string)trade.RequestMagic() + "\n"; desc += "Order ticket: " + (string)trade.RequestOrder() + "\n"; desc += "Order type: " + EnumToString(trade.RequestType()) + "\n"; desc += "Order filling: " + EnumToString(trade.RequestTypeFilling()) + "\n"; desc += "Order time type: " + EnumToString(trade.RequestTypeTime()) + "\n"; desc += "Order expiration: " + TimeToString(trade.RequestExpiration()) + "\n"; desc += "Price: " + (string)trade.RequestPrice() + "\n"; desc += "Deviation points: " + (string)trade.RequestDeviation() + "\n"; desc += "Stop Loss: " + (string)trade.RequestSL() + "\n"; desc += "Take Profit: " + (string)trade.RequestTP() + "\n"; desc += "Stop Limit: " + (string)trade.RequestStopLimit() + "\n"; desc += "Volume: " + (string)trade.RequestVolume() + "\n"; desc += "Comment: " + trade.RequestComment() + "\n"; desc += "Position: " + (string)trade.RequestPosition() + "\n"; desc += "Position by: " + (string)trade.RequestPositionBy(); Print(desc); Print("---===Result===---"); desc="Retcode: "+(string)trade.ResultRetcode()+"\n"; desc += "Retcode Desc: " + trade.ResultRetcodeDescription() + "\n"; desc += "Order ticket: " + (string)trade.ResultOrder() + "\n"; desc += "Deal ticket: " + (string)trade.ResultDeal() + "\n"; desc += "Volume: " + (string)trade.ResultVolume() + "\n"; desc += "Price: " + (string)trade.ResultPrice() + "\n"; desc += "Bid: " + (string)trade.ResultBid() + "\n"; desc += "Ask: " + (string)trade.ResultAsk() + "\n"; desc += "Comment: " + trade.ResultComment() + "\n"; desc += "Retcode external: " + (string)trade.ResultRetcodeExternal() + "\n"; Print(desc); } } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I get this error: failed instant buy 0.05 AUDCAD at 0.97083, close #2 sell 0.05 AUDCAD 0.97620111 [Invalid volume] I do not understand if the invalid volume error is related to opening the position or with closing the position. Before opening positions, I do the following checks to avoid using an invalid volume:
Is this not sufficient to check for invalid volume? If the error is related to closing of the position, how is the EA allowed to open a 0.5 lot position but not close a 0.5 lot position and how can I check for that?