Changing Param in Backtest

I can see how to change parameters (param) in a chart, and also in the "old" backtester, but I cannot see how to change them in the current backtester. Is the only way to use optimize? I don't want to optimize, just change parameters manually between each backtest.


You should not use Param functions in analysis and especially should not use it for backtesting.

Originally Param functions were made for charts only.

In analysis char tID is always zero (and for all analysis windows). So it leads to problems if you do not take care.

Instead for backtesting (and analysis in general) best solution is to use hardcoded values.


So, really no way to use Param and Optimize inputs at the same time it looks like? Has to be one or the other?

This is not very user friendly. Doesn't it make sense to have Parameters and Optimize be in the same spot, where you can toggle between each in the UI without having to go to code?

I am a programmer and it makes me no difference, but my clients are not and they are complaining.....

1 Like

@fxshrat prefers not to use Param statements in Analysis, but that's his personal preference, not a limitation of AmiBroker. I use Param* functions for my clients all the time, for exactly the reason you stated. You can simply use a construct like this:

myValueDefault = Param("My Value", 3, 1, 5, 1);
myValue = Optimize("My Value",  myValueDefault, 1, 5, 1);


It's got nothing to do with personal preferences! This wrong statement alone shows that you do not fully understand how param functions operate at all.

It has got to do with feature design and pitfalls. And params were designed for charts. Historical fact since mentioned by designer himself.

Have you actually understood what has been written? Obviously not.

Param functions are dependent on ChartID and in analysis ChartID is always zero for all analysis windows. Since all analysis have ChartID value zero it may lead to problems (even more so for beginners or technology illiterates) as parameters are shared. If you change param in one window it will effect param of any other analysis window. So they influence each other.

Summary about the main pitfalls of Param.. functions in analysis window (for which they were not designed for):

  • If params of Param.. functions have same parameter name then changing one param in one analysis window will set param with same parameter name of any other analysis window to same set value
  • If params of Param... functions have different parameter name then changing one param in one analysis window will reset any param of any other analysis window back to default value.
  • Set params of Param... functions are not saved to project files.
  • (And of course params are reset to default value if closing and reopen an analysis window. Well, that one is expected.)

Yeah, ... simply... not understood a single thing of what has been said. (And BTW, you can simply do anything simple but the question is about negative effects being forgotten and put aside).

Clients wasting money on incompetent vendors (still being amateurs themselves) who don't even tell those poor clients about possible consequences that may occur in return (and wasted time in the end because of wrong applied features). Don't waste money on people who do not fully understand AmiBroker functionalities, implementations and proper programming.

And FYI, Tomasz himself has told about param functions design several times in the past.

  1. Tomasz quote:

Currently the best solution is using Parameters for CHARTS ONLY,
and NOT using them for Analysis. Parameters in fact were designed as chart-only tool to begin with,
and quite frankly adding them to Analysis window was a mistake.

  1. Tomasz quote (still about params in analysis)

BTW, if you want to use params for analysis via saver way then read here


@fxshrat: Thanks for your insights on this topic. Now that @vjsworld has plenty of input on the pros and cons of various approaches, I'm confident that he can choose the method that's most appropriate for his own development.

1 Like

@vjsworld perhaps there is a role here for your clients to use a function that combines Param and Optimize,

function ParamOptimize( pname, defaultval, minv, maxv, step )
	return Optimize( pname, 
	Param( pname, defaultval, minv, maxv, step ),
	minv, maxv, step );

From @Tomasz (scroll to bottom)

I am not sure how this fits in with all of the information that @fxshrat has just posted.



You ask how that fits in with upper information?

Since you still don't seem to understand (how about testing yourself?)... It suffers from same effects in analysis windows. It does not matter where you place params in your code. I mean why are you guys not able to test upper mentioned main pitfalls yourself?

Once again all Params between more than one analysis windows interfere with each other because all analysis windows have same chart id (0). Params were designed for charts originally. It is that simple.

Just keep following in mind:
Param functions are dependent on chartid. And analysis is not equal to chart.

