% from all time high

How would I find the percentage difference from the current price to the all time high (or at least the last 20 years)?

So if company X is currently at 50 but it was at 500 nine years ago, then the function would return 90% down, or maybe expressed as -90%.

Or…

Detecting a general downtrend in price over a long period like the one below…

Thanks
Tony


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.


A bar is a trading day. So with about 250 trading days per year, 4500 bars will take you back 18 years.

I don’t know why Andrew’s formula didn’t work. What ticker is this?

I think I got it figured out. Seems to be working now.

On another note, how do I calculate the price increase from price originally paid?

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)…

I did not consider that, but I will look into it. Thanks

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.

Did you try the “Stop Loss” tab in the simulation?

You also need “allow rebuy” set to on to prevent thrashing with daily rebalances…