乐于分享
好东西不私藏

比普通MA更灵活!自适应均线指标源码来了

比普通MA更灵活!自适应均线指标源码来了

大家好,我是EA侠!

今天这个指标,侠哥觉得用均线的朋友可以看看。均线这个东西大家都不陌生,SMA、EMA这些,刚开始用的时候觉得挺简单,线往上就看多,线往下就看空。

可一到震荡行情,它又特别容易来回拐,一会儿像要涨,一会儿像要跌,最后人都被它看懵了。 

今天这款叫 Cong AMA,自适应移动平均。名字听起来有点专业,其实理解起来没那么难。你可以把它当成一条会“看行情脸色”的均线。 

简单说,就是一边看价格这段时间到底走出了多少空间,一边看行情中间折腾了多少波动。如果价格是真的走出来了,它就会更灵敏;如果只是来回乱晃,它就不会那么容易被带偏。 图上也很好看懂,涨的时候是绿色线,跌的时候是红色线,没什么方向就是灰色线。

平时看盘不用想太复杂,绿色的时候多关注多单机会,红色的时候多关注空单机会,灰色的时候就别太着急。 它还有过滤功能,这个侠哥觉得挺实用。 

比如你本来有自己的进场方法,那就让它先帮你看方向。绿色只找多,红色只找空,灰色少动手。很多时候,少做几单乱单,比多抓一两个机会还重要。 最后还是那句话,指标只是辅助,不是万能的。 

交易别上头,别重仓,先稳住,再谈盈利。 不会安装、不会调参数的可以问侠哥:wzc10106 源码侠哥放下面了,需要的朋友可以自取。

