switch symbol to another on current chart - page 2

 
whroeder1:

If OP can't open more than one/two charts, and my 7 year old laptop can open 30, there's a problem. Instead of OP kludging he needs to find the real problem.

OP could be running a processor intensive pattern reco algo on the indi thread and has saved it to the default template. If that's the case then the problem is MT and op would need to open less charts. Who are we to automatically assume OP has a "real problem". That's like if you went to the doctor for a laceration and instead of examining your wound - he writes you a prescription for Viagra and slams the door on his way out.
 
Guys, please stay on topic. Thanks.
 
input string         Button_Symbol_01                             = "EURUSD" ;

//+------------------------------------------------------------------+
//+- Roll 1 Button Symbol 01 ----------------------------------------+
   if (id == CHARTEVENT_OBJECT_CLICK)
   {
   if (sparam == "SymbolButton01")
   {
//+---
   ChartSetSymbolPeriod(0, ObjectGetString(0, Button_Symbol_01, OBJPROP_TEXT), _Period);
//+---
   }
   ObjectSetInteger(0, "SymbolButton01", OBJPROP_STATE, false);
   }


You put the variable name in quotes. So the code will treat the variable as a string instead of a variable that holds a string value. Your code will look for a symbol named "Button_Symbol_01". The correct way to change the symbol is with either of the two lines of code below.

ChartSetSymbolPeriod(0, ObjectGetString(0, Button_Symbol_01, OBJPROP_TEXT), _Period); //You will want to use this since you are taking input that can be changed by the end user.


ChartSetSymbolPeriod(0, ObjectGetString(0, "EURUSD", OBJPROP_TEXT), _Period); //You will want to use this if the symbol you want to switch to is constant.



The line of code below is all that is needed to change a symbol of the current chart. Just change the second parameter to a string value of which pair you want to switch to.

ChartSetSymbolPeriod(0,"HK50",PERIOD_CURRENT);