Scan for Weighted Alpha

Solution
The ToS platform does not provide Alpha as part of its data stream so the calculations ascribed in your link cannot be performed.

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

Hello everyone!
Trying to figure out how to scan for Weighted Alpha in ToS
Weighted Alpha calculations

Barcharts has this in the screening tool (https://help.barchart.com/support/s...w-does-barchart-com-calculate-weighted-alpha-)

Wondering if someone can help me add this into the scan. I would scan for a value between X and Y , or Greater than or less than
Thanks
https://tos.mx/!vxa3crFx

For TOS had to use a "fold" function along with a few other work arounds - but this should be close. How are you using this???

Code:
# ============================================================
# Weighted Alpha Indicator with Swing/Day Auto Function + #Scanner compatibility
#
# Author: ANTWERKS | Revision: 2025-10-21
# ============================================================

declare lower;

# === Auto Mode Selection ===
# Automatically switches based on chart timeframe
# 0 = Swing mode, 1 = Day mode
def mode = if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN then 1 else 0;

input lengthSwing = 60;     # bars for swing mode (about 3 months)
input lengthDay = 90;       # bars for intraday mode (~90 1m-15m bars)
input decayStart = 0.5;     # older bar weight (linear mode)
input decayFactor = 0.95;   # exponential factor (day mode)
input bullishThreshold = 5; # bullish % threshold
input showLabel = yes;

def price = close;
def barsAvailable = BarNumber();

# === Choose lookback length ===
def useLen = if mode == 0 then lengthSwing else lengthDay;
def useLenSafe = if useLen < 1 then 1 else useLen;

# Pre-calc linear step (ok to compute even if not used in day mode)
def step = (1 - decayStart) / Max(useLenSafe - 1, 1);

# === WeightedSum and WeightTotal computed via inline conditional folds ===
def weightedSum = if mode == 0 then
    fold i = 0 to useLenSafe - 1 with s = 0 while 1 do
        s + (if !IsNaN(GetValue(price, i)) and GetValue(price, i) > 0
             then ((price - GetValue(price, i)) / GetValue(price, i)) * (1 - i * step)
             else 0)
else
    fold iA = 0 to useLenSafe - 1 with sA = 0 while 1 do
        sA + (if !IsNaN(GetValue(price, iA)) and GetValue(price, iA) > 0
             then ((price - GetValue(price, iA)) / GetValue(price, iA)) * Power(decayFactor, iA)
             else 0);

def weightTotal = if mode == 0 then
    fold j = 0 to useLenSafe - 1 with w = 0 while 1 do
        w + (if !IsNaN(GetValue(price, j)) and GetValue(price, j) > 0
             then (1 - j * step)
             else 0)
else
    fold jA = 0 to useLenSafe - 1 with wA = 0 while 1 do
        wA + (if !IsNaN(GetValue(price, jA)) and GetValue(price, jA) > 0
             then Power(decayFactor, jA)
             else 0);

# Protect against divide by zero
def weightedAlpha = 100 * (weightedSum / Max(weightTotal, 1));

# === Plot Weighted Alpha ===
plot WA1 = weightedAlpha;
WA1.SetLineWeight(2);
WA1.AssignValueColor(
    if WA1 > bullishThreshold then Color.DARK_GREEN
    else if WA1> 0 then Color.GREEN
    else if WA1 < 0 then Color.RED
    else Color.GRAY
);

# === Mode Labels ===
AddLabel(showLabel,
    "Mode: " + (if mode == 0 then "Swing" else "Day") +
    " | WA: " + AsText(Round(WA1, 2)) + "%",
    if WA1 > bullishThreshold then Color.DARK_GREEN
    else if WA1 > 0 then Color.GREEN
    else Color.RED
);

# === Bullish Scanner Output ===
plot BullishScan = WA1 > bullishThreshold;
BullishScan.SetDefaultColor(Color.GREEN);

# ============================================================

1761062740395.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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