文章 "交易员生存技巧: 由指标制作的快餐" - 页 8

 
Rashid Umarov:

PS 我在 USDJPY M30 2017.02.01-2018.01.18 "All ticks"(如文章所述)MetaQuotes-Demo 上运行了标准 MACD 样本。

如何在 8 秒内完成?尤其是1秒钟?

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

讨论文章 "交易员的生活窍门:用指标烹饪快餐"

fxsaber, 2018.01.26 11:06 AM.

什么都没做。按原样运行。在上述日志中重现所有数据。 在利润方面,你的结果应该和我的完全一样。性能方面也不会有太大差别。

 
Rashid Umarov:
真的吗?当你声称在 花钱买来的文章中发现了错误或问题时,我一定会核实的。同时,我们不要 "我们"。因为你说得好像你在颐指气使。
 
fxsaber:

在您的设置中,MACD 从交割开始就变得简单了。余额中的欧元从何而来?

测试时间还是比您的长很多。

2018.01.26 13:34:10.520 Core 1  authorized (agent build 1755)
2018.01.26 13:34:10.522 Tester  EURUSD,M1 (MetaQuotes-Demo): testing of Experts\Examples\MACD\MACD Sample.ex5 from 2017.09.01 00:00 to 2018.01.26 00:00

2018.01.26 13:34:16.792 Core 1  EURUSD,M1 (MetaQuotes-Demo): generating based on real ticks
2018.01.26 13:34:16.792 Core 1  EURUSD,M1: testing of Experts\Examples\MACD\MACD Sample.ex5 from 2017.09.01 00:00 to 2018.01.26 00:00 started with inputs:
2018.01.26 13:34:16.792 Core 1    InpLots=0.1
2018.01.26 13:34:16.792 Core 1    InpTakeProfit=50
2018.01.26 13:34:16.792 Core 1    InpTrailingStop=30
2018.01.26 13:34:16.792 Core 1    InpMACDOpenLevel=3
2018.01.26 13:34:16.792 Core 1    InpMACDCloseLevel=2
2018.01.26 13:34:16.792 Core 1    InpMATrendPeriod=26


2018.01.26 13:25:46.482 Core 1  final balance 10168.90 USD
2018.01.26 13:25:46.482 Core 1  EURUSD,M1: 9753093 ticks, 147480 bars generated. Environment synchronized in 0:00:02.610. 
Test passed in 0:00:19.062 (including ticks preprocessing 0:00:02.078).
2018.01.26 13:25:46.482 Core 1  EURUSD,M1: total time from login to stop testing 0:00:21.672 (including 0:00:02.610 for history data synchronization)
2018.01.26 13:25:46.482 Core 1  600 Mb memory used including 44 Mb of history data, 256 Mb of tick data
 

在文章中的时间框架上,欧元兑美元 M30 和美元兑日元 M30

MACD Sample One value at a time.mq5:

final balance 100180.01 USD
EURUSD,M30: 26390728 ticks, 12510 bars generated. Environment synchronized in 0:00:00.125. Test passed in 0:00:41.016 (including ticks preprocessing 0:00:02.328).
EURUSD,M30: total time from login to stop testing 0:00:41.141 (including 0:00:00.125 for history data synchronization)
756 Mb memory used including 1.88 Mb of history data, 512 Mb of tick data

final balance 99523.31 USD
USDJPY,M30: 29801706 ticks, 11837 bars generated. Environment synchronized in 0:00:00.032. Test passed in 0:01:00.937 (including ticks preprocessing 0:00:02.735).
USDJPY,M30: total time from login to stop testing 0:01:00.969 (including 0:00:00.032 for history data synchronization)
819 Mb memory used including 1.88 Mb of history data, 576 Mb of tick data


MACD Sample 4 to 5 MQL4 style.mq5:

final balance 100192.51 USD
EURUSD,M30: 26390728 ticks, 12510 bars generated. Environment synchronized in 0:00:00.140. Test passed in 0:01:37.969 (including ticks preprocessing 0:00:02.329).
EURUSD,M30: total time from login to stop testing 0:01:38.109 (including 0:00:00.140 for history data synchronization)
755 Mb memory used including 1.88 Mb of history data, 512 Mb of tick data

final balance 99550.10 USD
USDJPY,M30: 29801706 ticks, 11837 bars generated. Environment synchronized in 0:00:00.031. Test passed in 0:01:51.328 (including ticks preprocessing 0:00:02.500).
USDJPY,M30: total time from login to stop testing 0:01:51.359 (including 0:00:00.031 for history data synchronization)
819 Mb memory used including 1.88 Mb of history data, 576 Mb of tick data

测试时间相差两次。而且不是 8 秒或 1 秒。

如果比较余额 - 是的,数字上有细微差别,但在图表上并不明显。

 
Vasiliy Sokolov:

