Indicator · Pine Script v5 · On the chart

Snag - Swing Trade Long Term

by dearvn· code credited to thinhdangho

Snag - Swing Trade Long Term calculates 13-period, 48-period, and 200-period Weighted Moving Averages to evaluate market direction for long-term swing trading.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code136
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago25 Jul 2022

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

136 lines of Pine Script v5 from swingtrade.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=5
indicator("Snag - SWING TRADE LONG TERM", overlay=true)

// Trend Up Strong
// Close Cross Up EMA 13, or Close Cross Up EMA 50 or Close Cross Up EMA 200
// Mark as Begin Up Trend
// Wait for EMA 13 Cross Up EMA 48 🡪 Confirm Strong Uptrend 🡪 BUY
// EMA 48 CROSS UP EMA 200 🡪 STRONGER UPTREND
// Trend Down Strong
// Close Cross Down EMA 13, or Close Cross Down EMA 50 or Close Cross Down EMA 200
// Mark as Begin Down Trend
// Wait for EMA 13 Cross Down EMA 48 🡪 Confirm Strong Downtrend 🡪 SELL
// EMA 48 CROSS DOWN EMA 200 🡪 STRONGER DOWNTREND

wma13 = ta.wma(close, 13)
plot(wma13, title="WMA13", color=color.blue)

wma48 = ta.wma(close, 48)
plot(wma48, title="WMA48", color=color.yellow)

wma200 = ta.wma(close, 200)
plot(wma200, title="WMA200", color=color.white)

crossUpWMA13 = ta.crossover(close, wma13)
crossDownWMA13 = ta.crossunder(close, wma13)
crossUpWMA48 = ta.crossover(close, wma48)
crossDownWMA48 = ta.crossunder(close, wma48)
crossUpWMA200 = ta.crossover(close, wma200)
crossDownWMA200 = ta.crossunder(close, wma200)

crossUpWMA13_48 = ta.crossover(wma13, wma48)
crossDownWMA13_48 = ta.crossunder(wma13, wma48)
crossUpWMA48_200 = ta.crossover(wma48, wma200)
crossDownWMA48_200 = ta.crossunder(wma48, wma200)

var bool isUpTrend = false
var bool isDownTrend = false

if crossUpWMA13 and isUpTrend == false
    isUpTrend := true
    isDownTrend := false
else if crossUpWMA48 and isUpTrend == false
    isUpTrend := true
    isDownTrend := false
else if crossUpWMA200 and isUpTrend == false
    isUpTrend := true
    isDownTrend := false

if crossDownWMA13 and isDownTrend == false
    isUpTrend := false
    isDownTrend := true
else if crossDownWMA48 and isDownTrend == false
    isUpTrend := false
    isDownTrend := true
else if crossDownWMA200 and isDownTrend == false
    isUpTrend := false
    isDownTrend := true
    
var int trendUp = 0
var int trendDown = 0

txtMarkTrend = ''
txtOrder = 'N/A'
if isUpTrend
    if crossUpWMA13_48
        trendUp := 1
        trendDown := 0
    if crossUpWMA48_200
        trendUp := 2
        trendDown := 0
        
if isDownTrend
    if crossDownWMA13_48
        trendUp := 0
        trendDown := 1
    if crossDownWMA48_200
        trendUp := 0
        trendDown := 2
        
if isUpTrend
    txtMarkTrend := 'Begin Up Trend'
    if trendUp == 1
        txtMarkTrend := 'Confirm Strong Uptrend'
        txtOrder := 'BUY'
    else if trendUp == 2
        txtMarkTrend := 'STRONGER UPTREND'
        txtOrder := 'BUY'

else if isDownTrend
    txtMarkTrend := 'Begin Down Trend'
    if trendDown == 1
        txtMarkTrend := 'Confirm Strong Downtrend'
        txtOrder := 'SELL'
    else if trendDown == 2
        txtMarkTrend := 'STRONGER DOWNTREND'
    txtOrder := 'SELL'
    
