Mistake somewhere in work of standard library (a method of the choice of a position). The similar mistake has emerged in the Russian part of a forum: https://www.mql5.com/ru/forum/99060.
Please give such information: reboot the terminal and copy the first three lines from a tab "Journal". Shall be approximately so:
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
For each program a trade environment is prepared at different stages:
For each program a trade environment is prepared at different stages:
The expert version of the test code :
void OnDeinit(const int reason) { }
void OnTick() { CloseAll(); }
#include <Trade\Trade.mqh>
void CloseAll()
{
CTrade trade;
for (int i=PositionsTotal()-1;i>=0; i--)
{
{
if(!trade.PositionClose(PositionGetSymbol(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(),")");
}
}
}
}
The script version of the test code :
#include <Trade\Trade.mqh>
void CloseAll()
{
CTrade trade;
for (int i=PositionsTotal()-1;i>=0; i--)
{
{
if(!trade.PositionClose(PositionGetSymbol(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(),")");
}
}
}
}
These are the versions I have tested. Feel free to test them too.
Forum on trading, automated trading systems and testing trading strategies
trade.PositionClose() is not working
Vladimir Karputov, 2016.10.27 10:26
And another question: what type of account - hedge or netting?Mistake somewhere in work of standard library (a method of the choice of a position). The similar mistake has emerged in the Russian part of a forum: https://www.mql5.com/ru/forum/99060.
Please give such information: reboot the terminal and copy the first three lines from a tab "Journal". Shall be approximately so:
2016.10.28 08:25:41.374 Terminal Windows 10 Pro (x64 based PC), IE 11.00, UAC, Intel Core i3-3120M @ 2.50GHz, RAM: 3698 / 8077 Mb, HDD: 38140 / 233310 Mb, GMT+02:00
2016.10.28 08:25:41.374 Terminal C:\Users\KVN\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
Also specify the name of the trade server to which you are connected, and also account type: hedge or netting.
PositionClose(PositionGetSymbol(i),0.1)) add 0.1=deviation
try it!