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

 
fxsaber:

标准指标(文章中只讨论了这些指标)是以基本方式缓存的!因为所有输入参数都是已知的。

要写出一个通用的哈希函数是很困难的。但文章并不要求这样做。它处理的是最简单的情况。即使是最简单的情况,也没有哈希函数。

MACD 样本 4 至 5 MQL4 style.mq5


无缓存

i = 0 Pass = 0 OnTester = 15.070 s.: Count = 9753093, 647186.0 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 14.969 s.: Count = 9753093, 651552.7 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


使用愚蠢的缓存

i = 0 Pass = 0 OnTester = 11.073 s.: Count = 9753093, 880799.5 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 11.007 s.: Count = 9753093, 886080.9 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


如果不做任何俏皮话(正面),速度会快 25%。对上述方法 "效率低下 "的 批评是有道理的。

 
能给我看看代码吗?
 
Rashid Umarov:
可以显示代码吗?
template <typename T>
struct HANDLE
{
private:  
  int Handle;
  
  T Inputs;

public:  
  HANDLE() : Handle(INVALID_HANDLE)
  {
  }
  
  bool operator ==( const T &Inputs2 ) const
  {
    return(this.Inputs == Inputs2);
  }
  
  void operator =( const T &Inputs2 )
  {
    this.Inputs = Inputs2;
  }
  
  int GetHandle()
  {
    return((this.Handle != INVALID_HANDLE) ? this.Handle : (this.Handle = this.Inputs.GetHandle()));
  }
};

template <typename T>
int GetHandle( HANDLE<T> &Handles[], const T &Inputs )
{
  const int Size = ArraySize(Handles);
  
  for (int i = 0; i < Size; i++)
    if (Handles[i] == Inputs)
      return(Handles[i].GetHandle());

  ArrayResize(Handles, Size + 1);
  Handles[Size] = Inputs;
  
  return(Handles[Size].GetHandle());
}

struct MACD
{
  string             symbol;
  ENUM_TIMEFRAMES    period;
  int                fast_ema_period;
  int                slow_ema_period;
  int                signal_period;
  ENUM_APPLIED_PRICE applied_price;
  
  MACD( void )
  {
  }
  
  MACD( const string             &isymbol,
        const ENUM_TIMEFRAMES    &iperiod,
        const int                &ifast_ema_period,
        const int                &islow_ema_period,
        const int                &isignal_period,
        const ENUM_APPLIED_PRICE &iapplied_price ) : 
        symbol((isymbol == NULL) || (isymbol == "") ? _Symbol : isymbol),
        period(iperiod == PERIOD_CURRENT ? ::Period() : iperiod),
        fast_ema_period(ifast_ema_period),
        slow_ema_period(islow_ema_period),
        signal_period(isignal_period),
        applied_price(iapplied_price)     
  {
  }
  
  int GetHandle( void ) const
  {
    return(::iMACD(this.symbol, this.period, this.fast_ema_period, this.slow_ema_period, this.signal_period, this.applied_price));
  }
  
  bool operator ==( const MACD &Inputs ) const
  {
    return((this.symbol == Inputs.symbol) &&
           (this.period == Inputs.period) &&
           (this.fast_ema_period == Inputs.fast_ema_period) &&
           (this.slow_ema_period == Inputs.slow_ema_period) &&
           (this.signal_period == Inputs.signal_period) &&
           (this.applied_price == Inputs.applied_price));
  }  
};

struct MA
{
  string             symbol;
  ENUM_TIMEFRAMES    period;
  int                ma_period;
  int                ma_shift;
  ENUM_MA_METHOD     ma_method;
  ENUM_APPLIED_PRICE applied_price;
  
  MA( void )
  {
  }
  
  MA( const string             &isymbol,
      const ENUM_TIMEFRAMES    &iperiod,
      const int                &ima_period,
      const int                &ima_shift,
      const ENUM_MA_METHOD     &ima_method,
      const ENUM_APPLIED_PRICE &iapplied_price ) :
      symbol((isymbol == NULL) || (isymbol == "") ? _Symbol : isymbol),
      period(iperiod == PERIOD_CURRENT ? ::Period() : iperiod),
      ma_period(ima_period),
      ma_shift(ima_shift),
      ma_method(ima_method),
      applied_price(iapplied_price)
  {
  }
  
