WDUTX Indicator

Jdiddy1957

New member
I recently found about an indicator called WDUTX, which uses the two EFT’S Wood (lumber) and XLU (utilities). It is used as a timing tool over bought/over sold and I would like to see how it does back testing it ranges of time periods. Was shown 2 weeks and 13 weeks as time period. In a sample I looked at, it had a sell in January 2020. I would like to learn how to code it and then run various different timeframes to see myself how it works.

Here is a link to look for the WOOD:XLU chart: https://schrts.co/BdCPFQwq On stock charts. It would be great to have this converted

thank you

Jim
 
Last edited by a moderator:
Solution
@Jdiddy1957 Simple version of what halcyonguy coded elegantly.
Code:
declare lower;

input LENGTH = 1;
input ticker_1 = "wood";
input ticker_2 = "xlu";
input lengthwood = 10;
input lengthxlu = 80;

def tick_1 =simpleMovingAvg(price = close(ticker_1), length = length);
def tick_2 = simpleMovingAvg(price = close(ticker_2), length = length);

plot data = (tick_1 / tick_2);

plot tick1 =simpleMovingAvg(price = data, length = lengthwood);
plot tick2 = simpleMovingAvg(price = data, length = lengthxlu);
@Jdiddy1957 Gonna assume this is what you're looking for. Just a disclaimer but AddChart is a deprecated function so it might look off since it's not supported by ToS.
Code:
declare lower;
input symbol1 = "WOOD";
input symbol2 = "XLU";
input agg = AggregationPeriod.DAY;

def o = open(symbol = symbol1, period = agg) / open(symbol = symbol2, period = agg);
def h = high(symbol = symbol1, period = agg) / high(symbol = symbol2, period = agg);
def l = low(symbol = symbol1, period = agg) / low(symbol = symbol2, period = agg);
def c = close(symbol = symbol1, period = agg) / close(symbol = symbol2, period = agg);

def oup;
def hup;
def lup;
def cup;
if c > o
then {
    oup = o;
    hup = h;
    lup = l;
    cup = c;
} else {
    oup = Double.NaN;
    hup = Double.NaN;
    lup = Double.NaN;
    cup = Double.NaN;
}

def odn;
def hdn;
def ldn;
def cdn;
if c < o
then {
    odn = o;
    hdn = h;
    ldn = l;
    cdn = c;
} else {
    odn = Double.NaN;
    hdn = Double.NaN;
    ldn = Double.NaN;
    cdn = Double.NaN;
}

AddChart(high = hup, low = lup, open = cup, close = oup, type = ChartType.CANDLE, COLOR.GREEN);
AddChart(high = hdn, low = ldn, open = odn, close = cdn, type = ChartType.CANDLE, COLOR.RED);
 
@Jdiddy1957 Ok, I'm confused. Do you want the WOOD:XLU chart converted or a indicator called WDUTX?
Thank you for your work. Unfortunately when I tried to copy and paste the last line became highlighted in red and didn’t know what to do after that. I work on my iPad and not even sure how to import it so I went to my laptop and even had trouble there. Any ideas? Sorry, I thought I could at least copy/paste but couldn’t figure it out. Thanks though
 
Here is a link to look for the WOOD:XLU chart: https://schrts.co/BdCPFQwq On stock charts. It would be great to have this converted so it can be used on Sink/Swim. Any ideas would be appreciated.

Jim
here is my interpretation of what you are looking for.
use close prices of WOOD and XLU , with selectable 2nd agg times, to plot a ratio of them, with a couple of average lines, in a lower chart.

Python:
# index_wood_xlu_01

# -----------------
# 21-05-31
# halcyonguy
# desc:  my interpretation of jdiddy1957's request
# -----------------

