Libraries: BestInterval - page 24

 
Enrique Dangeroux:
Minor cosmetic fix, int => bool. Or if I may suggest returning AmountDeleteIntervals instead.

Thanks, will have to fix that.

 

Please consider AverageHolding as an addition to the library

Interval.mqh

  datetime AverageHolding;

  void CalculateFinal( void )
  {
    this.ProfitMinus = this.Profit - this.ProfitPlus;

    this.ProfitFactor = this.ProfitMinus ? -this.ProfitPlus / this.ProfitMinus : DBL_MAX;
    this.Mean = this.Total ? this.Profit / this.Total : 0;

    this.TotalMinus = this.Total - this.TotalPlus;
    
    this.AverageHolding = this.Total ? this.AverageHolding / this.Total : 0;

    return;
  }

  void Calculate( const DEAL &Deals[], const int Left, const int Right )
  {
    this.Init();

    for (int i = Left; i < Right; i++)
      if (!Deals[i].IsNull())
      {
        if (Deals[i].Profit > 0)
        {
          this.ProfitPlus += Deals[i].Profit;

          this.TotalPlus++;
        }
        
        this.AverageHolding += Deals[i+1].OpenTime - Deals[i].OpenTime;
        this.Profit += Deals[i].Profit;
        this.Total++;
      }

    this.CalculateFinal();

    this.OpenTime = Deals[Left-1].OpenTime + 1;
    this.CloseTime = Deals[Right].OpenTime - 1;

    
    return;
  }



BestInterval.mqh

#define  MACROS_GET(A, B)         \
  B Get##A( void ) const         \
  {                              \
    return(this.FullInterval.A); \
  }

  MACROS_GET(Profit, double)
  MACROS_GET(ProfitPlus, double)
  MACROS_GET(ProfitMinus, double)

  MACROS_GET(Total, int)
  MACROS_GET(TotalPlus, int)
  MACROS_GET(TotalMinus, int)

  MACROS_GET(ProfitFactor, double)
  MACROS_GET(Mean, double)

  MACROS_GET(MaxDrawDown, double)
  MACROS_GET(RecoveryFactor, double)
  
  MACROS_GET(AverageHolding, datetime)
#undef  MACROS_GET
 
Enrique Dangeroux:

Please consider AverageHolding as an addition to the library

Average life time of a closed position - what is it for?

This is not how it should be calculated. You need to know the closing time.

 
fxsaber:

Average lifetime of a closed position - what is it for?

I am referring to the average life time of a position (OrderCloseTime - OrderOpentime). This can be useful as custom GA criteria. For example, lead GA to increase transaction frequency combined with a minimum profit per transaction threshold.


fxsaber:

That's not how to calculate it. You need to know the closing time.

For the DEAL IN / OUT netting account the open time is sufficient for calculation, for proper implementation you need to use the close time, which is currently not accounted for in the library.

There is a problem that will remain. The tester forces the closing of the last position. Atomic clock accuracy may not be needed for all strategies, it will remain a problem. Also GA can be driven to a higher trading frequency by simply returning 0 when BestInterval.GetTotal () <xxx, for example as you wrote in some post.

That way it looks not worth it while trouble is chasing.

 
Enrique Dangeroux:

I am referring to the average life time of the position (OrderCloseTime - OrderOpentime). This can be useful as custom GA criteria. For example, lead GA to increase transaction frequency combined with a minimum profit per transaction threshold.

Give the optimisation criterion as a schematic source code of the OnTester function.

 

Forum on trading, automated trading systems and testing trading strategies

Libraries: BestInterval

fxsaber, 2019.12.05 13:48 PM.

To say I'm pleased is clearly an understatement.... BestInterval is awesome now. And the changes are minimal. As always, an example.


Here's a 24-hour pass.


We apply the classic BestInterval.

Profit = 8018.00 = 8018.00 + 0.00 (0.00%) - Amount of Delete Intervals = 0 (2019.09.14 - 2019.12.04)
00:00:00 - 23:59:59 : Profit = 8018.00 (100.00%), Total = 739 (73.34%), PF = 1.44, Mean = 10.85, DD = 1317.00, RF = 6.09
SUMMARY: 00:00:00 - 23:59:59 : Profit = 8018.00 (100.00%), Total = 739 (73.34%), PF = 1.44, Mean = 10.85, DD = 1317.00, RF = 6.09

Profit = 10721.00 = 8018.00 + 2703.00 (33.71%) - Amount of Delete Intervals = 1 (2019.09.14 - 2019.12.04), 13:00 - 08:00, CountHours = 18
00:00:00 - 08:03:48 : Profit = 3278.00 (30.58%), Total = 161 (79.50%), PF = 2.21, Mean = 20.36, DD = 518.00, RF = 6.33
13:07:59 - 23:59:59 : Profit = 7443.00 (69.42%), Total = 389 (74.55%), PF = 2.14, Mean = 19.13, DD = 417.00, RF = 17.85
SUMMARY: 00:00:00 - 23:59:59 : Profit = 10721.00 (100.00%), Total = 550 (76.00%), PF = 2.16, Mean = 19.49, DD = 536.00, RF = 20.00

We can see that the profit has increased by one third, and other indicators have become better.


But we wanted flexibility. And here it is.

Profit = 8018.00 = 8018.00 + 0.00 (0.00%) - Amount of Delete Intervals = 0 (2019.09.14 - 2019.12.04)
00:00:00 - 23:59:59 : Profit = 8018.00 (100.00%), Total = 739 (73.34%), PF = 1.44, Mean = 10.85, DD = 1317.00, RF = 6.09
SUMMARY: 00:00:00 - 23:59:59 : Profit = 8018.00 (100.00%), Total = 739 (73.34%), PF = 1.44, Mean = 10.85, DD = 1317.00, RF = 6.09

