//+------------------------------------------------------------------+ //| LSMA nrp.mq4 | //| mladen | //+------------------------------------------------------------------+ //------------------------------------------------------------------ #property copyright "www.forex-station.com" #property link "www.forex-station.com" //------------------------------------------------------------------ #property indicator_chart_window #property indicator_buffers 4 #property strict input int LSMAPeriod = 24; // Lsma period input ENUM_APPLIED_PRICE LSMAPrice = 0; // Lsma price input color ColorUp = clrDodgerBlue; // Candles up color input color ColorDn = clrRed; // Color for down input int WickWidth = 1; // Candle wick width input int CandleWidth = 2; // Candle body width double valhu[],valhd[],valhbu[],valhbd[],lsma[],valc[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // int OnInit() { IndicatorBuffers(6); SetIndexBuffer(0,valhu, INDICATOR_DATA); SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,WickWidth,ColorUp); SetIndexBuffer(1,valhd, INDICATOR_DATA); SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,WickWidth,ColorDn); SetIndexBuffer(2,valhbu,INDICATOR_DATA); SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,CandleWidth,ColorUp); SetIndexBuffer(3,valhbd,INDICATOR_DATA); SetIndexStyle(3,DRAW_HISTOGRAM,EMPTY,CandleWidth,ColorDn); SetIndexBuffer(4,lsma); SetIndexBuffer(5,valc); 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; // // // // // for (; i>=0 && !_StopFlag; i--) { lsma[i] = iLinr(iMA(NULL,0,1,0,MODE_SMA,LSMAPrice,i),LSMAPeriod,i,rates_total); valhu[i] = valhd[i] = valhbu[i] = valhbd[i] = EMPTY_VALUE; valc[i] = (ilsma[i+1]) ? 1 : (lsma[i]=0; k++) { double weight = period-k; lwmw += weight; lwma += weight*workLinr[r-k][instanceNo]; sma += workLinr[r-k][instanceNo]; } return(3.0*lwma/lwmw-2.0*sma/period); }