Thierry Ramaniraka:
Hello everyone,
I desire to auto scale the width of an histogram buffer according the zoom scale's candle.
My problem is it only works when i change the time frame.
I want it to be directly after zooming in/out.
I have put the function in : OnInit + OnCalculate + OnChartEvent ... but, it doesn't work instantly.
Here is my code :
Please help.
Regards.
Hello everyone,
I desire to auto scale the width of an histogram buffer according the zoom scale's candle.
My problem is it only works when i change the time frame.
I want it to be directly after zooming in/out.
I have put the function in : OnInit + OnCalculate + OnChartEvent ... but, it doesn't work instantly.
Here is my code :
Please help.
Regards.
You'd be better off using a switch expression
int TLR_Hist_Width() { switch((int)ChartGetInteger(0, CHART_SCALE)){ case 5: return 12; case 4: return 6; case 3: return 4; case 2: return 2; } return 1; }
Regarding your main question, you haven't provided enough code/context for help.
//+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexStyle(index,EMPTY,EMPTY,TLR_Hist_Width()); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_CHART_CHANGE) SetIndexStyle(index,EMPTY,EMPTY,TLR_Hist_Width()); } //+------------------------------------------------------------------+
nicholi shen:
You'd be better off using a switch expression
Regarding your main question, you haven't provided enough code/context for help.
Ernst Van Der Merwe:
Thank you very much both of you.
It works perfectly.
Kind regards.
Rob Hayne #: I have the same request. How do I place the correct code into this indicator so that as I zoom, the histogram width changes?
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
int width=0; int OnInit(){ width = (int) ChartGetInteger(0,CHART_SCALE); //--- indicator buffers mapping SetIndexBuffer(0,…); SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, width); ⋮ } int OnCalculate(…){ if(ChartGetInteger(0,CHART_SCALE) != width) OnInit(); ⋮

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I desire to auto scale the width of an histogram buffer according the zoom scale's candle.
My problem is it only works when i change the time frame.
I want it to be directly after zooming in/out.
I have put the function in : OnInit + OnCalculate + OnChartEvent ... but, it doesn't work instantly.
Here is my code :
Please help.
Regards.