0% found this document useful (0 votes)
432 views2 pages

FVG Strategy Limit

This strategy script defines a trading strategy that uses a Fibonacci-based volume indicator (FVG) to generate signals. It will enter long positions when the low is below the FVG bullish trigger and short positions when the high is above the FVG bearish trigger, within the defined trading session. Stop losses and take profits are also included. The strategy is backtested between specified start and end times.
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)
432 views2 pages

FVG Strategy Limit

This strategy script defines a trading strategy that uses a Fibonacci-based volume indicator (FVG) to generate signals. It will enter long positions when the low is below the FVG bullish trigger and short positions when the high is above the FVG bearish trigger, within the defined trading session. Stop losses and take profits are also included. The strategy is backtested between specified start and end times.
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/ 2

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

0 at
https://mozilla.org/MPL/2.0/
// © Hiubris_Indicators

//@version=5
strategy(title = "FVG Strategy", overlay = true, default_qty_value = 100,
initial_capital=100000,default_qty_type=strategy.percent_of_equity, pyramiding=0,
process_orders_on_close=true)

tz = input.string("UTC-4", title="TimeZone")

// NEWDAY
is_newbar(res) =>
t = time(res)
not na(t) and (na(t[1]) or t > t[1])
newDay = is_newbar("D")

// Trading Session
in_session(sess) =>
t = time(timeframe.period, sess, tz)
r = na(t) ? false : true
r

sessionfvg = input.session("1000-1100", title="FVG Time")+":1234567"

session = input.session("1000-1555", title="Trading Time")+":1234567"


closeAll = true // input(false, title='Close Trades in the above Session')

trading_session_filter = in_session(session)
insessionfvg = in_session(sessionfvg)
bgcolor(trading_session_filter?color.new(color.green , 90):na)

bull_fvg = low>high[2] and insessionfvg


bear_fvg = high<low[2] and insessionfvg

long = low < ta.valuewhen(bull_fvg, low , 0) and trading_session_filter


short= high> ta.valuewhen(bear_fvg, high, 0) and trading_session_filter

sl_long = ta.lowest(3)
sl_short= ta.highest(3)

tp = input.float(2.0, title="Take Profit R:R", minval=0, step=0.1)


tp_long = low +math.abs(low -sl_long )*tp
tp_short = high-math.abs(high-sl_short)*tp

//plotshape(bull_fvg and trading_session_filter and strategy.opentrades==0,


textcolor=color.lime, color=color.lime, style=shape.triangleup , title="Buy" ,
text="FVG", location=location.belowbar, offset=0, size=size.tiny)
//plotshape(bear_fvg and trading_session_filter and strategy.opentrades==0,
textcolor=color.red, color=color.red, style=shape.triangledown, title="Sell",
text="FVG", location=location.abovebar, offset=0, size=size.tiny)
barcolor(bull_fvg and trading_session_filter and strategy.opentrades==0?
color.yellow : bear_fvg and trading_session_filter and strategy.opentrades==0?
color.fuchsia : na, title='FVG')

nr = str.tostring(bar_index)

// Strategy Backtest Limiting Algorithm


i_startTime = input.time(defval = timestamp("01 Sep 2002 13:30 +0000"), title =
"Backtesting Start Time")
i_endTime = input.time(defval = timestamp("30 Sep 2099 19:30 +0000"), title =
"Backtesting End Time" )
timeCond = (time > i_startTime) and (time < i_endTime)

equity = strategy.initial_capital + strategy.netprofit

trades = 0
trades:= newDay? 0 : trades[1]

if (strategy.opentrades>0 or strategy.closedtrades>strategy.closedtrades[1]) and


trades==0
trades := 1

if bull_fvg and trading_session_filter and equity>0 and timeCond and


strategy.opentrades==0 and trades==0
strategy.entry("long", strategy.long , comment='Long', limit=low)
strategy.exit("SL/TPL", from_entry = "long" , stop=sl_long , limit=tp_long ,
comment_profit ='TP', comment_loss='SL')

if bear_fvg and trading_session_filter and equity>0 and timeCond and


strategy.opentrades==0 and trades==0
strategy.entry("short", strategy.short, comment='Short', limit=high)
strategy.exit("SL/TPS", from_entry = "short", stop=sl_short, limit=tp_short,
comment_profit ='TP', comment_loss='SL')

if not trading_session_filter
strategy.cancel("long")
strategy.cancel("short")
if closeAll
strategy.close_all(comment='Exit')

You might also like