//+------------------------------------------------------------------+ //| 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 6 //--- plot RoC #property indicator_label1 "RoC" #property indicator_type1 DRAW_LINE #property indicator_color1 clrYellow #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- 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 //--- plot MidBand #property indicator_label6 "MidBand" #property indicator_type6 DRAW_LINE #property indicator_color6 clrMagenta #property indicator_style6 STYLE_DOT #property strict enum stdMethods { std_custSam, // Custom - with sample correction std_custNos // Custom - without sample correction }; //--- input parameters input int SampleWindow = 20; // period of the rate of change input int MaPeriod = 5; // Ma smoothing period input ENUM_MA_METHOD MaMode = MODE_EMA; // Ma smoothing method input ENUM_APPLIED_PRICE MaPrice = PRICE_CLOSE; // Ma smoothing price input stdMethods DeviationType = std_custSam; // Deviation calculation type input int BandPeriod = 60; // Volatility band period input double BandMultiplier1 = 1.0; // Volatility band multiplier input double BandMultiplier2 = 2.0; // Volatility band multiplier //--- indicator buffers double roc[],bandUp1[],bandUp2[],bandMi[],bandDn2[],bandDn1[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,roc, INDICATOR_DATA); SetIndexBuffer(1,bandUp1,INDICATOR_DATA); SetIndexBuffer(2,bandUp2,INDICATOR_DATA); SetIndexBuffer(3,bandDn2,INDICATOR_DATA); SetIndexBuffer(4,bandDn1,INDICATOR_DATA); SetIndexBuffer(5,bandMi, INDICATOR_DATA); IndicatorSetString(INDICATOR_SHORTNAME,"Turning point ("+(string)SampleWindow+")"); 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[]) { int i=rates_total-prev_calculated+1; if (i>=rates_total) i=rates_total-1; // // // for (; i>=0 && !_StopFlag; i--) { double pma = iMA(NULL,0,MaPeriod,0,MaMode,MaPrice,i+SampleWindow); double cma = iMA(NULL,0,MaPeriod,0,MaMode,MaPrice,i); roc[i] = (pma!=0) ? 100*(cma-pma)/pma : 0; bandMi[i] = 0; for (int k=0; k=0; k++) { newMean = (workDev[i-k]-oldMean)/(k+1)+oldMean; squares += (workDev[i-k]-oldMean)*(workDev[i-k]-newMean); oldMean = newMean; } return(sqrt(squares/fmax(k-isSample,1))); }