@Almighty1 Not within TOS.
I have a question on this one, I added this and I noticed for a few securities, it is showing NaN currently as seen below...52-week high/low is the highest and lowest price at which a stock has traded during the previous year. It is a technical indicator used by some traders and investors who view the 52-week high or low as an important factor in determining a stock's current value and predicting future price movement.
"Paris: Here's a watchlist you can use for percentage off 52 week high. For 52 week low, you can modify this."
Code:# Percentage Off 52 Week High Watchlist # Nick Name NAG® # 11.02.2015 # This assumes a daily aggregation. You will need to use # daily or higher, adjust the 252 length as needed. Round((close / Highest(high, 252) - 1) * 100)
Would it be possible instead of using the indicator as we know the 52 week low and 52 week high numbers, to just have a % treating 0 as the 52 week low and 100% as the 52 week high? So basically if the 52 week low was $1.00 and 52 week high was $100.00, and the current price was $49.00, it would show 49%?@Almighty1 Not within TOS.
here's what you requested, its going to show as the numerical percentage from 0-100 value rather than a histogram.Would it be possible instead of using the indicator as we know the 52 week low and 52 week high numbers, to just have a % treating 0 as the 52 week low and 100% as the 52 week high? So basically if the 52 week low was $1.00 and 52 week high was $100.00, and the current price was $49.00, it would show 49%?
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 12) ;
def YearLow = Lowest(priceLow, 12) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
plot scan = percent;
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 12) ;
def YearLow = Lowest(priceLow, 12) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
AddLabel(yes, Concat("52wk% = ", percent), color.orange);
Ben, thank you for the code. I checked and the % in the display box seems to be incorrect, compared to the 52w H/L.@PATrader Here you go
Code:def priceHigh = high; def pricelow = low; def YearHigh = Highest(priceHigh, 12) ; def YearLow = Lowest(priceLow, 12) ; def range = Yearhigh-Yearlow; def closing_value = close - Yearlow; def percent = (closing_value/range)*100; AddLabel(yes, Concat("52wk% = ", percent), color.orange);
here's what you requested, its going to show as the numerical percentage from 0-100 value rather than a histogram.
Be sure to set the scan aggregation to MONTH
(instead of 52 week high, i used 12 month high to account better for leap years)
Code:def priceHigh = high; def pricelow = low; def YearHigh = Highest(priceHigh, 12) ; def YearLow = Lowest(priceLow, 12) ; def range = Yearhigh-Yearlow; def closing_value = close - Yearlow; def percent = (closing_value/range)*100; plot scan = percent;
you requested:Many thanks, just tried it with scan aggregation to Month and compared to the script in the OP of this thread using AAPL as a example for today which has the following data:
52 week low $53.1525
52 week high $145.09
Last $130.84
OP script shows -9.82% which would be $130.84
The script above shows 84.5% which would be $122.60105 as it should be 90.18%
Interesting. Is there a way to actually do it without the timeframe part since the lows and highs for 52 weeks are already defined so for example,you requested:
"to just have a % treating 0 as the 52 week low and 100% as the 52 week high"
thats what that script does in post #70 of this thread that i posted.
the OP (post in post #1) is completely different and is the % away from the 252 day high.
Also keep in mind there is a difference from 252 days and 12 months in your calculations.
youre requesting the same thing jus with a different example, the code for that is listed above.Interesting. Is there a way to actually do it without the timeframe part since the lows and highs for 52 weeks are already defined so for example,
if the 52 week low is $50 and 52 week high is $150. So if the current price was $125, then it would be 75%, $110 would be 60%, $100 would be 50%, $90 would be 40%.
Did it manually and you are right, the range is basically $91.9375 with YearHigh being 145.09 and YearLow being 53.125 so using that, if the closing was $130.84, which means it moved up $77.6875 from the YearLow so $77.6875/$91.9375=84.5%. Just need to understand how the different scan aggregation works even though one can probably tell that 252 means days in a year and 12 means months in a year.youre requesting the same thing jus with a different example, the code for that is listed above.
you stated:Did it manually and you are right, the range is basically $91.9375 with YearHigh being 145.09 and YearLow being 53.125 so using that, if the closing was $130.84, which means it moved up $77.6875 from the YearLow so $77.6875/$91.9375=84.5%. Just need to understand how the different scan aggregation works even though one can probably tell that 252 means days in a year and 12 means months in a year.
What I actually meant was I am still new to ThinkorSwim, only used it briefly over 3 months and trying to understand thinkscript which is why I said 252 basically requires a day aggregation while 12 is months, I am sure the aggregation will be set to week if the 12 was changed to 52 since like you said, it's how it's broken down and ofcourse with what I wanted, the results are based on two other variables while for the OP, it's based just on one variable.you stated:
"Just need to understand how the different scan aggregation works"
its just the basics of distance, rate, and ratio over time
simpler example:
you can drive one kilometer in 2 mins or drive 0.621371 miles in 2 mins.. end result of making it to 1 kilometer in 2 mins is the same because one kilomter is 0.621371 miles. how you decide to mathematically break down the distance traveled per minute inbetween is up to you and the possible varying different statistics in the smaller increments of the drive (which can possibly be more complicated).
#52 Week high has happened within past XYZ Days (bars);
#Default setting is 52 Week high has happened within past 60 Days
# By XeoNoX via usethinkscript.com
#Set Scan Aggregation to Day
declare lower;
input DaysWithin = 60;
#252 days represent one trading year
def YearHigh = Highest(high, 252);
def RecentHigh = Highest(high, DaysWithin);
plot scan = RecentHigh == YearHigh;
@rad14733, I tried adding this to ToS scanner as a custom study and it says "At least one plot should be defined" and wont let me save it. What am I missing?@lowtrade This should get you there, or close...
Ruby:#52 weeks in days, or 1 trading year def high252 = Highest(close, 252); def result = close crosses above high252 within 60 bars and close < high252 / 2;
@rad14733, I tried adding this to ToS scanner as a custom study and it says "At least one plot should be defined" and wont let me save it. What am I missing?
#52 weeks in days, or 1 trading year
def high252 = Highest(close, 252);
plot result = close crosses above high252 within 60 bars and close < high252 / 2;
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
New Intraday Highs and Lows For ThinkOrSwim | Indicators | 0 |
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.