Strategy · Pine Script v5 · On the chart

Silver Setup Strategy

by GreyssonEnterprises· code credited to trading-setups

A strategy version of the paint bar setup.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code316
Settings12inputs
LicenceMIT
Last update2 months ago1 Aug 2026

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

316 lines of Pine Script v5 from strategies/silver/pinescript/strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © trading-setups

//@version=5
strategy(title="Silver Setup Strategy", shorttitle="Silver Strategy", overlay=true, 
         default_qty_type=strategy.percent_of_equity, default_qty_value=100, 
         commission_type=strategy.commission.percent, commission_value=0.1,
         slippage=2, process_orders_on_close=true)

// ═══════════════════════════════════════════════════════════════════════════════════════════
// INPUT PARAMETERS
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Time session filters
time_session_1 = input.session("0700-0900", "Morning Session (7-9 AM)", group="Time Windows")
time_session_2 = input.session("1000-1200", "Mid-Day Session (10 AM-12 PM)", group="Time Windows")
time_session_3 = input.session("", "Optional Third Session", group="Time Windows")

// Risk management parameters
risk_multiplier = input.float(4.6, "Take Profit Multiplier", minval=1.0, maxval=10.0, step=0.1, group="Risk Management")
stop_offset = input.int(3, "Stop Loss Offset (bars)", minval=1, maxval=5, group="Risk Management")
risk_per_trade = input.float(2.0, "Risk Per Trade (%)", minval=0.5, maxval=10.0, step=0.5, group="Risk Management")

// Strategy settings
allow_long = input.bool(true, "Allow Long Positions", group="Strategy Settings")
allow_short = input.bool(true, "Allow Short Positions", group="Strategy Settings")
close_daily = input.bool(true, "Close Positions at 1 PM PT", group="Strategy Settings")

// Visual settings
show_paint_levels = input.bool(true, "Show Paint Bar Levels", group="Display Options")
show_stop_target = input.bool(true, "Show Stop/Target Levels", group="Display Options")
show_entry_signals = input.bool(true, "Show Entry Signals", group="Display Options")

// ═══════════════════════════════════════════════════════════════════════════════════════════
// PAINT BAR DETECTION
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Paint bar conditions
bull_paint_condition = low > high[2]
bear_paint_condition = high < low[2]

// ═══════════════════════════════════════════════════════════════════════════════════════════
// TIME SESSION MANAGEMENT
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Time session detection
is_time_1 = time(timeframe.period, time_session_1, "America/Los_Angeles")
is_time_2 = time(timeframe.period, time_session_2, "America/Los_Angeles")
is_time_3 = time(timeframe.period, time_session_3, "America/Los_Angeles")

// Combined time window filter
in_time_window = (not na(is_time_1) or not na(is_time_2) or not na(is_time_3)) and 
                 dayofweek != dayofweek.saturday and dayofweek != dayofweek.sunday

// Daily close detection (1 PM Pacific)
close_time = time(timeframe.period, "1300-1301", "America/Los_Angeles")
should_close = close_daily and not na(close_time) and dayofweek != dayofweek.saturday and dayofweek != dayofweek.sunday

// ═══════════════════════════════════════════════════════════════════════════════════════════
// STATE MANAGEMENT VARIABLES
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Bull paint state variables
var float bull_paint_high = na
var float bull_paint_low = na
var float bull_stop_level = na
var float bull_target_level = na
var bool bull_paint_active = false

// Bear paint state variables
var float bear_paint_low = na
var float bear_paint_high = na
var float bear_stop_level = na
var float bear_target_level = na
var bool bear_paint_active = false

// ═══════════════════════════════════════════════════════════════════════════════════════════
// PAINT BAR DETECTION AND LEVEL CALCULATION
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Detect new bull paint bar
if bull_paint_condition and not bull_paint_active and strategy.position_size == 0
    bull_paint_high := high
    bull_paint_low := low
    bull_stop_level := low[stop_offset]
    
    // Calculate take profit level (risk multiplier)
    risk_distance = bull_paint_low - bull_stop_level
    bull_target_level := bull_paint_low + (risk_distance * risk_multiplier)
    
    bull_paint_active := true
    bear_paint_active := false  // Cancel opposing paint

// Detect new bear paint bar
if bear_paint_condition and not bear_paint_active and strategy.position_size == 0
    bear_paint_low := low
    bear_paint_high := high
    bear_stop_level := high[stop_offset]
    
    // Calculate take profit level (risk multiplier)
    risk_distance = bear_stop_level - bear_paint_high
    bear_target_level := bear_paint_high - (risk_distance * risk_multiplier)
    
    bear_paint_active := true
    bull_paint_active := false  // Cancel opposing paint

