//+------------------------------------------------------------------+ //| oma.mq5 | //| oma Copyright 2016, fxborg | //| http://fxborg-labo.hateblo.jp/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, fxborg" #property link "http://fxborg-labo.hateblo.jp/" #property version "1.00" #property indicator_chart_window #property indicator_buffers 9 #property indicator_plots 1 #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrRed,clrDodgerBlue #property indicator_width1 2 input int InpLength=125; // Length input double InpSpeed=8.0; // Speed input bool InpAdaptive=true; // use Adaptive input double InpThreshold=50; // Shreshold double Threshold=InpThreshold*_Point; double OMA[]; double E1[]; double E2[]; double E3[]; double E4[]; double E5[]; double E6[]; double OMA_CLR[]; double SIG[]; // setting for adaptive double MinPeriod = InpLength/2.0; double MaxPeriod = MinPeriod*5.0; int EndPeriod = (int)MathCeil(MaxPeriod); int min_rates_total=EndPeriod+1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0,OMA,INDICATOR_DATA); SetIndexBuffer(1,OMA_CLR,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,SIG,INDICATOR_CALCULATIONS); SetIndexBuffer(3,E1,INDICATOR_CALCULATIONS); SetIndexBuffer(4,E2,INDICATOR_CALCULATIONS); SetIndexBuffer(5,E3,INDICATOR_CALCULATIONS); SetIndexBuffer(6,E4,INDICATOR_CALCULATIONS); SetIndexBuffer(7,E5,INDICATOR_CALCULATIONS); SetIndexBuffer(8,E6,INDICATOR_CALCULATIONS); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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,first; if(rates_total<=min_rates_total) return(0); //--- int begin_pos=min_rates_total; first=begin_pos; if(first+1SIG[i-1]) SIG[i]=OMA[i]; else if((OMA[i]+Threshold)SIG[i])OMA_CLR[i]=0; else OMA_CLR[i]=OMA_CLR[i-1]; } //---- //---- return(rates_total); } //+------------------------------------------------------------------+