Sets_the_chart_scale

Author: Alexey Viktorov
1 Views
0 Downloads
0 Favorites
Sets_the_chart_scale
ÿþ//+------------------------------------------------------------------+

//|                                         Sets the chart scale.mq5 |

//|                                                  Alexey Viktorov |

//|                     https://www.mql5.com/ru/users/alexeyvik/news |

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

#property copyright "Alexey Viktorov"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.00"

#property indicator_chart_window

#property indicator_plots   0



double half=0;

int chartScale;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   chartScale=(int)ChartGetInteger(0,CHART_SCALE);

   half=NormalizeDouble(ChartGetDouble(0,CHART_PRICE_MAX)-(ChartGetDouble(0,CHART_PRICE_MAX)+ChartGetDouble(0,CHART_PRICE_MIN))/2,_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[])

  {

   double chartMax = ChartGetDouble(0, CHART_PRICE_MAX);

   double chartMin = ChartGetDouble(0, CHART_PRICE_MIN);

   double chartMid = NormalizeDouble((chartMax+chartMin)/2, _Digits);

   int firstVisibleBar=(int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR);

   int visibleBars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS);

   int ratesBar=rates_total-firstVisibleBar-3+visibleBars;

   ChartSetInteger(0,CHART_SCALEFIX,true);

   ChartSetDouble(0,CHART_FIXED_MAX,(open[ratesBar]+close[ratesBar])/2+half);

   ChartSetDouble(0,CHART_FIXED_MIN,(open[ratesBar]+close[ratesBar])/2-half);

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

   return(rates_total);

  }



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

//|                                                                  |

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

void OnDeinit(const int reason)

  {

   ChartSetInteger(0,CHART_SCALEFIX,false);

  }

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

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