PROTECTED SOURCE SCRIPT

Moving Average Crossover Strategy Ver 5.0 /r/WallStreetTrader

13
patreon.com/c/wallstreettrader

Moving Average Crossover Strategy Ver 5.0 /r/WallStreetTrader

This script is a dual-system trading approach combining
(1) moving-average trend signals and
(2) peak/dip detection using smoothed highs/lows and a minimum profit-gap filter. It tries to catch trend-aligned buy/sell points, but only confirms signals when both the moving-average regime and local price-extreme logic agree.

✅ FULL STRATEGY DESCRIPTION

This is NOT a simple MA crossover script.
It is a combined trend + swing-reversal system that uses:

✅ Trend tracking → via MA50 and MA100
✅ Short-term direction → via MA10 / MA20
✅ Swing highs & swing lows → via smoothed extremes
✅ Profit-gap filters → ensure only meaningful moves
✅ Signal de-duplication → prevents spam labels

This creates a system intended for day-trading or swing-trading reversals inside trend direction.

🔵 PART 1 — Moving Averages (Trend Logic)

The script calculates four SMAs:

MA10 – very fast, day-trading signal
MA20 – short-term fast trend
MA50 – main trend reference
MA100 – slow trend reference

The MA50 vs MA100 relationship defines trend direction:

Bullish trend when:
close > MA50 AND close > MA100
MA50 crosses ABOVE MA100 = buySignal1
close already above both = buySignal2

Bearish trend when:
close < MA50 AND close < MA100
MA50 crosses BELOW MA100 = sellSignal1
close already below both = sellSignal2

Meaning:
The script only wants to Buy in an uptrend and Sell in a downtrend.

🔵 PART 2 — Peak/Dip Detection (Swing Logic)

It smooths highs & lows with a moving average:
smoothedHigh = SMA(high, smoothingPeriod)
smoothedLow = SMA(low, smoothingPeriod)

Then checks whether these smoothed values are extreme over a lookback window:
isPeak → smoothed high = highest high in last N bars
isDip → smoothed low = lowest low in last N bars

This detects:
Local swing highs
Local swing lows

BUT they must also meet a minimum gap profit rule:
minGapPercent = 2% // e.g. high must be 2% above last buy price

This prevents signals when price barely moves.

🔵 PART 3 — Label & Signal Filtering (No Spam)

The script stores:
lastBuyPrice
lastSellPrice
lastBuyLabel
lastSellLabel

When a new swing appears:

A. For Sell signals (peaks)
If isPeak AND (high - lastBuyPrice) >= lastBuyPrice * minGapPercent:
delete previous Sell label
place a new Sell label

B. For Buy signals (dips)
If isDip AND (lastSellPrice - low) >= lastSellPrice * minGapPercent:
delete previous Buy label
place a new Buy label

This ensures:
Only ONE buy per cycle
Only ONE sell per cycle
Only AFTER meaningful price movement

🔵 PART 4 — Final Confirmation Signals

The MA trend signals and Peak/Dip signals combine:
plotshape(isDip AND buySignal) // “confirmed buy”
plotshape(isPeak AND sellSignal) // “confirmed sell”

A Buy Confirmation requires BOTH:
Price in an uptrend (MA condition)
A dip detected (swing low)
A Sell Confirmation requires BOTH:
Price in a downtrend (MA condition)
A peak detected (swing high)

This is the core idea:
📌 “Only buy dips in an uptrend, only sell peaks in a downtrend.”


🔥 What This Strategy is Trying to Do

Identify the dominant trend using MA50/MA100.
Find swing lows inside a bullish regime → buy dips.
Find swing highs inside a bearish regime → sell rallies.

Filter out noise using:
Smooth highs/lows
Lookback extremes
Minimum profit-gap threshold
State-resetting labels to avoid duplicates

Only mark the “best” dip or peak in each mini-trend run.


🧠 How It Would Perform (likely behaviour)

✔ Works best in:
Trending markets
Smooth swingy markets
High liquidity assets
Indices (SPY, QQQ)
Crypto on higher timeframes

❌ Performs poorly in:
Chop/range-bound price
Flash crashes
Super-high volatility with no trend
Assets with large gaps

Because the system requires:
Clean dips
Clean peaks
Enough momentum to hit minGapPercent
Smooth behaviour for MA50/MA100 to hold direction

⭐ TL;DR – Simple Description
This strategy finds dips in an uptrend and peaks in a downtrend.
It uses MA50/MA100 to define trend direction and smoothed swing-high/low detection to identify reversals. It only fires if price moves at least a minimum percentage away from the last entry, avoiding overtrading. It confirms signals only when both trend and swing logic agree.

Perfectly summarized:
➡ “Trend + Swing Reversal Filter: Buy strong dips, sell strong peaks, inside clean trend structure.”

patreon.com/c/wallstreettrader

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.