A strategy that shades a chosen trading session on the price chart and looks for candles whose low sits above the high from two bars back, or whose high sits below the low from two bars back.
//@version=5
strategy("Silverstrat", overlay=true)
// Time constraints
// ### Trading Session
ts = input.bool(true, title="Show Trade Session")
tz = input.string("America/New_York", title="Timezone", options=["Asia/Tokyo", "Europe/London", "America/New_York"])
label = input.string("CME Open", title="Label", tooltip="For easy identification")
startHour = input.int(9, title="analysis Start hour")
startMinute = input.int(0, title="analysis Start minute")
startHour2 = input.int(9, title="Session Start hour")
startMinute2 = input.int(30, title="Session Start minute")
endHour2 = input.int(21, title="Session End hour")
endMinute2 = input.int(0, title="Session End minute")
rangeColor = input.color(color.new(color.green, 90), title="Color")
showMon = input.bool(true, title="Monday")
showTue = input.bool(true, title="Tuesday")
showWed = input.bool(true, title="Wednesday")
showThu = input.bool(true, title="Thursday")
showFri = input.bool(true, title="Friday")
showSat = input.bool(false,title="Saturday")
showSun = input.bool(false,title="Sunday")
tzYear = year(time, tz)
tzMonth = month(time, tz)
tzDay = dayofmonth(time, tz)
tzDayOfWeek = dayofweek(time, tz)
startTime = timestamp(tz, tzYear, tzMonth, tzDay, startHour, startMinute)
endTime = timestamp(tz, tzYear, tzMonth, tzDay, endHour2, endMinute2)
is_time_ok = if startTime <= time and time <= endTime and ts
if tzDayOfWeek == dayofweek.monday and showMon
true
else if tzDayOfWeek == dayofweek.tuesday and showTue
true
else if tzDayOfWeek == dayofweek.wednesday and showWed
true
else if tzDayOfWeek == dayofweek.thursday and showThu
true
else if tzDayOfWeek == dayofweek.friday and showFri
true
else if tzDayOfWeek == dayofweek.saturday and showSat
true
else if tzDayOfWeek == dayofweek.sunday and showSun
true
else
false
else
false
bgcolor(color=is_time_ok ? rangeColor : na, title = "Session Background")
// Calculate the range from 12 AM to 6 AM, the "Market Session"
var float rangeHigh = na
var float rangeLow = na
if (hour(time) == 0 and minute(time) == 0)
rangeHigh := high
rangeLow := low
if (hour(time) < 6)
rangeHigh := math.max(rangeHigh, high)
rangeLow := math.min(rangeLow, low)
// Calculate 50% levels
float midRange = (rangeHigh + rangeLow) / 2
// Candle pattern
BullPaint = low > high[2] and is_time_ok
BearPaint = high < low[2] and is_time_ok
barcolor(BullPaint ? color.green : BearPaint ? color.red : na, offset=-1)
// Trade setup variables
var float bullEntryPrice = na
var float bullStopLoss = na
var float bullTakeProfit = na
var float bearEntryPrice = na
var float bearStopLoss = na
var float bearTakeProfit = na
// Detect trade setup
if BullPaint and is_time_ok
bullEntryPrice := (high[0] + low[2]) / 2
bullStopLoss := low[0]
bullTakeProfit := bullEntryPrice + 2 * (bullEntryPrice - bullStopLoss)
if BearPaint and is_time_ok
bearEntryPrice := (low[0] + high[2]) / 2
bearStopLoss := high[0]
bearTakeProfit := bearEntryPrice - 2 * (bearStopLoss - bearEntryPrice)
// Execute trade when price reaches entry level
if not na(bullEntryPrice) and close[1] <= bullEntryPrice and close => bullEntryPrice
strategy.entry("Bullish Entry", strategy.long)
strategy.exit("Bullish TP/SL", "Bullish Entry", stop=bullStopLoss, limit=bullTakeProfit)
// Reset trade setup
bullEntryPrice := na
bullStopLoss := na
bullTakeProfit := na
if not na(bearEntryPrice) and close[1] >= bearEntryPrice and close =< bearEntryPrice
strategy.entry("Bearish Entry", strategy.short)
strategy.exit("Bearish TP/SL", "Bearish Entry", stop=bearStopLoss, limit=bearTakeProfit)
// Reset trade setup
bearEntryPrice := na
bearStopLoss := na
bearTakeProfit := na
Overview
Entry is placed at the midpoint of the gap, the stop at the signal candle extreme, and the target at twice the risk. Inputs set the timezone, session hours and active weekdays. It also tracks an overnight range midpoint.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Show Trade Session
bool
true
ts
Timezone
string
America/New_York
tz
Label
string
CME Open
label
analysis Start hour
int
9
startHour
analysis Start minute
int
0
startMinute
Session Start hour
int
9
startHour2
Session Start minute
int
30
startMinute2
Session End hour
int
21
endHour2
Session End minute
int
0
endMinute2
Color
color
color.new(color.green, 90)
rangeColor
Monday
bool
true
showMon
Tuesday
bool
true
showTue
Show all 17 settings
Setting
Type
Default
Variable
Wednesday
bool
true
showWed
Thursday
bool
true
showThu
Friday
bool
true
showFri
Saturday
bool
false
showSat
Sunday
bool
false
showSun
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.
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
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
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
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
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
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