SPY & VXX DMI Labels for ThinkorSwim

Xiuying

Member
Simple labels for Spy and Vxx that will Display their name on the main chart and color them either Red or Green depending on if Dmi+ > Dmi- or vice versa.

Since TOS will only run scripts each tick that the stock acquires volume(correct me if I'm wrong), I would advise to be careful when you're on a stock that is barely getting any volume or even has "ticks" where there is no volume at all. Since it'll create "unreliable" results. Haven't had any issues on the main stocks with it though that always get volume (aapl, Ba, msft,nflx, etc) .

I kept the basic ADX calculations and labels in, in case someone wanted to use them as well. You just need to delete the "#". Plots are hidden by default but left them in, if someone was curious how'd they look or if they wanted to use it for a custom study.

https://tos.mx/Uu9Kccz
Code:
#So Simple a monkey could create it Spy & Vxx DMI Labels
#Green Label = DMI+ > DMI- , Red Label = DMI- > DMI+
#Xiuying 4/28/2020

#Grab High and Lows for Spy and VXX

def SpyhiDiff = high("SPY") - high("SPY")[1];
def SpyloDiff = low("SPY")[1] - low("SPY");

def VxxhiDiff = high("VXX") - high("VXX")[1];
def VxxloDiff = low("VXX")[1] - low("VXX");

#Define +/- DM

def SpyPlusDM = if SpyhiDiff > SpyloDiff and SpyhiDiff > 0 then SpyhiDiff else 0;
def SpyMinusDM =  if SpyloDiff > SpyhiDiff and SpyloDiff > 0 then SpyloDiff else 0;

def VxxplusDM = if VxxhiDiff > VxxloDiff and VxxhiDiff > 0 then VxxhiDiff else 0;
def VxxminusDM =  if VxxloDiff > VxxhiDiff and VxxloDiff > 0 then VxxloDiff else 0;

#Define Spy/Vxx ATR
def SpyATR = MovingAverage(AverageType.Wilders, TrueRange(high("SPY"), Close("SPY"), low("SPY")), 14);

def VxxATR = MovingAverage(AverageType.Wilders, TrueRange(high("VXX"), close("VXX"), low("VXX")), 14);

#Plotting & Hiding

plot SpyDMP = 100 *  MovingAverage(AverageType.WILDERS, SpyPlusDM, 14) / SpyATR;
SpyDMP.Hide();

plot SpyDMM = 100 * MovingAverage(AverageType.WILDERS, SpyMinusDM, 14) / SpyATR;
SpyDMM.Hide();

plot VxxDMP = 100 *  MovingAverage(AverageType.WILDERS, VxxPlusDM, 14) / VxxATR;
VxxDMP.Hide();

plot VxxDMM = 100 * MovingAverage(AverageType.WILDERS, VxxMinusDM, 14) / VxxATR;
VxxDMM.Hide();


#def SpyDX = if (SpyDMP + SpyDMM > 0) then 100 * AbsValue(SpyDMP - SpyDMM) / (SpyDMP + SpyDMM) else 0;
#def SpyADX = MovingAverage(AverageType.WILDERS, SpyDX, 14);

#def VxxDX = if (VxxDMP + VxxDMM > 0) then 100 * AbsValue(VxxDMP - VxxDMM) / (VxxDMP + VxxDMM) else 0;
#def VxxADX = MovingAverage(AverageType.WILDERS, VxxDX, 14);

#labels

AddLabel(yes,"VXX", (if VXXDMP > VXXDMM then COLOR.GREEN else COLOR.RED));
#AddLabel(yes, if VxxADX > 25 then "Vxx ADX > 25" else "Vxx ADX < 25");

AddLabel(yes,"SPY", (if SPYDMP > SPYDMM then COLOR.GREEN else COLOR.RED));
#AddLabel(yes, if SpyADX > 25 then "Spy ADX > 25" else "Spy ADX < 25");

0AjGfiR.png
 
Last edited by a moderator:

DoQtorNo

Member
This is good work. When i run it, the colors are inverse when positive or negative. I also tried using the same coding template to display nasdaq, dow etc and the same, when positive, red appears and vice versa
 

alexR

Member
This is good work. When i run it, the colors are inverse when positive or negative. I also tried using the same coding template to display nasdaq, dow etc and the same, when positive, red appears and vice versa
Hi could you share labels for NQ and S&P
 

alexR

Member
@Xiuying I have a question, how come when I change the SPY for COMP in the script above it doesn't work for the COMP, the COMP label remains black? thanks
 

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.
Top