Hi traders,

I want to structure my scripts by using functions and parameter lists for data exchange.
For example I have a function to calculate a long entry signal and another one for the short signal.
Both functions calculate own price series for the same indicators.Order management is performed in the run function.

My problem is, that I do not understand the error message.

Error 041: Inconsistent series calls / too many series
Error 041: Inconsisten series!
Bar 270: 32 – bar 271:16

“Number or order of series calls in the script are different between run cycles, due to a bug in the script. Make sure that all series calls - or function calls that internally create series, such as LowPass, ATR, etc. - have the same order in every run, and are not skipped with if statements. Make also sure that your script does not generate series in tick-based intrabar functions (TMF, tick) or in endless loops.”

Sample code:

int Detect_Long_Signal (void)
vars Close = series(priceClose());
vars myEMA9 = series(EMA(Close,9));

int Overall_Long_Signal=0;

if (<conditions>)
EMA9_Long_Signal = 1;

// plot indicators from function

// determine overall long signal

if (<set of conditions>)
Overall_Long_Signal = 1;
Overall_Long_Signal = 0;

return (Overall_Long_Signal);

Corresponding coding for
int Detect_Short_Signal (void)

Why should it be not possible to calculate the same indicator in local functions and return only the results to the run function?

Same question is for the plotting function. How can I plot different indicator courses in one chart from different functions in the right chronological order?

Must this be handled centrally from the main program and the functions would have to exchange all data sets via pointer parameter list?
For example like this?
vars Detect_Long_Signal (vars, Price, var string_name, var value, int type, int color)
for the plot values?

Any help is highly appreciated.
Thanks a lot in advance.