Because on the second (re)-init() you (re) create and thus overwrite the initial value of the variable
thisChartID
Try to declare the variables outside of oninit()
long thisChartID = ChartID(); long chartID = ChartFirst(); int OnInit() { //-------------------------------- int i=0,limit=100; while(i<limit) { if (chartID == thisChartID) // currently open chart {} else ChartClose(chartID); chartID = ChartNext(chartID); if ( chartID < 0) break; i++; } //------------------------------- ChartOpen(Asset1,PERIOD_M30); ChartOpen(Asset2,PERIOD_M30); ChartOpen(Asset3,PERIOD_M30); ChartOpen(Asset4,PERIOD_M30); ChartOpen(Asset5,PERIOD_M30); ChartOpen(Asset6,PERIOD_M30); ChartOpen(Asset7,PERIOD_M30); ChartOpen(Asset8,PERIOD_M30); ChartOpen(Asset9,PERIOD_M30); ChartOpen(Asset10,PERIOD_M30); }
Even if you move in two different variables globally, the result does not change. Every time I click on a button to change graph I leave the current graph
Of course.
Because you coded it like that.
int i=0,limit=100; while(i<limit) { if (chartID == thisChartID) // currently open chart {} else ChartClose(chartID); chartID = ChartNext(chartID); if ( chartID < 0) break; i++; }I dont see any buttons so i have no idea.
void Bottom (string nome, string text, int XSIZE, int YSIZE, int XDISTANCE, int YDISTANCE, color colore ){ ObjectCreate (0,nome,OBJ_BUTTON,0,0,0); ObjectSetInteger(0,nome,OBJPROP_COLOR, White); ObjectSetString (0,nome,OBJPROP_TEXT,0,text); ObjectSetInteger(0,nome,OBJPROP_BGCOLOR, colore); ObjectSetInteger(0,nome,OBJPROP_XDISTANCE,XDISTANCE); ObjectSetInteger(0,nome,OBJPROP_BORDER_COLOR,LightSeaGreen); ObjectSetInteger(0,nome,OBJPROP_YDISTANCE,YDISTANCE); ObjectSetInteger(0,nome,OBJPROP_BORDER_TYPE,BORDER_FLAT); ObjectSetInteger(0,nome,OBJPROP_XSIZE,XSIZE); ObjectSetInteger(0,nome,OBJPROP_HIDDEN,true); ObjectSetInteger(0,nome,OBJPROP_YSIZE,YSIZE); ObjectSetInteger(0,nome,OBJPROP_STATE,false); ObjectSetInteger(0,nome,OBJPROP_FONTSIZE,15); ObjectSetInteger(0,nome,OBJPROP_STATE,false); } void Pannel(){ Bottom("A1" ,Asset1,90,22,250,25 ,Black); Bottom("A2" ,Asset2,90,22,350,25 ,Black); Bottom("A3" ,Asset3,90,22,450,25 ,Black); Bottom("A4" ,Asset4,90,22,550,25 ,Black); Bottom("A5" ,Asset5,90,22,650,25 ,Black); Bottom("A6" ,Asset6,90,22,750,25 ,Black); Bottom("A7" ,Asset7,90,22,850,25 ,Black); Bottom("A8" ,Asset8,90,22,950,25 ,Black); Bottom("A9" ,Asset9,90,22,1050,25 ,Black); Bottom("A10",Asset10,90,22,1150,25,Black); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_OBJECT_CLICK) { if(sparam=="A1") { ChartSetSymbolPeriod(0,Asset1,30); ObjectSetInteger(0,"A1",OBJPROP_STATE,false); } if(sparam=="A2") { ChartSetSymbolPeriod(0,Asset2,30); ObjectSetInteger(0,"A2",OBJPROP_STATE,false); } if(sparam=="A3") { ChartSetSymbolPeriod(0,Asset3,30); ObjectSetInteger(0,"A3",OBJPROP_STATE,false); } if(sparam=="A4") { ChartSetSymbolPeriod(0,Asset4,30); ObjectSetInteger(0,"A4",OBJPROP_STATE,false); } if(sparam=="A5") { ChartSetSymbolPeriod(0,Asset5,30); ObjectSetInteger(0,"A5",OBJPROP_STATE,false); } if(sparam=="A6") { ChartSetSymbolPeriod(0,Asset6,30); ObjectSetInteger(0,"A6",OBJPROP_STATE,false); } if(sparam=="A7") { ChartSetSymbolPeriod(0,Asset7,30); ObjectSetInteger(0,"A7",OBJPROP_STATE,false); } if(sparam=="A8") { ChartSetSymbolPeriod(0,Asset8,30); ObjectSetInteger(0,"A8",OBJPROP_STATE,false); } if(sparam=="A9") { ChartSetSymbolPeriod(0,Asset9,30); ObjectSetInteger(0,"A9",OBJPROP_STATE,false); } if(sparam=="A10") { ChartSetSymbolPeriod(0,Asset10,30); ObjectSetInteger(0,"A10",OBJPROP_STATE,false); } } }
I have a small problem with the addition of 10 charts in my indicator. In OnInit () I added this code to add 10 assets but first delete those open except the first one.
Created
buttons work but if I click to change assets, the 10 assets are deleted
then added but then back to the second graph and not the first one.
I hope I did not get confused in the explanation
I'm not sure if what you're trying to convey is being lost in translation, but the description of your desired outcome is unclear.
By the way, here is a cleaner loop for iterating chart windows.
for(long id=ChartFirst();id>=0;id=ChartNext(id)) if(id != ChartID()) ChartClose(id);
I'm not sure if what you're trying to convey is being lost in translation...
I believe he is only looking for a way how to return the focus back to the starting chart window.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a small problem with the addition of 10 charts in my indicator. In OnInit () I added this code to add 10 assets but first delete those open except the first one.
Created buttons work but if I click to change assets, the 10 assets are deleted then added but then back to the second graph and not the first one.
I hope I did not get confused in the explanation