//+------------------------------------------------------------------+ //| DS.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://mql5.com" #property version "1.00" #property description "Demand/Supply oscillator" #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 1 //--- plot DS #property indicator_label1 "DS" #property indicator_type1 DRAW_COLOR_HISTOGRAM #property indicator_color1 clrGreen,clrRed,clrDarkGray #property indicator_style1 STYLE_SOLID #property indicator_width1 8 //--- input parameters input uint InpPeriod = 14; // Period input ENUM_MA_METHOD InpMethod = 0; // Method //--- indicator buffers double BufferDS[]; double BufferColors[]; double BufferRAW[]; //--- global variables int period_ds; int handle_ma; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- set global variables period_ds=int(InpPeriod<1 ? 1 : InpPeriod); //--- indicator buffers mapping SetIndexBuffer(0,BufferDS,INDICATOR_DATA); SetIndexBuffer(1,BufferColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,BufferRAW,INDICATOR_CALCULATIONS); //--- setting indicator parameters IndicatorSetString(INDICATOR_SHORTNAME,"Demand/Supply Osc ("+(string)period_ds+")"); IndicatorSetInteger(INDICATOR_DIGITS,Digits()); //--- setting buffer arrays as timeseries ArraySetAsSeries(BufferDS,true); ArraySetAsSeries(BufferColors,true); ArraySetAsSeries(BufferRAW,true); //--- 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[]) { //--- Установка массивов буферов как таймсерий ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); ArraySetAsSeries(tick_volume,true); //--- Проверка количества доступных баров if(rates_total1) { limit=rates_total-period_ds-2; ArrayInitialize(BufferDS,0); ArrayInitialize(BufferColors,2); ArrayInitialize(BufferRAW,0); } //--- Подготовка данных for(int i=limit; i>=0 && !IsStopped(); i--) { double hl=high[i]-low[i]; double buy=(hl!=0 ? (fabs(close[i]-low[i])/(high[i]-low[i]))*tick_volume[i] : 0); double sell=(hl!=0 ? (fabs(high[i]-close[i])/(high[i]-low[i]))*tick_volume[i] : 0); BufferRAW[i]=buy-sell; } //--- Расчёт индикатора for(int i=limit; i>=0 && !IsStopped(); i--) { BufferDS[i]=GetMA(rates_total,i,InpMethod,period_ds,BufferRAW,BufferDS); BufferColors[i]=(BufferDS[i]>BufferDS[i+1] ? 0 : BufferDS[i]rates_total-period-1) return array_src[shift]; double sum=0; for(int i=0; i=rates_total-2 || period<1 ? price : prev+2.0/(1+period)*(price-prev)); } //+------------------------------------------------------------------+ //| Linear Weighted Moving Average | //+------------------------------------------------------------------+ double LWMA(const int rates_total,const double &array_src[],const int period,const int shift) { if(period<1 || shift>rates_total-period-1) return 0; double sum=0; double weight=0; for(int i=0; i0 ? sum/weight : 0); } //+------------------------------------------------------------------+ //| Smoothed Moving Average | //+------------------------------------------------------------------+ double SMMA(const int rates_total,const double &array_src[],const double prev,const int period,const int shift) { if(period<1 || shift>rates_total-period-1) return 0; double smma=0; if(shift==rates_total-period-1) smma=SMA(rates_total,array_src,period,shift); else if(shift