@Ahmet Metin Yilmaz@Keith Watford@Sergey Gerasimov@Vladimir Kazennov@William Roeder@nicholish enHello guys,
I have been struggling to fix this problem in my code below because it keeps opening multiple buy positions instead of printing failed to buy in the journal!
What should be done to handle failed trade errors using Ctrade?
My Apologies since iam not well familiar with mql5!... and thanks for your time cheers
Hi, What you can do is save the value of
trade.Buy
in a variable .
bool buy =false;
So, declare the variable before you open the trade, when you open the trade just make it
buy = trade.Buy( 0.2,//how much NULL,//current symbol Ask,//buy prices 0,//stop loss 0,//take profit NULL//comment );
And when you want to check if you opened a trade, check if buy is true or false
Hi, What you can do is save the value of
in a variable .
So, declare the variable before you open the trade, when you open the trade just make it
And when you want to check if you opened a trade, check if buy is true or false
Hi , Thanks for your reply ... I did what you said but failed it stills open multiple buy position s and all I need is just reporting buy error has failed!
//Create an instance of CTrade #include <Trade\Trade.mqh> CTrade trade; CPositionInfo m_position; input double LotSize=0.2; bool buy=true; void OnTick() {// double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); Buy=trade.Buy( 0.2,//how much NULL,//current symbol Ask,//buy prices 0,//stop loss 0,//take profit NULL//comment ); //Buy when condition true if(PositionsTotal()==0) {// trade.Buy( 0.2,//how much NULL,//current symbol Ask,//buy prices 0,//stop loss 0,//take profit NULL//comment ); }// //INCASE BUY FAILED... if(buy==false) {// //PRINT SOMETHING Print("Request to open BUY has failed. Return code=",trade.ResultRetcode(), ".Code Description:",trade.ResultRetcodeDescription()); }// }//Ontick
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
@Ahmet Metin Yilmaz@Keith Watford@Sergey Gerasimov@Vladimir Kazennov@William Roeder@nicholish enHello guys,
I have been struggling to fix this problem in my code below because it keeps opening multiple buy positions instead of printing failed to buy in the journal!
What should be done to handle failed trade errors using Ctrade?
My Apologies since iam not well familiar with mql5!... and thanks for your time cheers