//+------------------------------------------------------------------+ //| ADXW.mq5 | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2000-2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property description "Average Directional Movement Index" #property description "by Welles Wilder" #include //--- #property indicator_separate_window #property indicator_buffers 10 #property indicator_plots 3 #property indicator_type1 DRAW_LINE #property indicator_style1 STYLE_SOLID #property indicator_width1 1 #property indicator_color1 clrLightSeaGreen #property indicator_type2 DRAW_LINE #property indicator_style2 STYLE_DOT #property indicator_width2 1 #property indicator_color2 clrYellowGreen #property indicator_type3 DRAW_LINE #property indicator_style3 STYLE_DOT #property indicator_width3 1 #property indicator_color3 clrWheat #property indicator_label1 "ADX Wilder" #property indicator_label2 "+DI" #property indicator_label3 "-DI" //--- input parameters input int InpPeriodADXW=14; // Period ADX //--- indicator buffers double ExtADXWBuffer[]; double ExtPDIBuffer[]; double ExtNDIBuffer[]; double ExtPDSBuffer[]; double ExtNDSBuffer[]; double ExtPDBuffer[]; double ExtNDBuffer[]; double ExtTRBuffer[]; double ExtATRBuffer[]; double ExtDXBuffer[]; int ExtADXWPeriod; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- check for input parameters if(InpPeriodADXW>=100 || InpPeriodADXW<=0) { ExtADXWPeriod=14; PrintFormat("Incorrect value for input variable InpPeriodADXW=%d. Indicator will use value=%d for calculations.",InpPeriodADXW,ExtADXWPeriod); } else ExtADXWPeriod=InpPeriodADXW; //--- indicator buffers SetIndexBuffer(0,ExtADXWBuffer); SetIndexBuffer(1,ExtPDIBuffer); SetIndexBuffer(2,ExtNDIBuffer); //--- calculation buffers SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(5,ExtDXBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(6,ExtTRBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(7,ExtATRBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(8,ExtPDSBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(9,ExtNDSBuffer,INDICATOR_CALCULATIONS); //--- set draw begin PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXWPeriod<<1); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXWPeriod+1); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXWPeriod+1); //--- indicator short name string short_name="ADX Wilder("+string(ExtADXWPeriod)+")"; IndicatorSetString(INDICATOR_SHORTNAME,short_name); PlotIndexSetString(0,PLOT_LABEL,short_name); //--- indicator digits IndicatorSetInteger(INDICATOR_DIGITS,2); } //+------------------------------------------------------------------+ //| 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[]) { //--- checking for bars count if(rates_total1) start=prev_calculated-1; else { start=1; for(int i=0; i