事实上,这里对这一主题的描述是在一个稍有不同的层面上进行的:

  • 数以千计的指标已经编写完成,通过 iCustom 访问,并分配适当的缓冲区/句柄,如此等等。这是一个缓慢且耗费资源的过程;
  • 指标可以作为智能交易系统中的一个纯函数来实现--在这种情况下,所需数值的计算速度会更快,所需的内存也会更少。

我们的想法是编写某种接口,允许统一访问任何自定义指标但如果指标是作为单独的纯函数实现的,则会引用该函数而不是句柄。 这样,我们就能获得良好的加速效果,同时也不会失去对任意指标的访问权限。这是个有趣的话题,我甚至想研究一下。

试一试,看看是否值得。我希望采用这种方法--我们从指标中取出 OnCalculate,用一个新名称稍加修改,然后将其添加到指标代码中,现在我们就可以将该函数作为 bibilio 函数使用,从智能交易系统中向其传递参数。对吗?
 
Rashid Umarov:
......我希望采用这种方法--我们从指标中取出 OnCalculate,用一个新名称稍作修改,然后将其添加到指标代码中,现在我们就可以将该函数作为 bibilio 函数使用,并将 Expert Advisor 中的参数传递给它。对吗?
我们需要考虑如何实现。现在很难说如何实现。
 
Rashid Umarov:
试试吧,看看是否值得。我希望采用这种方法--我们从指标中取出 OnCalculate,用一个新名称稍加修改,然后将其添加到指标代码中,现在我们就可以将该函数作为 bibilio 函数使用,并将 Expert Advisor 中的参数传递给它。对吗?

我在 iRSIOnArray() 中就是这么做的,它不在 mql5 中。它在指标中起作用。要从智能交易系统中调用它,就不能这么直接了。

