//------------------------------------------------------------------ #property copyright "© mladen, 2019" #property link "mladenfx@gmail.com" #property description "Sharp modified moving average" //+------------------------------------------------------------------ #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 1 #property indicator_label1 "Sharp MMA" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrDarkGray,clrMediumSeaGreen,clrOrangeRed #property indicator_width1 2 // // // input int inpPeriod = 14; // Average period input ENUM_APPLIED_PRICE inpPrice = PRICE_CLOSE; // Price // //--- // double val[],valc[],avg[],prices[]; int ª_maHandle; //------------------------------------------------------------------ // Custom indicator initialization function //------------------------------------------------------------------ // // // int OnInit() { // //--- indicator buffers mapping // SetIndexBuffer(0,val ,INDICATOR_DATA); SetIndexBuffer(1,valc ,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,avg ,INDICATOR_CALCULATIONS); SetIndexBuffer(3,prices,INDICATOR_CALCULATIONS); ª_maHandle = iMA(_Symbol,0,inpPeriod,0,MODE_SMA,inpPrice); if (!_checkHandle(ª_maHandle,"average")) return(INIT_FAILED); // //--- indicator short name assignment // IndicatorSetString(INDICATOR_SHORTNAME,"Sharp MMA ("+(string)inpPeriod+")"); return (INIT_SUCCEEDED); } void OnDeinit(const int reason) { } //------------------------------------------------------------------ // Custom indicator iteration function //------------------------------------------------------------------ // //--- // #define _setPrice(_priceType,_target,_index) \ { \ switch(_priceType) \ { \ case PRICE_CLOSE: _target = close[_index]; break; \ case PRICE_OPEN: _target = open[_index]; break; \ case PRICE_HIGH: _target = high[_index]; break; \ case PRICE_LOW: _target = low[_index]; break; \ case PRICE_MEDIAN: _target = (high[_index]+low[_index])/2.0; break; \ case PRICE_TYPICAL: _target = (high[_index]+low[_index]+close[_index])/3.0; break; \ case PRICE_WEIGHTED: _target = (high[_index]+low[_index]+close[_index]+close[_index])/4.0; break; \ default : _target = 0; \ }} // //--- // 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 _copyCount = rates_total-prev_calculated+1; if (_copyCount>rates_total) _copyCount=rates_total; if (CopyBuffer(ª_maHandle,0,0,_copyCount,avg)!=_copyCount) return(prev_calculated); // //--- // int i=prev_calculated-1; if (i<0) i=0; for (; i=k; k++) _slope += prices[i-k]*(inpPeriod-(1.0+2.0*k))/2.0; val[i] = avg[i] + 6.0*_slope / ((inpPeriod+1)*inpPeriod); valc[i] = (i>0) ?(val[i]>val[i-1]) ? 1 :(val[i]=0; i--) IndicatorRelease(_chandles[i]); ArrayResize(_chandles,0); Alert(_description+" initialization failed"); } return(_answer); } //------------------------------------------------------------------