Problem skipping function call in indicator

Questions about MultiCharts and user contributed studies.
sparkz
Posts: 64
Joined: 16 Mar 2007

Problem skipping function call in indicator

Postby sparkz » 14 Jul 2007

Has anyone had this problem?

I have a function which I call from an indicator which has a length as one of the parameters. My main indicator allows this to be turned off so I check for the length being zero to skip the function call eg:

if SmoothLength > 0 then
Ind2 = MySmooth(Ind, SmoothLength)
else
Ind2 = Ind;

However, this doesn't seem to work as the indicator crashes with a divide by zero error when the length is zero. The function does do a divide by the length as one of the calculations. If I comment this call out it's fine.

The way around this is to have 2 seperate functions but it's a pain to do this everytime I want optional parameters like this.

Any ideas?

Thanks

User avatar
ABC
Posts: 628
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 355 times
Contact:

Postby ABC » 15 Jul 2007

sparkz,

if I understand you correctly, the problem lies inside the function which does divide one value through the Length.

Adding:

Code: Select all

If Length <> 0 then YourParameter/Length

to function should stop the divide by zero error.

Regards,

Chris


Return to “MultiCharts”