Changing width scale according zoom scale
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()); } //+------------------------------------------------------------------+
You'd be better off using a switch expression
Regarding your main question, you haven't provided enough code/context for help.
Thank you very much both of you.
It works perfectly.
Kind regards.
-
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(); ⋮
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.