点评 发表于 2023-12-22 12:38:58

高手指点一下,加权移动改为简单移动均线

我想把MACD双线   指标源码里的逻辑 EMA   加权移动平均线改为平常用的   简单平滑移动线SMA,怎么在它的代码里找不到这个加权移动平均线的代码EMA,,怎么回事??代码高手进来看一下 ,多谢。
下面是这个双线MACD的源代码 :



//+------------------------------------------------------------------+
//| macd vs macd |
//+------------------------------------------------------------------+

#property indicator_buffers 6
#property indicator_separate_window
#property indicator_level1 0
#property indicator_color1 White
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Lime
#property indicator_color5 Yellow
#property indicator_color6 Blue

//---- buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double UP[];
double DO[];

extern int Fast = 12;
extern int Slow = 26;
extern int Signal = 9;
extern bool Alert_Switch=true;
static double SX;


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   //IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexStyle(1,DRAW_LINE,0,1);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,2);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(4,233);
   SetIndexArrow(5,234);

   SetIndexBuffer(0,Buffer1);
   SetIndexBuffer(1,Buffer2);
   SetIndexBuffer(2,Buffer3);
   SetIndexBuffer(3,Buffer4);
   SetIndexBuffer(4,UP);
   SetIndexBuffer(5,DO);


   IndicatorShortName("MACD("+Fast+","+Slow+","+Signal+")");
   SetIndexLabel(0,"MACD_MAIN");
   SetIndexLabel(1,"MACD_SIGNAL");
   SetIndexLabel(2,"MAIN-SIGNAL");
   SetIndexLabel(3,"MAIN-SIGNAL");
   SetIndexLabel(4,"BUY_SIGNAL");
   SetIndexLabel(5,"SELL-SIGNAL");
   IndicatorDigits(Digits+2);
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                     |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int limit,counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   double B_Temp;
//---- main loop
   for(int i=0; i<limit; i++)
   {
      Buffer1=iMACD(NULL,0,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
      Buffer2=iMACD(NULL,0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
      B_Temp=Buffer1 - Buffer2;
      if (B_Temp>=0)
      {
      Buffer3=B_Temp;
      Buffer4=EMPTY_VALUE;
      }
      else
      {
      Buffer4=B_Temp;
      Buffer3=EMPTY_VALUE;
      }
   }
   for(i=0; i<limit; i++)
   {
      UP=EMPTY_VALUE;
      DO=EMPTY_VALUE;
      if (Buffer1>Buffer2&&Buffer1<Buffer2)
      UP=Buffer2;
      if (Buffer1<Buffer2&&Buffer1>Buffer2)
      DO=Buffer2;
      if (Buffer1>Buffer2&&Buffer1==Buffer2&&Buffer1<Buffer2)
      UP=Buffer2;
      if (Buffer1<Buffer2&&Buffer1==Buffer2&&Buffer1>Buffer2)
      DO=Buffer2;
   }
   if (Alert_Switch==true && Buffer1>Buffer2&&Buffer1<Buffer2 && SX!=Time)
   {
   Alert(Symbol(),"",Period(),":","MACD金叉");
   SX=Time;
   }
   if (Alert_Switch==true && Buffer1<Buffer2&&Buffer1>Buffer2 && SX!=Time)
   {
   SX=Time;
   Alert(Symbol(),"",Period(),":","MACD死叉");
   }
   if (Alert_Switch==true && Buffer1>Buffer2&&Buffer1==Buffer2&&Buffer1<Buffer2 && SX!=Time)
   {
   SX=Time;
   Alert(Symbol(),"",Period(),":","MACD金叉");
   }
   if (Alert_Switch==true && Buffer1<Buffer2&&Buffer1==Buffer2&&Buffer1>Buffer2 && SX!=Time)
   {
   SX=Time;
   Alert(Symbol(),"",Period(),":","MACD死叉");
   }
//----
   return(0);
}
//+------------------------------------------------------------------+


qwe11 发表于 2023-12-22 14:23:24

本帖最后由 qwe11 于 2023-12-22 14:27 编辑

{:1_189:}

点评 发表于 2023-12-27 11:54:24

非常感谢你的指点,多谢。

潍坊却无法 发表于 2024-3-30 20:22:08

谢谢

生命 发表于 2024-9-28 16:46:21

谢谢
页: [1]
查看完整版本: 高手指点一下,加权移动改为简单移动均线