Topic: Portfolio Experts Failing Execution at Market Rollover

Hi Popov

I have recently launched 16 Portfolio Experts (containing 5 strategies each) on 16 different currency pairs all trading on the H4 timeframe. I have discovered that trade orders (buy, sell or modify) are failing to execute each day at market open/close (i.e. at rollover). Please refer attached log file.

Initially I launched a similar portfolio on the D1 timeframe but had to abandon it as it would not take any trades.

Any advice would be appreciated.

Many thanks
Mark

Post's attachments

20180613.log 16.33 kb, 6 downloads since 2018-06-14 

You don't have the permssions to download the attachments of this post.

Re: Portfolio Experts Failing Execution at Market Rollover

I'm going to add a function of the EAs to postpone the signals until the broker resumes trading.

Re: Portfolio Experts Failing Execution at Market Rollover

Thank you Popov for the quick response, great support and great service!

4 (edited by geektrader 2018-06-17 21:19:28)

Re: Portfolio Experts Failing Execution at Market Rollover

I´ve requested this already too a while back and since there has been no implementation so far, I´ve added my own one. Here is how you need to modify the portfolio expert MQL4 code:

In the inputs section (right under the "static input int    Base_Magic_Number") of the MQL4 code you add:

extern string TradingBreakFrom = "23:59";
extern string TradingBreakUntil = "00:01";

So it should now look like:

static input double Entry_Amount      = 0.01; // Entry lots
static input int    Base_Magic_Number = 100;  // Base Magic Number
extern string TradingBreakFrom = "23:59";
extern string TradingBreakUntil = "00:01";

Then go ahead and find the "void OnTick()" function. This function is modified like this:

void OnTick()
  {
   if(IsForceSessionClose())
     {
      CloseAllPositions();
      return;
     }

   if(Time[0]>barTime && checkTradingBreak(TradingBreakFrom, TradingBreakUntil) == false)
     {
      barTime=Time[0];
      OnBar();
     }
  }

And at the very end of the MQL4 file, you simply paste these 2 functions:

bool checkTradingBreak(string TimeFrom, string TimeTo)
{
    bool RevertRange = false;

    if (TimeStringToDateTime(TimeTo) < TimeStringToDateTime(TimeFrom))
        RevertRange = true;

    if (RevertRange == false && (TimeCurrent() < TimeStringToDateTime(TimeFrom) || TimeCurrent() > TimeStringToDateTime(TimeTo)))
    {
        return(false);
    }
    else if (RevertRange == true && (TimeCurrent() > TimeStringToDateTime(TimeTo) && TimeCurrent() < TimeStringToDateTime(TimeFrom)))
    {
        return(false);
    }

    return(true);
}

datetime TimeStringToDateTime(string time) {
   string date = TimeToStr(TimeCurrent(),TIME_DATE);//"yyyy.mm.dd"
   return (StrToTime(date + " " + time));
}

Now you can compile the MQL4 code and afterward you can simply set the rollover trading break of your broker in the expert properties (in my case I´ve set 23:59 - 00:01).

Good luck :-)

Re: Portfolio Experts Failing Execution at Market Rollover

Many thanks geektrader, this will be very helpful until Popov can get to this item on his never-ending To Do List!

A great forum, everyone is very helpful, hopefully I can reciprocate in a like manner one day.

Much appreciated.

Cheers
Mark

Re: Portfolio Experts Failing Execution at Market Rollover

Hello GeekTrader,

Thank you for the provided code!

As I see it only prevent trading between the specified time. However, this is not the complete solution. Here is how I see working:
- the expert must detect the rollover time alone (error 132 or similar). It can be a maxRolloverTime limit set to 10 minutes by default.
- it must store this current signal.
- check for re-opening of the trade at every 10 sec for example.
- if the market is re-opened during the specified interval, it must execute a close order. In case of open order, it must check if the market was changed in the trader's favor. If not, it can cancel an entry order (here we can pre-set max negative slippage)
- the EA must write in the log when such conditions happen
- the EA must detect SL, TP and Trailing Stop events also.

There are probably other cases that can be covered also.

Re: Portfolio Experts Failing Execution at Market Rollover

@KiwiTrader: you are most welcome!

@Popov: now that would be very nice, my one is just a quick fix to prevent trading during rollover, if you know when that is (most people can find out easily). Having it all on auto would be even better of course! Storing the signal is a great idea too, but it might be somehwat tricky, because the spread is often high at rollover (on ECN brokers it can easily be ~20 pips or more sometimes). So storing that signal might not be a good idea, because it might simply have been triggered by a spread spike, which never is simulated like that in the EA Studio backtests where we use fixed spreads all the time. I found it to work better if simply waiting +1 minute (most brokers like IC Markets just have such a short rollover protection), then spread is a lot better / more realistic again already and the signal should still be very close at 00:01 compared to what it was at 00:00. But for sure, such an intelligent implementation is the way to go if you have the time to do it :-) But since that might take a while and many trade live (me too), having a simple solution that works right now is better than not handling the rollover at all :-)

Re: Portfolio Experts Failing Execution at Market Rollover

Hi GeekTrader.

Verstehe ich das richtig, daß wenn das Signal eigentlich 0 Uhr kommt, es dann auch 0.01 oder 0.05 Uhr gehandelt wird. Weil wir mit Deinem Code die Zeit verschoben haben?

Danke, Marcus

Re: Portfolio Experts Failing Execution at Market Rollover

Hi Marcus,

es ist einfach so, dass der 00:00 Balken für das EA einfach erst 00:0X nutzbar wird (je nachdem was du eingetragen hast). Das heisst aber auch, dass wenn normalerweise 00:00 ein Signal gekommen wäre (wie dann eben im Backtest), es 00.0X nicht mehr existieren könnte - es wird kein 00:00 Signal gespeichert und dann erst später ausgeführt, sondern der EA wird eben wirklich erst 00:0X gestartet, durch eine Verschiebung des Balkenanfangs auf 00:0X.

Re: Portfolio Experts Failing Execution at Market Rollover

geektrader wrote:

Hi Marcus,

es ist einfach so, dass der 00:00 Balken für das EA einfach erst 00:0X nutzbar wird (je nachdem was du eingetragen hast). Das heisst aber auch, dass wenn normalerweise 00:00 ein Signal gekommen wäre (wie dann eben im Backtest), es 00.0X nicht mehr existieren könnte - es wird kein 00:00 Signal gespeichert und dann erst später ausgeführt, sondern der EA wird eben wirklich erst 00:0X gestartet, durch eine Verschiebung des Balkenanfangs auf 00:0X.

Hi Geektrader,

danke Dir für Deine Antwort. In dem Fall verstehe ich es so, daß die Backtests dann durchaus nicht mit live Handel übereinstimmen könnten.
Wenn Du mal Zeit hast, schau mal noch in meine PM bitte.
Danke smile