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:
void OnTick() { MqlDateTime now; datetime current_time=TimeCurrent(); TimeToStruct(current_time,now); if (PositionsTotal() > 0) { if (now.hour > 15) { CloseAllPositions(); }; }; ExtExpert.OnTick(); }
Calling a function:
void CloseAllPositions() { CTrade c_trade; for(int i=PositionsTotal()-1;i>=0;i--) { int ticket=PositionGetTicket(i); c_trade.PositionClose(i); } }
It does not seem to be working… Any ideas?