Is it possible to create a hedge exit rule that evaluates for number of days or bars since hedge entry? Thanks
That's not currently possible. There are no available functions to determine when a hedge position was opened or to calculate how long it has been active.
I hate to contradict Walter, but yes, one can do this by referencing the hedge entry rule and changing the offsets. For example, let's say you want to hedge when the 15-bar SMA of the S&P 500 is below the 200-bar SMA, and you want to keep the hedge on for precisely 100 bars. So your entry rule would be SMA(15,0,$SP500) < SMA(200,0,$SP500) and your exit rule would be SMA(15,100,$SP500) < SMA(200,100,$SP500).
Yuval,
I was starting to draft something exactly like you described but couldn’t clock how. Your example helps. Thank you.
Yuval, thanks for the catch!
I like your solution and believe it will work, but I think the hedge is non-retriggerable. In other words, if a new hedge-on condition is triggered while a hedge is already active, the hedge will still release according to the original schedule from the first trigger. I believe I've identified that edge case correctly.
Yuval, thanks for the catch!
I like your solution and believe it will work, but I think the hedge is non-retriggerable. In other words, if a new hedge-on condition is triggered while a hedge is already active, the hedge will still release according to the original schedule from the first trigger. I believe I have that edge case right.
I think you can keep it from re-triggering by putting a similar rule in the entry where it checks to see if X bars ago it was NOT in hedge. Therefore if you exited due to elapsed bars but the entry factor was still True, you wouldn’t immediately re-enter.
Sorry, I don’t get how the exit rule works. Wouldn’t this one trigger at any occasion where 100-days lagged SMA15<SMA200 = true? So if the hedge checks for the exit rule in week 2 of the simulation, wouldn’t it just trigger an exit (or not) based on 100 days prior SMA’s?
Yes, that's correct, but if it's too early in the simulation for the hedge to be entered, that doesn't matter. Also, I'm not suggesting that this is a good or effective exit rule, just that it'll take effect 100 days after the entrance, which is what was asked for.
But that’s the part I don’t understand. Does the offset result in FALSE for every day except 100d from entry? So is the offest in this exit formula somehow “tied” to entry date? As I understand offset from other formulas, it just sets offset from today meaning as-of-date of the current rebalancing. How does the offset in the exit rule “communicate” with the hedge entry date? Am I missing something? If my hedge was entered 60 bars ago that shouldn’t hinder the exit rule to check SMAs 100 bars ago (offset) and trigger if the condition is met, no? Just want to understand the mechanics behind it.
Well, the hedge couldn't have been triggered 60 days ago and the condition for exit be met, since the conditions are the same. The hedge has to stay in effect for precisely 100 days. After that, it's possible that the hedge would be entered and exited again in a kind of on-off pattern if the conditions for entry persist longer than 100 days, so there's room for formula improvement for those cases.
