Strategy · Pine Script v5 · On the chart

Swing Trade

by might-tree

This strategy plots three swing lines on the price chart.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code30
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago2 Aug 2023

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

30 lines of Pine Script v5 from Strategies/Swing_Trade.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Swing_Trade.pine
//Run the following Script on PINE EDITOR or any platform supporting Pine Script

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

//@version=5
strategy("Swing Trade", overlay=true, margin_long=100, margin_short=100)

small_high = if(high[0]>high[1])
    high
small_low = if(low[0]<low[1])
    low

plot(high[0]>high[1]? small_high : small_low, color=#48b3ff, linewidth=2, title="Small Swing")


medium_high = if(high[0]>high[1] and high[1] > high[2])
    high
medium_low = if(low[0]<low[1] and low[1] < low[2])
    low

plot(high[0]>high[1]? medium_high : medium_low, color=color.rgb(241, 210, 98), linewidth=2, title="Medium Swing")


large_high = if(high[0]>high[1] and high[1] > high[2] and high[2] > high[3])
    high
large_low = if(low[0]<low[1] and low[1] < low[2] and low[2] < low[3])
    low

plot(high[0]>high[1]? large_high : large_low, color=color.rgb(250, 72, 226), linewidth=2, title="Large Swing")

Overview

A small swing marks the current high after one higher high, or the current low after one lower low. A medium swing requires two consecutive rising highs or falling lows, and a large swing requires three. The lines use fixed blue, gold, and magenta colors, and there are no user inputs. Although declared as a strategy, it never opens or closes positions and has no stop loss, take profit, or position sizing.

Details

Published by

might-tree on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

  • The strategy enters trades without a stop loss
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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated 2 days ago · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout

Omar Edited WF

by Alorse
330 stars

Omar Edited WF is a trading strategy overlay built around Williams Fractals and multiple Exponential Moving Averages. It detects high and low fractal pivot points over configurable lookback periods alongside three adjustable EMA trendlines. Long entries are ma

Strategy v5 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of Omar Edited WF
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 7 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar
106 stars

This overlay strategy plots a two-timeframe Ichimoku setup on the price chart, with Tenkan, Kijun, Chikou, and Kumo from a base higher timeframe and an optional highest-timeframe cloud. It allows two entries in the same direction and uses ATR-based trailing st

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 2Tier Ichimoku Pyramiding [Takazudo]
104 stars

This strategy combines three Exponential Moving Averages with Williams Fractals to execute trend-following or mean-reverting trades. It analyzes price structure using short, medium, and long-term EMAs along with fractal highs and lows. Entries trigger when fra

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of 3MA and Fractals Strategy

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers