hello guys,
I'm trying a very simple EA that should close position at the end of the week . it enters long when the price is above the last high and exit on friday at 23 or for a stoploss triggered. same thing for short position.
during backtesting it enters and triggers stoplosses but does not close on friday night!!
it's called on every tick and works on weekly bars data.
it's the very first advisor I write, i started by modifing my_first_EA.
I hope someone exeprienced could see at glance my mistake.
the code is below
basically the if(we) PositionClose...is never called it seems it never gets a tick on friday at 23:00 or later...
If trading closes at 23:00 ( going by your Broker's Server time ) then the last tick before the weekend will be before 23:00 on Friday night . . . what time (Broker Server time) does your Broker stop trading on Friday night ?
datetime TimeTradeServer();
Returns the calculated current time of the trade server.
Unlike TimeCurrent(), the calculation of the time value is performed in the client terminal and depends on the time settings on your computer.
There are 2 variants of the function.
- www.mql5.com
my broker fri close one hour earlier
please note that some holidays ends earlier too
hello guys,
I'm trying a very simple EA that should close position at the end of the week . it enters long when the price is above the last high and exit on friday at 23 or for a stoploss triggered. same thing for short position.
during backtesting it enters and triggers stoplosses but does not close on friday night!!
it's called on every tick and works on weekly bars data.
it's the very first advisor I write, i started by modifing my_first_EA.
I hope someone exeprienced could see at glance my mistake.
the code is below
basically the if(we) PositionClose...is never called it seems it never gets a tick on friday at 23:00 or later...
void OnTick() { if(close_end_of_week()) { Close_allpending(symbol_index,POSITION_TYPE_SELL); Close_allpending(symbol_index,POSITION_TYPE_BUY); } } //+------------------------------------------------------------------+ //| Close all positions by opposite positions | //+------------------------------------------------------------------+ void Close_allpending(int symbol_index,ENUM_POSITION_TYPE type) { int total=PositionsTotal(); // number of open positions //--- iterate over all open positions for(int i=total-1; i>=0; i--) { //--- parameters of the order ulong position_ticket=PositionGetTicket(i); // ticket of the position string position_symbol=PositionGetString(POSITION_SYMBOL); // symbol int digits=(int)SymbolInfoInteger(position_symbol,SYMBOL_DIGITS); // ticket of the position ulong magic=PositionGetInteger(POSITION_MAGIC); // MagicNumber of the position //--- if the MagicNumber matches if(magic==EXPERT_MAGIC) { if(position_symbol==PositionGetSymbol(i)) // symbol of the opposite position { //--- if the symbols of the opposite and initial positions match if(position_symbol==symbol_list[symbol_index] && PositionGetInteger(POSITION_MAGIC)==EXPERT_MAGIC) { //--- leave, if the types of the initial and opposite positions match if(type==PositionGetInteger(POSITION_TYPE)) { // close end off week trade.PositionClose(position_ticket); } } } } } } //+------------------------------------------------------------------+ bool close_end_of_week() { MqlDateTime Gmt_time; TimeGMT(Gmt_time); if(chose_stop_end_of_week) if(Gmt_time.hour>=hour_end_week && Gmt_time.day_of_week>=end_week) { return true; } return false; }
result:
before:
after:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello guys,
I'm trying a very simple EA that should close position at the end of the week . it enters long when the price is above the last high and exit on friday at 23 or for a stoploss triggered. same thing for short position.
during backtesting it enters and triggers stoplosses but does not close on friday night!!
it's called on every tick and works on weekly bars data.
it's the very first advisor I write, i started by modifing my_first_EA.
I hope someone exeprienced could see at glance my mistake.
the code is below
basically the if(we) PositionClose...is never called it seems it never gets a tick on friday at 23:00 or later...