//+------------------------------------------------------------------+ //| DoubleCCI.mq4 | //| Copyright © 2005, Jason Robinson (jnrtrading). | //| http://www.jnrtrading.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, Jason Robinson (jnrtrading)." #property link "http://www.jnrtrading.co.uk" #property indicator_separate_window #property indicator_buffers 7 #property indicator_color1 RoyalBlue #property indicator_width1 1 #property indicator_color2 Red #property indicator_width2 1 #property indicator_color3 CLR_NONE #property indicator_width3 1 #property indicator_color4 Khaki #property indicator_width4 2 #property indicator_color5 CLR_NONE #property indicator_width5 1 #property indicator_color6 DeepSkyBlue #property indicator_width6 1 #property indicator_color7 Crimson #property indicator_width7 1 //#property indicator_level1 0 #property indicator_level2 100 #property indicator_level3 -100 #property indicator_level4 200 #property indicator_level5 -200 #property indicator_levelwidth 1 #property indicator_levelstyle 0 #property indicator_levelcolor Gray //---- input parameters extern int TrendCCI_Period = 14; extern int EntryCCI_Period = 14; extern bool Zero_Cross_Alert = False; extern int period=13; extern int method=3; extern int price=5; extern int LineSize=2; int FromZero =0; // Distance from zero level double TrendCCI[]; double EntryCCI[]; double CCITrendUp[]; double CCITrendDown[]; double Uptrend[]; double Dntrend[]; double ExtMapBuffer[]; int trendUp, trendDown; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_HISTOGRAM); SetIndexBuffer(0, CCITrendUp); SetIndexStyle(1, DRAW_HISTOGRAM); SetIndexBuffer(1, CCITrendDown); SetIndexStyle(2, DRAW_LINE); SetIndexBuffer(2, EntryCCI); SetIndexLabel(2, "EntryCCI"); SetIndexStyle(3, DRAW_LINE); SetIndexBuffer(3, TrendCCI); SetIndexLabel(3, "TrendCCI"); // SetIndexStyle(4,DRAW_LINE); SetIndexBuffer(4,ExtMapBuffer); SetIndexStyle(5,DRAW_ARROW,STYLE_SOLID,LineSize); SetIndexBuffer(5, Uptrend); SetIndexArrow(5,167); SetIndexStyle(6,DRAW_ARROW,STYLE_SOLID,LineSize); SetIndexBuffer(6, Dntrend); SetIndexArrow(6,167); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } double WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method, price, x)); } //---- //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, trendCCI, entryCCI; int counted_bars = IndicatorCounted(); static datetime prevtime = 0; //---- 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; trendCCI = TrendCCI_Period; entryCCI = EntryCCI_Period; IndicatorShortName("(TrendCCI: " + trendCCI + ", EntryCCI: " + entryCCI + ") "); for(i = limit; i >= 0; i--) { CCITrendDown[i] = 0; CCITrendUp[i] = 0; TrendCCI[i] = iCCI(NULL, 0, trendCCI, PRICE_TYPICAL, i); EntryCCI[i] = iCCI(NULL, 0, entryCCI, PRICE_TYPICAL, i); if (TrendCCI[i] > 0) { CCITrendUp[i] = TrendCCI[i]; } if (TrendCCI[i] < 0) { CCITrendDown[i] = TrendCCI[i]; } } if (Zero_Cross_Alert == true) { if (prevtime == Time[0]) { return(0); } else { if(EntryCCI[0] < 0) { if((TrendCCI[0] < 0) && (TrendCCI[1] >= 0)) { Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed below zero"); } } else if(EntryCCI[0] > 0) { if((TrendCCI[0] > 0) && (TrendCCI[1] <= 0)) { Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed above zero"); } } else if(EntryCCI[0] > 100) { if((TrendCCI[0] > 100) && (TrendCCI[1] <= 100)) { Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed above +100"); } } else if(EntryCCI[0] < -100) { if((TrendCCI[0] < -100) && (TrendCCI[1] >= -100)) { Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed below -100"); } } else if(EntryCCI[0] > 200) { if((TrendCCI[0] > 200) && (TrendCCI[1] <= 200)) { Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed above +200"); } } else if(EntryCCI[0] < -200) { if((TrendCCI[0] < -200) && (TrendCCI[1] >= -200)) { Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed below -200"); } } prevtime = Time[0]; } //---- Middle Line HMA int x = 0; int p = MathSqrt(period); int e = Bars - counted_bars + period + 1; double vect[], trend[]; if(e > Bars) e = Bars; ArrayResize(vect, e); ArraySetAsSeries(vect, true); ArrayResize(trend, e); ArraySetAsSeries(trend, true); for(x = 0; x < e; x++) { vect[x] = 2*WMA(x, period/2) - WMA(x, period); } for(x = 0; x < e-period; x++) ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x); Uptrend[x] =0; Dntrend[x] =0; for(x = e-period; x >= 0; x--) { trend[x] = trend[x+1]; if (ExtMapBuffer[x] - ExtMapBuffer[x+1] > 0) trend[x] =1; if (ExtMapBuffer[x+1] - ExtMapBuffer[x] > 0) trend[x] =-1; if (trend[x]> 0) { Uptrend[x] = 0; Dntrend[x] = EMPTY_VALUE; } if (trend[x] <0) { Dntrend[x] = 0; Uptrend[x] = EMPTY_VALUE; } } } //---- return(0); } //+------------------------------------------------------------------+