This code snippet below is a quick and dirty follow up to some statistical analysis performed on the FTSE 100. It showed that over the long run, (since 1995) going long on a Friday appeared to have a statistical edge (53%). As a bit of fun, I wanted to create a quick pine script backtest to test this and see if it is possible to profit from it. After all, the index might finish up 53% of the time, but that doesn’t mean one can profit from it. For a start, some of those winners may have only closed a fraction higher leaving the losers to eat our pie. Furthermore, overnight futures action might mean the index is well up before the open. If that was the case, it would be hard to profit from the strategy unless you are a spread bettor or futures trader. Finally, execution style might also prevent one from profiting. E.g. stops that are too tight.
A link to the original article is here: Statistical Analysis: FTSE 100 Period Trends
The code in this post is based on the following assumptions:
- The strategy will be traded at the open. This should allow the strategy to be traded with ETF’s.
- We have access to FTSE futures, CFD or spread betting data. In other words, we have access to Index data pre-market and post-market. Note: For the purposes of this post, Oanda’s UK100 CFD data was used.
- The script must run on the 4H time frame…..Why? It is a quick and dirty implementation and it relies on entering a long position on the 4H bar before the market opens. This way the position will enter at the open of the market. (Since positions are always opening on the bar following an entry signal).
A copy of the code can be found on Tradingview here: https://www.tradingview.com/script/EMbHfcnn-FTSE-Fridays/
strategy("FTSE Fridays", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Author: Backtest-Rookies.com
// Version: 1.0
// Description: A simple backtest to
// - This strategy is intended to be run on a 4H timeframe only. It uses some
// the prior 4H bar to enter. This in turn allows the strategy to go long at
// the open.
// - The strategy is inspired by some statistical analysis that showed in most
// years going long on Fridays only has an edge.
// - 4H low stop takes the low of the 4H prior to the market opening to use as
// a stop
// - Daily ATR stop, sets the stop at the close - daily ATR value.
// Create General Strategy Inputs
st_yr_inp = input(defval=2012, title='Backtest Start Year', type=integer)
st_mn_inp = input(defval=01, title='Backtest Start Month', type=integer)
st_dy_inp = input(defval=01, title='Backtest Start Day', type=integer)
en_yr_inp = input(defval=2025, title='Backtest End Year', type=integer)
en_mn_inp = input(defval=01, title='Backtest End Month', type=integer)
en_dy_inp = input(defval=01, title='Backtest End Day', type=integer)
stp_inp = input(defval="None", title="Type of Stop to use", options=["None","4H Low", "Daily ATR"] )
stp_atr_inp = input(defval=7, title='Period used for ATR stop', type=integer, minval=1)
// Set start and end dates for backtest
start = timestamp(st_yr_inp, st_mn_inp, st_dy_inp,00,00)
end = timestamp(en_yr_inp, en_mn_inp, en_dy_inp,00,00)
// Setup Daily ATR
atr_ind = security(tickerid, "D", atr(stp_atr_inp))
pre_mkt = time(period, "0400-0800")
mkt_hrs = time(period, "0800-1600")
eod = time(period, "1200-1600")
// go long in pre_mkt so next bar enters at the open.
long_condition = dayofweek == 6 and
time >= start and
time <= end
strategy.entry("Long Entry", strategy.long)
if strategy.position_size <= 0 and stp_inp == "4H Low" // Less than as in both direction strat - Could be long before switching
stop = low // Stop at low of the pre-market
strategy.exit('4H Stop Exit', "Long Entry", stop=stop)
if strategy.position_size <= 0 and stp_inp == "Daily ATR"
stop = close - atr_ind
strategy.exit('ATR Stop Exit', "Long Entry", stop=stop)
strategy.close_all(eod) // so will close at 16:00 (next bar on 4 hour time frame)
// Testing & Debug Plots
plot(dayofweek == 6 ? 1 : 0)
plot(dayofweek == 6 and pre_mkt ? 1 : 0, color=red)
The two parameters in the code which might benefit from further explanation are:
- 4H low Stop Loss: This takes the low of the 4H prior to the market. I was interested to see if the pre-market lows would often be hit during open hours for winning days. If not, the stop should limit losses on days which go against us.
- Daily ATR stop: This sets the stop at the close – daily ATR value. The idea here is to give more room for the trade to breathe but also limit losses to one average days worth of movement.
Over the last 5 years (2012 to Dec 2017), the default settings produce a return of 15% with a Max drawdown of 7% and the largest losing trade coming in at just 2%. If you add a 4H stop loss, the return is reduced (to 13%) but so is the max drawdown and largest losing trade (4.4% max drawdown and 0.7% largest losing trade). If an ATR based stop is used with a lookback period of 7, the net profit increases to 16%. However, so do the max drawdown and largest loser. (6.56% and 1.69%).
Note that these results are subject to change as December plays out.
So overall, not a fantastic result to only return about 3% a year. However, when you consider the amount of time in the market to achieve those returns and consider that you never need to hold onto overnight risk, it becomes a little better in my opinion.
The main takeaway for me, however, is a reminder that simplicity works. We often find ourselves in the pursuit of complexity. Working hard and spending countless hours developing a “smart” strategy. Hard work must payoff right? It has to…We have this message ingrained in us from a young age. While I am sure no one will argue that in general, the path to bettering ourselves involves hard work, it doesn’t always work that way in the financial markets. So take a step back to the basics once in a while in order to see the woods for the trees.