Changing width scale according zoom scale

To add comments, please log in or register
Thierry Ramaniraka
540
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 :
int TLR_Hist_Width()
      {
        // Zoom +/-
        long ChartScale=ChartGetInteger(0,CHART_SCALE);

        if(ChartScale==5)
            {
                TLR_NR0_Width=12;
            }
        if(ChartScale==4)
            {
                TLR_NR0_Width=6;
            }
        if(ChartScale==3)
            {
                TLR_NR0_Width=4;
            }
        if(ChartScale==2)
            {
                TLR_NR0_Width=2;
            }
        if(ChartScale==1)
            {
                TLR_NR0_Width=1;
            }
        if(ChartScale==0)
            {
                TLR_NR0_Width=0;
            }
        return(0);
      }
    //+---------------------------------------------------------------+
Please help.
Regards.
nicholi shen
2392
nicholi shen  
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.

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. 

Ernst Van Der Merwe
6528
Ernst Van Der Merwe  
//+------------------------------------------------------------------+
//| 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());
  }
//+------------------------------------------------------------------+
Thierry Ramaniraka
540
Thierry Ramaniraka  
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.

To add comments, please log in or register