Cribbage
Member
I've been backtesting a strategy for a while and realized I can probably automate what I'm doing with better Think Script. I currently use a study that tells me what percentage a stock moved above it's previous day's close. I rewrote the same study for the percentage it closes below the previous day's close. If the value is greater than 10% it changes color which makes it easier for me to manually test the information when I look back. This is the part I want to automate - I want to make 5 different versions of this watchlist columns (WLCs) so I can just pull up a stock from 5 days ago and the 5 columns will tell me what I'm looking for rather than manually entering the data.
plot PerMove = round (((high - close[1]) / close [1] * 100), 2);
PerMove.assignValueColor (if PerMove>10 then color.green else color.magenta);
The thing I'm getting hung up on is how to tell the WLCs which number to use. I want the column to return its value based on which ever absolute number is greater (I think absolute is the correct math term?). In other words:
Stock A's high was 15% higher then previous day, its low was -3%, WLC would show 15%
Stock B's high was 3% higher than previous day, low was -15%, WLC would show -15%
And preferably, if the absolute value of the percent move is below 9.5 I would like the column to be blank.
I know I should be able to write this but I can't for the life of me figure it out. Any help is appreciated.
plot PerMove = round (((high - close[1]) / close [1] * 100), 2);
PerMove.assignValueColor (if PerMove>10 then color.green else color.magenta);
The thing I'm getting hung up on is how to tell the WLCs which number to use. I want the column to return its value based on which ever absolute number is greater (I think absolute is the correct math term?). In other words:
Stock A's high was 15% higher then previous day, its low was -3%, WLC would show 15%
Stock B's high was 3% higher than previous day, low was -15%, WLC would show -15%
And preferably, if the absolute value of the percent move is below 9.5 I would like the column to be blank.
I know I should be able to write this but I can't for the life of me figure it out. Any help is appreciated.
Last edited: