//+----------------------------------------------------------+ //| Ehlers fisher transform.mq4 | //| mladen | //+----------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 6 #property indicator_color1 clrDeepSkyBlue #property indicator_color2 clrSandyBrown #property indicator_color3 clrSandyBrown #property indicator_color4 clrSilver #property indicator_color5 clrBlue #property indicator_color6 clrRed #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 3 #property indicator_style4 STYLE_DOT #property strict // // // // // input int period = 10; // Transform period input ENUM_APPLIED_PRICE PriceType = PRICE_MEDIAN; // Price to use input double Weight = 2; // Smoothing weight input double SignalPeriod = 9; // Signal period input int ArrowSize = 2; // Arrow size input int ArrowCodeUp = 159; // Arrow code up input int ArrowCodeDn = 159; // Arrow code down double buffer1[],buffer2[],buffer3[],buffer4[],crossUp[],crossDn[],Prices[],Values[],Cross[]; //+----------------------------------------------------------+ //| | //+----------------------------------------------------------+ // // // // // int OnInit() { IndicatorBuffers(9); SetIndexBuffer(0,buffer1,INDICATOR_DATA); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1,buffer2,INDICATOR_DATA); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(2,buffer3,INDICATOR_DATA); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(3,buffer4,INDICATOR_DATA); SetIndexStyle(3,DRAW_LINE); SetIndexBuffer(4,crossUp,INDICATOR_DATA); SetIndexStyle(4,DRAW_ARROW,0,ArrowSize); SetIndexArrow(4,ArrowCodeUp); SetIndexBuffer(5,crossDn,INDICATOR_DATA); SetIndexStyle(5,DRAW_ARROW,0,ArrowSize); SetIndexArrow(5,ArrowCodeDn); SetIndexBuffer(6,Prices); SetIndexBuffer(7,Values); SetIndexBuffer(8,Cross); IndicatorShortName("Ehlers\' Fisher transform ("+(string)period+")"); return(INIT_SUCCEEDED); } //+----------------------------------------------------------+ //| | //+----------------------------------------------------------+ // // // // // int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int i=rates_total-prev_calculated+1; if (i>=rates_total) i=rates_total-1; double alpha = 2.0/(1.0+Weight); double ema = 2.0/(1.0+SignalPeriod); if (Cross[i]==-1) CleanPoint(i,buffer2,buffer3); for (; i>=0 && !_StopFlag; i--) { Prices[i] = iMA(NULL,0,1,0,MODE_SMA,PriceType,i); double MaxH = Prices[ArrayMaximum(Prices,period,i)]; double MinL = Prices[ArrayMinimum(Prices,period,i)]; Values[i] = (ibuffer4[i+1]) if (buffer1[i]>buffer1[i+1]) buffer4[i] = buffer4[i+1]+ema*(buffer1[i]-buffer4[i+1]); if (buffer1[i]buffer4[i]) ? 1 : (buffer1[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; } }