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