0% found this document useful (0 votes)
24 views3 pages

FAR Fibonacci RSI Strategy

Uploaded by

nourchip95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

FAR Fibonacci RSI Strategy

Uploaded by

nourchip95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © MohamedYAbdelaziz. 12/12/23 > v5 updates from Lloydy123

// Intraday Trading
// Best used for Short Timeframes [1-30 Minutes]
// If you have any modifications please tell me to update it

//@version=5
strategy(title='Fibonacci + RSI - Strategy', overlay=true,
default_qty_type=strategy.cash, initial_capital=10000, default_qty_value = 100,
commission_value = 0.01, currency=currency.USD)

// Inputs
// Stop Loss %
loss_percent = input.float(title='Stop Loss (%)', minval=0.0, step=0.1, defval=0.5)
/ 100
dynamic_close = input.bool(false, 'Dynamic close (Whenever Fib line crossed?')
// RSI Inputs
len = input.int(title='[RSI] Length', minval=0, step=1, defval=14)
overSold = input(title='[RSI] Over Sold %', defval=30)
overBought = input(title='[RSI] Over Bought %', defval=70)
// Fibonacci Levels
length = input.int(title='[Fibonacci] Length', defval=200, minval=1)
src = input(hlc3, title='[Fibonacci] Source')
mult = input.float(title='[Fibonacci] Multiplier', defval=3.0, minval=0.001,
maxval=50)
level = input(title='[Fibonacci] Level', defval=764)
var bool useCustomRiskInput = input.bool(true, title = 'Use Custom Risk', group =
'Risk Management - Fixed $ stops')
var bool useCompoundingInput = input.bool(false, title = 'Use Compounding Option',
group = 'Risk Management - Fixed $ stops')
var int investCapitalInput = input.int(1000, title = 'Capital Size (USD)', group =
'Risk Management - Fixed $ stops')
var float maxRiskPerTradeInput = input.float(3.0, minval = 0.1, step = 0.1, title =
'% Risk Per Trade', group = 'Risk Management - Fixed $ stops') / 100

// Calculate Fibonacci
basis = ta.vwma(src, length)
dev = mult * ta.stdev(src, length)
fu764 = basis + 0.001 * level * dev
fu1 = basis + 1 * dev
fd764 = basis - 0.001 * level * dev
fd1 = basis - 1 * dev

// Calculate RSI
vrsi = ta.rsi(close, len)
// Custom risk calculation
calcPositionSize(unitRisk) =>
float qty = na
if useCustomRiskInput
totalRisk = (useCompoundingInput ? strategy.equity : investCapitalInput) *
maxRiskPerTradeInput
qty := totalRisk / unitRisk
math.round(qty, 6)
// Calculate the Targets
targetUp = fd764
targetDown = fu764
// Actual Targets
bought = strategy.position_size[0] > strategy.position_size[1]
exit_long = ta.valuewhen(bought, targetUp, 0)
sold = strategy.position_size[0] < strategy.position_size[1]
exit_short = ta.valuewhen(sold, targetDown, 0)
//plot (exit_long, color = color.fuchsia)
// Calculate Stop Losses
stop_long = strategy.position_avg_price * (1 - loss_percent)
stop_short = strategy.position_avg_price * (1 + loss_percent)

// Conditions to Open Trades


openLong = low < fd1 and ta.crossover(vrsi[1], overSold)
openShort = high > fu1 and ta.crossunder(vrsi[1], overBought)

// Conditions to Close Trades


closeLong = high > exit_long
closeShort = low < exit_short

// Plots
plot(basis, color=color.new(color.blue, 0), linewidth=2, title='[Fibonacci Level]
Basis')
plot(fu764, color=color.new(color.white, 0), linewidth=1, title='[Fibonacci Level]
Short Target')
plot(fu1, color=color.new(color.red, 0), linewidth=2, title='[Fibonacci Level]
Top')
plot(fd764, color=color.new(color.white, 0), linewidth=1, title='[Fibonacci Level]
Long Target')
plot(fd1, color=color.new(color.green, 0), linewidth=2, title='[Fibonacci Level]
Bottom')
// Define variables
var float trade_qty = na
var float trade_qty_alert = na
var float longRisk = na
var float shortRisk = na
var float long_tp = na
var float long_sl = na
var float short_tp = na
var float short_sl = na
var float entryPrice = na
// Strategy Orders
if openLong and high < targetUp and strategy.position_size == 0

long_tp := fd764
long_sl := close * (1 - loss_percent)
longRisk := close - long_sl
entryPrice := close
trade_qty := useCustomRiskInput ? calcPositionSize(longRisk) : na
strategy.entry(id='Long', direction=strategy.long, qty = trade_qty) // qty =
trade_qty
strategy.exit(id='Long',from_entry = 'Long', limit=long_tp, stop=long_sl)

if openShort and low > targetDown and strategy.position_size == 0


short_tp := fu764
short_sl := close * (1 + loss_percent)
shortRisk := short_sl - close
entryPrice := close
trade_qty := useCustomRiskInput ? calcPositionSize(shortRisk) : na
strategy.entry(id='Short', direction=strategy.short, qty = trade_qty)
strategy.exit(id='Short', from_entry = 'Short', limit=short_tp,
stop=short_sl)//, qty = trade_qty

strategy.exit(id='Long',from_entry = 'Long', limit=dynamic_close ? fd764 : long_tp,


stop=long_sl)
strategy.exit(id='Short', from_entry = 'Short', limit=dynamic_close ? fu764 :
short_tp, stop=short_sl)
e1 = plot( strategy.position_size != 0 ? entryPrice : na, color=color.rgb(255, 255,
255, 74), style=plot.style_linebr, linewidth=2, title="Entry Price")
sl = plot(strategy.position_size > 0 ? long_sl : strategy.position_size < 0 ?
short_sl : na , title='Stop Loss', color=color.rgb(255, 0, 0),
style=plot.style_linebr)
tp1 = plot( strategy.position_size > 0 ? long_tp : strategy.position_size < 0 ?
short_tp : na, color=color.new(color.green, 0), style=plot.style_linebr,
linewidth=2, title ='TP1 Level')
//ltp = plot(long_tp, color=color.new(color.green, 0), style=plot.style_linebr,
linewidth=2, title ='Long TP')
//stp = plot( short_tp, color=color.new(color.green, 0), style=plot.style_linebr,
linewidth=2, title ='Short TP')

// Exit Orders

You might also like