only calc on first pass of optimization

Questions about MultiCharts and user contributed studies.
ecarlino
Posts: 17
Joined: 02 Feb 2012
Has thanked: 3 times
Been thanked: 1 time

only calc on first pass of optimization

Postby ecarlino » 29 Jul 2015

i have certain values whose calculations are complex but do not change during each pass of the optimization (in other words, i'm optimizing for other values, not these).

is there a way to not have to recalc those blocks of code on each pass of a backtest?

three ideas i had were:
1. put that code in an indicator, write the values to a file and somehow put that data (from the file) into a data stream and treat it like another price series (so the bars line up)

2. i have (but rarely use) the C# version of MC - could i pull that file into an array and make available to the parts of the code that are being optimized?

3. it would be ideal if MC could add a new "code block" similar to "once" but had the effect that it would run the code inside of that block on every bar in the chart but only on the first pass of an optimization - then those values would remain static (on a per bar basis) and available to the rest of the code as the backtest runs thousands of times.

anyone have any ideas?

ecarlino
Posts: 17
Joined: 02 Feb 2012
Has thanked: 3 times
Been thanked: 1 time

Re: only calc on first pass of optimization

Postby ecarlino » 30 Jul 2015

Barstatus 0 is prior to first tic of bar

But during a backtest that is run 10,000 times, won't it be recalcd every time?
I'm trying to find a method that only runs once, not 10,000 times

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: only calc on first pass of optimization

Postby TJ » 30 Jul 2015

Barstatus 0 is prior to first tic of bar
::
Where did you get this idea?

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: only calc on first pass of optimization

Postby TJ » 30 Jul 2015

You can add a counter...

Code: Select all


var:
counter(0);

if counter = 0 then
begin

counter = 1;
// put your code here

end;

ecarlino
Posts: 17
Joined: 02 Feb 2012
Has thanked: 3 times
Been thanked: 1 time

Re: only calc on first pass of optimization

Postby ecarlino » 31 Jul 2015

Barstatus 0 is prior to first tic of bar
::
Where did you get this idea?

to be more precise:

Barstatus of 0 = the opening tick of a bar

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: only calc on first pass of optimization

Postby JoshM » 02 Aug 2015

it would be ideal if MC could add a new "code block" similar to "once" but had the effect that it would run the code inside of that block on every bar in the chart but only on the first pass of an optimization - then those values would remain static (on a per bar basis) and available to the rest of the code as the backtest runs thousands of times.
I don't think this is possible since each optimization run acts like a separate signal (that just has different inputs). Perhaps you can put the calculated values in a global variable, but since optimisation is multi-threaded you'd still would have to calculate the code more than once.

So your best bet would probably to load these values from a file at the beginning of each optimization run. Such a thing could be done by ELCollection or ADE, but I'm not sure how much you'd gain with this -- reading the data from the file can take more time than calculating the values once at the beginning of every calculation (depending on your computer hardware and code complexity, of course).


Return to “MultiCharts”