指标: J. F. Ehlers 重心

J. F. Ehlers 重心:

重心振荡器,由 John Ehlers 开发并发表于 "Stocks & Commodities (股票 & 期货)" 杂志 (2002 五月)。

图例.1 重心指标

作者: Nikolay Kositsin

很有用!......我想知道换色的标准。

您好、

这个振荡器很不错,但我用起来有问题。

根据最后一根蜡烛计算出的信号线 末端没有显示出来,因此当前时间总是显示红色。当我重置振荡器时,它会在信号线末端显示一段时间的良好值,但随后又切换回红色(即使它必须显示绿色)。

我该如何解决这个问题?

我试过重新调试,但没有用。

谢谢、

InfiniteDesign

在他看来, 这个指标 可以 与 mehor 、 符号 和时间框架一起使用。
该 指标 参数 的 最佳值是 多少 ?

非常非常感谢这个伟大的指标。

我发现以前的版本和新版本一样有趣、有用,甚至更有用。

能不能把旧版本也移植到 mq5 上?如果可以,我会非常感激。


谢谢

这个指标是非确定性的。在不同的时间两次询问相同的数据点,你会得到不同的答案。越接近当前时间,漂移越大。不一致性可高达 3.7 x 10^-04。
InfiniteDesign:

您好、

这个振荡器很不错,但我用起来有问题。

根据最后一根蜡烛计算出的信号线 末端没有显示出来,因此当前时间总是显示红色。当我重置振荡器时,它会在信号线末端显示一段时间的良好值,但随后又切换回红色(即使它必须显示绿色)。

我该如何解决这个问题?

我试过重新调试,但没有用。

谢谢、

InfiniteDesign

我也有同样的问题...

我试图用该指标创建一个信号,但无法...

有什么帮助吗?


//+------------------------------------------------------------------+
//|COG.mqh | |
//|布鲁诺-皮奥
//|http://www.mql5.com ||
//+------------------------------------------------------------------+
#property copyright "Bruno Pio"
#property link      "http://www.mql5.com"
#property version   "1.00"
#include "..\ExpertSignal.mqh"   // CExpertSignal 位于文件 ExpertSignal 中。
#property tester_indicator "CenterOfGravity.ex5"
// 向导描述开始
//+------------------------------------------------------------------+
//| 类的描述|
//| Title=重心信号|
//| 类型=高级信号|
//| Name=My_COG|
//| ShortName=CG|
//| Class=COG|
//| Page=不需要|
//| 参数=Period_,int,10,指标平均周期
//| 参数=SmoothPeriod,int,3,信号线平滑周期
//| 参数=MA_Method_,ENUM_MA_METHOD,MODE_EMA,信号方法
//| Parameter=AppliedPrice,int,1,Price constant | 参数=应用价格,int,1,价格常数
//+------------------------------------------------------------------+
// 向导描述 结束
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
class COG : public CExpertSignal
  {
private:
CiCustom             m_COG;               // 指标作为一个对象
//--- 可配置的模块参数
   int               m_Period_;           // 指标平均周期
   int               m_SmoothPeriod;      // 信号线平滑周期 
   ENUM_MA_METHOD    m_MA_Method_;        // 信号线平均法
   int               m_AppliedPrice;      // 价格常数
public:
                     COG(void);
                    ~COG(void);
//--- 检查输入数据的正确性
   bool              ValidationSettings();
//-- 为信号模块创建指标和时间序列
   bool              InitIndicators(CIndicators *indicators);
//--- 访问指标数据
   double            CG(const int index)                 const { return(m_COG.GetData(0,index)); }
   double            Signal(const int index)             const { return(m_COG.GetData(1,index)); }   
//--- 检查买入和卖出条件
   virtual int       LongCondition();
   virtual int       ShortCondition();
//--- 设置方法
   void              Period_(int value)               { m_Period_=value;        }
   void              SmoothPeriod(int value)          { m_SmoothPeriod=value;   }
   void              MA_Method_(ENUM_MA_METHOD value) { m_MA_Method_=value;     }
   void              AppliedPrice(int value)          { m_AppliedPrice=value;   }
protected:
   //--- 创建指标
   bool              CreateCOG(CIndicators *indicators);



  };
