One direction candle

Author: Copyright © 2020, Vladimir Karputov
Price Data Components
2 Views
0 Downloads
0 Favorites
One direction candle
ÿþ//+------------------------------------------------------------------+

//|                                         One direction candle.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

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

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.000"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot Candle

#property indicator_label1  "Candle"

#property indicator_type1   DRAW_COLOR_HISTOGRAM

#property indicator_color1  clrLavender,clrLimeGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  3

//--- input parameters

input int      Input1=9;

//--- indicator buffers

double   CandleBuffer[];

double   CandleColors[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,CandleBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,CandleColors,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 limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      if(open[0]<close[0])

        {

         CandleBuffer[0]=(close[0]-open[0])/Point();

         CandleColors[0]=0.0;

        }

      else

        {

         CandleBuffer[0]=(open[0]-close[0])/Point();

         CandleColors[0]=1.0;

        }

      limit=1;

     }

   for(int i=limit; i<rates_total; i++)

     {

      if(open[i]<close[i])

        {

         if(open[i-1]<close[i-1])

            CandleBuffer[i]=CandleBuffer[i-1]+(close[i]-open[i])/Point();

         else

            CandleBuffer[i]=(close[i]-open[i])/Point();

         CandleColors[i]=0.0;

        }

      else

        {

         if(open[i-1]>close[i-1])

            CandleBuffer[i]=CandleBuffer[i-1]+(open[i]-close[i])/Point();

         else

            CandleBuffer[i]=(open[i]-close[i])/Point();

         CandleColors[i]=1.0;

        }

     }

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

   return(rates_total);

  }

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

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 ---