//+------------------------------------------------------------------+ //| VoltyChannel_Stop_v6.7 600+.mq4 | //| Copyright © 2018, TrendLaboratory | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2003@yahoo.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2018, TrendLaboratory" #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" #property link "http://newdigital-world.com/forum.php" #property indicator_chart_window #property indicator_buffers 10 #property indicator_color1 clrRoyalBlue #property indicator_color2 clrCoral #property indicator_color3 clrRoyalBlue #property indicator_color4 clrCoral #property indicator_width3 2 #property indicator_width4 2 #property indicator_color5 clrRoyalBlue #property indicator_color6 clrCoral #property indicator_color7 clrTurquoise #property indicator_color8 clrRoyalBlue #property indicator_color9 clrLightCoral #property indicator_color10 clrIndianRed #property indicator_width7 3 #property indicator_width8 3 #property indicator_width9 3 #property indicator_width10 3 #property strict enum ENUM_MA_MODE { SMA, // Simple Moving Average EMA, // Exponential Moving Average Wilder, // Wilder Exponential Moving Average LWMA, // Linear Weighted Moving Average SineWMA, // Sine Weighted Moving Average TriMA, // Triangular Moving Average LSMA, // Least Square Moving Average (or EPMA, Linear Regression Line) SMMA, // Smoothed Moving Average HMA, // Hull Moving Average by A.Hull ZeroLagEMA, // Zero-Lag Exponential Moving Average DEMA, // Double Exponential Moving Average by P.Mulloy T3_basic, // T3 by T.Tillson (original version) ITrend, // Instantaneous Trendline by J.Ehlers Median, // Moving Median GeoMean, // Geometric Mean REMA, // Regularized EMA by C.Satchwell ILRS, // Integral of Linear Regression Slope IE_2, // Combination of LSMA and ILRS TriMAgen, // Triangular Moving Average generalized by J.Ehlers VWMA, // Volume Weighted Moving Average JSmooth, // M.Jurik's Smoothing SMA_eq, // Simplified SMA ALMA, // Arnaud Legoux Moving Average TEMA, // Triple Exponential Moving Average by P.Mulloy T3, // T3 by T.Tillson (correct version) Laguerre, // Laguerre filter by J.Ehlers MD, // McGinley Dynamic BF2P, // Two-pole modified Butterworth filter by J.Ehlers BF3P, // Three-pole modified Butterworth filter by J.Ehlers SuperSmu, // SuperSmoother by J.Ehlers Decycler, // Simple Decycler by J.Ehlers eVWMA // Elastic Volume Weighted Moving Average by C.Fries }; enum ENUM_PRICE { close, // Close open, // Open high, // High low, // Low median, // Median typical, // Typical weightedClose, // Weighted Close medianBody, // Median Body (Open+Close)/2 average, // Average (High+Low+Open+Close)/4 trendBiased, // Trend Biased haClose, // Heiken Ashi Close haOpen, // Heiken Ashi Open haHigh, // Heiken Ashi High haLow, // Heiken Ashi Low haMedian, // Heiken Ashi Median haTypical, // Heiken Ashi Typical haWeighted, // Heiken Ashi Weighted Close haMedianBody, // Heiken Ashi Median Body haAverage, // Heiken Ashi Average haTrendBiased // Heiken Ashi Trend Biased }; enum ENUM_BREAK { byclose, // by Close byhilo, // by High/Low byuplo, // by Up/Lo Band Price byuploma // by Up/Lo MA(Length,MA_Mode) }; #define pi 3.14159265358979323846 //---- input parameters input ENUM_TIMEFRAMES TimeFrame = 0; // input ENUM_PRICE UpBandPrice = 0; // Upper Band Price input ENUM_PRICE LoBandPrice = 0; // Lower Band Price input ENUM_BREAK BreakOutMode = 0; // Breakout Mode input int Length = 1; // MA Period input ENUM_MA_MODE MA_Method = SMA; // MA Method input int ATR_Length = 10; // ATR Period input double Multiplier = 4; // Volatility Multiplier input double Ratchet = 0.0; // Ratchet(-1-off,>= 0-on) input double MinMultiplier = 0; // Min Multiplier input double MoneyRisk = 1.00; // Offset Factor(eg.1.2) input bool ShowSignals = true; // Show Signals input bool ShowLines = true; // Show Lines input bool ShowDots = true; // Show Dots input bool ShowBars = true; // Show Bars input int CountBars = 0; // Number of bars counted: 0-all bars input string Alerts = "=== Alerts, Emails & Notifications ==="; input bool AlertOn = false; // Alert On/Off input int AlertShift = 1; // Alert Shift:0-current bar,1-previous bar input int SoundsNumber = 5; // Number of sounds after Signal input int SoundsPause = 5; // Pause in sec between sounds input string UpTrendSound = "alert.wav"; // Uptrend Sound Name input string DnTrendSound = "alert2.wav"; // Downtrend Sound Name input bool EmailOn = false; // Email On/Off input int EmailsNumber = 1; // Emails Number input bool PushNotificationOn = false; // Push Notification On/Off //---- indicator buffers double UpTrend[]; double DnTrend[]; double UpSignal[]; double DnSignal[]; double UpLine[]; double DnLine[]; double UpRisingBar[]; double UpFallingBar[]; double DnRisingBar[]; double DnFallingBar[]; double trend[]; double upPrice[]; double loPrice[]; int timeframe, length, atr_length, masize, cBars, sumlength, draw_begin; double mult[2], upband1[2], dnband1[2], upband2[2], dnband2[2], hh[2], ll[2]; datetime prevstime; string short_name, TF, IndicatorName; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { timeframe = TimeFrame; if(timeframe <= Period()) timeframe = Period(); TF = tf(timeframe); //---- IndicatorBuffers(13); SetIndexBuffer( 0, UpTrend); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0,159); SetIndexBuffer( 1, DnTrend); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1,159); SetIndexBuffer( 2, UpSignal); SetIndexStyle(2, DRAW_ARROW); SetIndexArrow(2,108); SetIndexBuffer( 3, DnSignal); SetIndexStyle(3, DRAW_ARROW); SetIndexArrow(3,108); SetIndexBuffer( 4, UpLine); SetIndexStyle(4, DRAW_LINE); SetIndexBuffer( 5, DnLine); SetIndexStyle(5, DRAW_LINE); SetIndexBuffer( 6, UpRisingBar); SetIndexStyle(6,DRAW_HISTOGRAM); SetIndexBuffer( 7,UpFallingBar); SetIndexStyle(7,DRAW_HISTOGRAM); SetIndexBuffer( 8, DnRisingBar); SetIndexStyle(8,DRAW_HISTOGRAM); SetIndexBuffer( 9,DnFallingBar); SetIndexStyle(9,DRAW_HISTOGRAM); SetIndexBuffer(10, trend); SetIndexBuffer(11, upPrice); SetIndexBuffer(12, loPrice); IndicatorDigits(Digits); //---- length = MathMax(1,Length); atr_length = MathMax(1,ATR_Length); masize = averageSize(MA_Method); IndicatorName = WindowExpertName(); short_name = IndicatorName+"["+TF+"]("+(string)UpBandPrice+","+(string)LoBandPrice+","+(string)BreakOutMode+","+(string)Length+","+(string)MA_Method+","+(string)ATR_Length+","+DoubleToStr(Multiplier,2)+","+DoubleToStr(Ratchet,2)+","+DoubleToStr(MoneyRisk,2)+")"; IndicatorShortName(short_name); if(ShowDots) { SetIndexLabel(0,"UpTrend Stop"); SetIndexLabel(1,"DnTrend Stop"); } else { SetIndexLabel(0,NULL); SetIndexLabel(1,NULL); } if(ShowSignals) { SetIndexLabel(2,"UpTrend Signal"); SetIndexLabel(3,"DnTrend Signal"); } else { SetIndexLabel(2,NULL); SetIndexLabel(3,NULL); } if(ShowLines) { SetIndexLabel(4,"UpTrend Line"); SetIndexLabel(5,"DnTrend Line"); } else { SetIndexLabel(4,NULL); SetIndexLabel(5,NULL); } if(ShowBars) { if(length > 1) { SetIndexLabel(6,"UpTrend Rising Bar" ); SetIndexLabel(7,"UpTrend Falling Bar"); SetIndexLabel(8,"DnTrend Rising Bar"); SetIndexLabel(9,"DnTrend Falling Bar"); } else { SetIndexLabel(6,"UpTrend Bar"); SetIndexLabel(7,NULL); SetIndexLabel(8,"DnTrend Bar"); SetIndexLabel(9,NULL); } } else { SetIndexLabel(6,NULL); SetIndexLabel(7,NULL); SetIndexLabel(8,NULL); SetIndexLabel(9,NULL); } //---- mult[0] = Multiplier; sumlength = MathMax(length,atr_length); if(CountBars == 0) cBars = timeframe/Period()*(iBars(NULL,TimeFrame) - sumlength); else cBars = CountBars*timeframe/Period(); draw_begin = Bars - cBars; SetIndexDrawBegin(0,draw_begin); SetIndexDrawBegin(1,draw_begin); SetIndexDrawBegin(2,draw_begin); SetIndexDrawBegin(3,draw_begin); SetIndexDrawBegin(4,draw_begin); SetIndexDrawBegin(5,draw_begin); SetIndexDrawBegin(6,draw_begin); SetIndexDrawBegin(7,draw_begin); SetIndexDrawBegin(8,draw_begin); SetIndexDrawBegin(9,draw_begin); //---- ArrayResize(tmp,masize); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| VoltyChannel_Stop_v6.7 600+ | //+------------------------------------------------------------------+ int start() { int shift, y, limit = 0, counted_bars=IndicatorCounted(); if(counted_bars > 0) limit = Bars - counted_bars - 1; if(counted_bars < 0) return(0); if(counted_bars < 1) { if(CountBars == 0) limit = Bars - 1; else limit = MathMin(Bars-1,cBars+5*sumlength); for(int i=0;i=0;shift--) { if(prevstime != Time[shift]) { mult[1] = mult[0]; upband1[1] = upband1[0]; dnband1[1] = dnband1[0]; upband2[1] = upband2[0]; dnband2[1] = dnband2[0]; hh[1] = hh[0]; ll[1] = ll[0]; prevstime = Time[shift]; } if(UpBandPrice <= 9) upPrice[shift] = getPrice((int)UpBandPrice,shift); else if(UpBandPrice > 9 && UpBandPrice <= 19) upPrice[shift] = HeikenAshi(0,UpBandPrice-10,MathMin(Bars-1,cBars+sumlength),shift); if(LoBandPrice <= 9) loPrice[shift] = getPrice((int)LoBandPrice,shift); else if(LoBandPrice > 9 && LoBandPrice <= 19) loPrice[shift] = HeikenAshi(1,LoBandPrice-10,MathMin(Bars-1,cBars+sumlength),shift); if(shift > MathMin(Bars-3,cBars+sumlength)-length) continue; double upMA = allAveragesOnArray(0,upPrice,length,MA_Method,masize,MathMin(Bars-1,cBars+sumlength)-length,shift); double loMA = allAveragesOnArray(1,loPrice,length,MA_Method,masize,MathMin(Bars-1,cBars+sumlength)-length,shift); double atr = iATR(NULL,0,atr_length,shift); if(trend[shift+1] != trend[shift+2]) mult[1] = MathMax(MinMultiplier,Multiplier); upband1[0] = upMA + MathMax(MinMultiplier,mult[1])*atr; dnband1[0] = loMA - MathMax(MinMultiplier,mult[1])*atr; upband2[0] = upband1[0] + 0.5*(MoneyRisk - 1)*(upband1[0] - dnband1[0]); dnband2[0] = dnband1[0] - 0.5*(MoneyRisk - 1)*(upband1[0] - dnband1[0]); mult[0] = mult[1]; hh[0] = hh[1]; ll[0] = ll[1]; trend[shift] = trend[shift+1]; switch(BreakOutMode) { case 1: if(High[shift] > upband1[1] && trend[shift+1] <= 0) {trend[shift] = 1; hh[0] = High[shift];} if(Low[shift] < dnband1[1] && trend[shift+1] >= 0) {trend[shift] =-1; ll[0] = Low [shift];} break; case 2: if(upPrice[shift] > upband1[1] && trend[shift+1] <= 0) {trend[shift] = 1; hh[0] = High[shift];} if(loPrice[shift] < dnband1[1] && trend[shift+1] >= 0) {trend[shift] =-1; ll[0] = Low [shift];} break; case 3: if(upMA > upband1[1] && trend[shift+1] <= 0) {trend[shift] = 1; hh[0] = High[shift];} if(loMA < dnband1[1] && trend[shift+1] >= 0) {trend[shift] =-1; ll[0] = Low [shift];} default: if(Close[shift] > upband1[1] && trend[shift+1] <= 0) {trend[shift] = 1; hh[0] = High[shift];} if(Close[shift] < dnband1[1] && trend[shift+1] >= 0) {trend[shift] =-1; ll[0] = Low [shift];} break; } hh[0] = MathMax(upPrice[shift],hh[0]); ll[0] = MathMin(loPrice[shift],ll[0]); UpTrend[shift] = EMPTY_VALUE; DnTrend[shift] = EMPTY_VALUE; UpSignal[shift] = EMPTY_VALUE; DnSignal[shift] = EMPTY_VALUE; UpLine[shift] = EMPTY_VALUE; DnLine[shift] = EMPTY_VALUE; UpRisingBar[shift] = EMPTY_VALUE; UpFallingBar[shift] = EMPTY_VALUE; DnRisingBar[shift] = EMPTY_VALUE; DnFallingBar[shift] = EMPTY_VALUE; if(trend[shift] > 0) { if(trend[shift+1] > 0 && Ratchet >= 0) { if(hh[0] > hh[1] && trend[shift+1] > 0) mult[0] -= Ratchet; if(dnband1[0] < dnband1[1]) dnband1[0] = dnband1[1]; if(dnband2[0] < dnband2[1]) dnband2[0] = dnband2[1]; } if(ShowDots ) UpTrend[shift] = dnband2[0]; if(ShowLines) UpLine[shift] = dnband2[0]; if(ShowSignals && trend[shift+1] < 0) UpSignal[shift] = dnband2[0]; if(ShowBars) { if(Close[shift] > 0.5*(upband1[0] + dnband1[0])) {UpRisingBar[shift] = MathMax(Open[shift],Close[shift]); UpFallingBar[shift] = MathMin(Open[shift],Close[shift]);} else { if(length > 1) { UpFallingBar[shift] = MathMax(Open[shift],Close[shift]); UpRisingBar[shift] = MathMin(Open[shift],Close[shift]); } else { UpRisingBar[shift] = MathMax(Open[shift],Close[shift]); UpFallingBar[shift] = MathMin(Open[shift],Close[shift]); } } } } if(trend[shift] < 0) { if(trend[shift+1] < 0 && Ratchet >= 0) { if(ll[0] < ll[1] && trend[shift+1] < 0) mult[0] -= Ratchet; if(upband1[0] > upband1[1]) upband1[0] = upband1[1]; if(upband2[0] > upband2[1]) upband2[0] = upband2[1]; } if(ShowDots ) DnTrend[shift] = upband2[0]; if(ShowLines) DnLine[shift] = upband2[0]; if(ShowSignals && trend[shift+1] > 0) DnSignal[shift] = upband2[0]; if(ShowBars) { if(Close[shift] < 0.5*(upband1[0] + dnband1[0])) {DnRisingBar[shift] = MathMax(Open[shift],Close[shift]); DnFallingBar[shift] = MathMin(Open[shift],Close[shift]);} else { if(length > 1) { DnFallingBar[shift] = MathMax(Open[shift],Close[shift]); DnRisingBar[shift] = MathMin(Open[shift],Close[shift]); } else { DnRisingBar[shift] = MathMax(Open[shift],Close[shift]); DnFallingBar[shift] = MathMin(Open[shift],Close[shift]); } } } } } //---- if(AlertOn || EmailOn || PushNotificationOn) { bool uptrend = trend[AlertShift] > 0 && trend[AlertShift+1] <= 0; bool dntrend = trend[AlertShift] < 0 && trend[AlertShift+1] >= 0; if(uptrend || dntrend) { if(isNewBar(timeframe)) { if(AlertOn) { BoxAlert(uptrend," : BUY Signal @ " +DoubleToStr(Close[AlertShift],Digits)); BoxAlert(dntrend," : SELL Signal @ "+DoubleToStr(Close[AlertShift],Digits)); } if(EmailOn) { EmailAlert(uptrend,"BUY" ," : BUY Signal @ " +DoubleToStr(Close[AlertShift],Digits),EmailsNumber); EmailAlert(dntrend,"SELL"," : SELL Signal @ "+DoubleToStr(Close[AlertShift],Digits),EmailsNumber); } if(PushNotificationOn) { PushAlert(uptrend," : BUY Signal @ " +DoubleToStr(Close[AlertShift],Digits)); PushAlert(dntrend," : SELL Signal @ "+DoubleToStr(Close[AlertShift],Digits)); } } else { if(AlertOn) { WarningSound(uptrend,SoundsNumber,SoundsPause,UpTrendSound,Time[AlertShift]); WarningSound(dntrend,SoundsNumber,SoundsPause,DnTrendSound,Time[AlertShift]); } } } } //---- return(0); } //----- int averageSize(int mode) { int arraysize; switch(mode) { case DEMA : arraysize = 2; break; case T3_basic : arraysize = 6; break; case JSmooth : arraysize = 5; break; case TEMA : arraysize = 4; break; case T3 : arraysize = 6; break; case Laguerre : arraysize = 4; break; default : arraysize = 0; break; } return(arraysize); } double tmp[][2][2], ma[2][4]; datetime prevtime[2]; double allAveragesOnArray(int index,double& price[],int period,int mode,int arraysize,int cbars,int bar) { if(period == 1) return(price[bar]); int i; double MA[4]; switch(mode) { case EMA: case Wilder: case SMMA: case ZeroLagEMA: case DEMA: case T3_basic: case ITrend: case REMA: case JSmooth: case SMA_eq: case TEMA: case T3: case Laguerre: case MD: case BF2P: case BF3P: case SuperSmu: case Decycler: case eVWMA: if(prevtime[index] != Time[bar]) { ma[index][3] = ma[index][2]; ma[index][2] = ma[index][1]; ma[index][1] = ma[index][0]; if(arraysize > 0) for(i=0;i= BF2P && mode < eVWMA)) for(i=0;i<4;i++) MA[i] = ma[index][i]; } switch(mode) { case EMA : ma[index][0] = EMAOnArray(price[bar],ma[index][1],period,cbars,bar); break; case Wilder : ma[index][0] = WilderOnArray(price[bar],ma[index][1],period,cbars,bar); break; case LWMA : ma[index][0] = LWMAOnArray(price,period,bar); break; case SineWMA : ma[index][0] = SineWMAOnArray(price,period,bar); break; case TriMA : ma[index][0] = TriMAOnArray(price,period,bar); break; case LSMA : ma[index][0] = LSMAOnArray(price,period,bar); break; case SMMA : ma[index][0] = SMMAOnArray(price,ma[index][1],period,cbars,bar); break; case HMA : ma[index][0] = HMAOnArray(price,period,cbars,bar); break; case ZeroLagEMA: ma[index][0] = ZeroLagEMAOnArray(price,ma[index][1],period,cbars,bar); break; case DEMA : ma[index][0] = DEMAOnArray(index,0,price[bar],period,1,cbars,bar); break; case T3_basic : ma[index][0] = T3_basicOnArray(index,0,price[bar],period,0.7,cbars,bar); break; case ITrend : ma[index][0] = ITrendOnArray(price,MA,period,cbars,bar); break; case Median : ma[index][0] = MedianOnArray(price,period,cbars,bar); break; case GeoMean : ma[index][0] = GeoMeanOnArray(price,period,cbars,bar); break; case REMA : ma[index][0] = REMAOnArray(price[bar],MA,period,0.5,cbars,bar); break; case ILRS : ma[index][0] = ILRSOnArray(price,period,cbars,bar); break; case IE_2 : ma[index][0] = IE2OnArray(price,period,cbars,bar); break; case TriMAgen : ma[index][0] = TriMA_genOnArray(price,period,cbars,bar); break; case VWMA : ma[index][0] = VWMAOnArray(price,period,bar); break; case JSmooth : ma[index][0] = JSmoothOnArray(index,0,price[bar],period,1,cbars,bar); break; case SMA_eq : ma[index][0] = SMA_eqOnArray(price,MA,period,cbars,bar); break; case ALMA : ma[index][0] = ALMAOnArray(price,period,0.85,8,bar); break; case TEMA : ma[index][0] = TEMAOnArray(index,price[bar],period,1,cbars,bar); break; case T3 : ma[index][0] = T3OnArray(index,0,price[bar],period,0.7,cbars,bar); break; case Laguerre : ma[index][0] = LaguerreOnArray(index,price[bar],period,4,cbars,bar); break; case MD : ma[index][0] = McGinleyOnArray(price[bar],ma[index][1],period,cbars,bar); break; case BF2P : ma[index][0] = BF2POnArray(price,MA,period,cbars,bar); break; case BF3P : ma[index][0] = BF3POnArray(price,MA,period,cbars,bar); break; case SuperSmu : ma[index][0] = SuperSmuOnArray(price,MA,period,cbars,bar); break; case Decycler : ma[index][0] = DecyclerOnArray(price,MA,period,cbars,bar); return(price[bar] - ma[index][0]); case eVWMA : ma[index][0] = eVWMAOnArray(price[bar],ma[index][1],period,cbars,bar); break; default : ma[index][0] = SMAOnArray(price,period,bar); break; } return(ma[index][0]); } // MA_Method=0: SMA - Simple Moving Average double SMAOnArray(double& array[],int per,int bar) { double sum = 0; for(int i=0;i= cbars) ema = price; else ema = prev + 2.0/(1 + per)*(price - prev); return(ema); } // MA_Method=2: Wilder - Wilder Exponential Moving Average double WilderOnArray(double price,double prev,int per,int cbars,int bar) { double wilder; if(bar >= cbars) wilder = price; else wilder = prev + (price - prev)/per; return(wilder); } // MA_Method=3: LWMA - Linear Weighted Moving Average double LWMAOnArray(double& array[],int per,int bar) { double sum = 0, weight = 0; for(int i=0;i 0) return(sum/weight); else return(0); } // MA_Method=4: SineWMA - Sine Weighted Moving Average double SineWMAOnArray(double& array[],int per,int bar) { double sum = 0, weight = 0; for(int i=0;i 0) return(sum/weight); else return(0); } // MA_Method=5: TriMA - Triangular Moving Average double TriMAOnArray(double& array[],int per,int bar) { int len = (int)MathCeil((per + 1)*0.5); double sum = 0; for(int i=0;i=1;i--) sum += (i - (per + 1)/3.0)*array[bar+per-i]; return(sum*6/(per*(per + 1))); } // MA_Method=7: SMMA - Smoothed Moving Average double SMMAOnArray(double& array[],double prev,int per,int cbars,int bar) { double smma = 0; if(bar == cbars) smma = SMAOnArray(array,per,bar); else if(bar < cbars) { double sum = 0; for(int i=0;i= cbars) zema = price[bar]; else zema = alpha*(2*price[bar] - price[bar+lag]) + (1 - alpha)*prev; return(zema); } // MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy double DEMAOnArray(int index,int num,double price,double per,double v,int cbars,int bar) { double dema = 0, alpha = 2.0/(1 + per); if(bar == cbars) {dema = price; tmp[num][index][0] = dema; tmp[num+1][index][0] = dema;} else if(bar < cbars) { tmp[num ][index][0] = tmp[num ][index][1] + alpha*(price - tmp[num ][index][1]); tmp[num+1][index][0] = tmp[num+1][index][1] + alpha*(tmp[num][index][0] - tmp[num+1][index][1]); dema = tmp[num ][index][0]*(1+v) - tmp[num+1][index][0]*v; } return(dema); } // MA_Method=11: T3 by T.Tillson double T3_basicOnArray(int index,int num,double price,int per,double v,int cbars,int bar) { double dema1, dema2, T3 = 0; if(bar == cbars) { T3 = price; for(int k=0;k<6;k++) tmp[num+k][index][0] = price; } else if(bar < cbars) { dema1 = DEMAOnArray(index,num ,price,per,v,cbars,bar); dema2 = DEMAOnArray(index,num+2,dema1,per,v,cbars,bar); T3 = DEMAOnArray(index,num+4,dema2,per,v,cbars,bar); } return(T3); } // MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers double ITrendOnArray(double& price[],double& array[],int per,int cbars,int bar) { double it = 0, alpha = 2.0/(per + 1); if(bar < cbars && array[1] > 0 && array[2] > 0) it = (alpha - 0.25*alpha*alpha)*price[bar] + 0.5*alpha*alpha*price[bar+1] -(alpha - 0.75*alpha*alpha)*price[bar+2] + 2*(1 - alpha)*array[1] -(1 - alpha)*(1 - alpha)*array[2]; else it = (price[bar] + 2*price[bar+1] + price[bar+2])/4; return(it); } // MA_Method=13: Median - Moving Median double MedianOnArray(double& price[],int per,int cbars,int bar) { double median = 0, array[]; ArrayResize(array,per); if(bar < cbars) { for(int i=0;i 0) median = array[num]; else median = 0.5*(array[num] + array[num+1]); } return(median); } // MA_Method=14: GeoMean - Geometric Mean double GeoMeanOnArray(double& price[],int per,int cbars,int bar) { double gmean = 0; if(bar < cbars) { gmean = MathPow(price[bar],1.0/per); for(int i=1;i 0 && array[2] > 0) rema = (array[1]*(1 + 2*lambda) + alpha*(price - array[1]) - lambda*array[2])/(1 + lambda); else rema = price; return(rema); } // MA_Method=16: ILRS - Integral of Linear Regression Slope double ILRSOnArray(double& price[],int per,int cbars,int bar) { double slope, sum = per*(per - 1)*0.5; double ilrs = 0, sum2 = (per - 1)*per*(2*per - 1)/6.0; if(bar < cbars) { double sum1 = 0; double sumy = 0; for(int i=0;i 0) return(sum/weight); else return(0); } // MA_Method=20: JSmooth - Smoothing by Mark Jurik double JSmoothOnArray(int index,int num,double price,int per,double power,int cbars,int bar) { double beta = 0.45*(per - 1)/(0.45*(per - 1) + 2); double alpha = MathPow(beta,power); if(bar == cbars) {tmp[num+4][index][0] = price; tmp[num+0][index][0] = price; tmp[num+2][index][0] = price;} else if(bar < cbars) { tmp[num+0][index][0] = (1 - alpha)*price + alpha*tmp[num+0][index][1]; tmp[num+1][index][0] = (price - tmp[num+0][index][0])*(1-beta) + beta*tmp[num+1][index][1]; tmp[num+2][index][0] = tmp[num+0][index][0] + tmp[num+1][index][0]; tmp[num+3][index][0] = (tmp[num+2][index][0] - tmp[num+4][index][1])*MathPow((1-alpha),2) + MathPow(alpha,2)*tmp[num+3][index][1]; tmp[num+4][index][0] = tmp[num+4][index][1] + tmp[num+3][index][0]; } return(tmp[num+4][index][0]); } // MA_Method=21: SMA_eq - Simplified SMA double SMA_eqOnArray(double& price[],double& array[],int per,int cbars,int bar) { double sma = 0; if(bar == cbars) sma = SMAOnArray(price,per,bar); else if(bar < cbars) sma = (price[bar] - price[bar+per])/per + array[1]; return(sma); } // MA_Method=22: ALMA by Arnaud Legoux / Dimitris Kouzis-Loukas / Anthony Cascino double ALMAOnArray(double& price[],int per,double offset,double sigma,int bar) { double m = MathFloor(offset*(per - 1)), s = per/sigma, w, sum = 0, wsum = 0; for(int i=0;i= cbars) tmp[i][index][0] = price; else { if(i == 0) tmp[i][index][0] = (1 - gamma)*price + gamma*tmp[i][index][1]; else tmp[i][index][0] = -gamma*tmp[i-1][index][0] + tmp[i-1][index][1] + gamma*tmp[i][index][1]; aPrice[i] = tmp[i][index][0]; } } double laguerre = TriMA_genOnArray(aPrice,order,cbars,0); return(laguerre); } // MA_Method=26: MD - McGinley Dynamic double McGinleyOnArray(double price,double prev,int per,int cbars,int bar) { double md = 0; if(bar == cbars) md = price; else if(bar < cbars) if(prev != 0) md = prev + (price - prev)/(per*MathPow(price/prev,4)/2); else md = price; return(md); } // MA_Method=27: BF2P - Two-pole modified Butterworth filter double BF2POnArray(double& price[],double& array[],int per,int cbars,int bar) { double a = MathExp(-1.414*pi/per); double b = 2*a*MathCos(1.414*1.25*pi/per); double c2 = b; double c3 = -a*a; double c1 = 1 - c2 - c3, bf2p; if(bar < cbars && array[1] > 0 && array[2] > 0) {bf2p = c1*(price[bar] + 2*price[bar+1] + price[bar+2])/4 + c2*array[1] + c3*array[2]; if(bar == cbars-1) Print("bar=",bar," cbars=",cbars," bf2p=",bf2p," array[1]=",array[1]," array[2]=",array[2]); } else bf2p = (price[bar] + 2*price[bar+1] + price[bar+2])/4; return(bf2p); } // MA_Method=28: BF3P - Three-pole modified Butterworth filter double BF3POnArray(double& price[],double& array[],int per,int cbars,int bar) { double a = MathExp(-pi/per); double b = 2*a*MathCos(1.738*pi/per); double c = a*a; double d2 = b + c; double d3 = -(c + b*c); double d4 = c*c; double d1 = 1 - d2 - d3 - d4, bf3p; if(bar < cbars && array[1] > 0 && array[2] > 0 && array[3] > 0) bf3p = d1*(price[bar] + 3*price[bar+1] + 3*price[bar+2] + price[bar+3])/8 + d2*array[1] + d3*array[2] + d4*array[3]; else bf3p = (price[bar] + 3*price[bar+1] + 3*price[bar+2] + price[bar+3])/8; return(bf3p); } // MA_Method=29: SuperSmu - SuperSmoother filter double SuperSmuOnArray(double& price[],double& array[],int per,int cbars,int bar) { double a = MathExp(-1.414*pi/per); double b = 2*a*MathCos(1.414*pi/per); double c2 = b; double c3 = -a*a; double c1 = 1 - c2 - c3, supsm; if(bar < cbars && array[1] > 0 && array[2] > 0) supsm = c1*(price[bar] + price[bar+1])/2 + c2*array[1] + c3*array[2]; else supsm = (price[bar] + price[bar+1])/2; return(supsm); } // MA_Method=30: Decycler - Simple Decycler by J.Ehlers double DecyclerOnArray(double& price[],double& hp[],int per,int cbars,int bar) { double alpha1 = (MathCos(1.414*pi/per) + MathSin(1.414*pi/per) - 1)/MathCos(1.414*pi/per); if(bar > cbars - 4) return(0); hp[0] = (1 - alpha1/2)*(1 - alpha1/2)*(price[bar] - 2*price[bar+1] + price[bar+2]) + 2*(1 - alpha1)*hp[1] - (1 - alpha1)*(1 - alpha1)*hp[2]; return(hp[0]); } // MA_Method=31: eVWMA - Elastic Volume Weighted Moving Average by C.Fries double eVWMAOnArray(double price,double prev,int per,int cbars,int bar) { double evwma; if(bar < cbars && prev > 0) { double max = 0; for(int i=0;i open) return((high + close)/2); else return((low + close)/2); break; default: return(close); break; } } // HeikenAshi Price double haClose[2][2], haOpen[2][2], haHigh[2][2], haLow[2][2]; datetime prevhatime[2]; double HeikenAshi(int index,int price,int cbars,int bar) { if(prevhatime[index] != Time[bar]) { haClose[index][1] = haClose[index][0]; haOpen [index][1] = haOpen [index][0]; haHigh [index][1] = haHigh [index][0]; haLow [index][1] = haLow [index][0]; prevhatime[index] = Time[bar]; } if(bar == cbars) { haClose[index][0] = Close[bar]; haOpen [index][0] = Open [bar]; haHigh [index][0] = High [bar]; haLow [index][0] = Low [bar]; } else if(bar < cbars) { haClose[index][0] = (Open[bar] + High[bar] + Low[bar] + Close[bar])/4; haOpen [index][0] = (haOpen[index][1] + haClose[index][1])/2; haHigh [index][0] = MathMax(High[bar],MathMax(haOpen[index][0],haClose[index][0])); haLow [index][0] = MathMin(Low [bar],MathMin(haOpen[index][0],haClose[index][0])); } switch(price) { case 0: return(haClose[index][0]); break; case 1: return(haOpen [index][0]); break; case 2: return(haHigh [index][0]); break; case 3: return(haLow [index][0]); break; case 4: return((haHigh [index][0] + haLow [index][0])/2); break; case 5: return((haHigh[index][0] + haLow[index][0] + haClose[index][0])/3); break; case 6: return((haHigh[index][0] + haLow[index][0] + 2*haClose[index][0])/4); break; case 7: return((haClose[index][0] + haOpen[index][0])/2); break; case 8: return((haHigh[index][0] + haLow[index][0] + haClose[index][0] + haOpen[index][0])/4); break; case 9: if(haClose[index][0] > haOpen[index][0]) return((haHigh[index][0] + haClose[index][0])/2); else return((haLow[index][0] + haClose[index][0])/2); break; default: return(haClose[index][0]); break; } } datetime prevnbtime; bool isNewBar(int tf) { bool res = false; if(tf >= 0) { if(iTime(NULL,tf,0) != prevnbtime) { res = true; prevnbtime = iTime(NULL,tf,0); } } else res = true; return(res); } string prevmess; bool BoxAlert(bool cond,string text) { string mess = IndicatorName + "("+Symbol()+","+TF + ")" + text; if (cond && mess != prevmess) { Alert (mess); prevmess = mess; return(true); } return(false); } datetime pausetime; bool Pause(int sec) { if(TimeCurrent() >= pausetime + sec) {pausetime = TimeCurrent(); return(true);} return(false); } datetime warningtime; void WarningSound(bool cond,int num,int sec,string sound,datetime curtime) { static int i; if(cond) { if(curtime != warningtime) i = 0; if(i < num && Pause(sec)) {PlaySound(sound); warningtime = curtime; i++;} } } string prevemail; bool EmailAlert(bool cond,string text1,string text2,int num) { string subj = "New " + text1 +" Signal from " + IndicatorName + "!!!"; string mess = IndicatorName + "("+Symbol()+","+TF + ")" + text2; if (cond && mess != prevemail) { if(subj != "" && mess != "") for(int i=0;i= PERIOD_H1 ) result = "H" + (string)(itimeframe/PERIOD_H1); if(itimeframe >= PERIOD_D1 ) result = "D" + (string)(itimeframe/PERIOD_D1); if(itimeframe >= PERIOD_W1 ) result = "W" + (string)(itimeframe/PERIOD_W1); if(itimeframe >= PERIOD_MN1) result = "MN" + (string)(itimeframe/PERIOD_MN1); } return(result); }