Other_Candles

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

//|                                                Other_Candles.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                                 https://mql5.com |

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

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

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

#property version   "1.01"

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_plots   1

//--- plot Candle

#property indicator_label1  "Candle"

#property indicator_type1   DRAW_COLOR_CANDLES

#property indicator_color1  clrLimeGreen,clrOrangeRed,clrGray

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input color    InpColorBullish   =  clrLimeGreen;  // Bullish candle color

input color    InpColorBearish   =  clrOrangeRed;  // Bearish candle color

//--- indicator buffers

double         BufferOpen[];

double         BufferHigh[];

double         BufferLow[];

double         BufferClose[];

double         BufferColors[];

//--- enums

enum ENUM_CANDLE_TYPE

  {

   CANDLE_TYPE_BULLISH, // KGLO A25G0

   CANDLE_TYPE_BEARISH, // 54256LO A25G0

   CANDLE_TYPE_DOJI     // >468

  };

//--- structures

struct SDataCandles

  {

   ENUM_CANDLE_TYPE  type;             // "8? A25G8

   double            body_size;        //  07<5@ B5;0 A25G8

   double            shadow_up_size;   //  07<5@ 25@E=59 B5=8

   double            shadow_dn_size;   //  07<5@ =86=59 B5=8

  } candle;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BufferOpen,INDICATOR_DATA);

   SetIndexBuffer(1,BufferHigh,INDICATOR_DATA);

   SetIndexBuffer(2,BufferLow,INDICATOR_DATA);

   SetIndexBuffer(3,BufferClose,INDICATOR_DATA);

   SetIndexBuffer(4,BufferColors,INDICATOR_COLOR_INDEX);

//--- settings plots parameters

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0);

   string symbol=Symbol();

   PlotIndexSetString(0,PLOT_LABEL,symbol+" Open;"+symbol+" High;"+symbol+" Low;"+symbol+" Close");

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,InpColorBullish);

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,InpColorBearish);

//--- settings indicators parameters

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

   IndicatorSetString(INDICATOR_SHORTNAME,"Other candles");

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferOpen,true);

   ArraySetAsSeries(BufferHigh,true);

   ArraySetAsSeries(BufferLow,true);

   ArraySetAsSeries(BufferClose,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[])

  {

//--- @>25@:0 =0 <8=8<0;L=>5 :>;8G5AB2> 10@>2 4;O @0AGQB0

   if(rates_total<1) return 0;

//--- #AB0=>2:0 8=45:A0F88 <0AA82>2 :0: B09<A5@89

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

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

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-1;

      ArrayInitialize(BufferOpen,0);

      ArrayInitialize(BufferHigh,0);

      ArrayInitialize(BufferLow,0);

      ArrayInitialize(BufferClose,0);

     }

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

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

     {

      SetCandleParams(i,open,high,low,close);

      BufferOpen[i]=0;

      if(candle.type==CANDLE_TYPE_BULLISH)

        {

         BufferColors[i]=0;

         BufferHigh[i]=candle.body_size+candle.shadow_up_size;

         BufferClose[i]=candle.body_size;

         BufferLow[i]=BufferOpen[i]-candle.shadow_dn_size;

        }

      else if(candle.type==CANDLE_TYPE_BEARISH)

        {

         BufferColors[i]=1;

         BufferLow[i]=-candle.body_size-candle.shadow_dn_size;

         BufferClose[i]=-candle.body_size;

         BufferHigh[i]=candle.shadow_up_size;

        }

      else

        {

         BufferClose[i]=0;

         BufferHigh[i]=candle.shadow_up_size;

         BufferLow[i]=-candle.shadow_dn_size;

         BufferColors[i]=2;

        }

     }

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

   return(rates_total);

  }

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

//| >72@0I05B ?0@0<5B@K A25G8                                       |

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

void SetCandleParams(const int index,const double &open[],const double &high[],const double &low[],const double &close[])

  {

   ZeroMemory(candle);

   candle.type=CandleType(index,open,close);

   candle.body_size=fabs(open[index]-close[index]);

   candle.shadow_up_size=high[index]-fmax(open[index],close[index]);

   candle.shadow_dn_size=fmin(open[index],close[index])-low[index];

  }

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

//| >72@0I05B B8? A25G8                                             |

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

ENUM_CANDLE_TYPE CandleType(const int index,const double &open[],const double &close[])

  {

   return(close[index]>open[index] ? CANDLE_TYPE_BULLISH : close[index]<open[index] ? CANDLE_TYPE_BEARISH : CANDLE_TYPE_DOJI);

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---