If you come from MT4, I suppose you are using an hedging account (please check as it could also be a netting account which is working differently).
With an hedging account, you have to specify the position ticket to close a given position, also you have to specify an opposite deal.
Forum on trading, automated trading systems and testing trading strategies
Alain Verleyen, 2016.04.15 08:07
When
modifying or closing a position in the hedging system, make sure to
specify its ticket (MqlTradeRequest::ticket). You can specify a ticket
in the netting system as well, however positions are identified by a
symbol name.
MetaTrader 5 features hedging position accounting system
- 2016.03.21
- MetaQuotes Software Corp.
- www.mql5.com
In order to expand possibilities of retail Forex traders, we have added the second accounting system — hedging. Now, it is possible to have multiple positions per symbol, including oppositely directed ones. This paves the way to implementing trading strategies based on the so-called "locking" — if the price moves against a trader, they can open a position in the opposite direction.
Thanks Alain,
i have an heding account, but what is wrong on my code?
accorrding the MQL documentation it should work, but it doesnt
Amando
amando:
Not it should not work, I suggest you to read the links I provided, it's all explained. Come back with your modified code if you still have difficulties.
Thanks Alain,
i have an heding account, but what is wrong on my code?
accorrding the MQL documentation it should work, but it doesnt
Amando
for(k=PositionsTotal()-1;k>=0;k--)
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
Hello,
i try to convert my EA from MT4 to MT5 and now i have the problem to close all position, in MT4 it was easy to say at a spezific time to close everything.
now on mt5 i use following code
{
if(PositionSelect(_Symbol)==true)
{
for(k=0;k<=PositionsTotal();k--)
{
ClosePosition();
}
}
}
in this case i use for the time
{
MqlDateTime tm;
TimeCurrent(tm);
return(tm.min);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Sekunde()
{
MqlDateTime tm;
TimeCurrent(tm);
return(tm.sec);
}
and for Position Close
{
MqlTradeRequest CloseOrder={0};
MqlTradeResult result;
//--- setting request
CloseOrder.symbol = _Symbol;
CloseOrder.deviation = 300;
return(OrderSendAsync(CloseOrder,result));
}
does anyone have an idea why its not working?
amando