//+------------------------------------------------------------------+ //| Ozymandias_Lite.mq5 (PunkBASSter's edition) | //| Copyright © 2014, GoldnMoney | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2014, GoldnMoney" #property link "http://www.mql5.com" //--- #property version "1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1 //--- #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrDeepPink,clrDodgerBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 3 #property indicator_label1 "Ozymandias_Lite" //--- #define RESET 0 //--- input uint Length=2; input ENUM_MA_METHOD MAType=MODE_SMA; input int Shift=0; //--- double IndBuffer[],ColorIndBuffer[]; //--- int min_rates_total; int HMA_Handle,LMA_Handle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- min_rates_total=int(Length); HMA_Handle=iMA(NULL,0,Length,0,MAType,PRICE_HIGH); if(HMA_Handle==INVALID_HANDLE) { Print(" Не удалось получить хендл индикатора iMA"); return(INIT_FAILED); } //--- LMA_Handle=iMA(NULL,0,Length,0,MAType,PRICE_LOW); if(LMA_Handle==INVALID_HANDLE) { Print(" Не удалось получить хендл индикатора iMA"); return(INIT_FAILED); } //--- SetIndexBuffer(0,IndBuffer,INDICATOR_DATA); ArraySetAsSeries(IndBuffer,true); //--- PlotIndexSetInteger(0,PLOT_SHIFT,Shift); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //--- SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX); ArraySetAsSeries(ColorIndBuffer,true); //--- PlotIndexSetInteger(1,PLOT_SHIFT,Shift); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); //--- IndicatorSetString(INDICATOR_SHORTNAME,"Ozymandias"); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- 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(HMA_Handle)rates_total || prev_calculated<=0)// проверка на первый старт расчета индикатора { limit=rates_total-min_rates_total-1; // стартовый номер для расчета всех баров trend1=0; nexttrend1=0; maxl1=0; minh1=9999999; } else limit=rates_total-prev_calculated; // стартовый номер для расчета только новых баров to_copy=limit+1; //--- копируем вновь появившиеся данные в массивы if(CopyBuffer(HMA_Handle,0,0,to_copy,HMA)<=0) return(RESET); if(CopyBuffer(LMA_Handle,0,0,to_copy,LMA)<=0) return(RESET); //--- индексация элементов в массивах как в таймсериях ArraySetAsSeries(close,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(HMA,true); ArraySetAsSeries(LMA,true); //--- nexttrend0=nexttrend1; maxl0=maxl1; minh0=minh1; //--- основной цикл расчета индикатора for(int bar=limit; bar>=0 && !IsStopped(); bar--) { hh=high[ArrayMaximum(high,bar,Length)]; ll=low[ArrayMinimum(low,bar,Length)]; lma=LMA[bar]; hma=HMA[bar]; trend0=trend1; //--- if(nexttrend0==1) { maxl0=MathMax(ll,maxl0); //--- if(hmaminh0 && close[bar]>high[bar+1]) { trend0=0; nexttrend0=1; maxl0=ll; } } //--- if(trend0==0) { if(trend1!=0.0) { IndBuffer[bar]=IndBuffer[bar+1]; ColorIndBuffer[bar]=1; } else { IndBuffer[bar]=MathMax(maxl0,IndBuffer[bar+1]); ColorIndBuffer[bar]=1; } } else { if(trend1!=1) { IndBuffer[bar]=IndBuffer[bar+1]; ColorIndBuffer[bar]=0; } else { IndBuffer[bar]=MathMin(minh0,IndBuffer[bar+1]); ColorIndBuffer[bar]=0; } } //--- if(bar) { nexttrend1=nexttrend0; trend1=trend0; maxl1=maxl0; minh1=minh0; } } //--- return(rates_total); } //+------------------------------------------------------------------+