// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.
0
at [Link]
// © bdrex95
//@version=5
// Rob Reversal Strategy - Official
// Using Rob Reversal Indicator: Original
strategy("Rob Reversal Strategy: Official", shorttitle="Official Rob Rev Strat",
overlay=true)
//--- Session Input ---
sess = [Link](defval = "0830-1315", title="Trading Session")
t = time([Link], sess)
sessionOpen = na(t) ? false : true
flat_time = [Link](defval = "1515-1600", title="Close All Open Trades")
ft = time([Link], flat_time)
flatOpen = na(ft) ? false : true
// Calculate start/end date and time condition
startDate = [Link](timestamp('2018-12-24T[Link]'),group = "ALL STRATEGY
SETTINGS BELOW")
finishDate = [Link](timestamp('2029-02-26T[Link]'),group = "ALL STRATEGY
SETTINGS BELOW")
time_cond = time >= startDate and time <= finishDate
emaColor = [Link]([Link], title="EMA Color")
emaLength = [Link](8, title="EMA Length")
emaInd = [Link](close, emaLength)
rr = input(1.0,"Enter RR",group = "TP/SL CONDITION INPUTS HERE")
sellShapeInput = [Link]("Arrow", title="Sell Entry Shape", options=["Arrow",
"Triangle"])
buyShapeInput = [Link]("Arrow", title="Buy Entry Shape", options=["Arrow",
"Triangle"])
sellShapeOption = switch sellShapeInput
"Arrow" => [Link]
"Triangle" => [Link]
buyShapeOption = switch buyShapeInput
"Arrow" => [Link]
"Triangle" => [Link]
O = open
C = close
H = high
L = low
sellEntry = (C[1] > O[1]) and (C < O) and (H[1] < H) and (C < H[1]) and (C > L[1])
and (L > L[1]) and (C < emaInd) and sessionOpen and time_cond
buyEntry = (C[1] < O[1]) and (C > O) and (H[1] > H) and (L[1] > L) and (C < H[1])
and (C > L[1]) and (C > emaInd) and sessionOpen and time_cond
sellEntry_index = [Link](sellEntry,bar_index,0)
sellEntry_hi = [Link](sellEntry,high,0)
sellEntry_low = [Link](sellEntry,low,0)
buyEntry_index = [Link](buyEntry,bar_index,0)
buyEntry_hi = [Link](buyEntry,high,0)
buyEntry_lo = [Link](buyEntry,low,0)
plotshape(buyEntry, color = [Link], location = [Link], style =
buyShapeOption, size = [Link])
plotshape(sellEntry, color = [Link], location = [Link], style =
sellShapeOption, size = [Link])
plot(emaInd, color=emaColor)
// Risk Management
entry_price_long = (buyEntry_hi + [Link])
entry_price_short = (sellEntry_low - [Link])
long_sl_price = (buyEntry_lo-[Link])
short_sl_price = (sellEntry_hi + [Link])
long_tp_price = ((entry_price_long - long_sl_price)*rr) + entry_price_long
short_tp_price = entry_price_short - ((short_sl_price - entry_price_short)*rr)
long_sl_ticks = (entry_price_long - long_sl_price) / [Link]
short_sl_ticks = (short_sl_price - entry_price_short) / [Link]
long_tp_ticks = (long_tp_price - entry_price_long) / [Link]
short_tp_ticks = (entry_price_short - short_tp_price) / [Link]
// Positions
if (buyEntry)
[Link]("Long", [Link],stop = H + [Link])
if strategy.position_size > 0
[Link]("Long Ex","Long", loss = long_sl_ticks, profit = long_tp_ticks,
comment_loss = "SL Long", comment_profit = "TP Long")
if (sellEntry)
[Link]("Short", [Link],stop = L - [Link])
if strategy.position_size < 0
[Link]("Short Ex","Short",loss = short_sl_ticks, profit =
short_tp_ticks, comment_loss = "SL Short", comment_profit = "TP Short")
// Cancel order if close beyond ema
if (C < emaInd)
[Link]("Long")
if (C > emaInd)
[Link]("Short")
// Go flat at close (for futures funded account)
if strategy.position_size > 0 and flatOpen
strategy.close_all(comment = "EOD Flat")
if strategy.position_size < 0 and flatOpen
strategy.close_all(comment = "EOD Flat")
//END