程序库: BestInterval - 页 24

 
Enrique Dangeroux:
小的外观修正,int => bool。或者,我建议用返回 AmountDeleteIntervals 代替。

谢谢,我们会解决这个问题的。

 

请考虑将 AverageHolding 添加到程序库中

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:

请考虑将 AverageHolding 加入图书馆

平仓头寸 的平均持仓 时间--它有什么用?

不应该这样计算。您需要知道平仓时间。

 
fxsaber:

平仓 的平均寿命--它有什么用?

我指的是头寸的平均使用时间(OrderCloseTime - OrderOpentime)。这可以作为自定义 GA 标准。例如,引导 GA 增加交易频率,同时设定每笔交易的最低利润阈值。


fxsaber

不是这样计算的。您需要知道收盘时间。

对于 DEAL IN / OUT 净额结算账户,开仓时间足以进行计算,但要正确执行,您需要使用平仓时间,而目前库中没有考虑到这一点。

还有一个问题将继续存在。测试仪强制关闭最后一个位置。并非所有策略都需要原子钟精度,但这仍然是一个问题。此外,GA 还可以通过简单地在 BestInterval.GetTotal () <xxx 时返回 0 来提高交易频率,例如您在某些帖子中写到的那样。

这样看起来不值得,而麻烦却在追逐。

 
Enrique Dangeroux:

我指的是头寸的平均有效时间(OrderCloseTime - OrderOpentime)。这可以作为自定义 GA 标准。例如,引导 GA 增加交易频率,同时设定每笔交易的最低利润阈值。

优化标准 作为 OnTester 函数的示意源代码给出。

 

关于交易、自动交易系统和测试交易策略的论坛

库:BestInterval

fxsaber, 2019.12.05 13:48 PM.

说我很高兴显然是轻描淡写....。BestInterval现在棒极了。而且改动很小。一如既往,举个例子。


下面是一个 24 小时通行证。


我们应用经典的 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

我们可以看到,利润增加了三分之一,其他指标也变得更好了。


但我们需要灵活性。就是这样。

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


利润没有增加,反而减少了!但看看其他指标。我们并没有找到利润最高、契合概率最高的区间,而是找到了一个更窄的区间,但比经典区间更有味道。


创新是这样添加的

#define  BESTINTERVAL_SLIPPAGE // 创建一个人工过滤器来计算最佳时间间隔。


现在,市场模式研究的质量有了很大提高。对多人测试工作具有重大意义。


有趣的是,如果把找到的如此美味的区间塞进 TS 中,并开始优化它以获得其中的最大利润,就很有可能找到一个狗屁区间。


还有一点。例如,BestInterval 会忽略从午夜到一小时内开启的交易。这并不意味着,如果在两点钟出现开仓信号,BestInterval 就会让您开仓。只有当从午夜开始被忽略的头寸被 "关闭 "时,Bibla 才会打开它。因此,您经常可以看到,用严格设定的时间间隔优化 TS 得到的结果比 BestInterval 显示的结果更糟糕。


最明显的例子是趋势上的反趋势 TS。假设 TS 发出卖出信号,而趋势正在上升。BestInterval 将忽略这些信号。

 

根据我的经验,我发现了这样一个特点。


如果优化标准 与轮廓曲线的平滑度无关。而最佳结果仍然是一条平滑的曲线,那么这就不是拟合。

例如,标准是最大利润。而最佳通过结果是一条笔直向上的曲线。这就不是拟合。

但如果标准是最小 R^2。而最佳通过结果是一条笔直向上的曲线。这可能是符合条件的。


我现在进退两难,BestInterval 到底是不是一个独立的优化标准?尤其是它的 "滑动分配 "技巧。

 
以上是一个具体的例子。我在欧元兑美元(EURUSD)上进行了 24 小时 TS 优化,使用了 BestInterval 和 SlipPage ~ -12 点。图片如下
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

也就是说,如果忽略所有不在 18:00-12:00 时间段内的交易,历史上的一切都将是美好的。


我将这一区间缝合到 TS 中,使 TS 不再全天候运行,并对其进行优化,以获得最大利润。

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

说得难听点,最好的遗传学传授就是垃圾。


ZY 这仍然是一个很弱的例子。当 BestInterval 的 PF > 3 而 Optimiser 的 PF < 1 时,就会出现这种情况。

 
fxsaber:

我有一个难题,BestInterval 是否是一个独立的优化标准?尤其是在使用 Slippage 任务芯片时。

事实上,Slippage 是一种佣金。佣金越高,BestInterval 在历史记录上显示的结果就越漂亮。

看来,佣金与市场模式无关。

 

关于交易、自动交易系统和测试交易策略的论坛

专家顾问:验证

fxsaber, 2020.08.23 07:44 AM

我写的时候可能没考虑到 CloseBy 交易。我什么都不记得了。很可能 BestInterval 也有同样的问题。我还没准备好编辑它。感谢您提供的信息。


看来你是对的。BestInterval 在潜在利润以及净额结算和套期保值的时间间隔方面给出了不同的结果。我还没有查看细节,但交易列表乍一看并不正确,CloseBy 平仓的开仓时间大多落在平仓订单的开仓时间上。