if barstate.islast
    var table panel = table.new("bottom_right", 6, 30)

    table.cell(panel, 0, 1, "TREND", bgcolor = color.yellow, text_color=color.black, width=18, text_halign=text.align_left)
    table.cell(panel, 1, 1, txtMarkTrend, bgcolor = color.yellow, text_color=color.black, width=18, text_halign=text.align_left)    
    table.cell(panel, 0, 2, "ORDER", bgcolor = color.yellow, text_color=color.black, width=18, text_halign=text.align_left)
    table.cell(panel, 1, 2, txtOrder, bgcolor = color.yellow, text_color=color.black, width=18, text_halign=text.align_left)    
    
        


// Alert
var time_wmacrossup_arr = array.new_int()
var time_wmacrossdown_arr = array.new_int()

if trendUp == 1 or trendUp == 2
    time_wmacrossdown_arr := array.new_int()
    if array.size(time_wmacrossup_arr) == 0
        array.push(time_wmacrossup_arr, time)
else if trendDown == 1 or trendDown == 2
    time_wmacrossup_arr := array.new_int()
    if array.size(time_wmacrossdown_arr) == 0
        array.push(time_wmacrossdown_arr, time)
        
is_alert_wmacrossup = false
is_alert_wmacrossdown = false

if array.size(time_wmacrossup_arr) > 0
    if time == array.get(time_wmacrossup_arr, array.size(time_wmacrossup_arr)-1)
        is_alert_wmacrossup := true
else if array.size(time_wmacrossdown_arr) > 0
    if time == array.get(time_wmacrossdown_arr, array.size(time_wmacrossdown_arr)-1)
        is_alert_wmacrossdown := true
        
alertcondition(is_alert_wmacrossdown, title='ENTER PUT', message='Get out Call and Enter PUT')
alertcondition(is_alert_wmacrossup, title='ENTER CALL', message='Get out Put and Enter CALL')

Overview

The indicator monitors price crossovers across each moving average to identify initial trend shifts, while moving average crossovers confirm stronger trend phases. It plots the three moving averages directly on the main chart and renders a table panel at the bottom right displaying the active trend phase and action bias.

Details

Published by

dearvn on GitHub

Code credit

thinhdangho, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Screeners & dashboards

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

futurestrading-strategiestradingview

Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

218 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of TradersPost Trading Checklist
92 stars

This indicator plots five moving averages of a chosen source on the price chart, defaulting to EMA lengths 10, 20, 30, 40 and 50. The user can switch the average type to SMA, WMA or HMA and recolor each line. Wide translucent glows sit under the lines, and sof

Indicator v5 TrendMoving averages
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev Rainbow MA Ribbon 10-50

EMA Ribbon Overlay

by iamrichardD
57 stars

Calculates exponential moving averages for fast, pivot, and slow lengths along with optional 50, 100, and 200 simple moving average context lines. It visualizes bullish and bearish ribbon fills on the main price chart alongside MACD calculations to generate ea

Indicator v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon Overlay
53 stars

This indicator analyzes historical candle direction and price range over a configurable lookback window to gauge market trend. It categorizes trend direction using candle count, price range sum, or both. Signals are filtered using a Simple Moving Average to en

Indicator v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of Candle Counter + MA + RSI + Mode
43 stars

This indicator evaluates market momentum and risk by calculating trend metrics and volatility stats, displaying them in an on-chart table pane. It measures short-term and long-term trend strength via two MACD configurations built on three customizable EMA leng

Indicator v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of Trend Strength & Volatility

Market Monitor - 15m

by chris-c-thomas
14 stars

Market Monitor - 15m is a directional bias chart overlay designed for 15-minute intraday chart analysis. It calculates a triple exponential moving average ribbon with EMA cloud shading, session VWAP with multiplier bands, prior day levels, a 30-minute opening

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Market Monitor - 15m

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers