MQL 4/5 Finding the center 25% and 75% of the candle

549 Views Asked by At

I am looking to plot a dot on the candle at 25%, 50% and 75% Levels. Code to plot a dot at 50% of the candle length is as below. How can I add a dot at 25% and 75% also.

The below code is for MT5. I have tried to change the logic by dividing as (high[i]+low[i])/4, but there is dot displayed at all.

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com"
#property version   "1.00"
#property description "Colored Middle Point of candles"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   1
//--- plot ColorMidPoint
#property indicator_label1  "Color Middle Point"
#property indicator_type1   DRAW_COLOR_ARROW
#property indicator_color1  clrDodgerBlue,clrDarkOrange,clrDarkGray
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- enums
enum ENUM_CANDLE_TYPE
  {
   TYPE_CANDLE_HL,      // Candle
   TYPE_CANDLE_OC       // Body
  };
//---
enum ENUM_ARROW_TYPE
  {
   TYPE_ARROW_DOT0      =  158,  // Smallest Dot
   TYPE_ARROW_DOT1      =  159,  // Small Dot
   TYPE_ARROW_DOT2      =  108,  // Big Dot
   TYPE_ARROW_SQUARE1   =  167,  // Small Square
   TYPE_ARROW_SQUARE2   =  110,  // Big Square
   TYPE_ARROW_DIAMOND1  =  115,  // Small Diamond
   TYPE_ARROW_DIAMOND2  =  116,  // Big Diamond
   TYPE_ARROW_CROSS     =  251   // Cross
  };
//--- input parameters
input ENUM_CANDLE_TYPE  InpTypeCandle     =  TYPE_CANDLE_HL;   // Middle point for
input ENUM_ARROW_TYPE   InpTypeArrow      =  TYPE_ARROW_DOT1;  // Dots type
//--- indicator buffers
double         BufferCMP[];
double         BufferColors[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferCMP,INDICATOR_DATA);
   SetIndexBuffer(1,BufferColors,INDICATOR_COLOR_INDEX);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,(int)InpTypeArrow);
//--- setting indicator parameters
   IndicatorSetString(INDICATOR_SHORTNAME,"CandleMidPoint");
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
//--- setting buffer arrays as timeseries
   ArraySetAsSeries(BufferCMP,true);
   ArraySetAsSeries(BufferColors,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(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);


   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-1;
      ArrayInitialize(BufferCMP,EMPTY_VALUE);
      ArrayInitialize(BufferColors,2);
     }

/
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      BufferCMP[i]=(InpTypeCandle==TYPE_CANDLE_OC ? (open[i]+close[i])/2.0 : (high[i]+low[i])/2.0);
      BufferColors[i]=(open[i]<close[i] ? 0 : open[i]>close[i] ? 1 : 2);
     }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
2

There are 2 best solutions below

0
On

If you want to add 3 different points to each candle, you will need 3 different indicator buffer, but you have only one:

double BufferCMP[];

If you create 3, you can assign to each buffer different method.

0
On

for 25% val25 = Low[i] + (High[i]-Low[i])/4; and for 75% val75 = High[i] - (High[i]-Low[i])/4;