Indicator · Pine Script v6 · On the chart

Forex Trading Strategy

by AmjadSaidam· code credited to Amjad_S

Forex Trading Strategy is an overlay indicator designed for multi-timeframe session analysis on forex markets.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code194
Settings6inputs
LicenceMIT
Last update4 weeks ago24 Sep 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 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

194 lines of Pine Script v6 from pine/session_breakout_pine.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

session_breakout_pine.txt
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Amjad_S
//@version=6

//+------------------------------------------------------------------+
//                                                         INDICATOR |
//<<+----------------------------------------------------------------+{
indicator('FOREX TRADING STRATEGY', 
     overlay = true)

//+------------------------------------------------------------------+}
//                                                            INPUTS |
//<<+----------------------------------------------------------------+{
// candle body threshold ---------------------------------------------
float candle_thresh = input(0.1, title = '1H Body to Wick Ratio')

// higher timeframes -------------------------------------------------
bool i_s1h = input(true, title = '1H')
bool i_s4h = input(true, title = '4H')
bool i_s8h = input(true, title = '8H')

// sl and tp 
atr = ta.atr(14)
float atr_mult = input(3.0, title = 'ATR SL MULTIPLIER')
float rr = input(1.0, title = 'RISK REWARD')

//>>+----------------------------------------------------------------+}
//                                           TRAILING SESSION PRINTS |
//<<+----------------------------------------------------------------+{
print_htf(t_true, t) =>

    var session_open = float(na)
    var session_high = float(na)
    var session_low = float(na)
    
    var start_high = float(na)
    var start_low = float(na)

    var higher_timeframe_close = float(na)

    is_new_session = ta.change(source = time(timeframe = t)) != 0 // non zero when first bar of timeframe
    if t_true
        // first bar of new session 
        if is_new_session
            start_high := high 
            start_low := low
            
            session_open := open 
            
            session_high := na
            session_low := na
        // session bars 
        else
            session_high := na(session_high) ? start_high : math.max(session_high, high)
            session_low := na(session_low) ? start_low : math.min(session_low, low) 
    // signals 
    else
        na
    
    [session_open, session_high, session_low] 

min_1h = 60 
min_4h = min_1h * 4
min_8h = min_1h * 8

higher_time_frames() =>
    [htf1_o, htf1_h, htf1_l] = print_htf(i_s1h, str.tostring(min_1h))
    [htf2_o, htf2_h, htf2_l] = print_htf(i_s4h, str.tostring(min_4h))
    [htf3_o, htf3_h, htf3_l] = print_htf(i_s8h, str.tostring(min_8h))
    
    [htf1_o, htf1_h, htf1_l,
         htf2_o, htf2_h, htf2_l, 
         htf3_o, htf3_h, htf3_l]

[htf1_o, htf1_h, htf1_l, 
     htf2_o, htf2_h, htf2_l, 
     htf3_o, htf3_h, htf3_l] = higher_time_frames()

//>>+----------------------------------------------------------------+}
//                                                        CONFLUENCE |
//<<+----------------------------------------------------------------+{
// candle body threshold ---------------------------------------------
candle_body_threshold(o, h, l, c, threshold) => 
    body_size = math.abs(o - c)    
    body_wick_ratio = body_size / (h - l)
    body_wick_ratio > threshold ? true : false

valid_candle = candle_body_threshold(htf1_o, htf1_h, htf1_l, close, candle_thresh)

// session overlap ---------------------------------------------------
ctm_time_session(chart_tfm, ses_ ,IANA_) =>
    //+{
    // returns true when timeframe is active, false otherwise
    //+}
    not na(time(chart_tfm, ses_, IANA_)) ? true : false 

// LDN
string TZ_GMT = "Europe/London" // UTC offset + 1:00
GMT = ctm_time_session(timeframe.period, "0800-1630", TZ_GMT)

// NY 
string TZ_NY = "America/New_York" // UTC offset - 4:00
NY = ctm_time_session(timeframe.period, "0930-1600", TZ_NY)

timeframe_cross = GMT or NY

//>>+----------------------------------------------------------------+}
//                                                           SIGNALS |
//<<+----------------------------------------------------------------+{
// long breakout 
long_signal = (close < htf3_o) and (close > htf2_o) and (close > htf1_o) 
long_signal_conf = long_signal and valid_candle and timeframe_cross

// short breakout
short_signal = (close > htf3_o) and (close < htf2_o) and (close < htf1_o) 
short_signal_conf = short_signal and valid_candle and timeframe_cross

// valid trades
long_valid = long_signal_conf[1]
short_valid = short_signal_conf[1]

//>>+----------------------------------------------------------------+}
//                                                           SL & TP |
//<<+----------------------------------------------------------------+{
rd(val) =>
    math.round(val, 5)

sl_tp(order) =>
    side = order == 'long' ? 1 : order == 'short' ? -1 : na 
    sl_dist = atr * atr_mult 
    sl = rd(open - sl_dist * side)
    tp = rd(open + sl_dist * side * rr)
    [sl, tp]

//>>+----------------------------------------------------------------+}
//                                                  VALIDATE SIGNALS |
//<<+----------------------------------------------------------------+{
long_trigger = long_valid and not long_valid[1]
short_trigger = short_valid and not short_valid[1] 

var FirstTrade = bool(na) 

if timeframe.change('D')
    FirstTrade := false 
else
    if long_trigger or short_trigger
        FirstTrade := true

FirstTradeValid = FirstTrade and not FirstTrade[1]

