Hi people!
I am still a newbie (35 days) of MQL5, so please be patient.
I assembled a simple EA with the Wizard -> Expert Advisor (generate), using intraday time filter (ITF), trailing and fixed trailing volume. However, I want all trades be closed as 16:00, and decided to change the code:
Calling a function:
It does not seem to be working... Any ideas?
c_trade.PositionClose(i)
That function can be called by passing a symbol name (a string), or a ticket number. you are passing the index of the position.
Nice and clean question asking. :like:
That function can be called by passing a symbol name (a string), or a ticket number. you are passing the index of the position.
c_trade.PositionClose(ticket);
void CloseAllPositions() { CTrade c_trade; for(int i=PositionsTotal()-1;i>=0;i--) { int ticket=PositionGetTicket(i); c_trade.PositionClose(ticket); } }
I would use OnTimer() to determine when 16:00 occurred. With OnTick, you must wait until a tick comes in.
Also, this may be of use:
https://www.mql5.com/en/docs/standardlibrary/expertclasses/expertbaseclasses/cexpert/cexpertcloseall
I would use OnTimer() to determine when 16:00 occurred. With OnTick, you must wait until a tick comes in.
Also, this may be of use:
https://www.mql5.com/en/docs/standardlibrary/expertclasses/expertbaseclasses/cexpert/cexpertcloseall
Great! But I still prefer OnTick() so I can simulate better on Strategy Tester, albeit it makes the code sluggish. I will try as you said.
I would use OnTimer() to determine when 16:00 occurred. With OnTick, you must wait until a tick comes in.
Also, this may be of use:
https://www.mql5.com/en/docs/standardlibrary/expertclasses/expertbaseclasses/cexpert/cexpertcloseall
OnTimer() { MqlDateTime TradeServerTime; TimeTradeServer(TradeServerTime); (int(TradeServerTime.hour)+int(TradeServerTime.min)/60) > 16.15 && (OrdersTotal() || PositionsTotal) ? expert.CloseAll() }
Like this?
Hi people!
I am still a newbie (35 days) of MQL5, so please be patient.
I assembled a simple EA with the Wizard -> Expert Advisor (generate), using intraday time filter (ITF), trailing and fixed trailing volume. However, I want all trades be closed as 16:00, and decided to change the code:
Calling a function:
It does not seem to be working... Any ideas?
TimeCurrent();
Because it will use local time, instead of trade server time
TimeTradeServer();
Warning: I now use MqlDateTime TradeServerTime; instead of
Because it will use local time, instead of trade server time
it's not local time.
these are 3 different times. (though can be same) TimeLocal() , TimeCurrent() , TimeTradeServer()
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi people!
I am still a newbie (35 days) of MQL5, so please be patient.
I assembled a simple EA with the Wizard -> Expert Advisor (generate), using intraday time filter (ITF), trailing and fixed trailing volume. However, I want all trades be closed as 16:00, and decided to change the code:
Calling a function:
It does not seem to be working... Any ideas?