[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help with trailing stop AFL code



PureBytes Links

Trading Reference Links

I am trying to implement trailing stop based on ATR (average true 
range) in AFL for exit signals. I beleive this is called chandelier 
exit. Basically, I would like to move the stop up based on close 
prices and ATR but never down. 

I came up with this: 

x = Close - ATR(10) * 3; 
ts = iif(x > ref(x, -1), x, Ref(x, -1)); 

However this does not work. The problem is that second statement 
continues to use raw "x" values where it should be using modified 
"ts" values based on second statment. I replaced second statement 
with following but that didn't help: 

x = iif(x > ref(x, -1), x, Ref(x, -1)); 

Any help is appreciated. 

Thanks. 
Deepinder.