TradingView
everget
7 mar 2020 14:49

Return on Investment (ROI) 

Apple Inc.NASDAQ

Beskrivning

Return on Investment (ROI) is a performance measure used to evaluate the efficiency of an investment in a particular asset.

This tool provides a %-based ROI that can be calculated starting from a specific date or across the entire history of an instrument.

Don't forget to toss a coin to your witcher (see the requisites below)
Kommentarer
formy76
Can I have the code? Or return adjusted for the risk, example (close-open(...) / atr), or compare return to benchmark. Please. Thanks.
everget
@formy76, I will update the code and make it open-source soon
formy76
@everget, thanks
formy76
@everget, //@version=4
study("compare")
baseSymbol = input(title="base symbol", type=input.symbol, defval="AMEX:SPY")
period = input(title="period", type=input.integer, defval=12, minval=1)
baseSymbolClose = security(baseSymbol,timeframe.period, close)

chartReturn = (close[0] - close[period])/close[period]*100
baseSymbolReturn = (baseSymbolClose[0] - baseSymbolClose[period])/baseSymbolClose[period]*100

chartReturn2 = (close - close[1])/close[1]
chartStdev = stdev(chartReturn2, period)
baseSymbolReturn2 = (baseSymbolClose - baseSymbolClose[1])/baseSymbolClose[1]
baseSymbolStdev = stdev(baseSymbolReturn2, period)
chartSharpe = (chartReturn/chartStdev)/100
baseSymbolSharpe = (baseSymbolReturn/baseSymbolStdev)/100

// Plot colors using macd colors
colGrowAbove = #26A69A
colGrowBelow = #FFCDD2
colFallAbove = #B2DFDB
colFallBelow = #EF5350
chartReturnColor = #0094ff
baseSymbolReturnColor = #ff6a00

hist = (chartSharpe - baseSymbolSharpe)
plot(hist, title="difference", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? colGrowAbove : colFallAbove) : (hist[1] < hist ? colGrowBelow : colFallBelow) ))
plot(chartReturn, title="chart", color=chartReturnColor, transp=0)
plot(baseSymbolReturn, title="base", color=baseSymbolReturnColor, transp=0)

my study have lookback, I would like to insert from a date like roi instead, is it possible?
Texas_Texas
Would love to see the code on this one. Thanks for posting either way !
Mer