#property copyright ""#property link      ""#property indicator_chart_window#property indicator_buffers 5#property strict//////input int                inpPeriod        = 26;                   // Periodinput ENUM_APPLIED_PRICE inpPrice         = PRICE_CLOSE;          // Price input int                inpFilPer        = 0;                    // Filter period (0 to use Period)input double             inpFilter        = 0;                    // Filter to use for filtering (<=0 for no filtering)enum  enFilterWhat      {         flt_prc,                                                 // price          flt_val,                                                 // value         flt_all                                                  // all       };input enFilterWhat       inpFilOn         = flt_all;              // Apply filter to :input string             __lin__00        = "";                   //.Lines settingsinput int                inpLinesWidth    = 3;                    // Lines widthinput color              inpColorUp       = clrLimeGreen;         // Bullish color for linesinput color              inpColorDn       = clrRed;               // Bearish color for linesinput color              inpColorNu       = clrDimGray;           // Neutral color for linesdouble val[],valc[],valUa[],valUb[],valDa[],valDb[];struct sGlobalStruct{   int      per;   int      lim;   int      fper;   double   pfil;   double   vfil;   double   hh;   double   ll;   double   eff;   double   num;   double   alp;};sGlobalStruct glo;//+------------------------------------------------------------------+//| Custom indicator initialization function                         |//+------------------------------------------------------------------+intOnInit(){   IndicatorBuffers(6);   SetIndexBuffer(0,val,  INDICATOR_DATA); SetIndexStyle(0, DRAW_LINE,EMPTY,inpLinesWidth,inpColorNu);   SetIndexBuffer(1,valUa,INDICATOR_DATA); SetIndexStyle(1, DRAW_LINE,EMPTY,inpLinesWidth,inpColorUp);   SetIndexBuffer(2,valUb,INDICATOR_DATA); SetIndexStyle(2, DRAW_LINE,EMPTY,inpLinesWidth,inpColorUp);   SetIndexBuffer(3,valDa,INDICATOR_DATA); SetIndexStyle(3, DRAW_LINE,EMPTY,inpLinesWidth,inpColorDn);   SetIndexBuffer(4,valDb,INDICATOR_DATA); SetIndexStyle(4, DRAW_LINE,EMPTY,inpLinesWidth,inpColorDn);   SetIndexBuffer(5,valc,INDICATOR_CALCULATIONS);   glo.per  = fmax(inpPeriod,1);   glo.fper = (glo.fper<=0)       ? inpPeriod : inpFilPer;   glo.pfil = (inpFilOn==flt_val) ? 0         : inpFilter;   glo.vfil = (inpFilOn==flt_prc) ? 0         : inpFilter;   IndicatorSetString(INDICATOR_SHORTNAME,"Cong AMA("+(string)inpPeriod+")");return(INIT_SUCCEEDED);  }//+------------------------------------------------------------------+//| Custom indicator iteration function                              |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,                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[]){   glo.lim = fmin(rates_total-prev_calculated+1,rates_total-1);    //   //   //   struct sWrkStruct    {        double prc;       double tem;   };      static sWrkStruct wrk[];   static int        wrkSize = -1;                 if (wrkSize<=rates_total) wrkSize = ArrayResize(wrk,rates_total+500,2000);   //   //   //   if(valc[glo.lim]== 1) iCleanPoint(glo.lim,rates_total,valUa,valUb);   if(valc[glo.lim]==-1) iCleanPoint(glo.lim,rates_total,valDa,valDb);     for(int i=glo.lim, r=rates_total-glo.lim-1; i>=0; i--,r++)   {      wrk[r].prc  = iFilter(iMA(_Symbol,_Period,1,0,MODE_SMA,inpPrice,i),glo.pfil,glo.fper,r,rates_total,0);      wrk[r].tem  = (r>0) ? fmax(high[i],close[i+1])-fmin(low[i],close[i+1]) : high[i]-low[i];      glo.hh      = high[ArrayMaximum(high,glo.per)];      glo.ll      =  low[ArrayMinimum( low,glo.per)];      glo.eff     = 0; for(int k=0; k<glo.per && (r-k)>0; k++){ glo.eff += wrk[r-k].tem; }   // atr sum      glo.num     = glo.hh - glo.ll;      glo.alp     = (glo.eff!=0) ? glo.num/glo.eff : 1;      val[i]      = (glo.alp==1.0) ? glo.alp*wrk[r].prc : iFilter(glo.alp*wrk[r].prc+(1.0-glo.alp)*val[i+1],glo.vfil,glo.fper,r,rates_total,1);      valc[i]     = (r>0) ? (val[i]>val[i+1]) ? 1 : (val[i]<val[i+1]) ? -1 : valc[i+1] : 0;      if(valc[i]==-1) iPlotPoint(i,rates_total,valDa,valDb,val); else valDa[i] = valDb[i] = EMPTY_VALUE;      if(valc[i]== 1) iPlotPoint(i,rates_total,valUa,valUb,val); else valUa[i] = valUb[i] = EMPTY_VALUE;   }return(rates_total);}//////doubleiFilter(doublevalue, double filter, int period, int i, int bars, int instance=0){   #define ¤ instance   #define _functionInstances 2      struct sFilterArrayStruct         {            double value;            double change;            double power;            double summc;            double summp;         };      static sFilterArrayStruct m_array[][_functionInstances];      static int m_arraySize = 0;             if (m_arraySize<bars)             {                 int _res = ArrayResize(m_array,bars+500);                 if (_res<bars) return(0);                     m_arraySize = _res;             }      //      //      //      m_array[i][¤].value  = value;  double _change = (i>0) ? m_array[i][¤].value-m_array[i-1][¤].value : 0;      m_array[i][¤].change = (_change>0) ? _change : - _change;         if (i>period)         {            #define _power(_val) ((_val)*(_val))              m_array[i][¤].summc =  m_array[i-1][¤].summc +m_array[i][¤].change-m_array[i-period][¤].change;              m_array[i][¤].power = _power(m_array[i][¤].change-m_array[i][¤].summc/(double)period);              m_array[i][¤].summp =  m_array[i-1][¤].summp+m_array[i][¤].power-m_array[i-period][¤].power;         }                       else         {            m_array[i][¤].summc  =            m_array[i][¤].summp = 0;            for(int k=0; k<period && i>=k; k++) m_array[i][¤].summc += m_array[i-k][¤].change;                                                m_array[i][¤].power  = _power(m_array[i][¤].change-m_array[i][¤].summc/(double)period);            for(int k=0; k<period && i>=k; k++) m_array[i][¤].summp += m_array[i-k][¤].power;         }                     if (i>0 && filter>0 && m_array[i][¤].change<filter*MathSqrt(m_array[i][¤].summp/(double)period)) m_array[i][¤].value=m_array[i-1][¤].value;   return (m_array[i][¤].value);   //   //   //   #undef ¤ #undef _power #undef _functionInstances}//-------------------------------------------------------------------//                                                                  //-------------------------------------------------------------------voidiCleanPoint(int i, int bars,double& first[],double& second[]){   if (i>=bars-3) return;   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))        second[i+1] = EMPTY_VALUE;   else      if ((first[i]  != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))           first[i+1] = EMPTY_VALUE;}voidiPlotPoint(int i, int bars,double& first[],double& second[],double& from[]){   if (i>=bars-2) return;   if (first[i+1] == EMPTY_VALUE)      if (first[i+2] == EMPTY_VALUE)             { first[i]  = from[i]; first[i+1]  = from[i+1]; second[i] = EMPTY_VALUE; }      else  { second[i] = from[i]; second[i+1] = from[i+1]; first[i]  = EMPTY_VALUE; }   else     { first[i]  = from[i];                          second[i] = EMPTY_VALUE; }}//+------------------------------------------------------------------+/*Function: MACongAdaptive{	TASC MAY 2023	Function: Scott Cong’s Adaptive Moving Average 	Scott Cong}inputs:	Price( numericseries ), 	Length( numericsimple );variables:	HH( 0 ),	LL( 0 ),	Result( 0 ), 	Effort( 0 ), 	AlphaValue( 0 );if CurrentBar = 1 then	MACongAdaptive = Priceelsebegin	HH = Highest(High, Length);	LL = Lowest(Low, Length);	Result = HH - LL;	Effort = Summation(TrueRange, Length);	if Effort <> 0 then		AlphaValue = Result / Effort 	else		AlphaValue = 1;	if AlphaValue = 1 then		MACongAdaptive = Price	else		MACongAdaptive = AlphaValue * Price 		 + (1 - AlphaValue) * _MACongAdaptive[1];end; */ 由于时间有限加上对源码的追溯做不到最终解释权,所以我们提供的源码EA仅仅只能用来做模拟测试使用,严格禁止商业使用和跑实盘!

相关学习资料