Programmatically Change Bear/Bull Candle color.

 

I have written an indicator that colors candles based on The Strat method. The indicator works as I intended coloring the 1 candles yellow and they 3 candles Magenta. Unfortunately this overrides the chart's default settings for Bull/Bear candles. I like for my Bull candles to be hollow and I am able to achieve this affect for candles not painted by the indicator by setting the Bull Candle color to the same color as my background in the chart properties, but after searching the documentation, I cannot find the right property to do this from within my code. The end result is pictured below here in as you can see, the green bull candles appear to be hollow as I want, but the candles which my inicator paints are solid regardless of direction. Both the yellow (1) and magenta (3) candles in the middle of this chart should be hollow. How can I achieve this?


EDIT#1: It seems the picture I tried to paste into the post is not showing.

EDIT#2: Chart image attached as advised.

EDIT#3: Adding code for reference.

//+------------------------------------------------------------------+
//|                                                TSCandleColor.mq5 |
//|                                                               NA |
//|                                                               NA |
//+------------------------------------------------------------------+
#property copyright "NA"
#property link      "NA"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   1
//--- plot Open
#property indicator_label1  "Open;High;Low;Close"
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrYellow,clrMagenta,clrNONE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         Open[];
double         High[];
double         Low[];
double         Close[];
double         Color[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Open,INDICATOR_DATA);
   SetIndexBuffer(1,High,INDICATOR_DATA);
   SetIndexBuffer(2,Low,INDICATOR_DATA);
   SetIndexBuffer(3,Close,INDICATOR_DATA);
   SetIndexBuffer(4,Color,INDICATOR_COLOR_INDEX);
//---
   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 begin=(prev_calculated<1)?1:(rates_total!=prev_calculated)?prev_calculated:prev_calculated-1;
   
   for(int i=begin;i<rates_total;i++)
     {
      Open[i]=open[i];
      High[i]=high[i];
      Low[i]=low[i];
      Close[i]=close[i];
      Color[i]=high[i]>high[i-1] && low[i]<low[i-1]?1:
               high[i]<high[i-1] && low[i]>low[i-1]?0:2;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
  
  int GetCandleId(int i)
  {
   if(iHigh(_Symbol,PERIOD_CURRENT,i)>iHigh(_Symbol,PERIOD_CURRENT,i+1) && iLow(_Symbol,PERIOD_CURRENT,i)<iLow(_Symbol,PERIOD_CURRENT,i+1))
      return 1;
   if(iHigh(_Symbol,PERIOD_CURRENT,i)>iHigh(_Symbol,PERIOD_CURRENT,i+1) && iLow(_Symbol,PERIOD_CURRENT,i)<iHigh(_Symbol,PERIOD_CURRENT,i+1) && iLow(_Symbol,PERIOD_CURRENT,i)>=iLow(_Symbol,PERIOD_CURRENT,i+1))
      return 2;
   if(iHigh(_Symbol,PERIOD_CURRENT,i)<=iHigh(_Symbol,PERIOD_CURRENT,i+1) && iHigh(_Symbol,PERIOD_CURRENT,i)>iLow(_Symbol,PERIOD_CURRENT,i+1) && iLow(_Symbol,PERIOD_CURRENT,i)<iLow(_Symbol,PERIOD_CURRENT,i+1))
      return 2;
   if(iHigh(_Symbol,PERIOD_CURRENT,i)<iHigh(_Symbol,PERIOD_CURRENT,i+1) && iLow(_Symbol,PERIOD_CURRENT,i)>iLow(_Symbol,PERIOD_CURRENT,i+1))
      return 0;
   else
      return 2;
  }
//+------------------------------------------------------------------+
Files:
 
Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Given that your rating is still too, you will not be able to embed images. You can however attach images as files using the "+ Attach" link just below the posting area.
 

Fernando Carreiro #:
Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

Thank you, my apologies as I thought when I clicked on new topic it would automatically set the same section.
 
Ron Westbrook #: Thank you, my apologies as I thought when I clicked on new topic it would automatically set the same section.

Yes, that is correct, but you clicked on the "New topic" for the "General" section and not the "Technical Indicators" section.

 
Fernando Carreiro #:
Given that your rating is still too, you will not be able to embed images. You can however attach images as files using the "+ Attach" link just below the posting area.
Thank you, image attached as advised.
 
Ron Westbrook: I have written an indicator that colors candles based on The Strat method. The indicator works as I intended coloring the 1 candles yellow and they 3 candles Magenta. Unfortunately this overrides the chart's default settings for Bull/Bear candles. I like for my Bull candles to be hollow and I am able to achieve this affect for candles not painted by the indicator by setting the Bull Candle color to the same color as my background in the chart properties, but after searching the documentation, I cannot find the right property to do this from within my code. The end result is pictured below here in as you can see, the green bull candles appear to be hollow as I want, but the candles which my inicator paints are solid regardless of direction. Both the yellow (1) and magenta (3) candles in the middle of this chart should be hollow. How can I achieve this?

Can you explain how you are colouring the candles?

Show a sample of the code that you are using for it. Are you using the "DRAW_COLOR_CANDLES" or something else?

Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_COLOR_CANDLES
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_COLOR_CANDLES
  • www.mql5.com
DRAW_COLOR_CANDLES - Indicator Styles in Examples - Custom Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Can you explain how you are colouring the candles?

Show a sample of the code that you are using for it. Are you using the "DRAW_COLOR_CANDLES" or something else?

Yes, I am using DRAW_COLOR_CANDLES. I've updated the original post with the code.
 
Ron Westbrook #: Yes, I am using DRAW_COLOR_CANDLES. I've updated the original post with the code.

Then, please note that the "DRAW_COLOR_CANDLES" (or the "DRAW_CANDLES") method does not have an option for "hollow" candles.

They are always "filled". That is to say that the border and fill are always the same colour, unlike the regular candles which can have separate colours.

 
Fernando Carreiro #:

Then, please note that the "DRAW_COLOR_CANDLES" (or the "DRAW_CANDLES") method does not have an option for "hollow" candles.

They are always "filled". That is to say that the border and fill are always the same, unlike the regular candles which can have separate colours.

Is there a method that does not draw the candles as filled? I was not able to find this on my own, but surely it exists if the native system is able to do it.
 
Ron Westbrook #: Is there a method that does not draw the candles as filled? I was not able to find this on my own, but surely it exists if the native system is able to do it.
Not, when using normal plot styles. You can probably do it with graphical objects, but I would not consider that ideal (but that is my own opinion).