//+------------------------------------------------------------------+ //| ColorSchaffRSITrendCycleCandle.mq5 | //| Copyright © 2015, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2015, Nikolay Kositsin" #property link "farria@mail.redcom.ru" #property description "ColorSchaffRSITrendCycleCandle" //---- номер версии индикатора #property version "1.00" //+----------------------------------------------+ //| Параметры отрисовки индикатора | //+----------------------------------------------+ //---- отрисовка индикатора в отдельном окне #property indicator_separate_window //---- для расчета и отрисовки индикатора использовано пять буферов #property indicator_buffers 5 //---- использовано всего одно графическое построение #property indicator_plots 1 //---- в качестве индикатора использованы цветные свечи #property indicator_type1 DRAW_COLOR_CANDLES #property indicator_color1 clrMagenta,clrGray,clrBlue //---- отображение метки индикатора #property indicator_label1 "ColorSchaffRSITrendCycleCandle Open;High;Low;Close" //+----------------------------------------------+ //| Параметры отображения горизонтальных уровней | //+----------------------------------------------+ //---- фиксирование верхней и нижней границ окна индикатора #property indicator_minimum -110 #property indicator_maximum +110 //+----------------------------------------------+ //| Объявление констант | //+----------------------------------------------+ #define RESET 0 // константа для возврата терминалу команды на пересчет индикатора //+----------------------------------------------+ //| Входные параметры индикатора | //+----------------------------------------------+ input uint Fast_RSI = 23; // Период быстрого RSI input uint Slow_RSI = 50; // Период медленного RSI input uint Cycle=10; // Период стохастического осциллятора input int HighLevel=+60; input int MiddleLevel=0; input int LowLevel=-60; //+----------------------------------------------+ //---- объявление динамических массивов, которые будут в //---- дальнейшем использованы в качестве индикаторных буферов double ExtOpenBuffer[]; double ExtHighBuffer[]; double ExtLowBuffer[]; double ExtCloseBuffer[]; double ExtColorBuffer[]; //---- объявление целочисленных переменных начала отсчета данных int min_rates_total; //---- объявление целочисленных переменных для хендлов индикаторов int Ind_Handle[4]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- int min_rates_1=int(Fast_RSI); int min_rates_2=int(Slow_RSI); min_rates_total=MathMax(min_rates_1,min_rates_2)+int(Cycle)+1+1; //---- получение хендла индикатора ColorSchaffRSITrendCycle Ind_Handle[0]=iCustom(NULL,0,"ColorSchaffRSITrendCycle",Fast_RSI,Slow_RSI,PRICE_OPEN,Cycle,0,0,0); if(Ind_Handle[0]==INVALID_HANDLE) { Print(" Не удалось получить хендл индикатора ColorSchaffRSITrendCycle["+string(0)+"]!"); return(INIT_FAILED); } //---- Ind_Handle[1]=iCustom(NULL,0,"ColorSchaffRSITrendCycle",Fast_RSI,Slow_RSI,PRICE_HIGH,Cycle,0,0,0); if(Ind_Handle[1]==INVALID_HANDLE) { Print(" Не удалось получить хендл индикатора ColorSchaffRSITrendCycle["+string(1)+"]!"); return(INIT_FAILED); } //---- Ind_Handle[2]=iCustom(NULL,0,"ColorSchaffRSITrendCycle",Fast_RSI,Slow_RSI,PRICE_LOW,Cycle,0,0,0); if(Ind_Handle[2]==INVALID_HANDLE) { Print(" Не удалось получить хендл индикатора ColorSchaffRSITrendCycle["+string(2)+"]!"); return(INIT_FAILED); } //---- Ind_Handle[3]=iCustom(NULL,0,"ColorSchaffRSITrendCycle",Fast_RSI,Slow_RSI,PRICE_CLOSE,Cycle,0,0,0); if(Ind_Handle[3]==INVALID_HANDLE) { Print(" Не удалось получить хендл индикатора ColorSchaffRSITrendCycle["+string(3)+"]!"); return(INIT_FAILED); } //---- превращение динамических массивов в индикаторные буферы SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA); SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA); SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA); //---- превращение динамического массива в цветовой, индексный буфер SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX); //---- индексация элементов в буферах как в таймсериях ArraySetAsSeries(ExtOpenBuffer,true); ArraySetAsSeries(ExtHighBuffer,true); ArraySetAsSeries(ExtLowBuffer,true); ArraySetAsSeries(ExtCloseBuffer,true); ArraySetAsSeries(ExtColorBuffer,true); //---- осуществление сдвига начала отсчета отрисовки индикатора 1 PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total); //---- установка формата точности отображения индикатора IndicatorSetInteger(INDICATOR_DIGITS,0); //---- имя для окон данных и метка для подокон string short_name="ColorSchaffRSITrendCycleCandl"; IndicatorSetString(INDICATOR_SHORTNAME,short_name); //---- количество горизонтальных уровней индикатора 3 IndicatorSetInteger(INDICATOR_LEVELS,3); //---- значения горизонтальных уровней индикатора IndicatorSetDouble(INDICATOR_LEVELVALUE,0,HighLevel); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,MiddleLevel); IndicatorSetDouble(INDICATOR_LEVELVALUE,2,LowLevel); //---- в качестве цветов линий горизонтальных уровней использованы серый и розовый цвета IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrMediumSeaGreen); IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGray); IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrMagenta); //---- в линии горизонтального уровня использован короткий штрих-пунктир IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASHDOTDOT); IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASHDOTDOT); IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DASHDOTDOT); //--- завершение инициализации return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //---- проверка количества баров на достаточность для расчета if(BarsCalculated(Ind_Handle[0])rates_total || prev_calculated<=0)// проверка на первый старт расчета индикатора { limit=rates_total-1; // стартовый номер для расчета всех баров } else { limit=rates_total-prev_calculated; // стартовый номер для расчета новых баров } //---- to_copy=limit+1; //---- копируем вновь появившиеся данные в массивы if(CopyBuffer(Ind_Handle[0],0,0,to_copy,ExtOpenBuffer)<=0) return(RESET); if(CopyBuffer(Ind_Handle[1],0,0,to_copy,ExtHighBuffer)<=0) return(RESET); if(CopyBuffer(Ind_Handle[2],0,0,to_copy,ExtLowBuffer)<=0) return(RESET); if(CopyBuffer(Ind_Handle[3],0,0,to_copy,ExtCloseBuffer)<=0) return(RESET); //---- основной цикл исправления и окрашивания свечей for(bar=limit; bar>=0 && !IsStopped(); bar--) { double Max=MathMax(ExtOpenBuffer[bar],ExtCloseBuffer[bar]); double Min=MathMin(ExtOpenBuffer[bar],ExtCloseBuffer[bar]); //---- ExtHighBuffer[bar]=MathMax(Max,ExtHighBuffer[bar]); ExtLowBuffer[bar]=MathMin(Min,ExtLowBuffer[bar]); //---- if(ExtOpenBuffer[bar]ExtCloseBuffer[bar]) ExtColorBuffer[bar]=0.0; else ExtColorBuffer[bar]=1.0; } //---- return(rates_total); } //+------------------------------------------------------------------+