Fibonacci Trend Reversals System
Fibonacci Trend Reversals System
// =========================================
// Input Groups
// =========================================
string rsi_group = "RSI"
string main_group = "Fib Sensitivity"
string atr_sl_finder_group = "ATR SL Finder"
string trade_execution_group = "Strategy Execution"
// =========================================
// Fibonacci Retracement Trend Reversal (AKA [IMBA]Algo by @IMBA_TRADER)
// =========================================
sensitivity_input = input.float(title = 'Sensitive', step = 0.1, defval = 18, group
= main_group)
var bool is_long_trend_started = false
var bool is_short_trend_started = false
var bool is_trend_change = na
var bool is_long_trend = false
var bool is_short_trend = false
var bool can_long = false
var bool can_short = false
sensitivity = sensitivity_input
sensitivity *= 10
// =========================================
// TSOT | Trend Strength Over Time © federalTacos5392b
// =========================================
countBull =
(trendBull1 ? 1 : 0) +
(trendBull2 ? 1 : 0) +
(trendBull3 ? 1 : 0) +
(trendBull4 ? 1 : 0) +
(trendBull5 ? 1 : 0) +
(trendBull6 ? 1 : 0) +
(trendBull7 ? 1 : 0) +
(trendBull8 ? 1 : 0) +
(trendBull9 ? 1 : 0) +
(trendBull10 ? 1 : 0)
countBear =
(trendBear1 ? 1 : 0) +
(trendBear2 ? 1 : 0) +
(trendBear3 ? 1 : 0) +
(trendBear4 ? 1 : 0) +
(trendBear5 ? 1 : 0) +
(trendBear6 ? 1 : 0) +
(trendBear7 ? 1 : 0) +
(trendBear8 ? 1 : 0) +
(trendBear9 ? 1 : 0) +
(trendBear10 ? 1 : 0)
// CAN LONG/SHORT
can_long := close >= imba_trend_line and close >= fib_236 and not is_long_trend and
tsot_bullish
can_short := close <= imba_trend_line and close <= fib_786 and not is_short_trend
and tsot_bearish
if can_long
is_long_trend := true
is_short_trend := false
is_long_trend_started := is_long_trend_started ? false : true
else if can_short
is_short_trend := true
is_long_trend := false
is_short_trend_started := is_short_trend_started ? false : true
else
is_trend_change := false
can_long := false
can_short := false
is_short_trend_started := false
is_long_trend_started := false
// =========================================
// ATR SL Finder © Veryfid
// =========================================
atrlength = input.int(title='Length', defval=14, minval=1, group =
atr_sl_finder_group)
smoothing = input.string(title='Smoothing', defval='RMA', options=['RMA', 'SMA',
'EMA', 'WMA'], group = atr_sl_finder_group)
m = input(3.5, 'Multiplier', group = atr_sl_finder_group)
src1 = high
src2 = low
ma_function(source, length) =>
if smoothing == 'RMA'
ta.rma(source, length)
else
if smoothing == 'SMA'
ta.sma(source, length)
else
if smoothing == 'EMA'
ta.ema(source, length)
else
ta.wma(source, length)
// =========================================
// Strategy Execution © nioboi (yours truly)
// =========================================
// This allows flexibility so we can allow and set what direction we want our
strategy to only execute upon.
tradeDirection = input.string("Both", "Trade Direction", ["Long Only", "Short
Only", "Both"], group = trade_execution_group, tooltip = "Select if you want this
strategy to run only Long or Only Short positions, or Both")
// Long Entries
-----------------------------------------------------------------------------------
------------------------------------------------------
if enterLong
entryPrice_long := close
// set entry price for exit calculation
sl_long := x2
// set SL from the ATR
risk = entryPrice_long - sl_long
// Calculate the Risk
tp1_long := entryPrice_long + ((risk_reward_ratio * risk) / 2)
// set the first TP by dividing the entire TP to 2 using risk_reward_ratio
tp2_long := entryPrice_long + (risk_reward_ratio * risk)
// set the 2nd TP
breakEven_long := entryPrice_long + (entryPrice_long * 0.002)
// set the break even to be few pips or 0.20% above the entry to compensate for
market fees and still result positive
strategy.entry("Long", strategy.long)
// create the entry
if not partialTp
// partial TP Management enabled?
strategy.exit("Exit Long", "Long", limit = tp2_long, stop = sl_long)
// if not enabled then we create exit triggers as usual in one order
else
strategy.exit("TP 1 Long", "Long", limit = tp1_long, qty_percent = 50)
// else, we set 1 exit order to be the first TP and closing half of our position
strategy.exit("TP 2 Long", "Long", limit = tp2_long, qty_percent = 50)
// we also set the 2nd TP to close the other remaining half
firstTPHit_long := false
// ensure global variable flag for first TP Hit is set to false
inLongPosition := true
// engage flag to notify below code we are in long position
//
-----------------------------------------------------------------------------------
------------------------------------------------------------------
// Short Entries
-----------------------------------------------------------------------------------
----------------------------------------------------
if enterShort
entryPrice_short := close
// set entry price for exit calculation
sl_short := x
// set SL from the ATR
risk = sl_short - entryPrice_short
// Calculate the Risk
tp1_short := entryPrice_short - ((risk_reward_ratio * risk)/2)
// set the first TP by dividing the entire TP to 2 using risk_reward_ratio
tp2_short := entryPrice_short - (risk_reward_ratio * risk)
// set the 2nd TP
breakEven_short := entryPrice_short - (entryPrice_short * 0.002)
// set the break even to be few pips or 0.20% above the entry to compensate for
market fees and still result positive
strategy.entry("Short", strategy.short)
// create the entry
if not partialTp
// partial TP Management enabled?
strategy.exit("Exit Short", "Short", limit = tp2_short, stop = sl_short)
// if not enabled then we create exit triggers as usual in one order
else
strategy.exit("TP 1 Short", "Short", limit = tp1_short, qty_percent = 50)
// else, we set 1 exit order to be the first TP and closing half of our position
strategy.exit("TP 2 Short", "Short", limit = tp2_short, qty_percent = 50)
// we also set the 2nd TP to close the other remaining half
firstTPHit_short := false
// ensure global variable flag for first TP Hit is set to false
inShortPosition := true
// engage flag to notify below code we are in long position
//
-----------------------------------------------------------------------------------
-----------------------------------------------------------------
// =========================================
// Entry Visuals © nioboi (yours truly)
// =========================================
// SL and TP Lines
longEntryMarker = plot(plotMarkers_long ? entryPrice_long : na, "Entry Marker L",
color = na)
longSLMarker = plot(plotMarkers_long ? sl_long : na, "SL Marker L", color =
#ff000050, linewidth = 1, style = plot.style_linebr)
longTP1Marker = plot(plotMarkers_long ? tp1_long : na, "TP1 Marker L", color =
#00ff0850, linewidth = 1, style = plot.style_linebr)
longTP2Marker = plot(plotMarkers_long ? tp2_long : na, "TP2 Marker L", color =
#1100ff50, linewidth = 1, style = plot.style_linebr)
// SL and TP Fills
fill(plot1 = longEntryMarker, plot2 = longSLMarker, title = "Long SL BG Fill",
color = #b2283320)
fill(plot1 = longEntryMarker, plot2 = longTP2Marker, title = "Long TP BG Fill",
color = #08998120)
fill(plot1 = shortEntryMarker, plot2 = shortSLMarker, title = "Short SL BG Fill",
color = #b2283320)
fill(plot1 = shortEntryMarker, plot2 = shortTP2Marker, title = "Short TP BG Fill",
color = #08998120)