Wave trend oscillator 1.5.mq4
Wave trend oscillator 1.5.mq4 FOREX MetaTrader4 Indicators Download
Wave trend oscillator 1.5.mq4 download link will appear after 20 seconds.
Wave trend oscillator 1.5.mq4 Programming source code.
#property indicator_separate_window #property indicator_buffers 13 #property indicator_color1 clrDeepSkyBlue #property indicator_color2 clrDeepSkyBlue #property indicator_color3 clrDimGray #property indicator_color4 clrSandyBrown #property indicator_color5 clrSandyBrown #property indicator_color6 clrSilver #property indicator_color7 clrDeepSkyBlue #property indicator_color8 clrDeepSkyBlue #property indicator_color9 clrSandyBrown #property indicator_color10 clrSandyBrown #property indicator_color11 clrOrange #property indicator_color12 clrDeepSkyBlue #property indicator_color13 clrSandyBrown #property indicator_style1 STYLE_DOT #property indicator_style2 STYLE_DOT #property indicator_style3 STYLE_DOT #property indicator_style4 STYLE_DOT #property indicator_style5 STYLE_DOT #property indicator_style11 STYLE_DOT #property indicator_width12 2 #property indicator_width13 2 #property strict // // // // // enum enPrices { pr_close, // Close pr_open, // Open pr_high, // High pr_low, // Low pr_median, // Median pr_typical, // Typical pr_weighted, // Weighted pr_average, // Average (high+low+open+close)/4 pr_medianb, // Average median body (open+close)/2 pr_tbiased, // Trend biased price pr_tbiased2, // Trend biased (extreme) price pr_haclose, // Heiken ashi close pr_haopen , // Heiken ashi open pr_hahigh, // Heiken ashi high pr_halow, // Heiken ashi low pr_hamedian, // Heiken ashi median pr_hatypical, // Heiken ashi typical pr_haweighted, // Heiken ashi weighted pr_haaverage, // Heiken ashi average pr_hamedianb, // Heiken ashi median body pr_hatbiased, // Heiken ashi trend biased price pr_hatbiased2 // Heiken ashi trend biased (extreme) price }; enum enColorOn { cl_slope, // Change color on slope change cl_sign, // Change color on sinal line cross cl_mid, // Change color on zero level cross cl_inc, // Change color on inner levels cross cl_out // Change color on outer levels cross }; enum enFilterWhat { flt_prc, // Filter the price flt_val, // Filter the value flt_sig, // Filter the signal value flt_prv, // Filter the price and value flt_prs, // Filter the price and signal flt_siv, // Filter the value and the signal flt_all // Filter all }; enum enMaTypes { ma_sma, // Simple moving average ma_ema, // Exponential moving average ma_smma, // Smoothed MA ma_lwma, // Linear weighted MA ma_tema // Triple exponential moving average - TEMA }; extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use extern int ChanPeriod = 10; // Channel period extern int AverPeriod = 21; // Average period extern enMaTypes AverType = ma_ema; // Average type extern int SignPeriod = 4; // Signal period extern enPrices Price = pr_typical; // Price to use extern double Filter = 0; // Filter to use (<= 0, no filter) extern int FilterPeriod = 0; // Filter period (0 to use channel period) extern enFilterWhat FilterOn = flt_val; // Apply filter to : extern int FlPeriod = 0; // Floating levels period (0 to use fixed levels) extern double ObLevel1 = 60; // Overbought level 1 extern double ObLevel2 = 53; // Overbought level 2 extern double OsLevel1 = -60; // Oversold level 1 extern double OsLevel2 = -53; // Oversold level 2 input enColorOn ColorOn = cl_out; // Color change on : extern bool alertsOn = false; // Turn alerts on? extern bool alertsOnCurrent = true; // Alerts on current (still opened) bar? extern bool alertsMessage = true; // Alerts should show pop-up message? extern bool alertsSound = false; // Alerts should play alert sound? extern bool alertsNotification = false; // Alerts should send push notification? extern bool alertsEmail = false; // Alerts should send email? extern int LineWidth = 2; // Line display width extern int UpDotCode = 159; // Code for up arrow extern int DnDotCode = 159; // Code for down arrow extern bool Interpolate = true; // Interpolate in multi time frame mode? // // // // // double wtos[],wtosua[],wtosub[],wtosda[],wtosdb[],signal[],prices[],levup1[],levup2[],levmi[],levdn1[],levdn2[],dotu[],dotd[],count[],parm[],trend[]; string indicatorFileName; #define _mtfCall(_buff,_y) iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,ChanPeriod,AverPeriod,AverType,SignPeriod,Price,Filter,FilterPeriod,FilterOn,FlPeriod,ObLevel1,ObLevel2,OsLevel1,OsLevel2,ColorOn,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotification,alertsEmail,_buff,_y) //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int init() { IndicatorBuffers(17); SetIndexBuffer(0,levup1); SetIndexBuffer(1,levup2); SetIndexBuffer(2,levmi); SetIndexBuffer(3,levdn2); SetIndexBuffer(4,levdn1); SetIndexBuffer(5,wtos); SetIndexBuffer(6,wtosua); SetIndexBuffer(7,wtosub); SetIndexBuffer(8,wtosda); SetIndexBuffer(9,wtosdb); SetIndexBuffer(10,signal); SetIndexBuffer(11,dotu); SetIndexStyle(11,DRAW_ARROW); SetIndexArrow(11,UpDotCode); SetIndexBuffer(12,dotd); SetIndexStyle(12,DRAW_ARROW); SetIndexArrow(12,UpDotCode); SetIndexBuffer(13,trend); SetIndexBuffer(14,prices); SetIndexBuffer(15,parm); SetIndexBuffer(16,count); for (int i=0; i<5; i++) SetIndexStyle(i,DRAW_LINE); for (int i=5; i<10; i++) SetIndexStyle(i,DRAW_LINE,EMPTY,LineWidth); // // // // // indicatorFileName = WindowExpertName(); TimeFrame = MathMax(TimeFrame,_Period); IndicatorShortName(timeFrameToString(TimeFrame)+" WaveTrend oscillator ("+(string)ChanPeriod+","+(string)AverPeriod+", filter "+(string)Filter+","+(string)FilterPeriod+")"); return(0); } // // // // // int start() { int counted_bars = IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit=MathMin(Bars-counted_bars,Bars-1); count[0] = limit; if (TimeFrame != _Period) { limit = (int)MathMax(limit,MathMin(Bars-1,_mtfCall(16,0)*TimeFrame/_Period)); if (trend[limit]== 1) CleanPoint(limit,wtosua,wtosub); if (trend[limit]==-1) CleanPoint(limit,wtosda,wtosdb); for (int i=limit;i>=0;i--) { int y = iBarShift(NULL,TimeFrame,Time[i]); int x = (i0 && y==iBarShift(NULL,TimeFrame,Time[i-1]))) continue; #define _interpolate(buff) buff[i+k] = buff[i]+(buff[i+n]-buff[i])*k/n int n,k; datetime time = iTime(NULL,TimeFrame,y); for(n = 1; i+n = time; n++) continue; for(k = 1; i+n =0;i--) { if (trend[i]== 1) PlotPoint(i,wtosua,wtosub,wtos); if (trend[i]==-1) PlotPoint(i,wtosda,wtosdb,wtos); } return(0); } // // // // // int tperiod = FilterPeriod; if (tperiod<=0) tperiod=ChanPeriod; double pfilter = Filter; if (FilterOn!=flt_prc && FilterOn!=flt_prv && FilterOn!=flt_prs && FilterOn!=flt_all) pfilter=0; double vfilter = Filter; if (FilterOn!=flt_val && FilterOn!=flt_prv && FilterOn!=flt_siv && FilterOn!=flt_all) vfilter=0; double sfilter = Filter; if (FilterOn!=flt_sig && FilterOn!=flt_prs && FilterOn!=flt_siv && FilterOn!=flt_all) sfilter=0; if (trend[limit]== 1) CleanPoint(limit,wtosua,wtosub); if (trend[limit]==-1) CleanPoint(limit,wtosda,wtosdb); for(int i = limit; i >= 0; i--) { prices[i] = iFilter(getPrice(Price,Open,Close,High,Low,i),pfilter,tperiod,i,0); // // // // // double esa = iCustomMa(AverType, prices[i] ,ChanPeriod,i,0); double d = iCustomMa(AverType,MathAbs(prices[i]-esa),ChanPeriod,i,1); if (d==0) d=_Point; double ci = (prices[i]-esa)/(0.015*d); wtos[i] = iFilter(iCustomMa(AverType,ci,AverPeriod,i,2),vfilter,tperiod,i,1); signal[i] = iFilter(iSma(wtos[i],SignPeriod,Bars-i-1,Bars,3),sfilter,tperiod,i,2);; wtosua[i] = EMPTY_VALUE; wtosub[i] = EMPTY_VALUE; wtosda[i] = EMPTY_VALUE; wtosdb[i] = EMPTY_VALUE; dotd[i] = EMPTY_VALUE; dotu[i] = EMPTY_VALUE; if (FlPeriod<=0) { levup1[i] = ObLevel1; levup2[i] = ObLevel2; levdn2[i] = OsLevel2; levdn1[i] = OsLevel1; levmi[i] = 0; } else { double min = wtos[i]; double max = wtos[i]; for (int k=1; k =Bars-1) continue; switch (ColorOn) { case cl_slope : trend[i] = trend[i+1]; if (wtos[i]>wtos[i+1]) trend[i]= 1; if (wtos[i] signal[i]) trend[i]= 1; if (wtos[i] levmi[i]) trend[i]= 1; if (wtos[i] levup2[i]) trend[i]= 1; if (wtos[i] levup1[i]) trend[i]= 1; if (wtos[i] =0; k++) avg += workSma[r-k][instanceNo+0]; avg /= (double)k; return(avg); } // // // // // double workEma[][_maWorkBufferx1]; double iEma(double price, double period, int r, int _bars, int instanceNo=0) { if (ArrayRange(workEma,0)!= _bars) ArrayResize(workEma,_bars); workEma[r][instanceNo] = price; if (r>0 && period>1) workEma[r][instanceNo] = workEma[r-1][instanceNo]+(2.0/(1.0+period))*(price-workEma[r-1][instanceNo]); return(workEma[r][instanceNo]); } // // // // // double workSmma[][_maWorkBufferx1]; double iSmma(double price, double period, int r, int _bars, int instanceNo=0) { if (ArrayRange(workSmma,0)!= _bars) ArrayResize(workSmma,_bars); workSmma[r][instanceNo] = price; if (r>1 && period>1) workSmma[r][instanceNo] = workSmma[r-1][instanceNo]+(price-workSmma[r-1][instanceNo])/period; return(workSmma[r][instanceNo]); } // // // // // double workLwma[][_maWorkBufferx1]; double iLwma(double price, double period, int r, int _bars, int instanceNo=0) { if (ArrayRange(workLwma,0)!= _bars) ArrayResize(workLwma,_bars); workLwma[r][instanceNo] = price; if (period<=1) return(price); double sumw = period; double sum = period*price; for(int k=1; k =0; k++) { double weight = period-k; sumw += weight; sum += weight*workLwma[r-k][instanceNo]; } return(sum/sumw); } // // // // // double workTema[][_maWorkBufferx3]; #define _tema1 0 #define _tema2 1 #define _tema3 2 double iTema(double price, double period, int r, int bars, int instanceNo=0) { if (ArrayRange(workTema,0)!= bars) ArrayResize(workTema,bars); instanceNo*=3; workTema[r][_tema1+instanceNo] = price; workTema[r][_tema2+instanceNo] = price; workTema[r][_tema3+instanceNo] = price; if (r>0 && period>1) { double alpha = 2.0 / (1.0+period); workTema[r][_tema1+instanceNo] = workTema[r-1][_tema1+instanceNo]+alpha*(price -workTema[r-1][_tema1+instanceNo]); workTema[r][_tema2+instanceNo] = workTema[r-1][_tema2+instanceNo]+alpha*(workTema[r][_tema1+instanceNo]-workTema[r-1][_tema2+instanceNo]); workTema[r][_tema3+instanceNo] = workTema[r-1][_tema3+instanceNo]+alpha*(workTema[r][_tema2+instanceNo]-workTema[r-1][_tema3+instanceNo]); } return(workTema[r][_tema3+instanceNo]+3.0*(workTema[r][_tema1+instanceNo]-workTema[r][_tema2+instanceNo])); } // // // // // #define filterInstances 4 double workFil[][filterInstances*3]; #define _fchange 0 #define _fachang 1 #define _fprice 2 double iFilter(double tprice, double filter, int period, int i, int instanceNo=0) { if (filter<=0 || period<=0) return(tprice); if (ArrayRange(workFil,0)!= Bars) ArrayResize(workFil,Bars); i = Bars-i-1; instanceNo*=3; // // // // // workFil[i][instanceNo+_fprice] = tprice; if (i<1) return(tprice); workFil[i][instanceNo+_fchange] = MathAbs(workFil[i][instanceNo+_fprice]-workFil[i-1][instanceNo+_fprice]); workFil[i][instanceNo+_fachang] = workFil[i][instanceNo+_fchange]; for (int k=1; k =0; k++) workFil[i][instanceNo+_fachang] += workFil[i-k][instanceNo+_fchange]; workFil[i][instanceNo+_fachang] /= period; double stddev = 0; for (int k=0; k =0; k++) stddev += MathPow(workFil[i-k][instanceNo+_fchange]-workFil[i-k][instanceNo+_fachang],2); stddev = MathSqrt(stddev/(double)period); double filtev = filter * stddev; if( MathAbs(workFil[i][instanceNo+_fprice]-workFil[i-1][instanceNo+_fprice]) < filtev ) workFil[i][instanceNo+_fprice]=workFil[i-1][instanceNo+_fprice]; return(workFil[i][instanceNo+_fprice]); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; // // // // // message = StringConcatenate(_Symbol," ",timeFrameToString(_Period)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," wave trend oscillator trend to "+doWhat); if (alertsMessage) Alert(message); if (alertsNotification) SendNotification(message); if (alertsEmail) SendMail(StringConcatenate(Symbol()," wave trend oscillator"),message); if (alertsSound) PlaySound("alert2.wav"); } } //------------------------------------------------------------------- // //------------------------------------------------------------------- // // // // // void CleanPoint(int i,double& first[],double& second[]) { if (i>=Bars-3) return; if ((second[i] != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE)) second[i+1] = EMPTY_VALUE; else if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE)) first[i+1] = EMPTY_VALUE; } void PlotPoint(int i,double& first[],double& second[],double& from[]) { if (i>=Bars-2) return; if (first[i+1] == EMPTY_VALUE) if (first[i+2] == EMPTY_VALUE) { first[i] = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; } else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; } else { first[i] = from[i]; second[i] = EMPTY_VALUE; } } // // // // // string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"}; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable[i]) return(sTfTable[i]); return(""); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // // #define priceInstances 1 double workHa[][priceInstances*4]; double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int instanceNo=0) { if (tprice>=pr_haclose) { if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); instanceNo*=4; int r = Bars-i-1; // // // // // double haOpen; if (r>0) haOpen = (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0; else haOpen = (open[i]+close[i])/2; double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0; double haHigh = MathMax(high[i], MathMax(haOpen,haClose)); double haLow = MathMin(low[i] , MathMin(haOpen,haClose)); if(haOpen haOpen) return((haHigh+haClose)/2.0); else return((haLow+haClose)/2.0); case pr_hatbiased2: if (haClose>haOpen) return(haHigh); if (haClose open[i]) return((high[i]+close[i])/2.0); else return((low[i]+close[i])/2.0); case pr_tbiased2: if (close[i]>open[i]) return(high[i]); if (close[i]