//+------------------------------------------------------------------+
//| 构造函数|
//+------------------------------------------------------------------+
COG::COG(void) :           m_Period_(10),                // 指标平均周期
                           m_SmoothPeriod(3),            // 信号线平滑周期 
                           m_MA_Method_(MODE_EMA),       // 信号线平均法
                           m_AppliedPrice(1)             // 价格常数
  {
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
COG::~COG()
  {
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//} 检查输入参数,如果一切正常则返回 true。
//+------------------------------------------------------------------+
bool COG:: ValidationSettings()
  {
   //--- 调用基类方法
   if(!CExpertSignal::ValidationSettings())  return(false);
   //--- 检查周期,用于计算 MA 的条数 >=1
   if(m_Period_<1)
     {
      PrintFormat("Incorrect value set for one of the period! Period_=%d",
                  m_Period_);
      return false;
     }
//--- 检查周期,用于计算 MA 的条数 >=1
   if(m_SmoothPeriod<1)
     {
      PrintFormat("Incorrect value set for one of the period! m_SmoothPeriod=%d",
                  m_SmoothPeriod);
      return false;
     }
//--- 快速 MA 平滑类型必须是枚举的四个值之一
   if(m_MA_Method_!=MODE_SMA && m_MA_Method_!=MODE_EMA && m_MA_Method_!=MODE_SMMA && m_MA_Method_!=MODE_LWMA)
     {
      PrintFormat("Invalid type of smoothing of the fast MA!");
      return false;
     }
//--- m_AppliedPrice 必须有效。
   if(m_AppliedPrice<1 || m_AppliedPrice>11) 
     {
      PrintFormat("Invalid type of Price!");
      return false;
     }
//--- 所有检查均已完成,一切正常
   return true;
  }
//+------------------------------------------------------------------+
//| 创建指标|
//| 输入:指向指示符集合的指针
//| 输出:成功则为 true,否则为 false
//+------------------------------------------------------------------+
bool COG::InitIndicators(CIndicators *indicators)
  {
//--- 对 NULL 指标集合进行标准检查
   if(indicators==NULL) return(false);
//-- 在附加过滤器中初始化指标和时间序列
   if(!CExpertSignal::InitIndicators(indicators)) return(false);
//--- 创建我们的指标
   if(!CreateCOG(indicators))                  return(false);   
//-- 达到这一部分,因此函数成功执行,返回 true
   return(true);
  }
//+------------------------------------------------------------------+
//| 创建 "COG "指示器|
//+------------------------------------------------------------------+
bool COG::CreateCOG(CIndicators *indicators)
  {
//--- 检查指针
   if(indicators==NULL) return(false);
//--- 向集合中添加一个对象
   if(!indicators.Add(GetPointer(m_COG)))
     {
      printf(__FUNCTION__+": Error adding an object of the COG");
      return(false);
     }
//--- 设置 COG 参数
   MqlParam parameters[5];
//---
   parameters[0].type=TYPE_STRING;
   parameters[0].string_value="CenterOfGravity.ex5";
   parameters[1].type=TYPE_INT;
   parameters[1].integer_value=m_Period_;                 // 期间
   parameters[2].type=TYPE_INT;
   parameters[2].integer_value=m_SmoothPeriod;            // 信号线平滑周期
   parameters[3].type=TYPE_INT;
   parameters[3].integer_value=m_MA_Method_;              // 信号线平均法
   parameters[4].type=TYPE_INT;
   parameters[4].integer_value=m_AppliedPrice;            // 价格常数
//--- 对象初始化 
   if(!m_COG.Create(m_symbol.Name(),0,IND_CUSTOM,5,parameters))
     {
      printf(__FUNCTION__+": Error initializing the object of the COG");
      return(false);
     }
//--- 缓冲区的数量
   if(!m_COG.NumBuffers(2)) return(false);
//-- 达到这一部分,因此函数成功执行,返回 true
   return(true);
  }
//+------------------------------------------------------------------+
//| 返回买入信号的强度|
//+------------------------------------------------------------------+
int COG::LongCondition()
  {
   int signal=0;
//--- 对于使用刻度线的操作,idx=0;对于使用成形条形图的操作,idx=1
   int idx=StartIndex();
//--- 最后形成的条形图上的 COG 值
   double last_fast_value=CG(idx);
   double last_slow_value=Signal(idx);
//---最后一个(仅一个)形成条形的 COG 值
   double prev_fast_value=CG(idx+1);
   double prev_slow_value=Signal(idx+1);   
//-- 如果 CG > 信号 && CG-1 < 信号-1
   if((last_fast_value>last_slow_value) && (prev_fast_value<prev_slow_value))
     {
      signal=100; // 有买入信号
     }
//--- 返回信号值
   return(signal);
  }
//+------------------------------------------------------------------+
//| 返回卖出信号的强度|
//+------------------------------------------------------------------+
int COG::ShortCondition()
  {
   int signal=0;
//--- 对于使用刻度线的操作,idx=0;对于使用成形条形图的操作,idx=1
   int idx=StartIndex();
//--- 最后形成的条形图上的 COG 值
   double last_fast_value=CG(idx);
   double last_slow_value=Signal(idx);
//---最后一个(仅一个)形成条形的 COG 值
   double prev_fast_value=CG(idx+1);
   double prev_slow_value=Signal(idx+1);   
//--如果 CG < 信号 && CG-1 > 信号-1
   if((last_fast_value<last_slow_value) && (prev_fast_value>prev_slow_value))
     {
      signal=100; // 有卖出信号
     }
//--- 返回信号值
   return(signal);
  }
有趣的是......需要确定战斗条件下的算法

指标编译无误:

并且可以运行

------------------

只需使用固定的 smoothalgorithms.mqh文件 - 查看帖子


Indicators: T3Taotra_HTF
Indicators: T3Taotra_HTF
  • 2016.06.30
  • www.mql5.com
T3Taotra_HTF: Author: Nikolay Kositsin...
Bruno Pio #:
我也有同样的问题……
我从社区获得了太多宝贵的东西,所以想回馈一点。

这是一个非常出色的指标(如果也考虑更高时间周期的趋势的话)。我发给你的是改进版,它的末端不再只是红色,而且在实时图表上能正常更新。

插入代码 时 请使用“代码”按钮(Alt-S)。

这次由版主修正了格式。今后请正确格式化代码;代码格式不规范的帖子可能会被删除。

/*
 * SmoothAlgorithms.mqh 文件必须放置在
 * terminal_data_folder\MQL5\Include 目录下
 */
//+------------------------------------------------------------------+
//|                                            Center of Gravity.mq4 |
//|                      版权所有 © 2007,MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net|
//+------------------------------------------------------------------+
#property copyright “版权所有 © 2007,MetaQuotes Software Corp.”
#property link      "http://www.metaquotes.net"
//---- 指标版本
#property version   "1.00"
//---- 在单独的窗口中绘制指示器
#property indicator_separate_window
//---- 使用三个缓冲区来计算和绘制该指标
#property indicator_buffers 3
//---- 使用了两个图
#property indicator_plots   2
//+----------------------------------------------+
//|  指标绘制参数                |
//+----------------------------------------------+
//---- 将指标 1 绘制为三色线
#property indicator_type1 DRAW_COLOR_LINE
//---- 用作三色线条的颜色
#property indicator_color1 Gray,Lime,Red
//---- 指标1的线是一条连续曲线
#property indicator_style1  STYLE_SOLID
//---- 指标 1 的线宽为 1
#property indicator_width1  1
//---- 显示指标标签 1
#property indicator_label1  "Center of Gravity"
//+----------------------------------------------+
//|  指标绘制参数                |
//+----------------------------------------------+
//---- 将指示器 2 绘制为一条线
#property indicator_type2   DRAW_LINE
//---- 指示线的颜色设为蓝色
#property indicator_color2  Blue
//---- 指标 2 的线条是一条连续曲线
#property indicator_style2  STYLE_SOLID
//---- 指示器 2 的线宽为 1
#property indicator_width2  1
//---- 显示指标线标签 2
#property indicator_label2  "Signal Line"
//---- 线条样式为点划曲线
#property indicator_style2 STYLE_DASHDOTDOT
//+-----------------------------------+
//|  指标输入参数      |
//+-----------------------------------+
enum Applied_price_ //常量的类型
  {
   PRICE_CLOSE_ = 1,     //PRICE_CLOSE
   PRICE_OPEN_,          //PRICE_OPEN
   PRICE_HIGH_,          //PRICE_HIGH
   PRICE_LOW_,           //PRICE_LOW
   PRICE_MEDIAN_,        //PRICE_MEDIAN
   PRICE_TYPICAL_,       //典型价格
   PRICE_WEIGHTED_,      //价格加权
   PRICE_SIMPLE_,//PRICE_SIMPLE_
   PRICE_QUARTER_,       //PRICE_QUARTER_
   PRICE_TRENDFOLLOW0_,  //PRICE_TRENDFOLLOW0_
   PRICE_TRENDFOLLOW1_   //PRICE_TRENDFOLLOW1_
  };
input int Period_=10;                          // 指标平滑周期
input int SmoothPeriod=3;                      // 信号线平滑周期
input ENUM_MA_METHOD MA_Method_=MODE_SMA;      // 信号线求平均法
input Applied_price_ AppliedPrice=PRICE_CLOSE_;// 价格常量
/* ,用于计算指标(1-收盘价,2-开盘价,3-最高价, 4-LOW,
  5-MEDIAN, 6-TYPICAL, 7-WEIGHTED, 8-SIMPLE, 9-QUARTER, 10-TRENDFOLLOW, 11-0.5 * TRENDFOLLOW.) */
//+-----------------------------------+
//---- 动态数组的声明,这些数组进一步
//---- 将用作指示缓冲区
double Ext1Buffer[];
double Ext2Buffer[];
double ColorExt2Buffer[];
//---- 用于开始数据计算的整型变量声明
int StartBar;
//+------------------------------------------------------------------+
//| iPriceSeries 函数说明                                |
//| Moving_Average 类描述                                 | 
//+------------------------------------------------------------------+ 
#include <SmoothAlgorithms.mqh> 
//+------------------------------------------------------------------+
//| 自定义指标初始化函数                         |
//+------------------------------------------------------------------+ 
void OnInit()
  {
//---- 常量的初始化
   StartBar=Period_;
//---- 将 MAMABuffer 动态数组设置为指示器缓冲区
   SetIndexBuffer(0,Ext1Buffer,INDICATOR_DATA);
//---- 创建要在 DataWindow 中显示的标签
   PlotIndexSetString(0,PLOT_LABEL,"Center of Gravity");
//---- 调整指标绘制起始位置
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartBar);
//---- 将动态数组转换为颜色索引缓冲区  
   SetIndexBuffer(1,ColorExt2Buffer,INDICATOR_COLOR_INDEX);
//---- 调整指标绘制起始位置
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,StartBar+1);

//---- 将 FAMABuffer 动态数组设置为指示器数组
   SetIndexBuffer(2,Ext2Buffer,INDICATOR_DATA);
//---- 创建要在 DataWindow 中显示的标签
   PlotIndexSetString(2,PLOT_LABEL,"Signal Line");
//---- 调整指标绘制起始位置
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,StartBar+1);

