//+------------------------------------------------------------------+ //| alma.mq4 | //| converted by mladen | //| mladenfx@gmail.com | //+------------------------------------------------------------------+ #property copyright "www.forex-station.com" #property link "www.forex-station.com" #property indicator_chart_window #property indicator_buffers 5 #property indicator_color1 clrLimeGreen #property indicator_color2 clrOrange #property indicator_color3 clrOrange #property indicator_color4 clrGray #property indicator_color5 clrGray #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 3 #property indicator_style4 STYLE_DOT #property indicator_style5 STYLE_DOT #property strict // // // input int AlmaPeriod = 14; // Alma period input double AlmaSigma = 6.0; // Alma sigma input double AlmaSample = 0.25; // Alma sample input ENUM_APPLIED_PRICE AlmaPrice = PRICE_CLOSE; // Alma price input int AtrPeriod = 20; // Range period input double AtrMultiplier = 2.0; // Range multiplier enum enAtrMode { atr_Rng, // Calculate using range atr_Atr // Calculate using ATR }; input enAtrMode AtrMode = atr_Rng; // Range calculating mode double val[],valda[],valdb[],bUp[],bDn[],slope[]; //------------------------------------------------------------------ // //------------------------------------------------------------------ int OnInit() { IndicatorBuffers(6); SetIndexBuffer(0,val ,INDICATOR_DATA); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1,valda,INDICATOR_DATA); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(2,valdb,INDICATOR_DATA); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(3,bUp ,INDICATOR_DATA); SetIndexStyle(3,DRAW_LINE); SetIndexBuffer(4,bDn ,INDICATOR_DATA); SetIndexStyle(4,DRAW_LINE); SetIndexBuffer(5,slope); IndicatorSetString(INDICATOR_SHORTNAME,"Alma bands ("+(string)AlmaPeriod+","+DoubleToStr(AlmaSigma,2)+","+DoubleToStr(AlmaSample,2)+")"); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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; // // // if (slope[i]==-1) CleanPoint(i,rates_total,valda,valdb); for (; i>=0 && !_StopFlag; i--) { double atr=0; for (int k=0; kval[i+1]) ? 1 : (val[i]=0; i++) { double coeff = exp(-((i-m)*(i-m))/(2.0*s*s)); sum += coeff*almaWork[r-i][instanceNo]; div += coeff; } double talma = price; if (div!=0) talma = sum/div; return(talma); } // // // void CleanPoint(int i,int bars,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,int bars,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; } }