You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!