Price Chart

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Price Chart
ÿþ//+------------------------------------------------------------------+

//|                                                  Price Chart.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_chart_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot MiddleLine

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrMagenta

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input ENUM_APPLIED_PRICE   Inp_applied_price = PRICE_MEDIAN;   // Type of price

//--- indicator buffers

double   PriceChartBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,PriceChartBuffer,INDICATOR_DATA);

//--- set labels for the line

   string text="NONE Price";

   switch(Inp_applied_price)

     {

      case PRICE_CLOSE:

         text="Close price";

         break;

      case PRICE_OPEN:

         text="Open price";

         break;

      case PRICE_HIGH:

         text="High price";

         break;

      case PRICE_LOW:

         text="Low price";

         break;

      case PRICE_MEDIAN:

         text="Median price";

         break;

      case PRICE_TYPICAL:

         text="Typical price price";

         break;

      case PRICE_WEIGHTED:

         text="Average price price";

         break;

     }

   PlotIndexSetString(0,PLOT_LABEL,text);

//---

   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)

      limit=0;

//--- main loop

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

     {

      switch(Inp_applied_price)

        {

         case PRICE_CLOSE:

            PriceChartBuffer[i]=close[i];

            break;

         case PRICE_OPEN:

            PriceChartBuffer[i]=open[i];

            break;

         case PRICE_HIGH:

            PriceChartBuffer[i]=high[i];

            break;

         case PRICE_LOW:

            PriceChartBuffer[i]=low[i];

            break;

         case PRICE_MEDIAN:

            PriceChartBuffer[i]=(high[i] + low[i])/2.0;

            break;

         case PRICE_TYPICAL:

            PriceChartBuffer[i]=(high[i] + low[i] + close[i])/3.0;

            break;

         case PRICE_WEIGHTED:

            PriceChartBuffer[i]=(high[i] + low[i] + close[i] + close[i])/4.0;

            break;

        }

     }

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