Problem: Call Chart_Shift but the Chart is not shifted right away?

To add comments, please log in or register
aphong
122
aphong  

Hello pro Coders,

I got a Problem with Chart Shift functions. Problem: Call Chart_Shift but the Chart is not shifted right away? :)

I noticed the ChartShift icon is changed right away after i hit "H" key but the CHart is not???
... Im new to coding, Please help!  ... & have a good day all :D

here is my code:

//+------------------------------------------------------------------+
//|                                           update chart shift.mq4 |
#property strict
#property indicator_chart_window

extern int ChartShift = 25;
input string H="H";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//  
void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
 {
   //
   if(id == CHARTEVENT_KEYDOWN)
   {
      if (lparam == StringGetChar(H,0))   updateCHARTSHIFT();
   }      
 }
  
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void updateCHARTSHIFT()
{
double result = ChartShiftSizeGet();
Print("ChartShiftSizeGet() = "+string(result));
//
if (result != ChartShift) 
{
ChartShiftSizeSet(ChartShift);
Print("ChartShiftSizeSet() = "+string(ChartShift));
}
//
bool isShifted   = ChartGetInteger(0,CHART_SHIFT,true);
Print("isShifted  = "+string(isShifted));
if   (!isShifted)  ChartSetInteger(0,CHART_SHIFT,true);
ChartRedraw(0);
;
}
//
double ChartShiftSizeGet(const long chart_ID=0) 
  { 
//--- prepare the variable to get the result 
   double result=EMPTY_VALUE; 
//--- reset the error value 
   ResetLastError(); 
//--- receive the property value 
   if(!ChartGetDouble(chart_ID,CHART_SHIFT_SIZE,0,result)) 
     { 
      //--- display the error message in Experts journal 
      Print(__FUNCTION__+", Error Code = ",GetLastError()); 
     } 
//--- return the value of the chart property 
   return(result); 
  } 
//
bool ChartShiftSizeSet(const double value,const long chart_ID=0) 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- set property value 
   if(!ChartSetDouble(chart_ID,CHART_SHIFT_SIZE,value)) 
     { 
      //--- display the error message in Experts journal 
      Print(__FUNCTION__+", Error Code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  }
 

To add comments, please log in or register