Daily Premium/Discount Indicator For ThinkOrSwim

Bingy

Member
The following Indicator pairs well with a standard RSI indicator to pinpoint short and long entries on the Daily Time Frame for stocks. It's a freebie to give back to the community here. The Threshold's in relation to "DLength" can be tuned to work on lower Time Frames as well. Enjoy...


Code:
declare lower;

#DISCOUNT INDICATOR
# Define input parameters
input Dprice = close;
input Dlength = 2000;
input premiumThreshold = 2.315; # Premium threshold
input discountThreshold = 0.6861; # Discount threshold

# Calculate the moving average
def smaValue = SimpleMovingAvg(Dprice, Dlength);



# Calculate the premium and discount levels
def isPremium = Dprice > smaValue * premiumThreshold;
def isDiscount = Dprice < smaValue * discountThreshold;


# Manually draw lines
AddVerticalLine(isPremium, "Search for Short", Color.GREEN);
AddVerticalLine(isDiscount, "Search for Long", Color.RED);
 
@Bingy : Thank you for the Discount Indicator...I'm having difficulty getting the vertical lines to draw...As suggested, I paired it with a standard RSI on a daily chart:

Code:
# filename: _Discount_Indicator_
# source: https://usethinkscript.com/threads/daily-premium-discount-indicator-for-thinkorswim.16994/post-133222

declare lower;

# Define input parameters
input Dprice = close;
input Dlength = 2000;
input premiumThreshold = 2.315; # Premium threshold
input discountThreshold = 0.6861; # Discount threshold

# Calculate the moving average
def smaValue = SimpleMovingAvg(Dprice, Dlength);

# Calculate the premium and discount levels
def isPremium = Dprice > smaValue * premiumThreshold;
def isDiscount = Dprice < smaValue * discountThreshold;

# Manually draw lines
AddVerticalLine(isPremium, "Search for Short", Color.GREEN);
AddVerticalLine(isDiscount, "Search for Long", Color.RED);


### RSI2
def length2 = 14;
def averageType2 = AverageType.WILDERS;
def price2 = close;

