U.S. Dollar Index (DXY) lower label

sm0414423

New member
how can i code a U.S. Dollar Index (DXY) lower label that changes color accordingly to dxy while I lookup different stocks
 
Last edited by a moderator:
Solution
Try it with GVZ:CGI and $DXY. But, their market hours are different than /GC, resulting in NaN values when applied to /CG's chart, and therefore further messing up the averages from the looks of it. The two indices print on different price scales too, so, as it stands now, it's going to be all separated and scrunched. This is going to be a real mess one way or the other. You should probably take a look at it before I get any deeper into it.
@sm0414423
I stand corrected. TDA didn't show it as an index available but the ticker does work on the charts.
No one will be able to help you further w/ scripting unless you provide the logic for what you want to trigger the label color changes.
 
trading /GC futures, it would be beneficial to know where GVZ and DXY levels were when placing or exiting a trade. Here is where I am starting, although, I do not see the lines plotted on my lower chart. Can you help point me in the right direction?

Code:
input showGVZ = yes;
input showDXY = yes;

def gvz = if showGVZ then close("GVZ") else Double.NaN;
def dxy = if showDXY then close("DXY") else Double.NaN;

def gvzMA = Average(gvz, 10);
def dxyMA = Average(dxy, 10);

plot GoldVol = gvz;
GoldVol.SetDefaultColor(Color.WHITE);
GoldVol.SetLineWeight(2);

plot Dollar = dxy;
Dollar.SetDefaultColor(Color.GREEN);
Dollar.SetLineWeight(2);

def gvzFalling = gvz < gvzMA;
def dxyFalling = dxy < dxyMA;

AddCloud(if gvzFalling and dxyFalling then gvz else Double.NaN, gvzMA, Color.DARK_GREEN, Color.BLACK);
AddCloud(if gvzFalling and !dxyFalling then gvz else Double.NaN, gvzMA, Color.DARK_ORANGE, Color.BLACK);
AddCloud(if !gvzFalling and dxyFalling then gvz else Double.NaN, gvzMA, Color.DARK_RED, Color.BLACK);
AddCloud(if !gvzFalling and !dxyFalling then gvz else Double.NaN, gvzMA, Color.GRAY, Color.BLACK);

AddLabel(yes, "GVZ: " + Round(gvz, 2) + (if gvzFalling then " ↓" else " ↑"), if gvzFalling then Color.GREEN else Color.RED);
AddLabel(yes, "DXY: " + Round(dxy, 2) + (if dxyFalling then " ↓" else " ↑"), if dxyFalling then Color.GREEN else Color.RED);
AddLabel(yes,
if gvzFalling and dxyFalling then "Condition: Calm Bullish"
else if !gvzFalling and !dxyFalling then "Condition: Risk-Off / Bearish"
else "Condition: Mixed",
Color.YELLOW);

Alert(gvzFalling and dxyFalling, "GVZ↓ and DXY↓ — Calm Bullish Setup!", Alert.BAR, Sound.Ring);
 
Last edited by a moderator:
Try it with GVZ:CGI and $DXY. But, their market hours are different than /GC, resulting in NaN values when applied to /CG's chart, and therefore further messing up the averages from the looks of it. The two indices print on different price scales too, so, as it stands now, it's going to be all separated and scrunched. This is going to be a real mess one way or the other. You should probably take a look at it before I get any deeper into it.
 
Solution
Try it with GVZ:CGI and $DXY. But, their market hours are different than /GC, resulting in NaN values when applied to /CG's chart, and therefore further messing up the averages from the looks of it. The two indices print on different price scales too, so, as it stands now, it's going to be all separated and scrunched. This is going to be a real mess one way or the other. You should probably take a look at it before I get any deeper into it.
Thank you for that. I am now able to see lines plotted for GVZ and DXY but it is separated. What other options do we have available?

Code:
declare lower;

input showGVZ = yes;
input showDXY = yes;

def gvz = if showGVZ and !IsNaN(close("GVZ:CGI")) then close("GVZ:CGI") else Double.NaN;
def dxy = if showDXY and !IsNaN(close("$DXY")) then close("$DXY") else Double.NaN;

def gvzMA = Average(gvz, 10);
def dxyMA = Average(dxy, 10);

plot GoldVol = gvz;
GoldVol.SetDefaultColor(Color.WHITE);
GoldVol.SetLineWeight(2);

plot Dollar = dxy;
Dollar.SetDefaultColor(Color.GREEN);
Dollar.SetLineWeight(2);

def gvzFalling = gvz < gvzMA;
def dxyFalling = dxy < dxyMA;

AddLabel(yes, "GVZ: " + Round(gvz, 2) + (if gvzFalling then " ↓" else " ↑"), if gvzFalling then Color.GREEN else Color.RED);
AddLabel(yes, "DXY: " + Round(dxy, 2) + (if dxyFalling then " ↓" else " ↑"), if dxyFalling then Color.GREEN else Color.RED);
AddLabel(yes,
if gvzFalling and dxyFalling then "Condition: Calm Bullish"
else if !gvzFalling and !dxyFalling then "Condition: Risk-Off / Bearish"
else "Condition: Mixed",
Color.YELLOW);

Alert(gvzFalling and dxyFalling, "GVZ↓ and DXY↓ — Calm Bullish Setup!", Alert.BAR, Sound.Ring);
 
Last edited by a moderator:
Typically, you would normalize them by percent change, perhaps from the open. In this case, even when in percent change format, one is extremely volatile, while the other is so dormant that it still ends up being flatlined compared to the other on the same scale. I think the best solution would be to compare their relative position between their own highest high and lowest low within the day.

mFuWnEk.png


That screen shot is applied to another random symbol. It's still not working on /CG, due to the discrepancy in trading hours. It's actually three sets, with one even starting at 9:31 instead of 9:30 for some odd reason. I'll finish it up when I get some more free time.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
384 Online
Create Post

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