// ═══════════════════════════════════════════════════════════════════════════════════════════
// ENTRY CONDITIONS (3 REASONS: LOCATION, MOMENTUM, STRUCTURE)
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Long entry conditions
long_location = in_time_window  // Reason 1: Location (time window)
long_momentum = bull_paint_active  // Reason 2: Momentum (paint bar directional bias)
long_structure = close > bull_paint_low and close < bull_paint_high and low <= bull_paint_low  // Reason 3: Structure (price re-entry)
long_filter = strategy.position_size == 0 and allow_long  // Position filter

long_entry_condition = long_location and long_momentum and long_structure and long_filter

// Short entry conditions
short_location = in_time_window  // Reason 1: Location (time window)
short_momentum = bear_paint_active  // Reason 2: Momentum (paint bar directional bias)
short_structure = close < bear_paint_high and close > bear_paint_low and high >= bear_paint_high  // Reason 3: Structure (price re-entry)
short_filter = strategy.position_size == 0 and allow_short  // Position filter

short_entry_condition = short_location and short_momentum and short_structure and short_filter

// ═══════════════════════════════════════════════════════════════════════════════════════════
// POSITION SIZING CALCULATION
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Calculate position size based on risk per trade
calculate_position_size(entry_price, stop_price) =>
    account_value = strategy.equity
    risk_amount = account_value * (risk_per_trade / 100)
    stop_distance = math.abs(entry_price - stop_price)
    
    if stop_distance > 0
        position_size = risk_amount / stop_distance
        // Limit position size to account equity
        math.min(position_size, account_value)
    else
        0

// ═══════════════════════════════════════════════════════════════════════════════════════════
// STRATEGY EXECUTION
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Long entry execution
if long_entry_condition
    qty = calculate_position_size(close, bull_stop_level)
    strategy.entry("Long", strategy.long, qty=qty, comment="LONG Entry")
    bull_paint_active := false

// Short entry execution
if short_entry_condition
    qty = calculate_position_size(close, bear_stop_level)
    strategy.entry("Short", strategy.short, qty=qty, comment="SHORT Entry")
    bear_paint_active := false

// ═══════════════════════════════════════════════════════════════════════════════════════════
// EXIT CONDITIONS AND EXECUTION
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Long position exits
if strategy.position_size > 0
    // Stop loss
    strategy.exit("Long Stop", "Long", stop=bull_stop_level, comment="LONG Stop")
    
    // Take profit
    strategy.exit("Long Target", "Long", limit=bull_target_level, comment="LONG Target")
    
    // Daily close
    if should_close
        strategy.close("Long", comment="LONG Daily Close")

// Short position exits
if strategy.position_size < 0
    // Stop loss
    strategy.exit("Short Stop", "Short", stop=bear_stop_level, comment="SHORT Stop")
    
    // Take profit
    strategy.exit("Short Target", "Short", limit=bear_target_level, comment="SHORT Target")
    
    // Daily close
    if should_close
        strategy.close("Short", comment="SHORT Daily Close")

// ═══════════════════════════════════════════════════════════════════════════════════════════
// PAINT BAR CLEANUP (REMOVE STALE PAINT BARS)
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Reset bull paint if price moves too far away or position is closed
if bull_paint_active and (high > bull_paint_high * 1.1 or low < bull_stop_level or strategy.position_size != 0)
    bull_paint_active := false

// Reset bear paint if price moves too far away or position is closed
if bear_paint_active and (low < bear_paint_low * 0.9 or high > bear_stop_level or strategy.position_size != 0)
    bear_paint_active := false

// ═══════════════════════════════════════════════════════════════════════════════════════════
// VISUAL ELEMENTS
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Paint bar coloring
barcolor(bull_paint_condition ? color.green : bear_paint_condition ? color.red : na, offset=-1)

// Entry signal shapes
plotshape(show_entry_signals and long_entry_condition, title="Long Entry Signal", 
          style=shape.triangleup, location=location.belowbar, color=color.lime, 
          size=size.normal, text="LONG")

plotshape(show_entry_signals and short_entry_condition, title="Short Entry Signal", 
          style=shape.triangledown, location=location.abovebar, color=color.red, 
          size=size.normal, text="SHORT")

// Paint bar levels
plot(show_paint_levels and bull_paint_active ? bull_paint_high : na, 
     color=color.new(color.green, 50), style=plot.style_line, linewidth=2, title="Bull Paint High")
plot(show_paint_levels and bull_paint_active ? bull_paint_low : na, 
     color=color.new(color.green, 50), style=plot.style_line, linewidth=2, title="Bull Paint Low")

plot(show_paint_levels and bear_paint_active ? bear_paint_high : na, 
     color=color.new(color.red, 50), style=plot.style_line, linewidth=2, title="Bear Paint High")
plot(show_paint_levels and bear_paint_active ? bear_paint_low : na, 
     color=color.new(color.red, 50), style=plot.style_line, linewidth=2, title="Bear Paint Low")

