百变霹雳小小招财猫!
大型投行
- 金钱
- 36815 美元
- 权重
- 437 股
|
VOLTY CHANNEL STOP (波动通道止损)是一个能够清楚标识出当前应该是做多还是做空的主图指标,远点代表进场的信号,细线是止损位。有一些专门根据这个指标发展出来的EA,也很受欢迎。
这里给大家介绍最新的VoltyChannel_Stop_v6.3.mq4,增加了很多新功能,指标比旧版本更为强大。当然,还是一如既往的直观和简单。
以下是设定部分:
VoltyChannel_Stop_v6.3.zip
(6.96 KB, 下载次数: 37, 售价: 5 金钱)
VoltyChannel_Stop_v6.3.mq4
(32.28 KB, 下载次数: 14, 售价: 5 金钱)
如需下载请回复,谢谢。
代码:
- //+------------------------------------------------------------------+
- //| VoltyChannel_Stop_v6.3.mq4 |
- //| Copyright ?2004-14, TrendLaboratory |
- //| http://finance.groups.yahoo.com/group/TrendLaboratory |
- //| E-mail: igorad2003@yahoo.co.uk |
- //+------------------------------------------------------------------+
- // List of MAs:
- // MA_Method= 0: SMA - Simple Moving Average
- // MA_Method= 1: EMA - Exponential Moving Average
- // MA_Method= 2: Wilder - Wilder Exponential Moving Average
- // MA_Method= 3: LWMA - Linear Weighted Moving Average
- // MA_Method= 4: SineWMA - Sine Weighted Moving Average
- // MA_Method= 5: TriMA - Triangular Moving Average
- // MA_Method= 6: LSMA - Least Square Moving Average (or EPMA, Linear Regression Line)
- // MA_Method= 7: SMMA - Smoothed Moving Average
- // MA_Method= 8: HMA - Hull Moving Average by Alan Hull
- // MA_Method= 9: ZeroLagEMA - Zero-Lag Exponential Moving Average
- // MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy
- // MA_Method=11: T3_basic - T3 by T.Tillson (original version)
- // MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers
- // MA_Method=13: Median - Moving Median
- // MA_Method=14: GeoMean - Geometric Mean
- // MA_Method=15: REMA - Regularized EMA by Chris Satchwell
- // MA_Method=16: ILRS - Integral of Linear Regression Slope
- // MA_Method=17: IE/2 - Combination of LSMA and ILRS
- // MA_Method=18: TriMAgen - Triangular Moving Average generalized by J.Ehlers
- // MA_Method=19: VWMA - Volume Weighted Moving Average
- // MA_Method=20: JSmooth - Smoothing by Mark Jurik
- // MA_Method=21: SMA_eq - Simplified SMA
- // MA_Method=22: ALMA - Arnaud Legoux Moving Average
- // MA_Method=23: TEMA - Triple Exponential Moving Average by Patrick Mulloy
- // MA_Method=24: T3 - T3 by T.Tillson (correct version)
- // MA_Method=25: Laguerre - Laguerre filter by J.Ehlers
- // MA_Method=26: MD - McGinley Dynamic
- #property copyright "Copyright ?2004-14, TrendLaboratory"
- #property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
- #property indicator_chart_window
- #property indicator_buffers 6
- #property indicator_color1 RoyalBlue
- #property indicator_color2 Coral
- #property indicator_color3 RoyalBlue
- #property indicator_color4 Coral
- #property indicator_width3 2
- #property indicator_width4 2
- #property indicator_color5 RoyalBlue
- #property indicator_color6 Coral
- //---- input parameters
- extern int TimeFrame = 0; //TimeFrame in min
- extern int UpBandPrice = 0; //Upper Band Price(ex.2 for High)
- extern int LoBandPrice = 0; //Lower Band Price(ex.3 for Low)
- extern int BreakOutMode = 0; //Breakout Mode:0-by Close,1-by Up/Lo Band Price,2-by Up/Lo MA(Length,MA_Mode)
- extern int Length = 1; //MA Period
- extern int MA_Mode = 0; //MA Method(see list above)
- extern int ATR_Length = 10; //ATR's Period
- extern double Multiplier = 3; //Volatility Multiplier
- extern double Ratchet = 0.0; //Ratchet(-1-off,>= 0-on)
- extern double MoneyRisk = 1.00; //Offset Factor(eg.1.2)
- extern int SignalMode = 1; //SignalMode: 0-off,1-on
- extern int LineMode = 1; //Line mode : 0-off,1-on
- extern int DotMode = 1; //Dot mode : 0-off,1-on
- extern string alerts = "--- Alerts & Emails ---";
- extern int AlertMode = 0;
- extern int SoundsNumber = 5; //Number of sounds after Signal
- extern int SoundsPause = 5; //Pause in sec between sounds
- extern string UpSound = "alert.wav";
- extern string DnSound = "alert2.wav";
- extern int EmailMode = 0; //0-on,1-off
- extern int EmailsNumber = 1; //0-on,1-off
- //---- indicator buffers
- double UpTrend[];
- double DnTrend[];
- double UpSignal[];
- double DnSignal[];
- double UpLine[];
- double DnLine[];
- int masize;
- double tmp[][2][2], ma[2][3];
- double mult[2], trend[3], upband1[2], dnband1[2], upband2[2], dnband2[2], hh[2], ll[2];
- datetime prevstime, prevtime[2], preTime, ptime;
- string ma_name, short_name, TF, IndicatorName, prevmess, prevemail;
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- if(TimeFrame <= Period()) TimeFrame = Period();
- TF = tf(TimeFrame);
-
- //----
- 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);
-
- IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
- //----
- Length = MathMax(1,Length);
- ATR_Length = MathMax(1,ATR_Length);
-
- ma_name = averageName(MA_Mode,masize);
-
- IndicatorName = WindowExpertName();
- short_name = IndicatorName+"["+TF+"]("+UpBandPrice+","+LoBandPrice+","+BreakOutMode+","+Length+","+ma_name+","+ATR_Length+","+DoubleToStr(Multiplier,2)+","+DoubleToStr(Ratchet,2)+","+DoubleToStr(MoneyRisk,2)+")";
- IndicatorShortName(short_name);
- SetIndexLabel(0,"UpTrend Stop");
- SetIndexLabel(1,"DnTrend Stop");
- SetIndexLabel(2,"UpTrend Signal");
- SetIndexLabel(3,"DnTrend Signal");
- SetIndexLabel(4,"UpTrend Line");
- SetIndexLabel(5,"DnTrend Line");
- //----
- mult[0] = Multiplier;
-
- int draw_begin = MathMax(2,Bars - iBars(NULL,TimeFrame)*TimeFrame/Period() + MathMax(Length,ATR_Length));
- SetIndexDrawBegin(0,draw_begin);
- SetIndexDrawBegin(1,draw_begin);
- SetIndexDrawBegin(2,draw_begin);
- SetIndexDrawBegin(3,draw_begin);
- SetIndexDrawBegin(4,draw_begin);
- SetIndexDrawBegin(5,draw_begin);
- //----
- ArrayResize(tmp,masize);
-
-
- return(0);
- }
- //----
- int deinit() {Comment(""); return(0);}
- //+------------------------------------------------------------------+
- //| VoltyChannel_Stop_v6.2 |
- //+------------------------------------------------------------------+
- int start()
- {
- int shift, limit, counted_bars=IndicatorCounted();
-
- if(counted_bars > 0) limit = Bars - counted_bars - 1;
- if(counted_bars < 0) return(0);
- if(counted_bars < 1)
- {
- limit = Bars-1;
- for(int i=0;i<limit;i++)
- {
- UpTrend[i] = EMPTY_VALUE;
- DnTrend[i] = EMPTY_VALUE;
- UpSignal[i] = EMPTY_VALUE;
- DnSignal[i] = EMPTY_VALUE;
- UpLine[i] = EMPTY_VALUE;
- DnLine[i] = EMPTY_VALUE;
- }
- }
-
-
- if(TimeFrame != Period())
- {
- limit = MathMax(limit,TimeFrame/Period());
-
- for(shift = 0;shift < limit;shift++)
- {
- int y = iBarShift(NULL,TimeFrame,Time[shift]);
-
- if(DotMode > 0)
- {
- UpTrend[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,BreakOutMode,Length,MA_Mode,ATR_Length,Multiplier,Ratchet,MoneyRisk,SignalMode,LineMode,DotMode,
- "",AlertMode,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,0,y);
-
- DnTrend[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,BreakOutMode,Length,MA_Mode,ATR_Length,Multiplier,Ratchet,MoneyRisk,SignalMode,LineMode,DotMode,
- "",AlertMode,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,1,y);
- }
-
- if(SignalMode > 0)
- {
- UpSignal[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,BreakOutMode,Length,MA_Mode,ATR_Length,Multiplier,Ratchet,MoneyRisk,SignalMode,LineMode,DotMode,
- "",AlertMode,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,2,y);
- DnSignal[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,BreakOutMode,Length,MA_Mode,ATR_Length,Multiplier,Ratchet,MoneyRisk,SignalMode,LineMode,DotMode,
- "",AlertMode,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,3,y);
- }
-
- if(LineMode > 0)
- {
- UpLine[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,BreakOutMode,Length,MA_Mode,ATR_Length,Multiplier,Ratchet,MoneyRisk,SignalMode,LineMode,DotMode,
- "",AlertMode,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,4,y);
- DnLine[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,BreakOutMode,Length,MA_Mode,ATR_Length,Multiplier,Ratchet,MoneyRisk,SignalMode,LineMode,DotMode,
- "",AlertMode,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,5,y);
- }
- }
-
- return(0);
- }
- else
- {
- for(shift=limit;shift>=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];
- trend[2] = trend[1];
- trend[1] = trend[0];
- hh[1] = hh[0];
- ll[1] = ll[0];
- prevstime = Time[shift];
- }
-
-
- if(trend[1] != trend[2]) mult[1] = Multiplier;
-
- double upMA = allAverages(0,UpBandPrice,Length,MA_Mode,masize,shift);
- double dnMA = allAverages(1,LoBandPrice,Length,MA_Mode,masize,shift);
-
- double atr = iATR(NULL,0,ATR_Length,shift);
-
- upband1[0] = upMA + mult[1]*atr;
- dnband1[0] = dnMA - 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]);
-
-
- trend[0] = trend[1];
- mult[0] = mult[1];
- hh[0] = hh[1];
- ll[0] = ll[1];
-
- switch(BreakOutMode)
- {
- case 1: if(iMA(NULL,0,1,0,0,UpBandPrice,shift) > upband1[1] && trend[1] <= 0) {trend[0] = 1; hh[0] = High[shift];}
- if(iMA(NULL,0,1,0,0,LoBandPrice,shift) < dnband1[1] && trend[1] >= 0) {trend[0] =-1; ll[0] = Low [shift];}
- break;
-
- case 2: if(upMA > upband1[1] && trend[1] <= 0) {trend[0] = 1; hh[0] = High[shift];}
- if(dnMA < dnband1[1] && trend[1] >= 0) {trend[0] =-1; ll[0] = Low [shift];}
-
- default: if(Close[shift] > upband1[1] && trend[1] <= 0) {trend[0] = 1; hh[0] = High[shift];}
- if(Close[shift] < dnband1[1] && trend[1] >= 0) {trend[0] =-1; ll[0] = Low [shift];}
- break;
- }
-
- hh[0] = MathMax(High[shift],hh[0]);
- ll[0] = MathMin(Low [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;
-
-
- if(trend[0] > 0)
- {
- if(trend[1] > 0 && Ratchet >= 0)
- {
- if(hh[0] > hh[1] && trend[1] > 0) mult[0] -= Ratchet;
-
- if(dnband1[0] < dnband1[1]) dnband1[0] = dnband1[1];
- if(dnband2[0] < dnband2[1]) dnband2[0] = dnband2[1];
- }
-
- if(DotMode > 0) UpTrend[shift] = dnband2[0];
- if(LineMode > 0) UpLine[shift] = dnband2[0];
- if(SignalMode > 0 && trend[1] < 0) UpSignal[shift] = dnband2[0];
- }
-
- if(trend[0] < 0)
- {
- if(trend[1] < 0 && Ratchet >= 0)
- {
- if(ll[0] < ll[1] && trend[1] < 0) mult[0] -= Ratchet;
-
- if(upband1[0] > upband1[1]) upband1[0] = upband1[1];
- if(upband2[0] > upband2[1]) upband2[0] = upband2[1];
- }
-
- if(DotMode > 0) DnTrend[shift] = upband2[0];
- if(LineMode > 0) DnLine[shift] = upband2[0];
- if(SignalMode > 0 && trend[1] > 0) DnSignal[shift] = upband2[0];
- }
- }
- //----
- if(AlertMode > 0)
- {
- bool uptrend = trend[1] > 0 && trend[2] <= 0;
- bool dntrend = trend[1] < 0 && trend[2] >= 0;
-
- if(uptrend || dntrend)
- {
- if(isNewBar(TimeFrame))
- {
- BoxAlert(uptrend," : BUY Signal at " +DoubleToStr(Close[1],Digits)+", StopLoss at "+DoubleToStr(UpSignal[1],Digits));
- BoxAlert(dntrend," : SELL Signal at "+DoubleToStr(Close[1],Digits)+", StopLoss at "+DoubleToStr(DnSignal[1],Digits));
- }
-
- WarningSound(uptrend,SoundsNumber,SoundsPause,UpSound,Time[1]);
- WarningSound(dntrend,SoundsNumber,SoundsPause,DnSound,Time[1]);
-
- if(EmailMode > 0)
- {
- EmailAlert(uptrend,"BUY" ," : BUY Signal at " +DoubleToStr(Close[1],Digits)+", StopLoss at "+DoubleToStr(UpSignal[1],Digits),EmailsNumber);
- EmailAlert(dntrend,"SELL"," : SELL Signal at "+DoubleToStr(Close[1],Digits)+", StopLoss at "+DoubleToStr(DnSignal[1],Digits),EmailsNumber);
- }
- }
- }
- }
-
-
- //----
- return(0);
- }
- string averageName(int mode,int& arraysize)
- {
- string _ma_name = "";
-
- switch(mode)
- {
- case 1 : _ma_name="EMA" ; break;
- case 2 : _ma_name="Wilder" ; break;
- case 3 : _ma_name="LWMA" ; break;
- case 4 : _ma_name="SineWMA" ; break;
- case 5 : _ma_name="TriMA" ; break;
- case 6 : _ma_name="LSMA" ; break;
- case 7 : _ma_name="SMMA" ; break;
- case 8 : _ma_name="HMA" ; break;
- case 9 : _ma_name="ZeroLagEMA"; break;
- case 10: _ma_name="DEMA" ; arraysize = 2; break;
- case 11: _ma_name="T3 basic" ; arraysize = 6; break;
- case 12: _ma_name="InstTrend" ; break;
- case 13: _ma_name="Median" ; break;
- case 14: _ma_name="GeoMean" ; break;
- case 15: _ma_name="REMA" ; break;
- case 16: _ma_name="ILRS" ; break;
- case 17: _ma_name="IE/2" ; break;
- case 18: _ma_name="TriMA_gen" ; break;
- case 19: _ma_name="VWMA" ; break;
- case 20: _ma_name="JSmooth" ; arraysize = 5; break;
- case 21: _ma_name="SMA_eq" ; break;
- case 22: _ma_name="ALMA" ; break;
- case 23: _ma_name="TEMA" ; arraysize = 4; break;
- case 24: _ma_name="T3" ; arraysize = 6; break;
- case 25: _ma_name="Laguerre" ; arraysize = 4; break;
- case 26: _ma_name="MD" ; break;
- default: _ma_name="SMA";
- }
-
- return(_ma_name);
-
- }
- double allAverages(int index,int price,int period,int mode,int arraysize,int bar)
- {
- double MA[3];
-
- if(prevtime[index] != Time[bar])
- {
- ma[index][2] = ma[index][1];
- ma[index][1] = ma[index][0];
- for(int i=0;i<arraysize;i++) tmp[i][index][1] = tmp[i][index][0];
-
- prevtime[index] = Time[bar];
- }
-
- for(i=0;i<3;i++) MA[i] = ma[index][i];
-
- switch(mode)
- {
- case 1 : ma[index][0] = EMA(price,ma[index][1],period,bar); break;
- case 2 : ma[index][0] = Wilder(price,ma[index][1],period,bar); break;
- case 3 : ma[index][0] = LWMA(price,period,bar); break;
- case 4 : ma[index][0] = SineWMA(price,period,bar); break;
- case 5 : ma[index][0] = TriMA(price,period,bar); break;
- case 6 : ma[index][0] = LSMA(price,period,bar); break;
- case 7 : ma[index][0] = SMMA(price,ma[index][1],period,bar); break;
- case 8 : ma[index][0] = HMA(price,period,bar); break;
- case 9 : ma[index][0] = ZeroLagEMA(price,ma[index][1],period,bar); break;
- case 10: ma[index][0] = DEMA(index,0,price,period,1,bar); break;
- case 11: ma[index][0] = T3_basic(index,0,price,period,0.7,bar); break;
- case 12: ma[index][0] = ITrend(price,MA,period,bar); break;
- case 13: ma[index][0] = Median(price,period,bar); break;
- case 14: ma[index][0] = GeoMean(price,period,bar); break;
- case 15: ma[index][0] = REMA(price,MA,period,0.5,bar); break;
- case 16: ma[index][0] = ILRS(price,period,bar); break;
- case 17: ma[index][0] = IE2(price,period,bar); break;
- case 18: ma[index][0] = TriMA_gen(price,period,bar); break;
- case 19: ma[index][0] = VWMA(price,period,bar); break;
- case 20: ma[index][0] = JSmooth(index,0,price,period,1,bar); break;
- case 21: ma[index][0] = SMA_eq(price,MA,period,bar); break;
- case 22: ma[index][0] = ALMA(price,period,0.85,8,bar); break;
- case 23: ma[index][0] = TEMA(index,price,period,1,bar); break;
- case 24: ma[index][0] = T3(index,0,price,period,0.7,bar); break;
- case 25: ma[index][0] = Laguerre(index,price,period,4,bar); break;
- case 26: ma[index][0] = McGinley(price,ma[index][1],period,bar); break;
- default: ma[index][0] = SMA(price,period,bar); break;
- }
-
- return(ma[index][0]);
- }
- // MA_Method=0: SMA - Simple Moving Average
- double SMA(int price,int per,int bar)
- {
- double Sum = 0;
- for(int i = 0;i < per;i++) Sum += iMA(NULL,0,1,0,0,price,bar+i);
-
- return(Sum/per);
- }
- double SMAOnArray(double& array[],int per,int bar)
- {
- double Sum = 0;
- for(int i = 0;i < per;i++) Sum += array[bar+i];
-
- return(Sum/per);
- }
-
- // MA_Method=1: EMA - Exponential Moving Average
- double EMA(int price,double prev,int per,int bar)
- {
- if(bar >= Bars - 2) double ema = iMA(NULL,0,1,0,0,price,bar);
- else
- ema = prev + 2.0/(1+per)*(iMA(NULL,0,1,0,0,price,bar) - prev);
-
- return(ema);
- }
- // MA_Method=2: Wilder - Wilder Exponential Moving Average
- double Wilder(int price,double prev,int per,int bar)
- {
- if(bar >= Bars - 2) double wilder = iMA(NULL,0,1,0,0,price,bar); //SMA(array1,per,bar);
- else
- wilder = prev + (iMA(NULL,0,1,0,0,price,bar) - prev)/per;
-
- return(wilder);
- }
- // MA_Method=3: LWMA - Linear Weighted Moving Average
- double LWMA(int price,int per,int bar)
- {
- double Sum = 0;
- double Weight = 0;
-
- for(int i = 0;i < per;i++)
- {
- Weight+= (per - i);
- Sum += iMA(NULL,0,1,0,0,price,bar+i)*(per - i);
- }
- if(Weight>0) double lwma = Sum/Weight;
- else lwma = 0;
- return(lwma);
- }
- double LWMAOnArray(double& array[],int per,int bar)
- {
- double Sum = 0;
- double Weight = 0;
-
- for(int i = 0;i < per;i++)
- {
- Weight+= (per - i);
- Sum += array[bar+i]*(per - i);
- }
- if(Weight>0) double lwma = Sum/Weight;
- else lwma = 0;
- return(lwma);
- }
-
- // MA_Method=4: SineWMA - Sine Weighted Moving Average
- double SineWMA(int price,int per,int bar)
- {
- double pi = 3.1415926535;
- double Sum = 0;
- double Weight = 0;
-
- for(int i = 0;i < per;i++)
- {
- Weight+= MathSin(pi*(i+1)/(per+1));
- Sum += iMA(NULL,0,1,0,0,price,bar+i)*MathSin(pi*(i+1)/(per+1));
- }
- if(Weight>0) double swma = Sum/Weight;
- else swma = 0;
- return(swma);
- }
- // MA_Method=5: TriMA - Triangular Moving Average
- double TriMA(int price,int per,int bar)
- {
- double sma;
- int len = MathCeil((per+1)*0.5);
-
- double sum=0;
- for(int i = 0;i < len;i++)
- {
- sma = SMA(price,len,bar+i);
- sum += sma;
- }
- double trima = sum/len;
-
- return(trima);
- }
- // MA_Method=6: LSMA - Least Square Moving Average (or EPMA, Linear Regression Line)
- double LSMA(int price,int per,int bar)
- {
- double Sum=0;
- for(int i=per; i>=1; i--) Sum += (i-(per+1)/3.0)*iMA(NULL,0,1,0,0,price,bar+per-i);
- double lsma = Sum*6/(per*(per+1));
- return(lsma);
- }
- // MA_Method=7: SMMA - Smoothed Moving Average
- double SMMA(int price,double prev,int per,int bar)
- {
- if(bar == Bars - per) double smma = SMA(price,per,bar);
- else
- if(bar < Bars - per)
- {
- double Sum = 0;
- for(int i = 0;i < per;i++) Sum += iMA(NULL,0,1,0,0,price,bar+i+1);
- smma = (Sum - prev + iMA(NULL,0,1,0,0,price,bar))/per;
- }
-
- return(smma);
- }
- // MA_Method=8: HMA - Hull Moving Average by Alan Hull
- double HMA(int price,int per,int bar)
- {
- double _tmp[];
- int len = MathSqrt(per);
-
- ArrayResize(_tmp,len);
-
- if(bar == Bars - per) double hma = iMA(NULL,0,1,0,0,price,bar);
- else
- if(bar < Bars - per)
- {
- for(int i=0;i<len;i++) _tmp[i] = 2*LWMA(price,per/2,bar+i) - LWMA(price,per,bar+i);
- hma = LWMAOnArray(_tmp,len,0);
- }
- return(hma);
- }
- // MA_Method=9: ZeroLagEMA - Zero-Lag Exponential Moving Average
- double ZeroLagEMA(int price,double prev,int per,int bar)
- {
- double alfa = 2.0/(1+per);
- int lag = 0.5*(per - 1);
-
- if(bar >= Bars - lag) double zema = iMA(NULL,0,1,0,0,price,bar);
- else
- zema = alfa*(2*iMA(NULL,0,1,0,0,price,bar) - iMA(NULL,0,1,0,0,price,bar+lag)) + (1-alfa)*prev;
-
- return(zema);
- }
- // MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy
- double DEMA(int index,int num,int price,double per,double v,int bar)
- {
- double alpha = 2.0/(1+per);
- if(bar == Bars - 2) {double dema = iMA(NULL,0,1,0,0,price,bar); tmp[num][index][0] = dema; tmp[num+1][index][0] = dema;}
- else
- if(bar < Bars - 2)
- {
- tmp[num ][index][0] = tmp[num ][index][1] + alpha*(iMA(NULL,0,1,0,0,price,bar) - 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);
- }
- double DEMAOnArray(int index,int num,double price,double per,double v,int bar)
- {
- double alpha = 2.0/(1+per);
- if(bar == Bars - 2) {double dema = price; tmp[num][index][0] = dema; tmp[num+1][index][0] = dema;}
- else
- if(bar < Bars - 2)
- {
- 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_basic(int index,int num,int price,int per,double v,int bar)
- {
- double dema1, dema2;
-
- if(bar == Bars - 2)
- {
- double T3 = iMA(NULL,0,1,0,0,price,bar);
- for(int k=0;k<6;k++) tmp[num+k][index][0] = T3;
- }
- else
- if(bar < Bars - 2)
- {
- T3 = iMA(NULL,0,1,0,0,price,bar);
- dema1 = DEMAOnArray(index,num ,T3 ,per,v,bar);
- dema2 = DEMAOnArray(index,num+2,dema1,per,v,bar);
- T3 = DEMAOnArray(index,num+4,dema2,per,v,bar);
- }
-
- return(T3);
- }
- // MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers
- double ITrend(int price,double& array[],int per,int bar)
- {
- double alfa = 2.0/(per + 1);
- if(bar < Bars - 7)
- double it = (alfa - 0.25*alfa*alfa)*iMA(NULL,0,1,0,0,price,bar) + 0.5*alfa*alfa*iMA(NULL,0,1,0,0,price,bar+1)
- - (alfa - 0.75*alfa*alfa)*iMA(NULL,0,1,0,0,price,bar+2) + 2*(1-alfa)*array[1] - (1-alfa)*(1-alfa)*array[2];
- else
- it = (iMA(NULL,0,1,0,0,price,bar) + 2*iMA(NULL,0,1,0,0,price,bar+1) + iMA(NULL,0,1,0,0,price,bar)+2)/4;
-
- return(it);
- }
- // MA_Method=13: Median - Moving Median
- double Median(int price,int per,int bar)
- {
- double array[];
- ArrayResize(array,per);
-
- for(int i = 0; i < per;i++) array[i] = iMA(NULL,0,1,0,0,price,bar+i);
- ArraySort(array);
-
- int num = MathRound((per-1)/2);
- if(MathMod(per,2) > 0) double median = array[num]; else median = 0.5*(array[num]+array[num+1]);
-
- return(median);
- }
- // MA_Method=14: GeoMean - Geometric Mean
- double GeoMean(int price,int per,int bar)
- {
- if(bar < Bars - per)
- {
- double gmean = MathPow(iMA(NULL,0,1,0,0,price,bar),1.0/per);
- for(int i = 1; i < per;i++) gmean *= MathPow(iMA(NULL,0,1,0,0,price,bar+i),1.0/per);
- }
-
- return(gmean);
- }
- // MA_Method=15: REMA - Regularized EMA by Chris Satchwell
- double REMA(int price,double& array[],int per,double lambda,int bar)
- {
- double alpha = 2.0/(per + 1);
- if(bar >= Bars - 3) double rema = iMA(NULL,0,1,0,0,price,bar);
- else
- rema = (array[1]*(1+2*lambda) + alpha*(iMA(NULL,0,1,0,0,price,bar) - array[1]) - lambda*array[2])/(1+lambda);
-
- return(rema);
- }
- // MA_Method=16: ILRS - Integral of Linear Regression Slope
- double ILRS(int price,int per,int bar)
- {
- double sum = per*(per-1)*0.5;
- double sum2 = (per-1)*per*(2*per-1)/6.0;
-
- double sum1 = 0;
- double sumy = 0;
- for(int i=0;i<per;i++)
- {
- sum1 += i*iMA(NULL,0,1,0,0,price,bar+i);
- sumy += iMA(NULL,0,1,0,0,price,bar+i);
- }
- double num1 = per*sum1 - sum*sumy;
- double num2 = sum*sum - per*sum2;
-
- if(num2 != 0) double slope = num1/num2; else slope = 0;
- double ilrs = slope + SMA(price,per,bar);
-
- return(ilrs);
- }
- // MA_Method=17: IE/2 - Combination of LSMA and ILRS
- double IE2(int price,int per,int bar)
- {
- double ie = 0.5*(ILRS(price,per,bar) + LSMA(price,per,bar));
-
- return(ie);
- }
- // MA_Method=18: TriMAgen - Triangular Moving Average Generalized by J.Ehlers
- double TriMA_gen(int price,int per,int bar)
- {
- int len1 = MathFloor((per+1)*0.5);
- int len2 = MathCeil((per+1)*0.5);
- double sum=0;
- for(int i = 0;i < len2;i++) sum += SMA(price,len1,bar+i);
- double trimagen = sum/len2;
-
- return(trimagen);
- }
- double TriMA_genOnArray(double& array[],int per,int bar)
- {
- int len1 = MathFloor((per+1)*0.5);
- int len2 = MathCeil((per+1)*0.5);
- double sum=0;
- for(int i = 0;i < len2;i++) sum += SMAOnArray(array,len1,bar+i);
- double trimagen = sum/len2;
-
- return(trimagen);
- }
- // MA_Method=19: VWMA - Volume Weighted Moving Average
- double VWMA(int price,int per,int bar)
- {
- double Sum = 0;
- double Weight = 0;
-
- for(int i = 0;i < per;i++)
- {
- Weight+= Volume[bar+i];
- Sum += iMA(NULL,0,1,0,0,price,bar+i)*Volume[bar+i];
- }
- if(Weight>0) double vwma = Sum/Weight;
- else vwma = 0;
- return(vwma);
- }
- // MA_Method=20: JSmooth - Smoothing by Mark Jurik
- double JSmooth(int index,int num,int price,int per,double pow,int bar)
- {
- double beta = 0.45*(per-1)/(0.45*(per-1)+2);
- double alpha = MathPow(beta,pow);
- double _ma = iMA(NULL,0,1,0,0,price,bar);
-
- if(bar == Bars - 2)
- {
- tmp[num+4][index][0] = _ma;
- tmp[num+0][index][0] = _ma;
- tmp[num+2][index][0] = _ma;
- }
- else
- if(bar < Bars - 2)
- {
- tmp[num+0][index][0] = (1-alpha)*_ma + alpha*tmp[num+0][index][1];
- tmp[num+1][index][0] = (_ma - 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_eq(int price,double& array[],int per,int bar)
- {
- if(bar == Bars - per) double sma = SMA(price,per,bar);
- else
- if(bar < Bars - per) sma = (iMA(NULL,0,1,0,0,price,bar) - iMA(NULL,0,1,0,0,price,bar+per))/per + array[1];
-
- return(sma);
- }
- // MA_Method=22: ALMA by Arnaud Legoux / Dimitris Kouzis-Loukas / Anthony Cascino
- double ALMA(int price,int per,double offset,double sigma,int bar)
- {
- double m = MathFloor(offset * (per - 1));
- double s = per/sigma;
-
- double w, sum =0, wsum = 0;
- for (int i=0;i < per;i++)
- {
- w = MathExp(-((i - m)*(i - m))/(2*s*s));
- wsum += w;
- sum += iMA(NULL,0,1,0,0,price,bar+(per-1-i))*w;
- }
-
- if(wsum != 0) double alma = sum/wsum;
-
- return(alma);
- }
- // MA_Method=23: TEMA - Triple Exponential Moving Average by Patrick Mulloy
- double TEMA(int index,int price,int per,double v,int bar)
- {
- double alpha = 2.0/(per+1);
- double _ma = iMA(NULL,0,1,0,0,price,bar);
- if(bar == Bars - 2) {tmp[0][index][0] = _ma; tmp[1][index][0] = _ma; tmp[2][index][0] = _ma;}
- else
- if(bar < Bars - 2)
- {
- tmp[0][index][0] = tmp[0][index][1] + alpha *(_ma - tmp[0][index][1]);
- tmp[1][index][0] = tmp[1][index][1] + alpha *(tmp[0][index][0] - tmp[1][index][1]);
- tmp[2][index][0] = tmp[2][index][1] + alpha *(tmp[1][index][0] - tmp[2][index][1]);
- tmp[3][index][0] = tmp[0][index][0] + v*(tmp[0][index][0] + v*(tmp[0][index][0]-tmp[1][index][0]) - tmp[1][index][0] - v*(tmp[1][index][0] - tmp[2][index][0]));
- }
-
- return(tmp[3][index][0]);
- }
- // MA_Method=24: T3 by T.Tillson (correct version)
- double T3(int index,int num,double price,int per,double v,int bar)
- {
- double len = MathMax((per + 5.0)/3.0-1,1), dema1, dema2;
- double T3, _ma = iMA(NULL,0,1,0,0,price,bar);
-
- if(bar == Bars - 2) for(int k=0;k<6;k++) tmp[num+k][index][0] = _ma;
- else
- if(bar < Bars - 2)
- {
- dema1 = DEMAOnArray(index,num ,_ma ,len,v,bar);
- dema2 = DEMAOnArray(index,num+2,dema1,len,v,bar);
- T3 = DEMAOnArray(index,num+4,dema2,len,v,bar);
- }
-
- return(T3);
- }
- // MA_Method=25: Laguerre filter by J.Ehlers
- double Laguerre(int index,int price,int per,int order,int bar)
- {
- double gamma = 1-10.0/(per+9);
- double _ma = iMA(NULL,0,1,0,0,price,bar);
- double aPrice[];
-
- ArrayResize(aPrice,order);
-
- for(int i=0;i<order;i++)
- {
- if(bar >= Bars - order) tmp[i][index][0] = _ma;
- else
- {
- if(i == 0) tmp[i][index][0] = (1 - gamma)*_ma + 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,0);
- return(laguerre);
- }
- // MA_Method=26: MD - McGinley Dynamic
- double McGinley(int price,double prev,int per,int bar)
- {
- if(bar == Bars - 2) double md = iMA(NULL,0,1,0,0,price,bar);
- else
- if(bar < Bars - 2 && prev > 0)
- {
- double p = iMA(NULL,0,1,0,0,price,bar);
- md = prev + (p - prev)/(per*MathPow(p/prev,4)/2);
- }
- return(md);
- }
- bool isNewBar(int tf)
- {
- static datetime pTime;
- bool res=false;
-
- if(tf >= 0)
- {
- if (iTime(NULL,tf,0)!= pTime)
- {
- res=true;
- pTime=iTime(NULL,tf,0);
- }
- }
- else res = true;
-
- return(res);
- }
- bool BoxAlert(bool cond,string text)
- {
- string mess = IndicatorName + "("+Symbol()+","+TF + ")" + text;
-
- if (cond && mess != prevmess)
- {
- Alert (mess);
- prevmess = mess;
- return(true);
- }
-
- return(false);
- }
- bool Pause(int sec)
- {
- if(TimeCurrent() >= preTime + sec) {preTime = TimeCurrent(); return(true);}
-
- return(false);
- }
- void WarningSound(bool cond,int num,int sec,string sound,datetime ctime)
- {
- static int i;
-
- if(cond)
- {
- if(ctime != ptime) i = 0;
- if(i < num && Pause(sec)) {PlaySound(sound); ptime = ctime; i++;}
- }
- }
- 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<num;i++) SendMail(subj, mess);
- prevemail = mess;
- return(true);
- }
-
- return(false);
- }
-
- string tf(int timeframe)
- {
- switch(timeframe)
- {
- case PERIOD_M1: return("M1");
- case PERIOD_M5: return("M5");
- case PERIOD_M15: return("M15");
- case PERIOD_M30: return("M30");
- case PERIOD_H1: return("H1");
- case PERIOD_H4: return("H4");
- case PERIOD_D1: return("D1");
- case PERIOD_W1: return("W1");
- case PERIOD_MN1: return("MN1");
- default: return("Unknown timeframe");
- }
- }
复制代码 |
|