//+------------------------------------------------------------------+ //| Vertex_mod.mq5 | //| Naguisa Unada | //| https://www.mql5.com/en/users/unadajapon/news | //+------------------------------------------------------------------+ #property copyright "Naguisa Unada" #property link "https://www.mql5.com/en/users/unadajapon/news" #property version "1.00" #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 3 #property indicator_level1 10 #property indicator_level2 0 #property indicator_level3 -10 #property indicator_levelcolor clrDimGray #property indicator_levelstyle STYLE_DOT //--- plot Vertex_ #property indicator_label1 "Vertex_" #property indicator_type1 DRAW_LINE #property indicator_color1 clrSilver #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot UpHisto_ #property indicator_label2 "UpHisto_" #property indicator_type2 DRAW_HISTOGRAM #property indicator_color2 clrLimeGreen #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot DnHisto_ #property indicator_label3 "DnHisto_" #property indicator_type3 DRAW_HISTOGRAM #property indicator_color3 clrCrimson #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- input parameters input int Control_Period = 14; //Period //--- indicator buffers double Vertex_Buffer[]; double UpHisto_Buffer[]; double DnHisto_Buffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0, Vertex_Buffer, INDICATOR_DATA); SetIndexBuffer(1, UpHisto_Buffer, INDICATOR_DATA); SetIndexBuffer(2, DnHisto_Buffer, INDICATOR_DATA); IndicatorSetInteger(INDICATOR_DIGITS,4); IndicatorSetString(INDICATOR_SHORTNAME, "Vertex_mod(" + (string)Control_Period + ")"); //--- 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, j, n, limit, bar_shift, bar_count; double trigger_high, trigger_low; double sum_up, sum_dn, complex_up, complex_dn; if (prev_calculated < 0) return (-1); if (prev_calculated == 0) limit = Control_Period + 2; else limit = prev_calculated - 1; for (i = limit; i < rates_total; i++) { complex_up = 0; complex_dn = 0; trigger_high = -999999; trigger_low = 999999; for (n = 0; n < Control_Period; n++) { sum_up = 0; sum_dn = 0; bar_shift = i - n; bar_count = bar_shift + Period(); if (bar_count > rates_total - 1) bar_count = rates_total - 1; for (j = bar_shift; j <= bar_count; j++) { if (high[j] > trigger_high) { trigger_high = high[j]; sum_up += close[j]; } if (low[j] < trigger_low) { trigger_low = low[j]; sum_dn += close[j]; } } complex_up += sum_up; complex_dn += sum_dn; } if (complex_dn != 0.0 && complex_up != 0.0) { Vertex_Buffer[i] = complex_dn / complex_up - complex_up / complex_dn; if (Vertex_Buffer[i] > 0) UpHisto_Buffer[i] = Vertex_Buffer[i]; else UpHisto_Buffer[i] = EMPTY_VALUE; if (Vertex_Buffer[i] < 0) DnHisto_Buffer[i] = Vertex_Buffer[i]; else DnHisto_Buffer[i] = EMPTY_VALUE; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+