problem with ibarshift getting values from higher timeframes in strategy tester

Back to topics list  | 1 2 3 To post a new topic, please log in or register
jjc 2016.10.07 17:42 #
It should work with W1.

Er, no. Thinking about it, it will round to a Thu-Wed week, not Sun-Sat. The following should work on all periods:

datetime RoundTime(datetime tm) {
   switch (Timeframe) {
      case PERIOD_MN1:
         return tm - (tm % 86400) - ((TimeDay(tm) - 1) * 86400);
      case PERIOD_W1:
         return tm - (tm % 86400) - (TimeDayOfWeek(tm) * 86400);
         return tm - (tm % (Timeframe * 60));


jjc 2016.10.07 18:28 #

This works well for the low /medium timeframes, however I'm not sure it will map correctly to the Weekly and Monthly boundaries

v3 attached, changing the RoundTime() function as above, and adding another couple of improvements (described in notes in the code's header).



I also profiled it and the overhead is smaller than I expected.

It's faster than I was expecting. For example, the performance of its internal MTF_iBarShift seems extremely close to that of MT4's own iBarShift - around half a microsecond per call, on my computer.

I had wondered whether storing the bar table in a hashtable might be a better approach, but I don't believe that anything written in and reliant on MQL4 is going to match the speed which it gets from being able to use the platform's own native-code ArrayBsearch. 

Attached files:
  timeseries-visualmode-fixup-3.mqh  (35.48 KB)
Back to topics list   | 1 2 3  

To add comments, please log in or register