Bull_Bear_Bar

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
0 Views
0 Downloads
0 Favorites
Bull_Bear_Bar
ÿþ//+------------------------------------------------------------------+

//|                                                Bull_Bear_Bar.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                                 https://mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://mql5.com"

#property version   "1.00"

#property description "Bull Bear Bar indicator\n"

#property description "Indicator painted a bar after it closes within a specified area\nof the bar's range, based on the following options:\n"

#property description "  1. Close within the top 1/4 of the bar's range.\n  2. Close within the top 1/3 of bar."

#property description "  3. Close within the mid 1/3 of bar.\n  4. Close within the bottom 1/3 of bar.\n  5. Close within the bottom 1/4 of bar. "

#property indicator_chart_window

#property indicator_buffers 10

#property indicator_plots   6

//--- plot Top14

#property indicator_label1  "Top 1/4"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot TopThird

#property indicator_label2  "Top Third"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrMediumSeaGreen

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot MidThird

#property indicator_label3  "Mid Third"

#property indicator_type3   DRAW_ARROW

#property indicator_color3  clrOrange

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- plot BottomThird

#property indicator_label4  "Bottom Third"

#property indicator_type4   DRAW_ARROW

#property indicator_color4  clrOrangeRed

#property indicator_style4  STYLE_SOLID

#property indicator_width4  1

//--- plot Bottom14

#property indicator_label5  "Bottom 1/4"

#property indicator_type5   DRAW_ARROW

#property indicator_color5  clrRed

#property indicator_style5  STYLE_SOLID

#property indicator_width5  1

//--- plot Candle

#property indicator_label6  "Open;High;Low;Close"

#property indicator_type6   DRAW_COLOR_CANDLES

#property indicator_color6  clrGreen,clrMediumSeaGreen,clrOrange,clrOrangeRed,clrRed,clrDarkGray

#property indicator_style6  STYLE_SOLID

#property indicator_width6  1

//--- input parameters

input color    InpColorTop    =  clrGreen;            // Top 1/4 Color

input color    InpColorMid1   =  clrMediumSeaGreen;   // Top Third Color

input color    InpColorMid2   =  clrOrange;           // Mid Third Color

input color    InpColorMid3   =  clrOrangeRed;        // Bottom Third Color

input color    InpColorBottom =  clrRed;              // Bottom 1/4 color

//--- indicator buffers

double         BufferTop14[];

double         BufferTopThird[];

double         BufferMidThird[];

double         BufferBottomThird[];

double         BufferBottom14[];

double         BufferCandleO[];

double         BufferCandleH[];

double         BufferCandleL[];

double         BufferCandleC[];

double         BufferColors[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BufferTop14,INDICATOR_DATA);

   SetIndexBuffer(1,BufferTopThird,INDICATOR_DATA);

   SetIndexBuffer(2,BufferMidThird,INDICATOR_DATA);

   SetIndexBuffer(3,BufferBottomThird,INDICATOR_DATA);

   SetIndexBuffer(4,BufferBottom14,INDICATOR_DATA);

   SetIndexBuffer(5,BufferCandleO,INDICATOR_DATA);

   SetIndexBuffer(6,BufferCandleH,INDICATOR_DATA);

   SetIndexBuffer(7,BufferCandleL,INDICATOR_DATA);

   SetIndexBuffer(8,BufferCandleC,INDICATOR_DATA);

   SetIndexBuffer(9,BufferColors,INDICATOR_COLOR_INDEX);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,158);

   PlotIndexSetInteger(1,PLOT_ARROW,158);

   PlotIndexSetInteger(2,PLOT_ARROW,158);

   PlotIndexSetInteger(3,PLOT_ARROW,158);

   PlotIndexSetInteger(4,PLOT_ARROW,158);

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferTop14,true);

   ArraySetAsSeries(BufferTopThird,true);

   ArraySetAsSeries(BufferMidThird,true);

   ArraySetAsSeries(BufferBottomThird,true);

   ArraySetAsSeries(BufferBottom14,true);

   ArraySetAsSeries(BufferCandleO,true);

   ArraySetAsSeries(BufferCandleH,true);

   ArraySetAsSeries(BufferCandleL,true);

   ArraySetAsSeries(BufferCandleC,true);

   ArraySetAsSeries(BufferColors,true);

//--- setting plot buffer parameters

   PlotIndexSetInteger(5,PLOT_SHOW_DATA,false);

//--- setting indicator parameters

   IndicatorSetString(INDICATOR_SHORTNAME,"Bull/Bear Bar");

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//---

   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[])

  {

//--- #AB0=>2:0 <0AA82>2 1CD5@>2 :0: B09<A5@89

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

//--- @>25@:0 :>;8G5AB20 4>ABC?=KE 10@>2

   if(rates_total<2) return 0;

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-1;

      ArrayInitialize(BufferTop14,EMPTY_VALUE);

      ArrayInitialize(BufferTopThird,EMPTY_VALUE);

      ArrayInitialize(BufferMidThird,EMPTY_VALUE);

      ArrayInitialize(BufferBottomThird,EMPTY_VALUE);

      ArrayInitialize(BufferBottom14,EMPTY_VALUE);

      ArrayInitialize(BufferCandleO,EMPTY_VALUE);

      ArrayInitialize(BufferCandleH,EMPTY_VALUE);

      ArrayInitialize(BufferCandleL,EMPTY_VALUE);

      ArrayInitialize(BufferCandleC,EMPTY_VALUE);

      ArrayInitialize(BufferColors,5);

     }



//---  0AGQB 8=48:0B>@0

   for(int i=limit; i>=0 && !IsStopped(); i--)

     {

      BufferCandleO[i]=open[i];

      BufferCandleH[i]=high[i];

      BufferCandleL[i]=low[i];

      BufferCandleC[i]=close[i];

      BufferColors[i]=5;

      ClearArrows(i);

      double Percentage=(high[i]-low[i])/100.0;

      double Position=(Percentage!=0 ? fabs(close[i]-low[i])/Percentage : 0);

      if(Position>=75)

        {

         BufferColors[i]=0;

         BufferTop14[i]=close[i];

        }

      else if(Position>=66)

        {

         BufferColors[i]=1;

         BufferTopThird[i]=close[i];

        }

      else if(Position<=25)

        {

         BufferColors[i]=4;

         BufferBottom14[i]=close[i];

        }

      else if(Position<=33)

        {

         BufferColors[i]=3;

         BufferBottomThird[i]=close[i];

        }

      else

        {

         BufferColors[i]=2;

         BufferMidThird[i]=close[i];

        }

     }

   

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void ClearArrows(const int shift)

  {

   BufferTop14[shift]=BufferTopThird[shift]=BufferMidThird[shift]=BufferBottomThird[shift]=BufferBottom14[shift]=EMPTY_VALUE;

  }

//+------------------------------------------------------------------+

Comments