ApplyStop - Incorrect type of argument(s). Expecting number here

FirstStopLevel = Param( "Stop %", 5, 1, 20, 1 );
SecondStopLevel = Param( "2nd Stop %", 2.5, 1, 10, 0.5 );
StopLevel = IIf( Combined OR Combined_S, SecondStopLevel, FirstStopLevel );
StopType = IIf( Combined OR Combined_S, stopTypeTrailing, stopTypeLoss );

ApplyStop( StopType, stopModePercent, StopLevel, True );

When applying the above I receive the following error:

Incorrect type of argument(s). Expecting number here.

I understand the message and was wondering if our community had any suggestions on how to get over this hurdle or achieve a similar objective?

@help_please, one possible cause is that in your code Combined or Combined_S variables are ARRAYS (not a NUMBER).

In such a case you should select a single value from the array (using some function like LastValue(), etc.)

If this is the cause of your problem, please review the IIF() documentation - READ IT ALL with attention, noting the following paragraph (I put in bold the array part).

When all arguments are scalars (numbers) then resulting value is also a scalar (number). When any of arguments is an array then the function returns an array.

1 Like

First argument has wrong type!
It has to be type number.
On the other hand 4th argument can be type number or type array.

You can call ApplyStop() multiple times within same code.

FirstStopLevel = Param( "Stop %", 5, 1, 20, 1 );
SecondStopLevel = Param( "2nd Stop %", 2.5, 1, 10, 0.5 );

ApplyStop( stopTypeLoss, stopModePercent, FirstStopLevel, 1);
ApplyStop( stopTypeTrailing, stopModePercent, SecondStopLevel, 1);

That makes no sense if he does backtest.

3 Likes

@fxshrat, agreed. LastValue() reference was a very bad choice example for the scenario where ApplyStop() is used.

1 Like

@beppe and @fxshrat, thank you both very much for taking the time to reply. Yes, Combined and Combined_S are ARRAYS.

I'll attempt to figure how to call ApplyStop() multiple times within same code.