The function
Highval(2000, 0,#High)
returns the highest high in the past 2000 bars. The farthest back you’re allowed is 2500 bars. But you can combine that with the offset to go farther:
Max(Highval(2000, 0,#High), Highval(2500,2000,#High))
should return the highest high of the past 4500 bars. Combine that with Price to get your desired percentage. Something like:
( Price / Max(Highval(2000, 0,#High), Highval(2500,2000,#High)) ) < .1
Thanks Pirate, that worked pretty well.
However I am still catching a few dogs like this. Any idea why it did not catch this one? Too much time passed? I am not sure what a “bar” is.
That’ll be in the transaction record. Click on the Transactions tab, then click on Realized.
If you want to use that value in a sell rule, it’s GainPct. In the Sell tab, go to the reference box on the bottom, click on Strategy, then click on Position. You’ll see a number of things you can do in sell rules, and using GainPct is one.
If I use GainPct as a sell rule, and the rebalance occurs every 52 weeks, then it will not be evaluated till the rebalance, correct?
If so, is there something similar to a stop loss, that evaluates gain?
Did you consider the function “Pctfromhi” ?
Use a daily rebalance, and preface all sell rules (except pctfromhi) with "nodays>N and " where N is your desired rebalance interval.
Optionally, you can force buys on Monday by adding a buy rule such as “weekday=2” (this gets more complex for holiday weekends)…
Thinking about how to implement PctFromHi, I don’t quite see how I can use it replace GainPct.
But I think the addition of NoDays>X with GainPct and and daily rebalance may do the trick.
This seems a little convoluted for something I would assume is a common task.
Update: doing this was a disaster because rebalancing everyday killed every good stock before it ever got off the ground.