// Stop and target levels for active positions
plot(show_stop_target and strategy.position_size > 0 ? bull_stop_level : na, 
     color=color.new(color.red, 20), style=plot.style_line, linewidth=3, title="Long Stop")
plot(show_stop_target and strategy.position_size > 0 ? bull_target_level : na, 
     color=color.new(color.blue, 20), style=plot.style_line, linewidth=3, title="Long Target")

plot(show_stop_target and strategy.position_size < 0 ? bear_stop_level : na, 
     color=color.new(color.red, 20), style=plot.style_line, linewidth=3, title="Short Stop")
plot(show_stop_target and strategy.position_size < 0 ? bear_target_level : na, 
     color=color.new(color.blue, 20), style=plot.style_line, linewidth=3, title="Short Target")

// ═══════════════════════════════════════════════════════════════════════════════════════════
// PERFORMANCE METRICS TABLE
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Display strategy performance information
if barstate.islast
    var table perf_table = table.new(position.top_right, 2, 10, bgcolor=color.white, border_width=1)
    
    // Strategy information
    table.cell(perf_table, 0, 0, "Silver Setup Strategy", text_color=color.black, text_size=size.small)
    table.cell(perf_table, 1, 0, "", text_color=color.black, text_size=size.small)
    
    // Current position
    pos_size = strategy.position_size
    pos_text = pos_size > 0 ? "LONG" : pos_size < 0 ? "SHORT" : "FLAT"
    pos_color = pos_size > 0 ? color.green : pos_size < 0 ? color.red : color.gray
    table.cell(perf_table, 0, 1, "Position", text_color=color.black, text_size=size.small)
    table.cell(perf_table, 1, 1, pos_text, text_color=pos_color, text_size=size.small)
    
    // Paint bar status
    table.cell(perf_table, 0, 2, "Bull Paint Active", text_color=color.black, text_size=size.small)
    table.cell(perf_table, 1, 2, bull_paint_active ? "YES" : "NO", 
               text_color=bull_paint_active ? color.green : color.red, text_size=size.small)
    
    table.cell(perf_table, 0, 3, "Bear Paint Active", text_color=color.black, text_size=size.small)
    table.cell(perf_table, 1, 3, bear_paint_active ? "YES" : "NO", 
               text_color=bear_paint_active ? color.green : color.red, text_size=size.small)
    
    // Time window status
    table.cell(perf_table, 0, 4, "In Time Window", text_color=color.black, text_size=size.small)
    table.cell(perf_table, 1, 4, in_time_window ? "YES" : "NO", 
               text_color=in_time_window ? color.green : color.red, text_size=size.small)
    
    // Performance metrics
    table.cell(perf_table, 0, 5, "Total Trades", text_color=color.black, text_size=size.small)
    table.cell(perf_table, 1, 5, str.tostring(strategy.closedtrades, "#"), text_color=color.black, text_size=size.small)
    
    table.cell(perf_table, 0, 6, "Win Rate", text_color=color.black, text_size=size.small)
    win_rate = strategy.closedtrades > 0 ? (strategy.wintrades / strategy.closedtrades) * 100 : 0
    table.cell(perf_table, 1, 6, str.tostring(win_rate, "#.#") + "%", text_color=color.black, text_size=size.small)
    
    table.cell(perf_table, 0, 7, "Profit Factor", text_color=color.black, text_size=size.small)
    pf_text = strategy.grossloss != 0 ? str.tostring(strategy.grossprofit / math.abs(strategy.grossloss), "#.##") : "N/A"
    table.cell(perf_table, 1, 7, pf_text, text_color=color.black, text_size=size.small)
    
    table.cell(perf_table, 0, 8, "Net Profit", text_color=color.black, text_size=size.small)
    net_profit_color = strategy.netprofit > 0 ? color.green : strategy.netprofit < 0 ? color.red : color.gray
    table.cell(perf_table, 1, 8, str.tostring(strategy.netprofit, "#.##"), text_color=net_profit_color, text_size=size.small)
    
    table.cell(perf_table, 0, 9, "Max Drawdown", text_color=color.black, text_size=size.small)
    table.cell(perf_table, 1, 9, str.tostring(strategy.max_drawdown, "#.##"), text_color=color.red, text_size=size.small)

// ═══════════════════════════════════════════════════════════════════════════════════════════
// TRADE ANNOTATION (OPTIONAL)
// ═══════════════════════════════════════════════════════════════════════════════════════════

// Add trade labels with entry/exit information
if strategy.position_size > 0 and strategy.position_size[1] == 0
    label.new(bar_index, low, "LONG\nEntry: " + str.tostring(close, "#.##") + 
              "\nStop: " + str.tostring(bull_stop_level, "#.##") + 
              "\nTarget: " + str.tostring(bull_target_level, "#.##"), 
              color=color.green, style=label.style_label_up, size=size.small)

