Plotting multiple assets

Posted By: chsmac85

Plotting multiple assets - 08/02/19 16:54

I'm trying to look at how currency pairs move together. Is there an example of how to plot multiple assets on a single chart? I couldn't find plotting multiple assets in the manual. I am able to get multiple indicators for the same asset to plot by adding another plot call but I can't figure out how to adjust the code to get multiple assets plotted.

The code below plots a chart based on the drop down selected in the panel. If I change the panel dropdown, I get a different chart, which is neat but I'd like to get them all on one chart for visual comparison.

Code
function run() 
{
	set(LOGFILE);
	set(PLOTNOW);
	BarPeriod = 60*24;
	assetList("AssetsFix.csv");
	
	vars Prices = series(price());
	var RSI_plot = RSI(Prices,14);
	
	plot("Plot_RSI", RSI_plot, LINE, BLUE);
	 
}


I think I could probably get it to work if I declared each asset, stored each pair in memory and then made len(assetList) calls to print but that seems overly verbose.

The manual mentions looping through the asset list with while(asset(loop(Assets))). Would the plot call need to happen outside this loop? My guess is yes. How can I print all of these assets if I don't have them stored in memory?
Posted By: chsmac85

Re: Plotting multiple assets - 08/02/19 17:51

As expected, if I manually write out the assets, I can get them to plot on the same chart.

Code
	asset("EUR/USD");
	vars Prices1 = series(price());
	var RSI_plot1 = RSI(Prices1,14);
	
	asset("EUR/CAD");
	vars Prices2 = series(price());
	var RSI_plot2 = RSI(Prices2,14);
	plot("EUR_RSI", RSI_plot1, LINE, RED);
	plot("EUR_RSI2", RSI_plot2, LINE, BLUE);
}
Posted By: chsmac85

Re: Plotting multiple assets - 08/02/19 21:24

I was able to get the chart that I wanted created but it took 150 lines of code to plot the big 28 pairs. Seems kind of silly
Posted By: SBGuy

Re: Plotting multiple assets - 08/12/19 17:03

I had a similar desire a while back and gave up as it got too complicated to maintain.

See this thread, maybe that'll give you some ideas.

https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Main=57298&Number=473236#Post473236
Posted By: jcl

Re: Plotting multiple assets - 08/13/19 15:26

For plotting multiple assets, use the PL_ALL flag.

https://manual.zorro-project.com/plotmode.htm
Posted By: chsmac85

Re: Plotting multiple assets - 08/14/19 01:38

I tried to adapt a previous answer and jcl's response.

Code
function run() 
{
	set(LOGFILE);
	set(PLOTNOW+PL_ALL);
	BarPeriod = 60*24;
	StartDate = 2019;
	assetList("AssetsFix.csv");
	
	
	int cnt=0;
	while(asset(loop(Assets))){
		 Prices[cnt]=series(price());
		 rsi[cnt]=series(RSI(Prices[cnt]));
		 cnt++;
		 }
	 
asset(Assets[0]);
PlotWidth = 600;
PlotHeight1 = 500;
PlotHeight2 = 500;
int i;

	for(i=0;i<cnt;i++){
		 plot(strf("rsi for %s",Assets[i]),smas[cnt],0,BLUE);
		 ...plot more stuff...
		 }
	 
	 
}


This doesn't work as I get an undeclared identifier error.

Additionally, it seems that the variable would not be available inside the second loop unless I am misunderstanding the scoping.
© 2024 lite-C Forums