//+------------------------------------------------------------------+ //| TrendMa.mq5 | //| Copyright 2015, fxborg | //| http://fxborg-labo.hateblo.jp/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, fxborg" #property link "http://fxborg-labo.hateblo.jp/" #property version "1.00" #include #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 1 #property indicator_type1 DRAW_COLOR_LINE #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE #property indicator_color1 clrRed,clrGainsboro,clrDodgerBlue #property indicator_width1 3 #property indicator_color2 clrSilver #property indicator_width2 1 #property indicator_style2 STYLE_DOT #property indicator_color3 clrSilver #property indicator_width3 1 #property indicator_style3 STYLE_DOT input int InpMaPeriod=20; // Ma Period input ENUM_MA_METHOD InpMaMethod=MODE_EMA; // Ma Method int InpAtrPeriod=10; // Calc Bar Count double InpThreshold=0.5;// Threshold Level double MaBuffer[]; double UBBuffer[]; double DBBuffer[]; double ColorBuffer[]; int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { min_rates_total=1; //--- indicator buffers mapping SetIndexBuffer(0,MaBuffer,INDICATOR_DATA); SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,UBBuffer,INDICATOR_DATA); SetIndexBuffer(3,DBBuffer,INDICATOR_DATA); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total); string short_name="Moving Average Regr"; IndicatorSetString(INDICATOR_SHORTNAME,short_name); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- //--- int i,first,begin_pos; begin_pos=min_rates_total; first=begin_pos; if(first+1=ma-th)sign=1; else if( MaBuffer[i]>ma)sign=2; else if( MaBuffer[i]