def NetChgAvg2 = MovingAverage(averageType2, price2 - price2[1], length2);
def TotChgAvg2 = MovingAverage(averageType2, AbsValue(price2 - price2[1]), length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;

plot RSI2 = 50 * (ChgRatio2 + 1);
RSI2.SetDefaultColor(Color.CYAN);
RSI2.SetLineWeight(3);
#RSI2.hide();

With the Dlength set to 2000, nothing plots:

202310250624_test_.jpg


So I changed the Dlength to 200 and just the RSI plots:

202310250632_test_.jpg


Should I try tweaking the Threshold inputs? The Threshold values look specific so I left them alone...

Please advise...
 
@Bingy : Thank you for the Discount Indicator...I'm having difficulty getting the vertical lines to draw...As suggested, I paired it with a standard RSI on a daily chart:

Code:
# filename: _Discount_Indicator_
# source: https://usethinkscript.com/threads/daily-premium-discount-indicator-for-thinkorswim.16994/post-133222

declare lower;

# Define input parameters
input Dprice = close;
input Dlength = 2000;
input premiumThreshold = 2.315; # Premium threshold
input discountThreshold = 0.6861; # Discount threshold

# Calculate the moving average
def smaValue = SimpleMovingAvg(Dprice, Dlength);

# Calculate the premium and discount levels
def isPremium = Dprice > smaValue * premiumThreshold;
def isDiscount = Dprice < smaValue * discountThreshold;

# Manually draw lines
AddVerticalLine(isPremium, "Search for Short", Color.GREEN);
AddVerticalLine(isDiscount, "Search for Long", Color.RED);


### RSI2
def length2 = 14;
def averageType2 = AverageType.WILDERS;
def price2 = close;

def NetChgAvg2 = MovingAverage(averageType2, price2 - price2[1], length2);
def TotChgAvg2 = MovingAverage(averageType2, AbsValue(price2 - price2[1]), length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;

plot RSI2 = 50 * (ChgRatio2 + 1);
RSI2.SetDefaultColor(Color.CYAN);
RSI2.SetLineWeight(3);
#RSI2.hide();

With the Dlength set to 2000, nothing plots:

View attachment 19988

So I changed the Dlength to 200 and just the RSI plots:

View attachment 19989

Should I try tweaking the Threshold inputs? The Threshold values look specific so I left them alone...

Please advise...
No, keep the threshold as is. Go to the daily time frame. Then change the daily time frame to "Max Available" as seen in the screenshot below, for stock symbol "H".

The settings are very sensitive and stringent, but this helps it to catch potentially gigantic moves to swing or hold long term. Scroll through a bunch of stock symbols with your timeframe set up like this and you'll see what I mean.

I personally find the red "Discount" lines to be the most accurate.

Check out some of the symbols below as examples:

XBI
QQQ
UPS
WMT
WYNN
etc.
 

Attachments

  • unnamed (1).png
    unnamed (1).png
    119.2 KB · Views: 417
Last edited:
@Bingy : Thanks for your recent reply and provided examples...I'm attaching screenshots to give you an idea of what I'm looking at...Interestingly enough, no green "premium" lines showed up...

Also, WMT, UPS and QQQ had no results whatsoever...Is this to be expected with "Max Available" selected? FWIW, I think this indicator would be an excellent candidate for a scan...Something along these lines:

Code:
input length = 14;

#### RSI2 #####
def NetChgAvg = WildersAverage(close - close[1], length);
def TotChgAvg = WildersAverage(AbsValue(close - close[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI2 = 50 * (ChgRatio + 1);

# Define input parameters
input Dprice = close;
input Dlength = 2000;
input premiumThreshold = 2.315; # Premium threshold
input discountThreshold = 0.6861; # Discount threshold

# Calculate the moving average
def smaValue = SimpleMovingAvg(Dprice, Dlength);

# Calculate the premium and discount levels
def isPremium = Dprice > smaValue * premiumThreshold;
def isDiscount = Dprice < smaValue * discountThreshold;

plot scan = Dprice < smaValue * discountThreshold;

Check out AMBA, DG, AA...Unfortunately these results were not typical...The scan needs more work...

One more thing, if I may, what threshold settings would you suggest if I wanted to use an hourly timeframe instead of the daily timeframe?
 

Attachments

  • 202310251338_WYNN_test_.jpg
    202310251338_WYNN_test_.jpg
    244.1 KB · Views: 290
  • 202310251340_WMT_test_.jpg
    202310251340_WMT_test_.jpg
    235 KB · Views: 278
  • 202310251341_UPS_test_.jpg
    202310251341_UPS_test_.jpg
    229.5 KB · Views: 256
  • 202310251343_QQQ_test_.jpg
    202310251343_QQQ_test_.jpg
    235.5 KB · Views: 247
  • 202310251345_XBI_test_.jpg
    202310251345_XBI_test_.jpg
    241.1 KB · Views: 244
  • 202310251346_H_test_.jpg
    202310251346_H_test_.jpg
    231.5 KB · Views: 282
@Bingy : Thanks for your recent reply and provided examples...I'm attaching screenshots to give you an idea of what I'm looking at...Interestingly enough, no green "premium" lines showed up...

Also, WMT, UPS and QQQ had no results whatsoever...Is this to be expected with "Max Available" selected? FWIW, I think this indicator would be an excellent candidate for a scan...Something along these lines:

Code:
input length = 14;

#### RSI2 #####
def NetChgAvg = WildersAverage(close - close[1], length);
def TotChgAvg = WildersAverage(AbsValue(close - close[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI2 = 50 * (ChgRatio + 1);

# Define input parameters
input Dprice = close;
input Dlength = 2000;
input premiumThreshold = 2.315; # Premium threshold
input discountThreshold = 0.6861; # Discount threshold

# Calculate the moving average
def smaValue = SimpleMovingAvg(Dprice, Dlength);

# Calculate the premium and discount levels
def isPremium = Dprice > smaValue * premiumThreshold;
def isDiscount = Dprice < smaValue * discountThreshold;

plot scan = Dprice < smaValue * discountThreshold;

Check out AMBA, DG, AA...Unfortunately these results were not typical...The scan needs more work...

One more thing, if I may, what threshold settings would you suggest if I wanted to use an hourly timeframe instead of the daily timeframe?
With the exact and original code that I provided at the start of this thread, if you look at the few stocks I provided examples of, with the "Max Available" data for the Daily time frame, you should see a time or 2 when the green line appears. It is however, far and few between. There are many times where it doesn't appear at all in the data because it's attempting to catch huge premiums, like how the red discount line is attempting to help pin point huge discounts. This isn't something that occurs often, but when it does many will feel it warrants attention, especially on stocks that it seems to have work well with in the past. And as a side note, when you pull up the "Max Available", you should be scrolling all the way to the left to see the rest of the historical data. I'm sure you know this, but just making sure you're not missing all the data.

I suggest you try to toy with the threshold on other timeframes. It takes about 15 mins to dial it in.


I hope this helps.
 
@Bingy : Thank you for your recent reply and informative tips...I sincerely appreciate it! I have been following your instructions and I can see what you've been describing...As you suggest, I will try toying with the thresholds to see if I can pinpoint the correct values for intraday timeframes, specifically the hourly...

Good Luck and Good Trading :cool:
 
@Bingy : Thank you for your recent reply and informative tips...I sincerely appreciate it! I have been following your instructions and I can see what you've been describing...As you suggest, I will try toying with the thresholds to see if I can pinpoint the correct values for intraday timeframes, specifically the hourly...

Good Luck and Good Trading :cool:
Sounds good. If you find settings that seem killer for a lower time frame, feel free to share it with the rest of the community that will be looking at this thread.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
250 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top