Niklaus

Alpha strategy - simple version

This Strategy goes long when Sharpe Ratio is > 1 and Alpha against the S&P500 is generated. It exits when conditions break away. en.wikipedia.org/wiki/Alpha_(finance). Use on daily or 5min.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
strategy("Alpha strategy - simple version", overlay=true)

//by NIKLAUS
//USE ON DAILY TIMEFRAME TO DETECT MOMO STOCKS & ETFs AND TRADE THEM
//USE ON 5MIN CHART FOR INTRADAY USAGE
//examples to try this on: GER30, NAS100, JPN225, AAPL, IBB, TSLA, FB, etc.

//This Strategy goes long when Sharpe Ratio is > 1 and Alpha against the S&P500 is generated. It exits when conditions break away.

//https://en.wikipedia.org/wiki/Alpha_(finance)
//------------------------------------------------------------------------------------------------------------------------------------
//Alpha is a measure of the active return on an investment, the performance of that investment compared to a suitable market index. 
//An alpha of 1% means the investment's return on investment over a selected period of time was 1% better than the market during that same period, 
//an alpha of -1 means the investment underperformed the market. 
//Alpha is one of the five key measures in modern portfolio theory: alpha, beta, standard deviation, R-squared and the Sharpe ratio.


//simplified sharpe
src = ohlc4, len = input(180, title = "Sharpe/Alpha/Beta Period")
pc = ((src - src[len])/src)
std = stdev(src,len)
stdaspercent = std/src
sharpe = pc/stdaspercent


//alpha
sym = "SPX500", res=period, src2 = close
ovr = security(sym, res, src2)

ret = ((close - close[1])/close)
retb = ((ovr - ovr[1])/ovr)
secd = stdev(ret, len), mktd = stdev(retb, len)
Beta = correlation(ret, retb, len) * secd / mktd

ret2 = ((close - close[len])/close)
retb2 = ((ovr - ovr[len])/ovr)

alpha = ret2 - retb2*Beta
//plot(Beta, color=green, style=area, transp=40)


smatrig = input(title="Sensitivity", type=integer, defval=2, minval=1, maxval=3) 
bgcolor (sma(sharpe,len/smatrig) > 1 and sma(alpha,len/smatrig) > 0 ? green : red, transp=70)

if (close > open) and (sma(sharpe,len/smatrig) > 1) and (sma(alpha,len/smatrig) > 0)
    strategy.entry("Alpha", strategy.long)
strategy.close("Alpha", when = (sma(sharpe,len/smatrig) < 1) or (sma(alpha,len/smatrig) < 0))