  int GetHandle( void ) const
  {
    return(::iMA(this.symbol, this.period, this.ma_period, this.ma_shift, this.ma_method, this.applied_price));
  }
  
  bool operator ==( const MA &Inputs ) const
  {
    return((this.symbol == Inputs.symbol) &&
           (this.period == Inputs.period) &&
           (this.ma_period == Inputs.ma_period) &&
           (this.ma_shift == Inputs.ma_shift) &&
           (this.ma_method == Inputs.ma_method) &&
           (this.applied_price == Inputs.applied_price));
  }  
};

// iMACD 的 MT5 变体。
int iMACD2( const string             symbol,
            const ENUM_TIMEFRAMES    period,
            const int                fast_ema_period,
            const int                slow_ema_period,
            const int                signal_period,
            const ENUM_APPLIED_PRICE applied_price )
{
  static HANDLE<MACD> Handles[];  
  const MACD Inputs(symbol, period, fast_ema_period, slow_ema_period, signal_period, applied_price);
  
  return(GetHandle(Handles, Inputs));
}            

// iMA 的 MT5 变体。
int iMA2( const string             symbol,
          const ENUM_TIMEFRAMES    period,
          const int                ma_period,
          const int                ma_shift,
          const ENUM_MA_METHOD     ma_method,
          const ENUM_APPLIED_PRICE applied_price )
{
  static HANDLE<MA> Handles[];  
  const MA Inputs(symbol, period, ma_period, ma_shift, ma_method, applied_price);
  
  return(GetHandle(Handles, Inputs));
}            


在 IndicatorsMQL4.mqh 中添加上述代码,并做如下修改

   int handle=iMACD2(symbol,timeframe,fast_ema_period,slow_ema_period,signal_period,applied_price);
//...
   int handle=iMA2(symbol,timeframe,ma_period,ma_shift,ma_method,applied_price);
 
Rashid Umarov:
我希望采用这种方法--我们从指标中取出 OnCalculate,用一个新名称稍作修改,然后将其添加到指标代码中,现在我们就可以将该函数作为 bibilio 函数使用,并将 Expert Advisor 中的参数传递给它。对吗?

我认为我们可以通过一个外层代码将任何指标的源代码与智能交易系统连接起来。然后像使用函数一样使用它们。

我们需要对宏和其他特殊情况稍作处理。此解决方案不会涵盖所有指标。但应该涵盖大部分指标。

 

尝试恢复:

我正在发布我的测量版本。MACD 样本 以一个 5 值作为 Expert Advisor 的基本版本。对其进行了一些小改动。由于所有指标值都收集在一个地方,因此不难进行简单的宏替换:我认为结论显而易见:在 MQL4 模式下调用指标 时,速度降低了 40%。

附加的文件:
 
Yuriy Koptsev:


看看/results/......open - stop is set, then the trawl pulls it over.


这里是图表的一个部分。还有这里的报告。它怎么能为几乎所有ATR * 0.5 (ATR = 80pp)的手设置150点的止损呢?在这样的设置下,止损点永远不应该离该手的开盘价 超过40点....。只有当它高于这个水平时,才会在其上进行交易。
附加的文件:
 
没机会读。
 
已更新,man....
 
 
Vasiliy Sokolov:

恢复尝试:

我正在发布我的测量版本。MACD 样本 以一个 5 值作为 Expert Advisor 的基本版本。对其进行了一些小改动。由于所有指标值都收集在一个地方,因此不难进行简单的宏替换:我认为结论显而易见:在 MQL4 模式下调用指标 时,速度降低了 40%。

您可以恢复(编辑)您的帖子:

调用指标 时,速度要慢 40%。


- 您的代码和测量结果描述都非常漂亮。