Discussion of article "Exploring options for creating multicolored candlesticks"

 

New article Exploring options for creating multicolored candlesticks has been published:

In this article I will address the possibilities of creating customized indicators with candlesticks, pointing out their advantages and disadvantages.

The great advantage of this last method is that we will have a more informative user interface, despite significantly increasing the number of buffers needed. However, we can extend this advantage by making our coloring rule give us not only information about business rules, but also the differentiation between bullish and bearish candles. This can be done simply by working on the edge colors and fillings of the candles seen previously. For each design we will want the edges and the filling of the low candles to be the same color, while for filling the high candles we will use white, for a price chart with a white background, giving the illusion of unfilled candles.

So we arrived at the objective of this article, which is the demonstration of how to create coloring rules according to some business rule applying it to a candle chart with and without filling. The final result of our work is shown in the image below.


Author: Samuel Manoel De Souza

 
Excelente Tutorial, Samuel! Parabéns e obrigado!!!
 
Excellent one.... my thought candle stick is also a straight one which can make somebody understand little about the trading term, I believe red one is to sell while the green one is to buy but they samething when green goes up to buy while red down to sell but at the end of  point of there line, green must taken a reverse and red must moving on as well while yellow Is jughing there price.  So in putting of  this to the mql5, everyone will know my query language (my ql).
 

Hello Samuel, 

Nice idea , but i cant to do this work. Can you submit this example on this article?


Best Regards,

 
Thanks so much so didactic..
 
cf23EA1l #:

Hello Samuel, 

Nice idea , but i cant to do this work. Can you submit this example on this article?


Best Regards,

//+------------------------------------------------------------------+
//|                                                Color Candles.mq5 |
//|                           Copyright 2020, Samuel Manoel de Souza |
//|                          https://www.mql5.com/pt/users/samuelmnl |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Samuel Manoel de Souza"
#property link      "https://www.mql5.com/pt/users/samuelmnl"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 12
#property indicator_plots   3
//--- plot bull
#property indicator_label1  "bull"
#property indicator_type1   DRAW_CANDLES
#property indicator_color1  clrGreen,clrBlack,clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot bear
#property indicator_label2  "bear"
#property indicator_type2   DRAW_CANDLES
#property indicator_color2  clrRed,clrBlack,clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot range
#property indicator_label3  "wait"
#property indicator_type3   DRAW_CANDLES
#property indicator_color3  clrGold,clrBlack,clrGold
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- indicator buffers
double         bullBuffer1[];
double         bullBuffer2[];
double         bullBuffer3[];
double         bullBuffer4[];
double         bearBuffer1[];
double         bearBuffer2[];
double         bearBuffer3[];
double         bearBuffer4[];
double         rangeBuffer1[];
double         rangeBuffer2[];
double         rangeBuffer3[];
double         rangeBuffer4[];

input int inpShift = 0; //Indicator Shift
input int inpBlue = 10;//Blue Shift
input int inpRed = 20; //Red Shift

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(inpBlue <= 0)
     {
      Alert("Blue Shift must be greater then 0!");
      return INIT_PARAMETERS_INCORRECT;
     }
   if(inpRed <= inpBlue)
     {
      Alert("Red Shift must be greater then Blue Shift!");
      return INIT_PARAMETERS_INCORRECT;
     }
//--- indicator buffers mapping
   SetIndexBuffer(0, bullBuffer1, INDICATOR_DATA);
   SetIndexBuffer(1, bullBuffer2, INDICATOR_DATA);
   SetIndexBuffer(2, bullBuffer3, INDICATOR_DATA);
   SetIndexBuffer(3, bullBuffer4, INDICATOR_DATA);
   SetIndexBuffer(4, bearBuffer1, INDICATOR_DATA);
   SetIndexBuffer(5, bearBuffer2, INDICATOR_DATA);
   SetIndexBuffer(6, bearBuffer3, INDICATOR_DATA);
   SetIndexBuffer(7, bearBuffer4, INDICATOR_DATA);
   SetIndexBuffer(8, rangeBuffer1, INDICATOR_DATA);
   SetIndexBuffer(9, rangeBuffer2, INDICATOR_DATA);
   SetIndexBuffer(10, rangeBuffer3, INDICATOR_DATA);
   SetIndexBuffer(11, rangeBuffer4, INDICATOR_DATA);