//---- 指标简称变量的初始化
   string shortname;
   StringConcatenate(shortname,"Center of Gravity(",Period_,")");
//---- 创建用于在单独子窗口和工具提示中显示的名称
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- 设置指标值的显示精度
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//----
  }
//+------------------------------------------------------------------+
//| 自定义指标迭代函数                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,    // 当前时间点历史数据中的K线数量
                const int prev_calculated,// 上一次调用时计算的柱数
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---- 检查小节数是否足以进行计算
   if(rates_total<StartBar) return(0);

//---- 浮点变量的声明 
   double price_,sma,lwma;
//---- 整型变量的声明
   int first1,first2,first3,bar;

//---- 在 OnCalculate() 代码块中初始化指标
   if(prev_calculated>rates_total || prev_calculated<=0)// 检查指标首次开始计算的时间
     {
      first1=0; // 用于计算所有第一循环小节的起始编号
      first2=Period_+1; // 计算所有信号线柱体的起始数值
      first3=Period_+SmoothPeriod+3; // 用于计算所有着色循环条的起始数值
     }
   else // 计算新K线的起始编号
     {
      first1=prev_calculated-1;
      first3=first1;
     }

//---- 修正(补充):在调用 jelvonal(信号线)MASeries 时,“begin” 参数始终
//---- 必须保持相同的“静态”可靠性阈值(Period_+1)——最初是有效的
//---- 原本错误地将它指向了始终变化的“first1”(即当前火花塞索引)
//---- 设置为:在每个实时时钟周期,将其与已处理的蜡烛数据保持一致,从而混淆了
//---- 贝尔索的“数据可信度”逻辑——正因如此才导致系统不稳定/出现错误
//---- 这是jelvonal的实时值,因此只有在进行TF切换(完全重新计算)后,该值才会“得到修正”。
   first2=Period_+1;

//---- Moving_Average 类的变量声明
   static CMoving_Average MA,LWMA,SIGN;

//---- 通道中心线计算的主循环
   for(bar=first1; bar<rates_total; bar++)
     {
      //---- 调用 PriceSeries 函数以获取输入价格“Series”
      price_=PriceSeries(AppliedPrice,bar,open,low,high,close);

      sma=MA.MASeries(0,prev_calculated,rates_total,Period_,MODE_SMA,price_,bar,false);
      lwma=LWMA.MASeries(0,prev_calculated,rates_total,Period_,MODE_LWMA,price_,bar,false);

      Ext1Buffer[bar]=sma*lwma/_Point;
      Ext2Buffer[bar]=SIGN.MASeries(first2,prev_calculated,rates_total,SmoothPeriod,MA_Method_,Ext1Buffer[bar],bar,false);
     }

//---- 信号线着色的主循环
   for(bar=first3; bar<rates_total; bar++)
     {
      ColorExt2Buffer[bar]=0;
      if(Ext1Buffer[bar]<Ext2Buffer[bar])
         ColorExt2Buffer[bar]=2;
      else ColorExt2Buffer[bar]=1;
     }
//----   
   return(rates_total);
  }
//+------------------------------------------------------------------+