Now... as for your link and Tomasz's function posted in comments section... Have you looked at the year it was posted? 2006! Right? Now it is year 2018 and we have AB of 2/3 bigger size.

Do you know about the state of AmiBroker back then in 2006? No? I tell you. Back then AmiBroker still had just one single analysis window(So one single chartid value=zero occurrence instead of multiple ones now) and no analysis projects feature.

And the quotes of Tomasz I was posting above are from many years later (2012) after AmiBroker already had implemented multithreaded new analysis with ability to open multi analysis windows side by side. Big difference to 2006. Right? (New analysis was introduced in 2011/2012, BTW.)

AmiBroker evolves and does not stand still. You have to know the history, features purposes and must be aware of pitfalls of this and that instead of just talking about "simply do this and that...".

BTW I am finding quite it hilarious that there are "vendors" here asking others on how to solve code issues (to do his/her job?).



Your posts are very educational, and much appreciated. I am on my third week of learning Amibroker. I have programmed on Tradestation, Trading Technologies, Bloomberg, and Reuters for the past twenty years. Yes, without the history that you have, there is no way to know these things. So I am reading as much as possible, asking questions, and mad experimenting. I am just trying my best to learn this new platform as fast as possible. I am not a vendor. I do not sell systems. I have a client that wants me to learn this platform, so here I am.

Once again, thank you to all who has helped me.


The big problem with using Param functions in an analysis window is they are tied to the Chart ID and all analysis windows have a chart ID of 0.

But each analysis window can hold separate "Apply to" filters and date ranges.

Perhaps as a future improvement the Param functions in analysis windows can be tied to the same ID that keeps the filter and date ranges unique instead of the chart IDs.

There is whole lot of misunderstanding presented in this thread.

One definitely CAN use Parameters in the Analysis.

Parameters in Analysis window are separate and independent from any chart.

One should only remember that if you run two or more Analyses then they would share parameters (possibly interfere) because, as it was said, Parameters are per-chartID and Analysis chartID is equal to zero, so you need to press "Reset All" in parameters when switching between different Analysis projects using different sets of Parameters. Another solution is to use unique naming convention for different Analysis projects, so parameters from different projects do not interfere due to name clash.


This is my take on this particular "feature".

While it may not have been intended this way by @Tomasz, I use the fact that the same AFL in two different Analysis windows will share the parameters.

I do this by optimizing in one window and then back-testing in the other window. I mainly do this when I run Smart Optimizers (CMAE) with multiple parameters, which takes time, so losing the optimization results is not desirable (and copy-pasting the optimization results into an Excel sheet is inconvenient).

You might want to use auto-optimization feature to store and include optimized values automatically.
This is available since AmiBroker 6.25

AFL: SetOption("OptimizeSaveParams", True ); - turns on generation of AFL file that contains values of optimization parameters producing best result. The generated file has the same name as formula run but has extension

This functionality is provided to simplify creation of auto-optimization schemes

How to use:

  1. Create your main formula, say it's file name is "Formulas/Custom/"
  2. Create your opt param formula: "Formulas/Custom/"
    In the opt param formula type:
// This file will be automatically overwritten by optimizer with best values
first_param = 6;
second_param = 12;
  1. In the main formula type:
#include "Formulas/Custom/"

x = Optimize("first_param", first_param, 3, 10, 1 );
y = Optimize("second_param", second_param, 11, 30, 1 );

// causes automatic generation of
SetOption("OptimizeSaveParams", 1 );

// dummy system using two params
Buy = Cross( C, MA( C, x ) );
Sell = Cross( MA( C, y ), C );
  1. Run optimization

After it is complete will be overwritten with optimum values



This is a cool feature and I will most definitely make use of this, however, this is not exactly what I meant in the previous post.

Using more than two features will not generate the 3D Optimization Chart, which I heavily use to determine stable parameter ranges, rather than just the top candidate. Therefore, as I am using multiple parameters during a smart optimization, I usually save the optimization results to look for stable parameter ranges. Thus, just saving the top result will not work for me in this specific use case.