当前位置:主页 > 时尚 >

[转载]MACD柱线与K线背离指标源码

        

        

        
        

        MACD列和K线分歧证明人源代码

            从情节中显示胜利,该指示是努力分歧指示的最适宜条件指示。,它将使K线尖顶。、山谷,与MACD柱线峰山谷现达非常饱,最理想的指示经过。。

            接下落,笔者将努力它的体系结构陈述及其应用手法。,到这地步扩展与的EA花样。,出价根底。

         //+------------------------------------------------------------------------------------------------+

        //| FX5_Divergence.mq4 |

        //| FX5 |

        //| hazem@uk2.net |

         //+-------------------------------------------------------------------------------------------------+

        #property copyright "Copyright ?2007, FX5"

        #property link hazem@uk2.net

        //----根本清晰度

        #property indicator_separate_window 子图中所示

        #property indicator_buffers 5 清晰度5个打扮

        #property indicator_color1 LimeGreen 前列色橙绿

        #property indicator_color2 FireBrick 另外的行色彩火砖色

        #property indicator_color3 Green 第三线绿色

        #property indicator_color4 Red 四线彩红

        //---- input parameters表面界限

        extern string separator1 = "*** OSMA Settings ***"; MACD柱设置

        extern int fastEMA = 12; 快线圈子数

        extern int slowEMA = 26; 慢行附近数

        extern int signal = 9; 搬迁圈子数

        extern string separator2 = "*** Indicator Settings ***"; //指示设置

        extern bool drawDivergenceLines = true; 撤回离线=真

        extern bool displayAlert = true; 打旗语显示=真

        //---- buffers打扮清晰度少数型

        double upOsMA[]; MACD柱升起

        double downOsMA[]; MACD柱停止

        double bullishDivergence[]; 牛场动身

        double bearishDivergence[]; //熊背离

        double OsMA[]; MACD柱线

        //----

        static datetime lastAlertTime; 动态可变的工夫日期典型:最末告警工夫

         //+------------------------------------------------------------------+

        //| Custom indicator initialization function |

         //+------------------------------------------------------------------+

        int init() //空载运转

        {

        //---- indicators

        SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 2);

        证明人典型(证明人0),画柱线,固体线,宽2像素

        SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);

        证明人典型(证明人1),画柱线,固体线,宽2像素

        SetIndexStyle(2, DRAW_ARROW);

        证明人典型(证明人2),箭镟)

        SetIndexStyle(3, DRAW_ARROW);

        证明人典型(证明人3),箭镟)

        SetIndexStyle(4, DRAW_NONE);

        证明人典型(证明人4),无绘画线)

        //----

        SetIndexBuffer(0, upOsMA) 证明人证明人(证明人0),MACD柱升起

        SetIndexBuffer(1, downOsMA) 证明人证明人(证明人1),MACD柱投下)

        SetIndexBuffer(2, bullishDivergence); 证明人证明人(证明人2),牛场动身

        SetIndexBuffer(3, bearishDivergence); 证明人证明人(证明人3),熊背离)

        SetIndexBuffer(4, OsMA) 证明人证明人(证明人4),MACD柱线

        //----

        SetIndexArrow(2, 233); 箭镟典型(证明人2),序列号233)

        SetIndexArrow(3, 234); 箭镟典型(证明人3),序列号234)

        //----

        IndicatorDigits(Digits + 2); 该证明人取少数位数(今天的阿拉伯数字系统 2)。,即使今天钱币对的阿拉伯数字系统数是5位,,少数位数证明人:5+2=7,与把剩的7位少数保存下落。,为了构造4家,与某人击掌问候条作用计算。,停止计列。

        IndicatorShortName("(" + fastEMA + "," + slowEMA + "," + signal + ")"); 证明人缩写(FXX为装支管指数的)(快核能谱),慢速电分析产生效果,搬迁圈子)

        复发(0)

        }

         //+------------------------------------------------------------------+

        //| Custom indicator deinitialization function |

         //+------------------------------------------------------------------+

        int deinit() //卸货作业

        {

        为(int) i = ObjectsTotal() - 1; i >= 0; i--) 附近反省(反对总额)1,0,缩减1

        {

        string label = 反对指定(i) 可变的译文典型:标志=反对指定(i)

        (StringSubstr(拉环), 0, 14) != "DivergenceLine")

        即使(皱缩译文(拉环),从0个字母开端。,取字母尺寸=14)

        continue; //持续

        ObjectDelete(label); 删去反对(拉环)

        }

        复发(0)

        }

         //+------------------------------------------------------------------+

        //| Custom indicator iteration function |

         //+------------------------------------------------------------------+

        int start() //主功用

        {

        int countedBars = IndicatorCounted(); 计算K线数=K线总功用

        if(countedBars < 0) // 即使(计算K线数< 0)

        countedBars = 0; 计算k行数=0

        CalculateIndicator(countedBars); 证明人计算(计算K行数)-自清晰度功用援引

        复发(0)

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-无复发典型:指示计算|

         //+------------------------------------------------------------------+

        void CalculateIndicator(int countedBars) //自清晰度功用:指数的计算(计算)K行数)

        {

        为(int) i = Bars - countedBars; i >= 0; i--) 附近反省(I= K行计数-K行计数),0,i=i-1)

        {

        CalculateOsMA(i); 计算MACD柱线(i)-自清晰度功用

        CatchBullishDivergence(i + 2); 被钩住牛分开功用(I 1)-自清晰度功用

        CatchBearishDivergence(i + 2); //捕获熊背离功用(i+2)-自清晰度功用

        }

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-无复发典型:计算MACD柱线|

        //+------------------------------------------------------------------+

        void CalculateOsMA(int i)//自清晰度功用:计算MACD柱线

        {

        OsMa [Ⅰ] = iOsMA(零点), 0, fastEMA, slowEMA, signal, PRICE_CLOSE, i);

         MACD柱[I]=援引MACD列线功用(今天钱币对),今天情节,快核能谱,慢速电分析产生效果,搬迁圈子,沉淀,i)

        if(OsMa [Ⅰ] > 0) 即使(MACD柱[I]>0)

        {

        upOsMa [Ⅰ] = OsMa [Ⅰ]; MACD柱升起[i]= MACD柱[I]

        downOsMa [Ⅰ] = 0; MACD柱停止[i]=0

        }

        else

        if(OsMa [Ⅰ] < 0) //即使(MACD柱[I]<0)

        {

        downOsMa [Ⅰ] = OsMa [Ⅰ]; MACD柱停止[i]=MACD柱[I]

        upOsMa [Ⅰ] = 0; MACD柱升起[i]=0

        }

        else

        {

        upOsMa [Ⅰ] = 0; MACD柱升起[i]=0

        downOsMa [Ⅰ] = 0; MACD柱停止[i]=0

        }

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-无复发典型:捕牛功用|

        //+------------------------------------------------------------------+

        void CatchBullishDivergence(int 移位) //捕牛功用(K行序列号

        {

        if(IsIndicatorTrough(移位) == 假) //即使(倘若是指示的浪尖(K行序列号=假)

        return;

        int currentTrough = shift; 可变的完整的典型:电流谷=k-线序数

        int lastTrough = GetIndicatorLastTrough(移位);

        可变的完整的典型:前番浪尖=获取指示的前番浪尖(K行序列号

        即使(OSMA [今天槽] > OsMA[lastTrough] && Low[currentTrough] < Low[lastTrough])

        (MACD柱线[电流槽] MACD柱[最末槽] 且 K线低[电流槽] > K线低[最末槽]

        {

        bullishDivergence[currentTrough] = OsMA[currentTrough];

        牛场动身[今天浪尖]=MACD柱[电流槽]

        if(drawDivergenceLines == 真的) 即使(撤回离线=真)

        {

        DrawPriceTrendLine(Time[currentTrough], Time[lastTrough],

        Low[currentTrough], Low[lastTrough], Green, STYLE_SOLID);

        绘制价钱方向线(获名次槽),获名次[最末槽],最少的价钱[今天槽],底价[最末一槽],绿色,实曲线)

        DrawIndicatorTrendLine(Time[currentTrough], Time[lastTrough],

        OsMA[currentTrough],OsMA[lastTrough], Green, STYLE_SOLID);

        绘制指数的方向线(获名次槽),获名次[最末槽],MACD柱[电流槽],MACD柱[最末槽],绿色,实曲线)

        }

        if(displayAlert == 真的) 即使(显示打旗语=真)

        DisplayAlert("Classical bullish divergence on: ", currentTrough);

        显示打旗语(规范恐吓为装支管)涌现。:”,电流槽

        }

        即使(OSMA [今天槽] < OsMA[lastTrough] && Low[currentTrough] > Low[lastTrough])

        //即使(MACD柱[电流槽]底价[最末一槽])

        {

        bullishDivergence[currentTrough] = OsMA[currentTrough];

        牛场动身[今天浪尖]=MACD柱[电流槽]

        if(drawDivergenceLines == 真的) 即使(撤回离线=真)

        {

        DrawPriceTrendLine(Time[currentTrough], Time[lastTrough], Low[currentTrough],

        Low[lastTrough], Green, STYLE_DOT);

        绘制价钱方向线(获名次槽),获名次[最末槽],最少的价钱[今天槽],底价[最末一槽],绿色,虚线)

        DrawIndicatorTrendLine(Time[currentTrough], Time[lastTrough],

        OsMA[currentTrough],OsMA[lastTrough], Green, STYLE_DOT);

        绘制指数的方向线(获名次槽),获名次[最末槽],MACD柱[电流槽],MACD柱[最末槽],绿色,虚线)

        }

        if(displayAlert == 真的) 即使(正告打旗语显示为真)

        DisplayAlert("Reverse bullish divergence on: ", currentTrough);

        正告打旗语显示(反向恐吓分开)涌现。:”,电流槽

        }

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-无复发典型:捕获熊背离功用|

         //+------------------------------------------------------------------+

        void CatchBearishDivergence(int 移位) //捕获熊背离功用(K行序列号

        {

        if(IsIndicatorPeak(移位) == 假) //即使(倘若是指示的波谷(K行序列号=假)

        return;

        int currentPeak = shift; 电流峰值=k行序数

        int lastPeak = GetIndicatorLastPeak(移位); //前番波谷=获取指示的前番波谷(K行序列号

        即使(OsMA[CurrimePosi]) < OsMA[lastPeak] && High[currentPeak] > High[lastPeak])

        (MACD柱线[电流波谷]高的价钱[最末一波]

        {

        bearishDivergence[currentPeak] = OsMA[currentPeak];

        //熊背离[今天波谷]=MACD柱[电流波谷]

        if(drawDivergenceLines == 真的) 即使(撤回离线=真)

        {

        DrawPriceTrendLine(Time[currentPeak], Time[lastPeak], High[currentPeak],

        High[lastPeak], Red, STYLE_SOLID);

        绘制价钱方向线(获名次),获名次[最末波谷],高的价钱[今天的主峰],高的价钱[最末一波],白色,实曲线)

        DrawIndicatorTrendLine(Time[currentPeak], Time[lastPeak], OsMA[currentPeak],

        OsMA[lastPeak], Red, STYLE_SOLID);

        绘制指数的方向线(获名次),获名次[最末波谷],MACD柱[电流波谷],MACD柱[最末一波],白色,实曲线)

        }

        if(displayAlert == 真的) 即使(打旗语显示=真)

        DisplayAlert("Classical bearish divergence on: ", currentPeak);

        //打旗语显示(“规范熊背离涌现:电流波谷

        }

        即使(OsMA[CurrimePosi]) > OsMA[lastPeak] && High[currentPeak] < High[lastPeak])

        (MACD柱线[电流波谷]>MACD柱[最末一波] 且高的价钱[今天的主峰]<高的价钱[最末一波]

        {

        bearishDivergence[currentPeak] = OsMA[currentPeak];

        //熊背离[今天波谷]=MACD柱[电流波谷]

        if(drawDivergenceLines == 真的) 即使(撤回离线=真)

        {

        DrawPriceTrendLine(Time[currentPeak], Time[lastPeak], High[currentPeak],

        High[lastPeak], Red, STYLE_DOT);

        绘制价钱方向线(获名次),获名次[最末波谷],高的价钱[今天的主峰],高的价钱[最末一波],白色,虚线)

        DrawIndicatorTrendLine(Time[currentPeak], Time[lastPeak], OsMA[currentPeak],

        OsMA[lastPeak], Red, STYLE_DOT);

        绘制指数的方向线(获名次),获名次[最末波谷],MACD柱[电流波谷],MACD柱[最末一波],白色,虚线)

        }

        if(displayAlert == 真的) 即使(正告打旗语显示为真)

        DisplayAlert("Reverse bearish divergence on: ", currentPeak);

        //告警打旗语显示(“反向熊背离涌现:电流波谷

        }

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-逻辑型:指数的峰值功用|

        //+------------------------------------------------------------------+

        bool IsIndicatorPeak(int 移位) //决定证明人倘若为峰值。K行序列号

        {

        即使(OSMA) > 0 && OSMA [移位] > OsMA[shift+1] && OSMA [移位] > OsMA[shift-1])

        即使MACD柱线[K行数]>0 且 MACD柱〔K行数〕 MACD列[ K行序列号 1 ] 且MACD柱〔K行数〕 MACD列[ K行序列号- 1 ]

        {

        为(int) i = shift + 1; i < Bars; i++) //附近查找(i=K行序列号+1,i

        {

        if(OsMa [Ⅰ] < 0) //即使(MACD柱[I]<0)

        return(真的);

        if(OsMa [Ⅰ] > OSMA [移位]) 即使(MACD柱[I]>MACD柱〔K行数〕

        break; //蹦跳

        }

        }

        return(假); 退货(假)

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-逻辑型:判别指示谷功用|

        //+------------------------------------------------------------------+

        bool IsIndicatorTrough(int 移位) //决定指数的倘若为低谷。K行序列号

        {

        即使(OSMA) < 0 && OSMA [移位] < OsMA[shift+1] && OSMA [移位] < OsMA[shift-1])

        即使MACD柱线[ K行数]<0 且 MACD柱线[K行序列号]< MACD列[ K行序列号 1 ] 且MACD柱〔K行数〕

        {

        为(int) i = shift + 1; i < Bars; i++) //附近查找(i=K行序列号+1,i

        {

        if(OsMa [Ⅰ] > 0) //即使(MACD柱[I]>0)

        return(真的);

        if(OsMa [Ⅰ] < OSMA [移位]) //即使(MACD柱[I]>MACD柱〔K行数〕

        break; //蹦跳

        }

        }

        return(假); 退货(假)

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-完整的型:获取证明人最末峰值|

        //+------------------------------------------------------------------+

        int GetIndicatorLastPeak(int 移位) //获取证明人最末峰值(K行序列号)

        {

        为(int) i = shift + 5; i < Bars; i++) //附近查找(i=K行序列号+5;i

        {

        if(OsMa [Ⅰ] >= OsMA[i+1] && OsMa [Ⅰ] > OsMA[i+2] &&

        OsMa [Ⅰ] >= OsMA[I-1 ] && OsMa [Ⅰ] > OsMA[i-2])

        //即使(MACD柱[I] MACD柱〔I+1〕 且MACD柱[I]>MACD柱线[i+2]

        且MACD柱[I] MACD柱[I-1 ] 且MACD柱[I]>MACD柱线[i-2])

        复发(i) 复发(i)

        }

        复发(- 1) 复发(- 1)

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-完整的型:最末东西证明人|

        //+------------------------------------------------------------------+

        int GetIndicatorLastTrough(int 移位) //最末东西证明人(K行序列号)

        {

        为(int) i = shift + 5; i < Bars; i++) //附近查找(i=K行序列号+5;i

        {

        if(OsMa [Ⅰ] <= OsMA[i+1] && OsMa [Ⅰ] < OsMA[i+2] &&

        OsMa [Ⅰ] <= OsMA[I-1 ] && OsMa [Ⅰ] < OsMA[i-2])

        //即使(MACD柱[I] <=MACD柱线[i+1] 且MACD柱[I]

        且MACD柱[I] <=MACD柱线[i-1] 且MACD柱[I]

        复发(i) 复发(i)

        }

        复发(- 1) 复发(- 1)

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-无复发典型:告警打旗语显示|

        //+------------------------------------------------------------------+

        void DisplayAlert(string message, int 移位) //告警打旗语显示(警告,K行序列号)

        {

        即使(移位 <= 2 && Time[shift] != lastAlertTime)

        //即使(K行序列号<=2 且 获名次[K行序列号]≠前番打旗语获名次)

        {

        lastAlertTime = 工夫[轮班] //前番打旗语获名次=获名次[K行序列号]

        警报(音讯), Symbol(), " , ", Period(), " minutes 情节

        行动正告窗口(警告),今天钱币对,“,”今天圈子,分钟计算

        }

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-无复发典型:绘制价钱方向线|

        //+------------------------------------------------------------------+

        void DrawPriceTrendLine(datetime x1, datetime x2, double y1,

        double y2, color lineColor, double 风骨

        //绘制价钱方向线(X1)工夫日期典型,X2-工夫日期典型,Y1-少数型,Y2-少数型,估计色,估计典型-少数型)

        {

        string label = " " + DoubleToStr(x1, 0);

        拉环=向后地脱机 阿拉伯数字系统到译文(X1),0)

        ObjectDelete(label); 删去反对(拉环)

        ObjectCreate(label, OBJ_TREND, 0, x1, y1, x2, y2, 0, 0);

        创立反对(拉环)),方向线,0,X1,Y1,X2,Y2,0,0,)

        反对集(拉环), OBJPROP_RAY, 0); 反对属性设置(拉环),射线,0)

        反对集(拉环), OBJPROP_COLOR, lineColor); 反对属性设置(拉环),色,估计色)

        反对集(拉环), OBJPROP_STYLE, 风骨; 反对属性设置(拉环),估计典型,典型)

        }

         //+------------------------------------------------------------------+

        //|自清晰度功用-无复发典型:绘制方向线|

        //+------------------------------------------------------------------+

        void DrawIndicatorTrendLine(datetime x1, datetime x2, double y1,

        double y2, color lineColor, double 风骨

        //绘制方向线(X1-工夫日期典型,X2-工夫日期典型,Y1-少数型,Y2-少数型,估计色,典型-阿拉伯数字系统典型

        {

        int indicatorWindow = WindowFind("(" + fastEMA + "," + slowEMA + "," + signal + ")");

        证明人窗口=证明人反省(FX5*为装支管 Express Enm EMA),慢线潜力,搬迁圈子

        if(indicatorWindow < 0)

        IF(证明人窗口号)<0

        return;

        string label = "$# " + DoubleToStr(x1, 0);

        拉环的实质=后退行$ 数值到译文(X1),0)

        ObjectDelete(label);

        删去反对(拉环)

        ObjectCreate(label, OBJ_TREND, indicatorWindow, x1, y1, x2, y2, 0, 0);

        创立反对(拉环),趋线,指示窗口,X1,Y1,X2,Y2,0,0)

        反对集(拉环), OBJPROP_RAY, 0);

        反对属性设置(拉环),射线,0)

        反对集(拉环), OBJPROP_COLOR, lineColor);

        反对属性设置(拉环),色,估计色)

        反对集(拉环), OBJPROP_STYLE, 风骨;

        反对属性设置(拉环),估计典型,典型)

        }

         //+------------------------------------------------------------------+

        clip_image002

        正文:MACD列线功用=iOsMA()

        是你这么说的嘛!指示打中OSMA功用,实为:MACD(12),26,9)柱状图。

上一篇:MACD柱线与K线背离指标源码 下一篇:没有了
返回顶部
Copyright © FG棋牌,乐游棋牌,爱棋牌 版权所有. 无