# https://usethinkscript.com/threads/help-with-script%E2%80%A6please.6743/#post-65343
# jdiddy1957
# I recently found about an indicator called WDUTX, which uses the two EFT’S Wood (lumber) and XLU (utilities). It is used as a timing tool over bought/over sold and I would like to see how it does back testing it ranges of time periods. Was shown 2 weeks and 13 weeks as time period. In a sample I looked at, it had a sell in January 2020. I would like to learn how to code it and then run various different timeframes to see myself how it works.

# Here is a link to look for the WOOD:XLU chart:  https://schrts.co/BdCPFQwq   On stockcharts.

#  1.40  WOOD:XLU
# 91.50  WOOD , ishares global timber & forestry ETF nasdaq
# 65.10  XLU , utilities sector SPDR fund nyse

# WOOD:XLU is the same as close(wood) / close(xlu)
# the stockcharts chart has ,  ma(10) , ma(80)


#addlabel(yes, " wood", color.cyan);

declare lower;

input use_chart_time = yes;

# WOOD:XLU is the same as close(wood) / close(xlu)

# wood parameters for 2nd agg
input sym1 = "WOOD";
input WOOD_agg_Period = AggregationPeriod.hour;
def wood1agg = close(symbol = sym1 , period = WOOD_agg_Period);

# xlu  parameters for 2nd agg
input sym2 = "XLU";
input XLU_agg_Period = AggregationPeriod.hour;
def xlu1agg = close(symbol = sym2 , period = XLU_agg_Period);

def woodcls;
def xlucls;
if  use_chart_time then {
  woodcls = close(symbol = sym1);
  xlucls = close(symbol = sym2);
} else {
  woodcls = wood1agg;
  xlucls = xlu1agg;
}

# ratio of 2 stocks    wood/xlu
def woodxlu = round(woodcls / xlucls, 2);

plot z = woodxlu;
z.SetDefaultColor(Color.yellow);

# ---------------------------------------------------

# plot 2 averages of woodxlu

def price = woodxlu;
# add averages  , values used on stockchart
input avg1_len = 10;
input avg1_type =  AverageType.simple;
def ma1 = MovingAverage(avg1_type, price, avg1_len);

input avg2_len = 80;
input avg2_type =  AverageType.simple;
def ma2 = MovingAverage(avg2_type, price, avg2_len);

plot avg1 = ma1;
avg1.SetDefaultColor(Color.blue);
avg1.hidebubble();
plot avg2 = ma2;
avg2.SetDefaultColor(Color.red);
avg2.hidebubble();

#


index_wood_xlu_01

http://tos.mx/OF9ei3H

to add a study link to TOS
copy the text of the link above
in TOS, top right , SETUP > open shared item
paste in the link
click on preview
change the name if you want
import

now you can go to edit studies and search for the name and add it to a chart


v5HWxFN.jpg
 
Last edited:
@Jdiddy1957 Simple version of what halcyonguy coded elegantly.
Code:
declare lower;

input LENGTH = 1;
input ticker_1 = "wood";
input ticker_2 = "xlu";
input lengthwood = 10;
input lengthxlu = 80;

def tick_1 =simpleMovingAvg(price = close(ticker_1), length = length);
def tick_2 = simpleMovingAvg(price = close(ticker_2), length = length);

plot data = (tick_1 / tick_2);

plot tick1 =simpleMovingAvg(price = data, length = lengthwood);
plot tick2 = simpleMovingAvg(price = data, length = lengthxlu);
 
Solution
@Jdiddy1957 Simple version of what halcyonguy coded elegantly.
Code:
declare lower;

input LENGTH = 1;
input ticker_1 = "wood";
input ticker_2 = "xlu";
input lengthwood = 10;
input lengthxlu = 80;

def tick_1 =simpleMovingAvg(price = close(ticker_1), length = length);
def tick_2 = simpleMovingAvg(price = close(ticker_2), length = length);

plot data = (tick_1 / tick_2);

plot tick1 =simpleMovingAvg(price = data, length = lengthwood);
plot tick2 = simpleMovingAvg(price = data, length = lengthxlu);

thank you, being self taught , i tend to be functional, but not always simple. heh
 

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
308 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