How do you INSERT the same AFL to different charts but use different parameters?

Hi I have 1 AFL.

I INSERTed the same AFL to multiple charts.

ISSUE: I want to use different parameters for each chart, but every time I change one, it changes in ALL the charts that I INSERTED the AFL on.

How do I configure this to have each chart independent and use the same code, but different parameters ?

Thanks

@DaFish It would be much easier to reply if you had pasted the code that you are using, but …

In general (in most cases) charts are independent. Two different charts may have same names of parameters, but parameters are independent if those charts have different ChartID.

There are some exceptions - for example if your formula uses Static variables. A quote from: https://www.amibroker.com/guide/afl/staticvarset.html

Static variable has static duration - it is allocated when the program begins and deallocated when the program ends. Static variables allow to share values between various formulas.

So if your code uses Static variables, their values are shared between all codes. If you want to make such Static variables unique, you can for example add the number of ChartID to their names:

StaticVarSet("myVariable" + GetChartID(), ExampleValue = 5);

Some other cases are described in this article:

http://www.amibroker.com/kb/2014/10/06/relationship-between-chart-panes/

You might also find these interesting:

http://www.amibroker.com/kb/2014/10/29/using-per-symbol-parameter-values-in-charts/

http://www.amibroker.com/kb/2006/10/16/how-to-save-layouts-that-hold-individual-parameter-values-for-different-symbols/

4 Likes

Hi Thanks a lot. The code is standard parameters.

I tried putting this line outside of the section, but that didn’t work.

TFType = ParamList(“TF (S, M, L)”, “STF|MTF|LTF”, 0 );

I added 3 new blank windows (different symbols with price), then inserted the indicator and when I change the parameters it changes it on every one of the windows. Not sure how to change that.

I added the top part of my code with the parameters.

MJF_FName = "MJF-ScoreNoTF";

	TFType 	= ParamList("TF (S, M, L)", "STF|MTF|LTF", 0 ); 				// Time frame - Short, Med, Long

_SECTION_BEGIN(MJF_FName);
//SetBarsRequired(200, 0);

{  	// parameters
	XBarsBack 	= Param( "XBarsBack", 4, 1, 10, 1 );							// how many bars back to look for a signal
	DSperiods 	= Param( "DSPeriods", 10, 2, 200, 1 );
	FTperiods 	= Param( "FTPeriods", 10, 2, 200, 1 );
	CCIperiods 	= Param( "CCIPeriods", 6, 2, 200, 1 );
	CCIOb 		= Param( "CCI OverBought", 100, 2, 200, 1 );
	CCIOs 		= Param( "CCI OverSold", -100, 2, 200, 1 );
	DSOb 		= Param( "DS OverBought", 85, 2, 100, 1 );						// Double Stochastic OverBought line
	DSOs 		= Param( "DS OverSold", 15, 2, 100, 1 );						// Double Stochastic OverSold line
	EMAPeriod_STF	= Param("EMA (STF)",39,1,100,1);							// EMA STF
	UseEMA 		= Param( "Use EMA",0,0,1,1);									// Do we use EMA in the Entry Signals	

	// Only trigger the buy if the previous bar is closed and the signal is on last bar AND this bar - Default Closed
	EntryBarClosed	= ParamToggle( "Entry Real Time or Closed bar", "Real|Closed",defaultval=1 ); 	

	ColourSVName = (Name() + "Colour" + TFType); 	 		
	BuySVName = (Name() + "Buy" + TFType); 	 		
	SellSVName = (Name() + "Sell" + TFType); 	 		
}

Hello Mark,

It doesn’t matter if this line is inside or outside the section.

… but the code that you have pasted is only a part (just the beginning) of the whole code. I can’t tell you what causes your problems because you didn’t write if it uses Static variables or not and you didn’t show the full code so that someone could check this.

If you drag and drop such code to blank new charts and don’t use Static variables, you shouldn’t have the problems that you describe. Because (link to the source KB article my first post):

Chart parameters are keyed by Chart ID so two different charts may have same names of parameters, yet parameters are independent if those charts have different ChartID.