Larry Williams Large Trade Index (LWTI) [Loxx] For ThinkOrSwim

didyougetone

New member
Larry Williams Large Trade Index (LWTI) [Loxx] is an indicatory by Larry Williams as explained in his book "Trade Stocks and Commodities with the Insiders: Secrets of the COT Report".

What is the Larry Williams Large Trade Index (LWTI)?
The original concept was specifically based on Trader (or Market) Sentiment and predicting market reversals. It's calculated as follows:

MovingAvg(Close - Close[Period], bars used in average)/MovingAvg(Range,bars used in average)*50 + 50
Sdtt1th.png



Here is the original Tradingview code:
https://www.tradingview.com/script/ECuloL0o-Larry-Williams-Large-Trade-Index-LWTI-Loxx/

For the new ThinkOrSwim code, you must scroll down to the next post
 
Last edited by a moderator:

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

I found an indicator called the Larry Williams Large Trade Index (lwti) on TradingView.
https://www.tradingview.com/script/ECuloL0o-Larry-Williams-Large-Trade-Index-LWTI-Loxx/

Here is what the indicator is supposed to do:

Larry Williams Large Trade Index (LWTI) [Loxx] is an indicatory by Larry Williams as explained in his book "Trade Stocks and Commodities with the Insiders: Secrets of the COT Report". I've added optional smoothing if you wish to smooth the output.

What is the Larry Williams Large Trade Index (LWTI)?
The original concept was specifically based on Trader (or Market) Sentiment and predicting market reversals. It's calculated as follows:

MovingAvg(Close - Close[Period], bars used in average)/MovingAvg(Range,bars used in average)*50 + 50

Included
  • Bar coloring
  • Signals
  • Alerts
View attachment 23808

