Indicator Ribbon/Cloud in oscillator MT4

 

 Hello, 

I'm trying without success to make  a cloud/ribbon in one of my oscillators but it doesn't work.


This method works on the main chart for creating candle sticks.



And yet I would like something like this;




Here is the code snippet I use;


              //custom functions
	       double s= currency_s(_Symbol, i);
               double ss= base_quote_s_s(_Symbol, i);
               double base_s = base_quote_s(_Symbol, i);
               double quote_s = base_quote_s(_Symbol, i, 1);
               double vup = MathMax(base_s, quote_s); 
               double vdn = MathMin(base_s, quote_s);

               int trend = trend_NEUTRAL;
               if(s> 3 && ss> 10) trend = trend_UP_strong;
               else if(s> 3 && ss< 10) trend = trend_UP_weak;
               else if(s< 3 && ss>= 20) trend = trend_UP_weak;

               else if(s< -3 && ss< -10) trend = trend_DN_strong;
               else if(s< 3 && ss> -10) trend = trend_DN_weak;
               else if(s> -3 && ss<= -20) trend = trend_DN_weak;

               down[i] = EMPTY_VALUE;//histogram buffer
               up[i] = EMPTY_VALUE;//histogram buffer
               if(trend == trend_UP_strong)
                  {
                     up[i] = vup;
                     down[i] = vdn;
                  }

               if(trend == trend_UP_weak)
                  {
                     up[i] = vup;
                     down[i] = vdn;

                  }

               if(trend == trend_DN_strong)
                  {
                     up[i] = vdn;
                     down[i] = vup;

                  }

               if(trend == trend_DN_weak)
                  {
                     up[i] = vdn;
                     down[i] = vup;

                  }


Thanks, any help and input will be highly appreciated.

 
Paul Carissimo:

 Hello, 

I'm trying without success to make  a cloud/ribbon in one of my oscillators but it doesn't work.

This method works on the main chart for creating candle sticks.

And yet I would like something like this;

In MT4, the only way is to mask out some of the displayed data.

Use the following program as a guide:

//+------------------------------------------------------------------+
//|                                               Test Indicator.mq4 |
//|                                                    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 strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Histo 1
#property indicator_label1  "Histo 1"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrLimeGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot Histo 2
#property indicator_label2  "Histo 2"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrMagenta
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- plot Histo 3
#property indicator_label3  "Histo 3"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  clrBlack
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//--- input parameters
input int               Fast_period     = 12;
input int               Slow_period     = 26;
input int               Signal_period   = 9;
//--- indicator buffers
double         Histo1_Buffer[];
double         Histo2_Buffer[];
double         Histo3_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   //--- indicator buffers mapping
   SetIndexBuffer(0, Histo1_Buffer);
   SetIndexBuffer(1, Histo2_Buffer);
   SetIndexBuffer(2, Histo3_Buffer);
   //---
   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, limit;

   if (prev_calculated < 0)
      return(-1);
   if (prev_calculated == 0)
      limit = rates_total - Slow_period;
   else
      limit  = rates_total - prev_calculated;

   for (i = limit; i >= 0; i--)
   {
      Histo1_Buffer[i] = iMACD(NULL, 0, Fast_period, Slow_period, Signal_period, PRICE_CLOSE, MODE_MAIN,   i) + 100.0;
      Histo2_Buffer[i] = iMACD(NULL, 0, Fast_period, Slow_period, Signal_period, PRICE_CLOSE, MODE_SIGNAL, i) + 100.0;

      if (Histo1_Buffer[i] > Histo2_Buffer[i])
         Histo3_Buffer[i] = Histo2_Buffer[i];
      else
         Histo3_Buffer[i] = Histo1_Buffer[i];
   }
   //--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
 

No need to mask. He should simply use the method used in the second example he showed (since the first versions of that indicator are free indicators available as mq4 source code it should be easy). Or he can make alternate method to do that (something like this :


 
Naguisa Unada:

In MT4, the only way is to mask out some of the displayed data.

Use the following program as a guide:

Thank you Unada, I've tested it and it works well, the only caveat is an additional buffer which I find unsavory. Could you explain why this works ?
Mladen Rakic:

No need to mask. He should simply use the method used in the second example he showed (since the first versions of that indicator are free indicators available as mq4 source code it should be easy). Or he can make alternate method to do that (something like this :


Mladen, I've searched for that indicator online but all I find are .ex4 files, do you have a link to the source code ?

Could you as well link to a code example on how to implement the alternate method you are referring to ?

Thanks.

 
Paul Carissimo:
Thank you Unada, I've tested it and it works well, the only caveat is an additional buffer which I find unsavory. Could you explain why this works ?

I think you will understand if you change the background color.

Histo1 and Histo2 are masked by a black histogram.

Mask

 

Maybe it's about this program.

He is using objects, not histograms.

Files:
 
Naguisa Unada:

I think you will understand if you change the background color.

Histo1 and Histo2 are masked by a black histogram.


Ok, that makes sense now.

ChartGetInteger(x,CHART_COLOR_BACKGROUND); // This should then be the histogram3 color
Naguisa Unada:

Maybe it's about this program.

He is using objects, not histograms.

Interesting use of Objects, is this cheaper on system resource usage ?

 
Paul Carissimo:

Ok, that makes sense now.

Interesting use of Objects, is this cheaper on system resource usage ?

I'm not sure, but it gets slow when there are too many objects.

 
Naguisa Unada:

I'm not sure, but it gets slow when there are too many objects.

Alright then, thanks for your help, your idea works well for me.