Long only using IFF()

Hi, I tried converting a strategy to AFL, but not sure if my assumptions are correct.

The result is that when the condition is met, the bot most only take LONG POSITIONS, and ignore any short signals.

Original code

lrs  = 1000*FUNCTIONS.LRS(close,0,LRSP)/(FUNCTIONS.SMA(close,LRSP))

if lrs > LRSL
.......Longonly (basically, ignores any SHORT signal as long as **lrs>LRSL**)

AFL version
[... buying/selling conditions....]

LRSP optimize(""""")
LRSL optimize(""""")

lrs = 1000 * LinRegSlope(Close, LRSP)/MA(Close, LRSP);

bullmode = tc1 AND bc1 AND bc2 AND bc3;
bearmode = tc1 AND sc1 AND sc2 AND sc3;

IIf (lrs > LRSL, bullmode, bearmode);

Cover = bullmode;
Short = bearmode;
Buy = Cover;
Sell = Short;

are my assumptions correct?

I must be making something wrong...on the scan I'm still getting long and short positions even when I'm forcing the values..

If you want long only, then why are you assigning the short and cover variables.

Why don't you just put Short = Cover = 0; at the end and just assign the Buy / Sell appropriately.

1 Like


Because I still want it to short , just not when the condition is met

You still have a lot of learning to do and also understand AFL.

There are many mistakes, like for eg. IIF() is a function, it returns an array and that is the one that has the values met by conditions with the True/False Part.

You've not used the return array anywhere.