You are mixing code usable (PositionGetSymbol) on a netting account while your account is an hedging one.
Please read the documentation and search on the forum, this has been asked and answered numerous time.
Change PositionGetSymbol(i) to PositionGetTicket(i)
void CloseAll() { for(int i=PositionsTotal()-1;i>=0; i--) { { if(!trade.PositionClose(PositionGetTicket(i),5)) { Print(PositionGetSymbol(i),"PositionClose() method failed. Return code=",trade.ResultRetcode(), ". Code description: ",trade.ResultRetcodeDescription()); } else { Print(PositionGetSymbol(i),"PositionClose() method executed successfully. Return code=",trade.ResultRetcode(), " (",trade.ResultRetcodeDescription(),")"); } } } }
I'm using the native OrderSend() function in order to open a new position using the below function:
That is working very fine.
However closing an opened position is not working, I tried to loop through orders to close them but OrdersTotal() is always returning zero knowing that there are already opened orders.
on the other hand the PositionsTotal() function is returning the number of opened orders correctly, so I tried to use the CTrade PositionClose() function to close all opened orders as shown below, but it is not closing any order:
it only prints the following:
Here is the full code:
Thanks in advance!!
- 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'm using the native OrderSend() function in order to open a new position using the below function:
That is working very fine.
However closing an opened position is not working, I tried to loop through orders to close them but OrdersTotal() is always returning zero knowing that there are already opened orders.
on the other hand the PositionsTotal() function is returning the number of opened orders correctly, so I tried to use the CTrade PositionClose() function to close all opened orders as shown below, but it is not closing any order:
it only prints the following:
Here is the full code:
Thanks in advance!!