Profit = 4868.00 = 8018.00 + -3150.00 (-39.29%) - Amount of Delete Intervals = 1 (2019.09.14 - 2019.12.04), 20:00 - 01:00, CountHours = 4
00:00:00 - 01:31:54 : Profit = 1067.00 (21.92%), Total = 32 (87.50%), PF = 4.63, Mean = 33.34, DD = 177.00, RF = 6.03
19:29:54 - 23:59:59 : Profit = 3801.00 (78.08%), Total = 118 (83.90%), PF = 5.53, Mean = 32.21, DD = 249.00, RF = 15.27
SUMMARY: 00:00:00 - 23:59:59 : Profit = 4868.00 (100.00%), Total = 150 (84.67%), PF = 5.29, Mean = 32.45, DD = 310.00, RF = 15.70


Profit didn't increase, it decreased! But look at the other indicators. Instead of finding the interval with the highest profit and probability of fitting, a much narrower interval was found, but much tastier than the classic.


The innovation is added like this

#define  BESTINTERVAL_SLIPPAGE // Creating an artificial filter to calculate BestInterval.


The quality of market pattern research is now very much improved. Significant implications for multi-tester work.


It is interesting that if the found so tasty interval is stuffed into the TS and start optimising it for maximum profit in it, there is a high probability that a bullshit will be found.


And another remark. BestInterval, for example, ignores trades opened from midnight to one hour. This does not mean that if a signal for opening comes at two o'clock, BestInterval will let you open it. Bibla will only open it if the ignored position from midnight is "closed". Therefore, you can often see that optimising a TS with a rigidly set interval gives worse results than BestInterval shows.


The most obvious example is a counter-trend TS on a trend. Let's assume that the TS gives a SELL signal and the trend is going up. BestInterval will ignore these signals.

 

I have noticed such a peculiarity, which is based on my experience.


If the Optimisation criterion has nothing to do with the smoothness of the profile curve. And the best result still gives a smooth curve, then it is not a fitting.

For example, the criterion is maximum profit. And the best pass results in a straight upward curve. That's not a fit.

But if the criterion is minimum R^2. And the best pass results in a straight up. That's probably a fit.


I have a dilemma, is BestInterval an independent Optimisation criterion or not? Especially with its Slippage assignment trick.

 
A specific example of the above. I took a 24-hour TS and optimised it on EURUSD, using BestInterval and SlipPage ~ -12 pips. This is the picture.
Profit = 490.00 = 490.00 + 0.00 (0.00%) - Amount of Delete Intervals = 0 (2020.07.01 - 2020.08.14)
00:00:00 - 23:59:59 : Profit = 490.00 (100.00%), Total = 183 (69.95%), PF = 1.03, Mean = 2.68, DD = 2441.00, RF = 0.20
SUMMARY: 00:00:00 - 23:59:59 : Profit = 490.00 (100.00%), Total = 183 (69.95%), PF = 1.03, Mean = 2.68, DD = 2441.00, RF = 0.20

Profit = 4858.00 = 490.00 + 4368.00 (891.43%) - Amount of Delete Intervals = 1 (2020.07.01 - 2020.08.14), 18:00 - 12:00, CountHours = 17
00:00:00 - 11:42:21 : Profit = 2925.00 (60.21%), Total = 68 (75.00%), PF = 1.89, Mean = 43.01, DD = 847.00, RF = 3.45
17:53:40 - 23:59:59 : Profit = 1933.00 (39.79%), Total = 36 (77.78%), PF = 2.06, Mean = 53.69, DD = 859.00, RF = 2.25
SUMMARY: 00:00:00 - 23:59:59 : Profit = 4858.00 (100.00%), Total = 104 (75.96%), PF = 1.95, Mean = 46.71, DD = 916.00, RF = 5.30

I.e. he says that if you ignore all trades that do not fall within the 18:00-12:00 interval, everything will be beautiful on the history.


I sew this interval into the TS, making the TS no longer round-the-clock, and optimise it for maximum profit.

Profit = 1924.00 = 1924.00 + 0.00 (0.00%) - Amount of Delete Intervals = 0 (2020.07.01 - 2020.08.14)
00:00:00 - 23:59:59 : Profit = 1924.00 (100.00%), Total = 163 (69.94%), PF = 1.20, Mean = 11.80, DD = 2075.00, RF = 0.93
SUMMARY: 00:00:00 - 23:59:59 : Profit = 1924.00 (100.00%), Total = 163 (69.94%), PF = 1.20, Mean = 11.80, DD = 2075.00, RF = 0.93

The best pass of genetics is, to put it mildly, rubbish.


ZY This is still a weak example. It occurs when BestInterval has PF > 3 and Optimiser gives PF < 1.

 
fxsaber:

I have a dilemma, is BestInterval an independent Optimisation criterion or not? Especially with its Slippage task chip.

In fact, Slippage is a commission. The higher the commission, the prettier the result BestInterval shows on the history.

It seems that the commission has nothing to do with market patterns.

 

Forum on trading, automated trading systems and testing trading strategies

Expert Advisors: Validate

fxsaber, 2020.08.23 07:44 AM

Probably didn't count on CloseBy trades when I wrote it. I don't remember anything anymore. It is quite likely that BestInterval has the same ailment. I'm not ready to edit it. Thanks for the information.


It looks like you are right. BestInterval gives different results both in terms of potential profit and time intervals for netting and hedging. I haven't looked at the details yet, but the Deals list looks incorrect at first glance, the opening time for CloseBy closes mostly falls on the opening time of the closing order.