//+------------------------------------------------------------------+
//| 数组上的相对强弱指数|
//+------------------------------------------------------------------+
template<typename T>
int RSIOnArray(const int rates_total,
               const int prev_calculated,
               const int begin,
               const int period,
               const T &price[],
               double &buffer_pos[],
               double &buffer_neg[],
               double &buffer_rsi[])
  {
   int   i;
   T     diff;
//--- 检查率计数
   if(period<1 || rates_total-begin<period) return(0);
//--- 保存系列标志
   bool as_series_price=ArrayGetAsSeries(price);
   bool as_series_rsi=ArrayGetAsSeries(buffer_rsi);
   if(as_series_price)
      ArraySetAsSeries(price,false);
   if(as_series_rsi)
     {
      ArraySetAsSeries(buffer_rsi,false);
      ArraySetAsSeries(buffer_pos,false);
      ArraySetAsSeries(buffer_neg,false);
     }
//--- 初步计算
   int pos=prev_calculated-1;
   if(pos<=period)
     {
      //--- 不计算指标的第一个 RSIPeriod 值
      buffer_rsi[0]=0.0;
      buffer_pos[0]=0.0;
      buffer_neg[0]=0.0;
      T SumP=0.0;
      T SumN=0.0;
      for(i=1; i<=period; i++)
        {
         buffer_rsi[i]=0.0;
         buffer_pos[i]=0.0;
         buffer_neg[i]=0.0;
         diff=price[i]-price[i-1];
         SumP+=(diff>0 ? diff : 0);
         SumN+=(diff<0 ?-diff : 0);
        }
      //--- 计算第一个可见值
      buffer_pos[period]=double(SumP/period);
      buffer_neg[period]=double(SumN/period);
      
      buffer_rsi[period]=100.0-(100.0/(1.0+buffer_pos[period]/(buffer_neg[period]>0 ? buffer_neg[period] : DBL_MIN)));
      //--- 为主计算准备位置值
      pos=period+1;
     }
//--- 主循环计算
   for(i=pos;i<rates_total && !IsStopped();i++)
     {
      diff=price[i]-price[i-1];
      buffer_pos[i]=(buffer_pos[i-1]*(period-1)+(diff>0.0 ? diff : 0.0))/period;
      buffer_neg[i]=(buffer_neg[i-1]*(period-1)+(diff<0.0 ?-diff : 0.0))/period;
      buffer_rsi[i]=100.0-100.0/(1+buffer_pos[i]/(buffer_neg[i]>0 ? buffer_neg[i] : DBL_MIN));
     }
//--- 恢复 as_series 标志
   if(as_series_price) ArraySetAsSeries(price,true);
   if(as_series_rsi)
     {
      ArraySetAsSeries(buffer_rsi,true);
      ArraySetAsSeries(buffer_pos,true);
      ArraySetAsSeries(buffer_neg,true);
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

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

讨论文章 "交易员的生活黑客:用指标烹饪快餐"

Rashid Umarov, 2018.01.26 11:30 AM

在您的设置中,MACD SaMple来自供应。欧元从何而来?

这不是重点。欧元来自这里


测试时间仍然比您的长很多。

2018.01.26 13:34:10.520 Core 1  authorized (agent build 1755)
2018.01.26 13:34:10.522 Tester  EURUSD,M1 (MetaQuotes-Demo): testing of Experts\Examples\MACD\MACD Sample.ex5 from 2017.09.01 00:00 to 2018.01.26 00:00

2018.01.26 13:34:16.792 Core 1  EURUSD,M1 (MetaQuotes-Demo): generating based on real ticks
2018.01.26 13:34:16.792 Core 1  EURUSD,M1: testing of Experts\Examples\MACD\MACD Sample.ex5 from 2017.09.01 00:00 to 2018.01.26 00:00 started with inputs:
2018.01.26 13:34:16.792 Core 1    InpLots=0.1
2018.01.26 13:34:16.792 Core 1    InpTakeProfit=50
2018.01.26 13:34:16.792 Core 1    InpTrailingStop=30
2018.01.26 13:34:16.792 Core 1    InpMACDOpenLevel=3
2018.01.26 13:34:16.792 Core 1    InpMACDCloseLevel=2
2018.01.26 13:34:16.792 Core 1    InpMATrendPeriod=26


2018.01.26 13:25:46.482 Core 1  final balance 10168.90 USD
2018.01.26 13:25:46.482 Core 1  EURUSD,M1: 9753093 ticks, 147480 bars generated. Environment synchronized in 0:00:02.610. 
Test passed in 0:00:19.062 (including ticks preprocessing 0:00:02.078).
2018.01.26 13:25:46.482 Core 1  EURUSD,M1: total time from login to stop testing 0:00:21.672 (including 0:00:02.610 for history data synchronization)
2018.01.26 13:25:46.482 Core 1  600 Mb memory used including 44 Mb of history data, 256 Mb of tick data

这是我在您的设置下的日志

EURUSD,M1 (MetaQuotes-Demo): generating based on real ticks
EURUSD,M1: testing of Experts\Examples\MACD\MACD Sample.ex5 from 2017.09.01 00:00 to 2018.01.26 00:00 started with inputs:
  InpLots=0.10
  InpTakeProfit=50
  InpTrailingStop=30
  InpMACDOpenLevel=3
  InpMACDCloseLevel=2
  InpMATrendPeriod=26

final balance 10000168.90 USD
EURUSD,M1: 9753093 ticks, 147480 bars generated. Environment synchronized in 0:00:00.031. Test passed in 0:00:06.302.
EURUSD,M1: total time from login to stop testing 0:00:06.333 (including 0:00:00.031 for history data synchronization)
571 Mb memory used including 44 Mb of history data, 256 Mb of tick data


为什么对我来说快了 3.5 倍(反向测试前通过重新编译删除了缓存)--我不知道。配置

2018.01.26 11:45:38.151 Terminal        Alpari Limited MT5 x64 build 1755 started (Alpari Limited)
2018.01.26 11:45:38.151 Terminal        Windows 7 Service Pack 1 (build 7601) x64, IE 9, Intel Core i7-2700 K  @ 3.50 GHz, Memory: 10147 / 16301 Mb, Disk: 3 / 29 Gb, GMT+2

让我们找出原因!我认为这一点非常重要。我没有硬盘(只有固态硬盘)。也许这就是问题所在。但这对 MT5 非常不利。这台电脑已经很老了,肯定有五年了。这就是为什么它很奇怪。

 
Vladimir Karputov:

测试时间相差两倍。而且不是 8 秒或 1 秒。

显示终端启动 日志中的配置行。

 
fxsaber:

我不知道为什么执行速度快了 3.5 倍(反向测试前通过重新编译消除了缓存)。配置

让我们找出原因!我认为这一点非常重要。我没有硬盘(只有固态硬盘)。也许这就是问题所在。但这对 MT5 非常不利。这台计算机已经很老了,肯定有五年历史了。所以才会出现这种奇怪的情况。

这是我的电脑,没有固态硬盘

MetaTrader 5 x64 build 1755 started (MetaQuotes Software Corp.)
Windows 10 (build 16299) x64, IE 11, UAC, Intel Core i7  920 @ 2.67 GHz, Memory: 6613 / 12277 Mb, Disk: 156 / 270 Gb, GMT+3

查看了所有的帖子--刻度数都是一样的

2018.01.26 13:25:46.482 Core 1  final balance 10168.90 USD
2018.01.26 13:25:46.482 Core 1  EURUSD,M1: 9753093  ticks, 147480 bars generated. Environment synchronized in 0:00:02.610. 
Test passed in 0:00:19.062 (including ticks preprocessing 0:00:02.078).
2018.01.26 13:25:46.482 Core 1  EURUSD,M1: total time from login to stop testing 0:00:21.672 (including 0:00:02.610 for history data synchronization)
2018.01.26 13:25:46.482 Core 1  600 Mb memory used including 44 Mb of history data, 256 Mb of tick data