I copied the code that was provided and was able to convert most of it (not sure if it's actually correct, but mostly free of errors). I'm new to coding and have done the best I can, but cannot get two errors to clear from the following code, which I've marked the troubles in Bold Red and Italics:
# Larry Williams Large Trade Index (LWTI) [Loxx]
# Converted to ThinkScript

input per = 8; # Period
input smthit = no; # Smooth LWPI?
input type = {EMA, WMA, RMA, SMA}; # Smoothing Type
input smthper = 5; # Smoothing Period
input colorbars = no; # Color bars?
input showsignals = no; # Show signals?

def greencolor = Color.GREEN;
def redcolor = Color.RED;

# Calculate the LWTI
def ma = Average(close - close[per], per);
def atr = Average(TrueRange(high, close, low), per);
def out = ma / atr * 50 + 50;

# Apply smoothing if enabled
rec smoothedOut = Double.NaN; # Initialize smoothedOut

if smthit {
if type == 0 { # SMA
smoothedOut = Average(out, smthper);
} else if type == 1 { # EMA
smoothedOut = ExpAverage(out, smthper);
} else if type == 2 { # RMA
smoothedOut = WildersAverage(out, smthper);
} else if type == 3 { # WMA
smoothedOut = WMA(out, smthper);
};



# Set color for the plot
def colorOut = if smoothedOut > 50 then greencolor else redcolor;

plot LWTI = smoothedOut;
LWTI.SetLineWeight(2);
LWTI.AssignValueColor(colorOut);

# Color bars if enabled
AssignPriceColor(if colorbars then colorOut else Color.CURRENT);

# Middle line at 50
plot Middle = 50;
Middle.SetDefaultColor(Color.GRAY);
Middle.SetStyle(Curve.MEDIUM_DASH);

# Long and Short signals
def goLong = smoothedOut crosses above 50;
def goShort = smoothedOut crosses below 50;

# Plot signals
plot LongSignal = if goLong and showsignals then low - 0.5 else Double.NaN;
LongSignal.SetPaintingStrategy(PaintingStrategy.TRIANGLEUP);
LongSignal.SetDefaultColor(greencolor);
LongSignal.SetLineWeight(3);

plot ShortSignal = if goShort and showsignals then high + 0.5 else Double.NaN;
ShortSignal.SetPaintingStrategy(PaintingStrategy.TRIANGLEDOWN);
ShortSignal.SetDefaultColor(redcolor);
ShortSignal.SetLineWeight(3);

# Alert conditions
Alert(goLong, "Larry Williams Large Trade Index (LWTI) [Loxx]: Long", Alert.BAR, Sound.Ding);
Alert(goShort, "Larry Williams Large Trade Index (LWTI) [Loxx]: Short", Alert.BAR, Sound.Ding);

That's the end of the code. I'll also include the Pine Script I used for the conversion:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx

//@version=5
indicator("Larry Williams Large Trade Index (LWTI) [Loxx]",
shorttitle="LWTI [Loxx]",
overlay = false,
timeframe="",
timeframe_gaps = true)

greencolor = #2DD204
redcolor = #D2042D

variant(type, src, len) =>
sig = 0.0
if type == "SMA"
sig := ta.sma(src, len)
else if type == "EMA"
sig := ta.ema(src, len)
else if type == "WMA"
sig := ta.wma(src, len)
else if type == "RMA"
sig := ta.rma(src, len)
sig

per = input.int(8, "Period", group = "Basic Settings")
smthit = input.bool(false, "Smooth LWPI?", group = "Basic Settings")
type = input.string("SMA", "Smoothing Type", options = ["EMA", "WMA", "RMA", "SMA"], group = "BasicR Settings")
smthper = input.int(5, "Smoothing Period", group = "Basic Settings")

colorbars = input.bool(false, "Color bars?", group = "UI Options")
showsignals = input.bool(false, "Show signals?", group = "UI Options")

ma = ta.sma(close - nz(close[per]), per)
atr = ta.atr(per)
out = ma/atr * 50 + 50
out := smthit ? variant(type, out, smthper) : out

colorout = out > 50 ? greencolor : redcolor
plot(out, color = colorout, linewidth = 2)
barcolor(colorbars ? colorout : na)

middle = 50

plot(middle, color = bar_index % 2 ? color.gray : na)

goLong = ta.crossover(out, middle)
goShort = ta.crossunder(out, middle)

plotshape(goLong and showsignals, title = "Long", color = greencolor, textcolor = greencolor, text = "L", style = shape.triangleup, location = location.bottom, size = size.auto)
plotshape(goShort and showsignals, title = "Short", color = redcolor, textcolor = redcolor, text = "S", style = shape.triangledown, location = location.top, size = size.auto)

alertcondition(goLong, title="Long", message="Larry Williams Large Trade Index (LWTI) [Loxx]: Long\nSymbol: {{ticker}}\nPrice: {{close}}")
alertcondition(goShort, title="Short", message="Larry Williams Large Trade Index (LWTI) [Loxx]: Short\nSymbol: {{ticker}}\nPrice: {{close}}")

That's the end of that one. Thank you for any assistance you can provide!!!
check the below:

CSS:
#// Indicator for TOS
#// © loxx
#indicator("Larry Williams Large Trade Index (LWTI) [Loxx]", shorttitle="LWTI [Loxx]"
# Converted by Sam4Cok@Samer800    - 01/2025

declare lower;

input timeframe = AggregationPeriod.MIN;
input colorBars = no; #, "Color bars?", group = "UI Options")
input showSignalLine = no; #, "Show signals?", group = "UI Options")
input Period = 8; #, "Period", group = "Basic Settings")
input Smoothing = no; # "Smooth LWPI?", group = "Basic Settings")
input SmoothingType = AverageType.SIMPLE; # "Smoothing Type"
input SmoothingPeriod = 5; #, "Smoothing Period", group = "Basic Settings")


def na = Double.NaN;
def last = IsNaN(close);
def cap = getAggregationPeriod();
def tf = Max(cap, timeframe);

def ma = Average(close(Period = tf) - close(Period = tf)[Period], Period);
def tr = TrueRange(high(Period = tf), close(Period = tf), low(Period = tf));
def atr = WildersAverage(tr, Period);
def out = ma / atr * 50 + 50;
def smooth = if Smoothing then MovingAverage(SmoothingType, out, SmoothingPeriod) else out;
def goL = (smooth > 50) and (smooth[1] <= 50);
def goS = (smooth < 50) and (smooth[1] >= 50);
#-- plot
plot lower = if !showSignalLine then na else if !last and goL then -150 else -200;
plot upper = if !showSignalLine then na else if !last and goS then 150 else 200;
plot LWTI = if !last then smooth else na;
plot middle = if !last then 50 else na;

lower.SetDefaultColor(Color.CYAN);
upper.SetDefaultColor(Color.MAGENTA);
middle.SetStyle(Curve.SHORT_DASH);
middle.SetDefaultColor(Color.GRAY);
LWTI.SetLineWeight(2);
LWTI.AssignValueColor(if LWTI > middle then Color.GREEN else Color.RED);

AddCloud(LWTI, middle, Color.DARK_GREEN, Color.DARK_RED);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if LWTI > middle then Color.GREEN else Color.RED);

#-- END of CODE
 
check the below:

CSS:
#// Indicator for TOS
#// © loxx
#indicator("Larry Williams Large Trade Index (LWTI) [Loxx]", shorttitle="LWTI [Loxx]"
# Converted by Sam4Cok@Samer800    - 01/2025

declare lower;

input timeframe = AggregationPeriod.MIN;
input colorBars = no; #, "Color bars?", group = "UI Options")
input showSignalLine = no; #, "Show signals?", group = "UI Options")
input Period = 8; #, "Period", group = "Basic Settings")
input Smoothing = no; # "Smooth LWPI?", group = "Basic Settings")
input SmoothingType = AverageType.SIMPLE; # "Smoothing Type"
input SmoothingPeriod = 5; #, "Smoothing Period", group = "Basic Settings")


def na = Double.NaN;
def last = IsNaN(close);
def cap = getAggregationPeriod();
def tf = Max(cap, timeframe);

def ma = Average(close(Period = tf) - close(Period = tf)[Period], Period);
def tr = TrueRange(high(Period = tf), close(Period = tf), low(Period = tf));
def atr = WildersAverage(tr, Period);
def out = ma / atr * 50 + 50;
def smooth = if Smoothing then MovingAverage(SmoothingType, out, SmoothingPeriod) else out;
def goL = (smooth > 50) and (smooth[1] <= 50);
def goS = (smooth < 50) and (smooth[1] >= 50);
#-- plot
plot lower = if !showSignalLine then na else if !last and goL then -150 else -200;
plot upper = if !showSignalLine then na else if !last and goS then 150 else 200;
plot LWTI = if !last then smooth else na;
plot middle = if !last then 50 else na;

lower.SetDefaultColor(Color.CYAN);
upper.SetDefaultColor(Color.MAGENTA);
middle.SetStyle(Curve.SHORT_DASH);
middle.SetDefaultColor(Color.GRAY);
LWTI.SetLineWeight(2);
LWTI.AssignValueColor(if LWTI > middle then Color.GREEN else Color.RED);

AddCloud(LWTI, middle, Color.DARK_GREEN, Color.DARK_RED);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if LWTI > middle then Color.GREEN else Color.RED);

#-- END of CODE
Thank you very much for the reworked code. Much Appreciation!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
642 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