Any way to Save\Load Parameters Presets?

Hey guys,
Do you think there is any way to store and then load different predefined sets of Parameter values for my formula?
I want to set up my formula Parameters and then store this preset as "Set1", then change some values and store as "Set2". So that in the future by choosing between these two presets I could quickly and without mistakes switch to Set1 or Set2.

As I understand there is no built-in solution and this should be done manually via code.
What would be your suggested course of actions?

Thank you

You are right, Params are user-driven events that occur through the Parameter window.

Moreover, Parameters are also cached and saved with chart/AA settings.

But isn't it very simple to define one version variable and then use that as a marker for other variables?

This parameter can then be set in AFL code or used by a parameter field.

Preset = 1;

// Variables that vary by set, define defaults
a1 = 1;    a2 = 2;    a3 = 3;

// Then use a condition code like if() or switch()

if ( Preset == 2 ) {
    a1 = 4;    a2 = 5;    a3 = 6;
}
else if  ( Preset == 3 ) {
    a1 = 7;    a2 = 8;    a3 = 9;
}
// and so on

Few sets if-else if ok otherwise a switch() would be another way.

Preset variable can be defined as a Param or directly edited in the AFL code as your convenience suits you.

Preset = Param( "Preset #", 1, 1, 5, 1);

Thank you @travick for your advice.
We are using 2 "presets" out of 3 and frequently switch between them. Also, we still keep adding/changing different features. The formula is in active development atm.
We've introduced quite a few Params and setting up formula became a risky endeavor. As so easy to make a mistake.
It would be fantastic if I could just switch presets within the Parameters window but I do realize it's easier said than done.

I suspect that in our case it will be even more difficult to implement your approach (as have to maintain even more code with every update).

I've been thinking if there is an easy way to write all params to a text file to read them later.
But seems that this will bring heaps of maintenance as well.
Thank you nevertheless.

You could share a specific scenario in your case but you then need to see the frequency among others things.

Read/writing to files may not be the most efficient, AFAIK, the fastest way would be when the values are embedded in the code itself.

If you are talking about parameters that are being computed on the fly, then that's another case but using Param* wouldn't be appropriate if you need them to also appear in the Parameter Window.

Edit: Also, I don't think its a good idea to use the model code I posted but replace the normal variables as Param fields. Its a nested structure but i'm sure TJ would object to that implementation.

I get what you are hinting at from the first post, but there isn't a feature yet where you can have a parent parameter and load a group of sub-parameters in the window based on that.

1 Like

In our case parameters are just a way for a user to configure formula before the trade starts. It's done once and we don't touch anything after that.
The main discomfort appears when we have to switch from "Set1" to "Set2" or "Set3".
Or when there is an update to a formula file issued, then values are set to "default" and we set up all values by hand.

Example:
Set1: WMAs 5\15, take profit 40, stoploss 30
Set2: WMAs 10\30, take profit 50, stoploss 40
Set3: WMAs 10\50. rake profit 60, stoploss 50

While in reality, we have over 40 parameters and around 10 of those have to be changed amongst these 3 sets.

Yes, you can store to separate file easily

Answer is #include file!

/// THIS is supposed to be an INCLUDE FILE with sample name "_ParamSet.afl"
/// File has to be put to "...\Formulas\Include" (for example)
/// Read more about include files here
/// @link https://www.amibroker.com/guide/afl/_include.html

// Set param set per row
matstr	=	"{{10,3,3}," +	// Set1
			"{15,4,3}," +	// Set2
			"{20,5,5}}";	// Set3
		
mat	= MxFromString(matstr);

This is main AFL calling include file

Version( 6.10 ); // AmiBroker 6.10 or higher required!

#include <_ParamSet.afl>

set = 1; // set1, set3 or set3

row = Max(0, Min(MxGetSize(mat,0), set)-1);

param1 = mat[row][0];
param2 = mat[row][1];
param3 = mat[row][2];

indicator = StochD(param1, param2, param3);

Plot( indicator, "Stoch from Set", colorRed );
2 Likes

Thank you @fxshrat
Let me try this out