360 发表于 2018-3-8 14:45:42

MACD Crossover Signal



//+------------------------------------------------------------------+
//|                                        MACD Crossover Signal.mq4 |
//+------------------------------------------------------------------+

#property copyright "Copyright ?2007, Robert Hill)"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(0, 221);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(1, 222);
   SetIndexBuffer(1, CrossDown);
   IndicatorDigits(2);
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                     |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double MACD_Main, MACD_Signal, MACD_MainPrevious, MACD_SignalPrevious;
   double Range, AvgRange;
   int 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;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++) {
         AvgRange=AvgRange+MathAbs(High-Low);
      }
      Range=AvgRange/10;
      
      MACD_Main = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_MAIN, i);
      MACD_MainPrevious = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_MAIN, i+1);
      MACD_Signal = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_SIGNAL, i);
      MACD_SignalPrevious = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_SIGNAL, i+1);

      
      if ((MACD_Signal < MACD_Main) && (MACD_SignalPrevious > MACD_MainPrevious)) {
         CrossUp = Low - Range*0.5;
      }
      else if ((MACD_Signal > MACD_Main) && (MACD_SignalPrevious < MACD_MainPrevious)) {
         CrossDown = High + Range*0.5;
      }
   }
   return(0);
}




zetyp 发表于 2020-6-7 21:22:31

小手一抖,积分到手!

素颜。 发表于 2020-6-13 15:36:38

没看完~~~~~~ 先顶,好同志

ssvlq 发表于 2020-7-19 12:46:17

帮你顶下哈!!

老★张 发表于 2020-7-30 12:50:32

学习了,不错

910023005 发表于 2020-8-18 22:47:46

帮你顶下哈!!

假如 发表于 2021-7-21 16:09:07

谢谢

夜宴叶问 发表于 2021-7-27 11:12:30

顶下

毛毛 发表于 2021-8-2 11:17:42

{:1_179:}

麦子 发表于 2021-8-9 10:00:21

{:1_181:}
页: [1]
查看完整版本: MACD Crossover Signal