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..
How to Skip Calculations or functions.
Re: How to Skip Calculations or functions.
ok, I solved by inserting the variable (TrueFalseSimple) inside the Function. Here is a rough example:
Signal:
Function:
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 ...
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;
Code: Select all
Input:TrFls(TrueFalseSimple);
If TrFls=True then begin
//here we have the rest of the function
end;
- ABC
- Posts: 723
- Joined: 16 Dec 2006
- Location: www.abctradinggroup.com
- Has thanked: 125 times
- Been thanked: 410 times
- Contact:
Re: How to Skip Calculations or functions.
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
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