Switch charts and show only that chart

To add comments, please log in or register
GrumpyDuckMan
882
GrumpyDuckMan  

Hello everyone,

I have been trying to use a button to switch between charts in the watch window. I can switch charts but the previous one isn't being removed/deleted.

void ChangeChart()
  {
     CurrentSymbol = SymbolName(Next_Symbol,false);Next_Symbol++;
     Close_Chart   = ChartClose(chartid+Next_Symbol);     
     Chart_to_Open = ChartOpen (CurrentSymbol,0);
  }

This code has no effect on closing a chart, but I don't really understand why its not closing the chart viewed previously.

William Roeder
20233
William Roeder  
Because chartid+Next-Symbol is not a chart ID.
GrumpyDuckMan
882
GrumpyDuckMan  
whroeder1:
Because chartid+Next-Symbol is not a chart ID.

Hello again,

Thank you for the helpful reply, now I'm stuck again. After I hit the button "Switch" I'd like the next chart in the watch window to be the active window and close the previous one.

I tried this code, but not successful. Some ideas please with code changes.

BTW code is MQL4.

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#include "Variables.mq4"
#include "Conditions.mq4"
#include "Forum_Test.mq4"
#include "Repair.mq4"
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ObjectBuild()
  {
   NewPanel=0;
   int D_X[] ={0,623,1242,0,623,1242,0,623,1242};    
   int D_Y[] ={0,0,0,343,343,343,685,685,685};
   int X[]   ={623,623,623,623,623,623,623,623,623};  
   int Y[]   ={343,343,343,343,343,343,343,343,343};
   for(SHIFT = 0; SHIFT<= 10; SHIFT++)
     {
      NewPanel++; if(NewPanel>=10) break;
      ObjectCreate(0,Build[NewPanel],OBJ_RECTANGLE_LABEL,0,0,0);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_XDISTANCE,D_X[SHIFT]);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_YDISTANCE,D_Y[SHIFT]);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_XSIZE,X[SHIFT]);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_YSIZE,Y[SHIFT]);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_BORDER_TYPE,BORDER_FLAT);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_BGCOLOR,clrNONE); 
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_COLOR,clrWhite);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,Build[NewPanel],OBJPROP_STATE,false); 
     }
   ObjectButton();
   ObjectDiscription();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ObjectButton() 
  {
   ObjectDelete(Button[1]); 
   ObjectDelete(Button[2]); 
   ObjectDelete(Button[3]); 
   ObjectDelete(Button[4]); 
   ObjectDelete(Button[5]);
   NewButton = 0;
   int D_X[] = {630,630,630,630,630,630,630,630,630,690,690,690,690,690,690,690,690,690,750,750,750,750,750,750,750,750,750,810,810,810,810,810,810,810,810,810};
   int D_Y[] = {3,36,69,102,135,168,201,234,267,3,36,69,102,135,168,201,234,267,3,36,69,102,135,168,201,234,267,3,36,69,102,135,168,201,234,267};
   int X[]   = {50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50};
   int Y[]   = {20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20};
   for(SHIFT = 0; SHIFT<= 37; SHIFT++)
     {
      NewButton++; if(NewButton>=37) break;
      ObjectCreate(0,Button[NewButton],OBJ_BUTTON,0,0,0);
      ObjectSetText(Button[NewButton],Labels[SHIFT],10,Button[0],clrBlue);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_XDISTANCE,D_X[SHIFT]);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_YDISTANCE,D_Y[SHIFT]);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_XSIZE,X[SHIFT]);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_YSIZE,Y[SHIFT]);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_BORDER_TYPE,BORDER_FLAT);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_BGCOLOR,clrBlue);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_COLOR,clrWhite);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,Button[NewButton],OBJPROP_STATE,true);
     }
   ObjectDiscription();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ObjectDiscription() 
  {
   CurrBid       = MarketInfo  (CurrentSymbol,           MODE_BID);
   CurrAsk       = MarketInfo  (CurrentSymbol,           MODE_ASK);
   StochSignal   = iStochastic (CurrentSymbol,0,8,3,3,   MODE_SMA,MODE_SIGNAL,STO_CLOSECLOSE,0);
   StochMain     = iStochastic (CurrentSymbol,0,8,3,3,   MODE_SMA,MODE_MAIN,STO_CLOSECLOSE,  0);
   Macd_Signal   = iMACD       (CurrentSymbol,0,12,26,9, PRICE_CLOSE,MODE_SIGNAL,            0);
   Macd_Main     = iMACD       (CurrentSymbol,0,12,26,9, PRICE_CLOSE,MODE_MAIN,              0);
   Senkou_Span_A = iIchimoku   (CurrentSymbol,0,9,26,52, MODE_SENKOUSPANA,                   0);
   Senkou_Span_B = iIchimoku   (CurrentSymbol,0,9,26,52, MODE_SENKOUSPANB,                   0);
   Tenkan_Sen    = iIchimoku   (CurrentSymbol,0,9,26,52, MODE_TENKANSEN,                     0);
   Kijun_Sen     = iIchimoku   (CurrentSymbol,0,9,26,52, MODE_KIJUNSEN,                      0);
   RVI_Signal    = iRVI        (CurrentSymbol,0,14,      MODE_SIGNAL,                        0);
   RVI_Main      = iRVI        (CurrentSymbol,0,14,      MODE_MAIN,                          0);
   RSI_Close     = iRSI        (CurrentSymbol,0,14,      PRICE_CLOSE,                        0);
   RSI_Open      = iRSI        (CurrentSymbol,0,14,      PRICE_OPEN,                         0);
   NewLabel= 0;
   string TEXT[15];
   TEXT[0] = DoubleToStr (CurrBid,convert); 
   TEXT[1] = DoubleToStr (CurrAsk,convert);  
   TEXT[2] = DoubleToStr (StochSignal,5);  
   TEXT[3] = DoubleToStr (StochMain,5);   
   TEXT[4] = DoubleToStr (Macd_Signal,5); 
   TEXT[5] = DoubleToStr (Macd_Main,5);
   TEXT[6] = DoubleToStr (Senkou_Span_A,convert);
   TEXT[7] = DoubleToStr (Senkou_Span_B,convert);
   TEXT[8] = DoubleToStr (Tenkan_Sen,convert);
   TEXT[9] = DoubleToStr (Kijun_Sen,convert); 
   TEXT[10]= DoubleToStr (RVI_Signal,5);  
   TEXT[11]= DoubleToStr (RVI_Main,5);
   TEXT[12]= DoubleToStr (RSI_Close,5);    
   TEXT[13]= DoubleToStr (RSI_Open,5);
   TEXT[14]= CurrentSymbol;

   int Label_X[] = {0,150,0,150,0,150,0,150,0,150,0,150,0,150,0,150,0,0};
   int Ladel_Y[] = {0,0,30,30,60,60,90,90,120,120,150,150,180,180,210,210,230,230};
   for(SHIFT = 0; SHIFT< 15; SHIFT++)
     {
      GetDigits();

      NewLabel++; if(NewLabel>15) break;
      ObjectCreate(0,Label[NewLabel],OBJ_LABEL,0,0,0);
      ObjectSetText(Label[NewLabel],TEXT[SHIFT],25,"P",clrWhite);
      ObjectSetInteger(0,Label[NewLabel],OBJPROP_XDISTANCE,Label_X[SHIFT]);
      ObjectSetInteger(0,Label[NewLabel],OBJPROP_YDISTANCE,Ladel_Y[SHIFT]);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   if(sparam==Button[1]){Destroy();}         if(sparam==Button[2]){Reset();}        
   if(sparam==Button[3]){Draw_Trendline();}  if(sparam==Button[4]){SHIFT_IN=0;SHIFT_OUT=0; Zoom();}
   if(sparam==Button[5]){ Zoom();}           if(sparam==Button[6]){ChangeChart(); }  
   if(sparam==Button[7]){Exit();}            if(sparam==Button[8]){Reset();}
   if(sparam==Button[9]){ResetPanels(); }    if(sparam==Button[10]){ResetPanels();} 
   if(sparam==Button[11]){ResetPanels();}    if(sparam==Button[12]){Draw_Trendline();}
   if(sparam==Button[13]){Reset();}          if(sparam==Button[14]){Exit();}     
   if(sparam==Button[15]){ChangeChart();}    if(sparam==Button[16]){Exit();}
   if(sparam==Button[17]){Reset();}          if(sparam==Button[18]){Reset();}  
   if(sparam==Button[19]){Zoom();}           if(sparam==Button[20]){ResetPanels();}
   if(sparam==Button[21]){Draw_Trendline();} if(sparam==Button[22]){Reset();}    
   if(sparam==Button[23]){Reset();}          if(sparam==Button[24]){ChangeChart();}
   if(sparam==Button[25]){Exit();}           if(sparam==Button[26]){Reset();}  
   if(sparam==Button[27]){Reset();}          if(sparam==Button[28]){Exit();}
   if(sparam==Button[29]){ResetPanels();}    if(sparam==Button[30]){Draw_Trendline();}
   if(sparam==Button[31]){Reset();}          if(sparam==Button[32]){Reset();}
   if(sparam==Button[33]){ChangeChart();}    if(sparam==Button[34]){Exit();} 
   if(sparam==Button[35]){Reset();}          if(sparam==Button[36]){Zoom();}
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Draw_Trendline()
  {
   datetime StartDate  = TimeLocal();
   double   Ref_Price[] = {0,0,0,0,0,0,0,0,0,0};
   int      Reference[] = {0,0,0,0,0,0,0,0,0,0};
   PriceClose = CopyClose(CurrentSymbol,Period(),0,100,ClosePriceArray);
   PriceOpen  = CopyOpen (CurrentSymbol,Period(),0,100,OpenPriceArray);
   Copy       = CopyTime (CurrentSymbol,Period(),0,100,DateArray);
   ObjectCreate(Chart_ID,Trend,OBJ_TREND,Chart_ID,DateArray[99],ClosePriceArray[99],DateArray[91],ClosePriceArray[91]);
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_COLOR,clrBlue);
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_WIDTH,1);
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_BACK,false); 
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_SELECTED,false); 
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_RAY_RIGHT,true);
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_HIDDEN,false); 
   ObjectSetInteger(Chart_ID,Trend,OBJPROP_ZORDER,false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ChangeChart()
  {
   CurrentSymbol = SymbolName(Next_Symbol,true);
   chartid = ChartOpen (CurrentSymbol,0);
   ObjectDiscription();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ResetPanels() 
  {
   Close_Chart   = ChartClose(chartid);
   CurrentSymbol = SymbolName(Next_Symbol++,true);
  }
void ResetButtons(){}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GetDigits()
  {
   digits = MarketInfo (CurrentSymbol,MODE_DIGITS);
   convertDoubleStr = DoubleToString(digits,0);
   convert = StringToInteger(convertDoubleStr);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Reset()
{
ObjectBuild();
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Zoom()
  {
   if(Button[4]=="Button4") SHIFT_IN++;
   ChartSetInteger(Chart_ID,CHART_SCALE,SHIFT_IN);
   ChartSetInteger(Chart_ID,CHART_SHIFT,3);
   if(Button[5]=="Button5") SHIFT_OUT--;
   ChartSetInteger(Chart_ID,CHART_SCALE,SHIFT_OUT);
   ChartSetInteger(Chart_ID,CHART_SHIFT,3);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
void Destroy()
  {
   for(SHIFT=36; SHIFT>=6; SHIFT--){ObjectDelete(Button[SHIFT]);}
   for(int DSHIFT=9; DSHIFT>=0; DSHIFT--)ObjectDelete(Build[DSHIFT]);
   for(int FSHIFT=15; FSHIFT>=0; FSHIFT--)ObjectDelete(Label[FSHIFT]); 
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
void Exit(){ExpertRemove();}
//+------------------------------------------------------------------+
To add comments, please log in or register