//>>+----------------------------------------------------------------+}
//                                                      SIGNAL PLOTS |
//<<+----------------------------------------------------------------+{
if long_trigger
    [sl, tp] = sl_tp('long')

    label.new(x = bar_index, y = low, 
        text = 'long' + '\n' + 'sl: @' + str.tostring(sl) + '\n' + 'tp: @' + str.tostring(tp), 
        color = FirstTradeValid ? color.green : color.gray,
        style = label.style_label_up)

    if FirstTradeValid
        alert(message = "LONG " + syminfo.ticker + " " + timeframe.period + " ent: @" + str.tostring(close, format.mintick) + 'sl: @' + str.tostring(sl) + 'tp: @' + str.tostring(tp),
             freq = alert.freq_once_per_bar)

if short_trigger
    [sl, tp] = sl_tp('short')

    label.new(x = bar_index, y = high, 
        text = 'short' + '\n' + 'sl: @' + str.tostring(sl) + '\n' + 'tp: @' + str.tostring(tp), 
        color = FirstTradeValid ? color.red : color.gray,
        style = label.style_label_down)

    if FirstTradeValid
        alert(message = "SHORT " + syminfo.ticker + " " + timeframe.period + " ent: @" + str.tostring(close, format.mintick) + 'sl: @' + str.tostring(sl) + 'tp: @' + str.tostring(tp),
             freq = alert.freq_once_per_bar)

//>>+----------------------------------------------------------------+}
//                                                       TIMES PLOTS |
//<<+----------------------------------------------------------------+{
plt_label = 'HIGHER TIME FRAME'

bool is_h1 = timeframe.change(str.tostring(min_1h))
bool is_h4 = timeframe.change(str.tostring(min_4h))
bool is_h8 = timeframe.change(str.tostring(min_8h))

plot(htf1_h, title = plt_label + '1 HIGH', color = color.lime, style = plot.style_linebr)
plot(htf1_l, title = plt_label + '1 LOW', color = color.red, style = plot.style_linebr)

plot(htf2_h, title = plt_label + '2 HIGH', color = color.green, style = plot.style_linebr)
plot(htf2_l, title = plt_label + '3 LOW', color = color.purple, style = plot.style_linebr)

plot(htf3_h, title = plt_label + '3 HIGH', color = color.teal, style = plot.style_linebr)
plot(htf3_l, title = plt_label + '3 LOW', color = color.navy, style = plot.style_linebr)

Overview

Forex Trading Strategy calculates open, high, and low values across 1-hour, 4-hour, and 8-hour timeframes to identify key session ranges. The script filters valid candle bars using a customizable body-to-wick ratio threshold and checks session overlap times. Configurable inputs include higher-timeframe toggles, body ratio thresholds, ATR stop-loss multipliers, and target risk-reward ratios. It displays session structures and breakout setup filters directly on the main price chart.

Details

Published by

AmjadSaidam on GitHub

Code credit

Amjad_S, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance, Sessions & time, Breakout

Markets

Forex

Timeframes

M1-M5, 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.

Topics

cryptocurrencyforexmetatrader5stockstrading-bot

Settings

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

SettingTypeDefaultVariable
1H Body to Wick Ratiofloat0.1candle_thresh
1Hbooltruei_s1h
4Hbooltruei_s4h
8Hbooltruei_s8h
ATR SL MULTIPLIERfloat3.0atr_mult
RISK REWARDfloat1.0rr
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

IB / ORB Live Stats

by TamaraKGreen
46 stars

This overlay indicator marks the New York initial balance and a configurable opening range on the price chart and reports live range statistics in two tables. It builds an IB box for a default 09:30–10:30 ET window, an ORB box from 09:30 for a set number of mi

Indicator v6 Sessions & timeBreakout
Updated 7 weeks ago · None stated GitHub repository of IB / ORB Live Stats

Zen-DAX GX

by Zen-Tim
29 stars

This indicator calculates and plots session ranges and key breakout levels for DAX futures directly on the price chart. It defines the overnight Globex session, the Frankfurt pre-market range, and the regular trading hours open using European timezone settings

Indicator v5 Sessions & timeBreakout
Updated 2 weeks ago · MIT GitHub repository of Zen-DAX GX

ORB Pro - Research-Based ORB

by Mrshahidali420
16 stars

The ORB Pro indicator calculates and plots Opening Range Breakout levels, stop-loss and take-profit zones, signal labels, and an status dashboard on the price chart. Built on academic research, it evaluates trades using an opening-candle direction filter, open

Indicator v6 BreakoutSessions & time Repaints
Updated 3 months ago · None stated GitHub repository of ORB Pro - Research-Based ORB

Nexural ORB

by JasonTeixeira
9 stars

This indicator plots opening range breakout levels across multiple timeframes, including five, fifteen, thirty, and sixty minutes, directly on the price chart. It also displays the session open and overnight high and low levels. The script calculates an openin

Indicator v6 BreakoutSessions & time
Updated 12 days ago · Custom licence GitHub repository of Nexural ORB

FX Market Sessions

by itmakesyousick
7 stars

FX Market Sessions highlights distinct trading sessions, such as London, New York, and Tokyo, directly on the main price chart. It draws background boxes for each active session and optionally plots opening ranges, Fibonacci retracement levels, and session ext

Indicator v5 Sessions & timeSupport & resistance
Updated 3 years ago · None stated GitHub repository of FX Market Sessions

Gold Breakout Trader

by eddiebelaval
7 stars

Plots timed breakout ranges directly on the price chart, designed for gold trading using dollar-based spacing. At scheduled trigger times or recurring two-hour intervals, it creates a central reference box flanked by upper and lower breakout stop lines, follow

Indicator v6 BreakoutSupport & resistance
Updated 3 months ago · None stated GitHub repository of Gold Breakout Trader

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