linear_price_bar_v1

Author: Copyright © 2006, Keris2112
0 Views
0 Downloads
0 Favorites
linear_price_bar_v1
ÿþ//+------------------------------------------------------------------+

//|                                             Linear_Price_Bar.mq4 |

//|                                      Copyright © 2006, Keris2112 |

//|                                                                  |

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

#property copyright "Copyright © 2006, Keris2112"

#property link      ""

#property description ""

//--- indicator version

#property version   "1.00"

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

//|  Indicator drawing parameters                |

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

//--- drawing the indicator in a separate window

#property indicator_separate_window

//--- five buffers are used for the indicator calculation and drawing

#property indicator_buffers 5

//--- one plot is used

#property indicator_plots   1

//--- color candlesticks are used as an indicator

#property indicator_type1   DRAW_COLOR_CANDLES

#property indicator_color1  clrDodgerBlue,clrRed

//--- displaying the indicator label

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

//--- declaration of dynamic arrays that

//--- will be used as indicator buffers

double ExtOpenBuffer[];

double ExtHighBuffer[];

double ExtLowBuffer[];

double ExtCloseBuffer[];

double ExtColorBuffer[];

//---

int min_rates_total;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

//--- initialization of global variables 

   min_rates_total=1;

//--- set dynamic arrays as indicator buffers

   SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);

//--- Setting a dynamic array as a color index buffer   

   SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);

//--- shifting the start of drawing of the indicator 1

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//--- setting the format of accuracy of displaying the indicator

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- name for the data window and the label for sub-windows 

   string short_name="Linear_Price_Bar";

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//---   

  }

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

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

  {

//--- checking if the number of bars is enough for the calculation

   if(rates_total<min_rates_total) return(0);

//--- declarations of local variables 

   int first,bar;

   double;

//--- calculation of the starting number 'first' for the cycle of recalculation of bars

   if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of the indicator calculation

     {

      first=0; // starting number for calculation of all bars

     }

   else first=prev_calculated-1; // Starting index for the calculation of new bars

//--- main calculation loop of the indicator

   for(bar=first; bar<rates_total && !IsStopped(); bar++)

     {

      ExtOpenBuffer[bar]=0.0;

      ExtCloseBuffer[bar]=(close[bar]-open[bar])/_Point;

      ExtHighBuffer[bar]=(high[bar]-open[bar])/_Point;

      ExtLowBuffer[bar]=(low[bar]-open[bar])/_Point;

      //---

      if(ExtCloseBuffer[bar]<0) ExtColorBuffer[bar]=1;

      else ExtColorBuffer[bar]=0;

     }

//---     

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