//---Setting which value make the bars invisible
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0);
   PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, 0);
//---Setting the shift values for each bar
   PlotIndexSetInteger(0, PLOT_SHIFT, inpShift);
   PlotIndexSetInteger(1, PLOT_SHIFT, inpShift);
   PlotIndexSetInteger(2, PLOT_SHIFT, inpShift);
//---Setting from where the bars must be drawed
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, inpRed - 1);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, inpRed - 1);
   PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, inpRed - 1);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---
//---If there is no sufficient bars, don't calculate
   if(rates_total < inpRed)
     {
      return rates_total;
     }
//---Defining from where we should start the calculation
   int limit;
   if(prev_calculated < inpRed)
      limit = inpRed;
   else
      limit = prev_calculated - 1;
//---Main calculation loop
   for(int i = limit; i < rates_total; i++)
     {
      int shift = BarIndex2shift(i);
      double open = iOpen(_Symbol, _Period, shift);
      double high = iHigh(_Symbol, _Period, shift);
      double low = iLow(_Symbol, _Period, shift);
      double close = iClose(_Symbol, _Period, shift);
      double red = price[i - (inpRed)]; //Getting the Red line value
      double blue = price[i - inpBlue]; //Getting the Blue line value
      double yellow = price[i];     //Getting the Yellow line value
      //There are three flags for this filter
      //0 = sell, 1= wait, 1 = buy
      // we can buy if 2 lines is above the red
      // we can sell if 2 lines is below the red
      int direction = 0;
      direction += (yellow > red) ? 1 : 0; // If Yellow is above Red, add 1
      red = blue;
      blue = yellow;
      direction += (blue > red) ? 1 : 0; // If Blue is above Red, add 1 .
      //For default bars isn't visible
      bullBuffer1[i] = 0;
      bullBuffer2[i] = 0;
      bullBuffer3[i] = 0;
      bullBuffer4[i] = 0;
      bearBuffer1[i] = 0;
      bearBuffer2[i] = 0;
      bearBuffer3[i] = 0;
      bearBuffer4[i] = 0;
      rangeBuffer1[i] = 0;
      rangeBuffer2[i] = 0;
      rangeBuffer3[i] = 0;
      rangeBuffer4[i] = 0;
      //We'll assign value to each bar according with the direction flag
      switch(direction)
        {
         case 0: // Is bear market
           {
            bearBuffer1[i] = open;
            bearBuffer2[i] = high;
            bearBuffer3[i] = low;
            bearBuffer4[i] = close;
            break;
           }
         case 1: // Is bull market
           {
            rangeBuffer1[i] = open;
            rangeBuffer2[i] = high;
            rangeBuffer3[i] = low;
            rangeBuffer4[i] = close;
            break;
           }
         case 2: // Is range market
           {
            bullBuffer1[i] = open;
            bullBuffer2[i] = high;
            bullBuffer3[i] = low;
            bullBuffer4[i] = close;
            break;
           }
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }

int BarIndex2shift(int bar) {return Bars(_Symbol, _Period) - bar - 1;}

//+------------------------------------------------------------------+
 
Thanks for this article.  I was able to follow along and apply it to my charts.  My question is have you done any articles that explain, how to call this indicator in an EA to use it to do automatically trade as well as strategy tester with visualization?
 
PanteraNoire #:
Thanks for this article.  I was able to follow along and apply it to my charts.  My question is have you done any articles that explain, how to call this indicator in an EA to use it to do automatically trade as well as strategy tester with visualization?

No.

You need use iCustom. And you can see the buffer numbers in the indicator to know about colors and values.

 

Ok. Thanks for the reply.  I will give it a try!


Samuel Manoel De Souza #:

No.

You need use iCustom. And you can see the buffer numbers in the indicator to know about colors and values.

 
How can I reduce the space between each candlestick? Is there a way?
Thanks in advance!
 
Genaro Cancino #:
How can I reduce the space between each candlestick? Is there a way?
Thanks in advance!

I don't understand the question.

If you zoom in/out the chart that may reduce or increase the space between the candles.

Reason: