Strategy · Pine Script v6 · On the chart

S50 TFEX Trend Following Breakout

by lumduan

A breakout strategy built for S50 futures on a 30-minute chart.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv6current
Lines of code92
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago9 Aug 2025

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

92 lines of Pine Script v6 from s50-trend-following-breakout.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

s50-trend-following-breakout.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lumduan
//@version=6

// For S50 TFEX Strategy Timeframe 30 minutes 
import candythink/MonthlyProfitTable/5 as MonthlyProfitTable       

// ————— Constants
float RISK_FREE_RATE = 2.0 // Risk-free rate for calculating Sharpe ratio
high_price_bar_color = color.green
low_price_bar_color = color.red
int high_price_bar_width = 1
int low_price_bar_width = 1

int contact_per_order = 1
float commission_price = 85.0 //THB

// Inputs for configuring the pivot point calculation
int left_bars = input(21) // Number of bars to the left for pivot calculation
int right_bars = input(2) // Number of bars to the right for pivot calculation
int risk_percent = input(1, title="Risk % per Trade") / 100
int atr_length = input(10, title="ATR Length")
int risk_reward_ratio = input(8, title="Risk-Reward Ratio")
int adx_length = input(14, title="ADX Length")
float adx_threshold = input(25.0, title="ADX Threshold")
int prec      = input(2, title = "Return Precision") // Precision of return percentages
bool show_table = input.bool(defval = true, title = "Show Return Rate Table On/Off") // Show or hide the table

strategy(title = "S50 TFEX Trend Following Breakout",overlay = true, calc_on_every_tick = true, default_qty_type = strategy.fixed, default_qty_value = contact_per_order, commission_type = strategy.commission.cash_per_contract, commission_value = commission_price , risk_free_rate = RISK_FREE_RATE)

// ATR Calculation
atr = ta.atr(atr_length)

// ADX Calculation using DMI
[diplus, diminus, adx] = ta.dmi(adx_length, adx_length)

// Account Equity & Risk Per Trade
strategy_equity = strategy.equity
risk_amount = strategy_equity * risk_percent

// swing
swing_high = ta.pivothigh(left_bars, right_bars)
swing_low = ta.pivotlow(left_bars, right_bars)

// Initialize high and low price variables
float high_price = 0.0
high_price := not na(swing_high) ? swing_high : high_price[1] // Update high price if a new swing high is detected, else carry forward previous value

float low_price = 0.0
low_price := not na(swing_low) ? swing_low : low_price[1] // Update low price if a new swing low is detected, else carry forward previous value

// Stop-Loss and Take-Profit Calculation
long_stop = swing_low - atr
short_stop = swing_high + atr

long_take_profit = swing_high + atr * risk_reward_ratio
short_take_profit = swing_low - atr * risk_reward_ratio

// Position Sizing: Contracts based on risk
long_contracts = risk_amount / (swing_high - long_stop)
short_contracts = risk_amount / (short_stop - swing_low)

is_long = false
is_short = false

is_long := high[0] > high_price
is_short := low[0] < low_price

// Long Entry with ADX filter
// if not na(swing_high)
if is_long //and adx > adx_threshold
    strategy.entry("Long", strategy.long, qty=long_contracts, stop=swing_high + syminfo.mintick, comment = "Long")
    strategy.exit("Long Exit", from_entry="Long", stop=long_stop, limit=long_take_profit, comment = "Short")

// Short Entry with ADX filter
// if not na(swing_low)
if is_short //and adx > adx_threshold
    strategy.entry("Short", strategy.short, qty=short_contracts, stop=swing_low - syminfo.mintick, comment = "Short")
    strategy.exit("Short Exit", from_entry="Short", stop=short_stop, limit=short_take_profit, comment = "Long")

// Plot high and low prices on the chart
plot(high_price, color = high_price_bar_color, linewidth = high_price_bar_width)
plot(low_price, color = low_price_bar_color, linewidth = low_price_bar_width)

// Plot Take Profit
plot(high_price + atr * risk_reward_ratio, title="Long Take-Profit", color=color.rgb(0, 240, 164, 50), linewidth=1, style=plot.style_stepline)
plot(low_price - atr * risk_reward_ratio, title="Short Take-Profit", color=color.rgb(0, 240, 164, 50), linewidth=1, style=plot.style_stepline)


// ======= TABLE =====
float equity = strategy.equity
MonthlyProfitTable.ProfitTable(equity)

Overview

S50 TFEX Trend Following Breakout tracks confirmed swing highs and lows from pivot detection and places stop-order entries when price breaks the latest swing level. The stop sits one ATR beyond the opposite swing, the target is a multiple of ATR beyond the broken swing, and contract count is sized from a percentage of equity risked. An ADX filter is defined but commented out of the entry. It draws on the price chart, with an optional monthly return table. Pivots are confirmed late and orders recalculate on every tick.

Details

Published by

lumduan on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Support & resistance, Volatility & bands

Markets

Indices

Timeframes

M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
left_barsint21left_bars
right_barsint2right_bars
Risk % per Tradeint1risk_percent
ATR Lengthint10atr_length
Risk-Reward Ratioint8risk_reward_ratio
ADX Lengthint14adx_length
ADX Thresholdfloat25.0adx_threshold
Return Precisionint2prec
Show Return Rate Table On/Offbooltrueshow_table
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

257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
16 stars

This strategy trades Donchian breakouts measured on weekly bars while orders execute on the chart timeframe. It allows long and short entries when price breaks the prior weekly channel and exits against the shorter weekly channel. Position size risks a set per

Strategy v6 TrendBreakout
Updated 12 months ago · None stated GitHub repository of Seykota Alt 4: Weekly Donchian
11 stars

Calculates upper and lower Donchian Channel bands over a customizable lookback length and plots them on the main price chart. At a specified exchange hour, the strategy places a long buy stop order at the upper Donchian Channel level. Unfilled pending orders a

Strategy v6 BreakoutSupport & resistance
Updated 5 months ago · Apache-2.0 GitHub repository of Estrategia Donchian Breakout
6 stars

This overlay strategy builds independent timed session ranges and marks range, trendline, mean, VWAP, and high-low levels when those displays are enabled. It enters on range breakouts and exits with strategy exits, choosing among range, ATR, fixed-point, and r

Strategy v5 Sessions & timeBreakout
Updated 7 months ago · None stated GitHub repository of MSG Enhanced LEGO System Strategy
3 stars

Donchian Channel Breakout is a Pine Script v5 strategy drawn on the price chart. It enters long when close crosses above the previous upper Donchian band and short when close crosses below the previous lower band, reversing with the opposite signal. An ATR tra

Strategy v5 BreakoutVolatility & bands
Updated 7 months ago · MIT GitHub repository of Donchian Channel Breakout

The Range Percent Breakout Strategy identifies range contraction and inside bar patterns where the current bar's range is within a specified percentage threshold of the previous bar. When this condition is met while flat, breakout levels are established above

Strategy v5 BreakoutVolatility & bands
Updated 5 months ago · None stated GitHub repository of Range Percent Breakout Strategy

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers