How to Skip Calculations or functions.

Questions about MultiCharts and user contributed studies.
Barbo
Posts: 7
Joined: 03 Nov 2021
Has thanked: 4 times
Been thanked: 1 time

How to Skip Calculations or functions.

Postby Barbo » 03 Nov 2021

Hello, sorry if the topic is banal but I'm new to programming.
i'm running a script with a really heavy function. Since I have to analyze very long series I would like this function to be calculated only every X bars (to reduce the optimization time), but I realized that the attempt is useless.
I noticed that if I prevent access to the function like this:
if 1 = 0 then begin
(function)
end;
the optimization time remains unchanged as if the function were executed at each bar.
is there a way to skip functions calculationl if a variable turns out to be true?
I hope it makes sense..
Thanks in advance..

Barbo
Posts: 7
Joined: 03 Nov 2021
Has thanked: 4 times
Been thanked: 1 time

Re: How to Skip Calculations or functions.

Postby Barbo » 03 Nov 2021

ok, I solved by inserting the variable (TrueFalseSimple) inside the Function. Here is a rough example:

Signal:

Code: Select all

Var:TrFls(False),Count(0); If Count=10 then begin TrFls=True; count=0; OURFUNCTION(TrFls); end; TrFls=False; Count+=1;
Function:

Code: Select all

Input:TrFls(TrueFalseSimple); If TrFls=True then begin //here we have the rest of the function end;
I don't know if I'm missing something, if it's a bug or i've made mistakes but this simple solution has allowed me to save 2/3 of the time for each optimization ...

User avatar
ABC
Posts: 721
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: How to Skip Calculations or functions.

Postby ABC » 04 Nov 2021

Barbo,

this depends on the function type and is expected behavior. A function of the type series will be executed on every bar, even if your code calls the function conditionally only. Depending on the function code you might be able to change the storage type to "simple". This should not execute the function on every bar.
In general a function could be “Simple”, unless you reference previous bar’s values in it (using square brackets) – in that case it would become “Series”.

Apart from that your approach works fine for skipping at least parts of a function.

Regards,

ABC


Return to “MultiCharts”