Change Chart Symbol Script

MPTM's new home
Post Reply
User avatar
basch312
Trader
Posts: 72
Joined: Mon Aug 19, 2013 10:53 pm
Location: Barcelona

Change Chart Symbol Script

Post by basch312 »

Hi again!

I'm trying to code a sript to change the current pairfor another.

I've found the way to change the chart where the script is running, but I can't get it running when I try to change the symbol in all the charts from one chart.

This is the code (revised):

Code: Select all

//+------------------------------------------------------------------+
//|                                              changeSymbolAll.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property show_inputs

extern string 	symbolToChange 		= "AUDCAD";
extern bool		changeAllWindows 	= false;
                   
int start()
{      
	long currChart,prevChart=ChartFirst();
	int i=0,limit=10;
	if(changeAllWindows)
	{
		//Print("ChartFirst =",ChartSymbol(prevChart)," ID =",prevChart);
		ChartSetSymbolPeriod(prevChart, symbolToChange, 0);
		while(i<limit)// We have certainly not more than 100 open charts
		{
			currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID
			if(currChart<0) break;          // Have reached the end of the chart list
			int period = ChartPeriod(currChart);
			//Print(i,ChartSymbol(currChart)," ID =",currChart);
			ChartSetSymbolPeriod(currChart, symbolToChange, period);
			prevChart=currChart;// let's save the current chart ID for the ChartNext()
			i++;// Do not forget to increase the counter
		}
		return(0);
	}
	else {ChartSetSymbolPeriod(prevChart, symbolToChange, 0);return(0);}
	
	return(0);
}
any help will be appreciated!

Regards!!

Adrian.
You do not have the required permissions to view the files attached to this post.
Last edited by basch312 on Mon May 19, 2014 3:00 pm, edited 2 times in total.
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Change Chart Symbol Script

Post by milanese »

Hi Adraian,

maybe the attached script code is a help for you..
ShowSymbol_EU_UC-M5_M15.mq4
Cheers :)

Tommaso
You do not have the required permissions to view the files attached to this post.
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
User avatar
basch312
Trader
Posts: 72
Joined: Mon Aug 19, 2013 10:53 pm
Location: Barcelona

Change Chart Symbol Script

Post by basch312 »

milanese » Sun May 18, 2014 11:08 pm wrote:Hi Adraian,

maybe the attached script code is a help for you..

Cheers :)

Tommaso

mmm... it is not exactly what I was searching for, but it is interesting.

You'll see, I'm doing a lot of profiles and I've realized that if I make just one profile it's enough as long as I could change the charts symbol instead of closing all, opening the charts and loading the templates.

Do you understand what I'm telling? I'm very bad explaining my ideas :smile:

I'm not sure if I can take advantage of your script, I'm not used to work with user32 functions so maybe I'm losing something.

Regards!!

Adrian
arts
Trader
Posts: 10
Joined: Thu Nov 17, 2011 2:09 pm

Change Chart Symbol Script

Post by arts »

Adrian,

You should be able to do what you want using the ChartSetSymbolPeriod() function within MQL. Look it up in MetaEditor. You can get the chart IDs for each chart using ChartFirst() and ChartNext().

John
User avatar
basch312
Trader
Posts: 72
Joined: Mon Aug 19, 2013 10:53 pm
Location: Barcelona

Change Chart Symbol Script

Post by basch312 »

arts » Mon May 19, 2014 11:29 am wrote:Adrian,

You should be able to do what you want using the ChartSetSymbolPeriod() function within MQL. Look it up in MetaEditor. You can get the chart IDs for each chart using ChartFirst() and ChartNext().

John

Wow, thank you!!

I've uploaded in the first post the script.
arts
Trader
Posts: 10
Joined: Thu Nov 17, 2011 2:09 pm

Change Chart Symbol Script

Post by arts »

You're welcome.

In fact there is a huge amount of new functionality added to Empty4 by the recent Builds which I suspect most people aren't even aware of. The rollout hasn't been handled particularly well at all and I generally share Steve's misgivings about Empty4, but I do think there are some major improvements in MQL now. I'd better stop though, before our esteemed leader shows me a straight red card for such talk!
User avatar
basch312
Trader
Posts: 72
Joined: Mon Aug 19, 2013 10:53 pm
Location: Barcelona

Change Chart Symbol Script

Post by basch312 »

arts » Mon May 19, 2014 7:41 pm wrote:You're welcome.

In fact there is a huge amount of new functionality added to Empty4 by the recent Builds which I suspect most people aren't even aware of. The rollout hasn't been handled particularly well at all and I generally share Steve's misgivings about Empty4, but I do think there are some major improvements in MQL now. I'd better stop though, before our esteemed leader shows me a straight red card for such talk!
I totally agree with you. It's not the first time I try to reinvent some function that is already created :smile:

Anyway, thank you again for the info!

Regards!

Adrian
User avatar
basch312
Trader
Posts: 72
Joined: Mon Aug 19, 2013 10:53 pm
Location: Barcelona

Change Chart Symbol Script

Post by basch312 »

arts » Mon May 19, 2014 7:41 pm wrote:You're welcome.

In fact there is a huge amount of new functionality added to Empty4 by the recent Builds which I suspect most people aren't even aware of. The rollout hasn't been handled particularly well at all and I generally share Steve's misgivings about Empty4, but I do think there are some major improvements in MQL now. I'd better stop though, before our esteemed leader shows me a straight red card for such talk!
I totally agree with you. It's not the first time I try to reinvent some function that is already created :smile:

Anyway, thank you again for the info!

Regards!

Adrian
Post Reply

Return to “Utilities Indicators and Scripts”