//+------------------------------------------------------------------+ //| TurningPointIndicator.mq5 | //| Copyright 2019, InvestingWithoptions | //| https://investingwithoptions.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, InvestingWithOptions." #property link "https://www.investingwithoptions.com" #property description "IWO Turning Point Indicator" #property version "1.00" #property indicator_separate_window #property indicator_buffers 7 #property indicator_plots 5 //--- plot RoC #property indicator_label1 "RoC" #property indicator_type1 DRAW_LINE #property indicator_color1 clrYellow #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot UpBand1 #property indicator_label2 "UpBand1" #property indicator_type2 DRAW_LINE #property indicator_color2 clrSalmon #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot UpBand2 #property indicator_label3 "UpBand2" #property indicator_type3 DRAW_LINE #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot LowBand2 #property indicator_label4 "LowBand2" #property indicator_type4 DRAW_LINE #property indicator_color4 clrGreen #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot LowBand1 #property indicator_label5 "LowBand1" #property indicator_type5 DRAW_LINE #property indicator_color5 clrLightGreen #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- input parameters input int SampleWindow=20; //period of the rate of change input int BandWindow=60; //period of the volatility bands //--- indicator buffers double RoCBuffer[]; double UpBand1Buffer[]; double UpBand2Buffer[]; double LowBand2Buffer[]; double LowBand1Buffer[]; double StdDevBuffer[]; double MaBuffer[]; //--- global variables int ExtSampleWindow; int ExtBandWindow; int ExtPlotBegin=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- check for input if(SampleWindow<1) { ExtSampleWindow=20; Print("Incorrect value for input variable SampleWindow=",SampleWindow, "Indicator will use value=",ExtSampleWindow,"for calculations."); } else { ExtSampleWindow=20; } if(BandWindow<2) { ExtBandWindow = 60; printf("Incorrect value for input variable BandWindow=",BandWindow,"Indicator will use value",ExtBandWindow,"for calculations."); } else { ExtBandWindow = BandWindow; } //--- indicator buffers mapping SetIndexBuffer(0,RoCBuffer,INDICATOR_DATA); SetIndexBuffer(1,UpBand1Buffer,INDICATOR_DATA); SetIndexBuffer(2,UpBand2Buffer,INDICATOR_DATA); SetIndexBuffer(3,LowBand2Buffer,INDICATOR_DATA); SetIndexBuffer(4,LowBand1Buffer,INDICATOR_DATA); SetIndexBuffer(5,StdDevBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(6,MaBuffer, INDICATOR_CALCULATIONS); //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS,2); //--- set first bar ExtPlotBegin=ExtSampleWindow-1; PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, ExtSampleWindow); PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, ExtSampleWindow); PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, ExtSampleWindow); PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, ExtSampleWindow); PlotIndexSetInteger(4, PLOT_DRAW_BEGIN, ExtSampleWindow); //--- 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[]) { //--- //Temporary StdDev Variables double StdDev_dTmp=0.0; if(rates_total