if strategy.position_size < 0 and strategy.position_size[1] == 0
    label.new(bar_index, high, "SHORT\nEntry: " + str.tostring(close, "#.##") + 
              "\nStop: " + str.tostring(bear_stop_level, "#.##") + 
              "\nTarget: " + str.tostring(bear_target_level, "#.##"), 
              color=color.red, style=label.style_label_down, size=size.small)

// Exit labels
if strategy.position_size == 0 and strategy.position_size[1] > 0
    exit_reason = should_close[1] ? "Daily Close" : high[1] >= bull_target_level ? "Target Hit" : "Stop Hit"
    label.new(bar_index, high, "LONG EXIT\n" + exit_reason + "\nPrice: " + str.tostring(close, "#.##"), 
              color=color.gray, style=label.style_label_down, size=size.small)

if strategy.position_size == 0 and strategy.position_size[1] < 0
    exit_reason = should_close[1] ? "Daily Close" : low[1] <= bear_target_level ? "Target Hit" : "Stop Hit"
    label.new(bar_index, low, "SHORT EXIT\n" + exit_reason + "\nPrice: " + str.tostring(close, "#.##"), 
              color=color.gray, style=label.style_label_up, size=size.small)

Overview

Silver Setup Strategy detects candles whose low is above the high from two bars earlier, or the mirror case, and trades only inside up to three user-set sessions on weekdays. Inputs set the take profit multiplier, stop offset in bars, a risk per trade percentage, long or short permission and an optional close of open positions at 1 PM Pacific. Commission and slippage are assumed in the strategy settings. It draws on the price chart.

Details

Published by

GreyssonEnterprises on GitHub

Code credit

trading-setups, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Sessions & time, Support & resistance

Markets

Any symbol

Timeframes

M15-H1

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.

Settings

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

SettingTypeDefaultVariable
Morning Session (7-9 AM)session0700-0900time_session_1
Mid-Day Session (10 AM-12 PM)session1000-1200time_session_2
Optional Third Sessionsessiontime_session_3
Take Profit Multiplierfloat4.6risk_multiplier
Stop Loss Offset (bars)int3stop_offset
Risk Per Trade (%)float2.0risk_per_trade
Allow Long Positionsbooltrueallow_long
Allow Short Positionsbooltrueallow_short
Close Positions at 1 PM PTbooltrueclose_daily
Show Paint Bar Levelsbooltrueshow_paint_levels
Show Stop/Target Levelsbooltrueshow_stop_target
Show Entry Signalsbooltrueshow_entry_signals
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

Daily Bias + FVG Strategy

by TradersPost
218 stars

This overlay strategy plots previous-day high and low, the daily open, and fair value gap zones on the price chart. It takes entries on a selectable timeframe when the FVG requirement and an optional session window allow them, then uses an ATR or fixed pip sto

Strategy v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Daily Bias + FVG Strategy
106 stars

This script monitors opening gap conditions and breakout behavior relative to the first candle's range across up to twenty configurable stock tickers. It detects whether following bars remain inside the opening range before breaking out, displaying the status

Strategy v4 Screeners & dashboardsBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 1St Bar GAP+BkOut Screener v2 by RM

ATOM 1m scalp HK

by dearvn
43 stars

This overlay strategy targets one-minute ATOM scalps. It tracks pivot highs and lows as resistance and support, compares a three-period EMA with a multi-stage smoothed close, and flags long or short when price crosses that curve in the matching direction. Dail

Strategy v5 ScalpingSupport & resistance Repaints
Updated 2 years ago · None stated GitHub repository of ATOM 1m scalp HK

P404 Smoke

by Musyimi97
16 stars

P404 Smoke is a price-chart strategy that sequences an optional higher-timeframe EMA bias, a liquidity range from recent pivots, a sweep of buy-side or sell-side liquidity, and a market structure shift within a set bar window. Comments state it then looks for

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 6 months ago · MIT GitHub repository of P404 Smoke

Fibonacci strategy

by JoelPasapera
11 stars

This strategy plots a Fibonacci retracement of the previous day's high-low range on the price chart. It places a single long limit order at that level when the bar hour matches the chosen entry hour and the close is below the level. Position size follows the l

Strategy v6 Support & resistanceSessions & time
Updated 5 months ago · Apache-2.0 GitHub repository of Fibonacci strategy

1-Min Gold Taylor Technique

by eddiebelaval
7 stars

This intraday strategy implements session-based trading rules tailored for gold on short timeframes. It tracks the Asian session price range, VWAP, 20-period EMA, and previous day high and low levels to identify liquidity sweeps during London and New York trad

Strategy v6 Sessions & timeSupport & resistance
Updated 3 months ago · None stated GitHub repository of 1-Min Gold Taylor Technique

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