//+------------------------------------------------------------------+ //| TSIsCDiCreate.mq5 | //| MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 1 //--- gráfico TSIsCD #property indicator_label1 "TSIsCD" #property indicator_type1 DRAW_COLOR_HISTOGRAM #property indicator_color1 Green,Red #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- parámetros de entrada input int r=25; input int s=13; input int sp=5; input ENUM_MA_METHOD sm=MODE_EMA; //--- Buffers del indicador double TSIsCDBuffer[]; double TSIsCDColors[]; double TsiBuffer[]; double TsiSignalBuffer[]; int Handle; //+------------------------------------------------------------------+ //| Función de inicialización del indicador personalizado | //+------------------------------------------------------------------+ int OnInit() { //--- mapeo de los buffers del indicador SetIndexBuffer(0,TSIsCDBuffer,INDICATOR_DATA); SetIndexBuffer(1,TSIsCDColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,TsiBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(3,TsiSignalBuffer,INDICATOR_CALCULATIONS); MqlParam Params[5]; Params[0].type=TYPE_STRING; Params[0].string_value="TSIs"; Params[1].type=TYPE_INT; Params[1].integer_value=r; Params[2].type=TYPE_INT; Params[2].integer_value=s; Params[3].type=TYPE_INT; Params[3].integer_value=sp; Params[4].type=TYPE_INT; Params[4].integer_value=sm; Handle=IndicatorCreate(_Symbol,PERIOD_CURRENT,IND_CUSTOM,5,Params); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,r+s+sp); IndicatorSetInteger(INDICATOR_DIGITS,2); //--- return(0); } //+------------------------------------------------------------------+ //| Función de iteración del indicador personalizado | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // dimensión de la matriz price[] const int prev_calculated,// número de barras procesadas en la llamada anterior const int begin, // desde donde tenemos datos significativos const double &price[] // matriz para cálculos ) { static bool error=true; int start; if(prev_calculated==0) { error=true; } if(error) { start=begin+1; error=false; } else { start=prev_calculated-1; } if(CopyBuffer(Handle,0,0,rates_total-start,TsiBuffer)==-1) { error=true; return(0); } if(CopyBuffer(Handle,1,0,rates_total-start,TsiSignalBuffer)==-1) { error=true; return(0); } for(int i=start;iTSIsCDBuffer[i-1])TSIsCDColors[i]=0; if(TSIsCDBuffer[i]