当前位置:主页 > 时尚 >

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位十进位的保存决定并宣布。,为了产生物理反应四家,第五条任务计算。,举行计列。

        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)柱状图。

上一篇:观念平台-两岸的国进民退 下一篇:没有了
返回顶部
Copyright © FG棋牌,乐游棋牌,爱棋牌 版权所有. 无