Hello
my EA is Multicurrency trdaing.
I have wrote this code to close all open positions . but some times the trade.positionclose(ticket,-1) doesnt work . i wirite print symbol of index i and find that sometimes it print null for index i.
the backtest log is so :
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =EURUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =AUDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =GBPUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =NZDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =EURUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =AUDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =GBPUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =NZDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =EURUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =AUDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =GBPUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =NZDUSDi
what is my problem .
Im gratefull for your Help
You are missing a PositionSelect() or PositionSelectByTicket()
Dominik Egert:
You are missing a PositionSelect() or PositionSelectByTicket()
i added PositionSelectByTicket() but the problem exist yet ;
void closeall(ulong magic) { int total = PositionsTotal(); for (int i=0 ; i < total ;i++ ) { ulong ticket = PositionGetTicket(i); PositionSelectByTicket(ticket); Print("symbol =" , PositionGetString(POSITION_SYMBOL) ); trade.PositionClose(ticket,-1); // CTrade trade } }
i added PositionSelectByTicket() but the problem exist yet ;
OK, here is the doc:
https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade
and for the function you are using:
https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradepositionclose
For the parameters you are passing in, -1 is a signed long integer and the doc says its an unsigned long integer.
But to resolve your problem, read the note in the doc.
Check the result of your request and try to find the reason for a failed execution there.

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
my EA is Multicurrency trdaing.
I have wrote this code to close all open positions . but some times the trade.positionclose(ticket,-1) doesnt work . i wirite print symbol of index i and find that sometimes it print null for index i.
the backtest log is so :
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =EURUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =AUDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =GBPUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =NZDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.18 06:09:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =EURUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =AUDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =GBPUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =NZDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 05:39:00 symbol = = =
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =EURUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =AUDUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =GBPUSDi
2021.04.11 14:12:47.491 Core 1 2020.02.19 06:11:00 symbol = = =NZDUSDi
what is my problem .
Im gratefull for your Help