Sometimes we code a strategy and it looks great but in reality the rewards might be lower than if we invested the money elsewhere. Why put money in a high risk strategy that returns just 3% per annum when you could get 4% somewhere else with lower risk? So I thought that I would code something that could be added to any strategy and so display the previous years overall return in percentage as well as the all time profit to date in percentage as well as a running profit for the current year so far in percentage.
I thought that I would share it just in case it is helpful to anyone else.
capital = 10000
once lastcapital = capital
runningperc = ((strategyprofit - laststrategyprofit) / lastcapital) * 100
if year <> year[1] then
annualreturn = runningperc[1]
laststrategyprofit = strategyprofit
lastcapital = capital + strategyprofit
endif
alltime = (strategyprofit / capital) * 100
graph runningperc coloured(0,128,0) as "Running % Return"
graph annualreturn coloured(0,0,150) as " Last Years Annual % Return"
graph alltime coloured(128,145,150) as "All Time % Return"
[attachment file=93662]
I thought that I would add an average of the annual percentage returns. Not tested but should work.
capital = 10000
once lastcapital = capital
runningperc = ((strategyprofit - laststrategyprofit) / lastcapital) * 100
if year <> year[1] then
annualreturn = runningperc[1]
laststrategyprofit = strategyprofit
lastcapital = capital + strategyprofit
total = total + annualreturn
count = count + 1
annualaverage = total/count
endif
alltime = (strategyprofit / capital) * 100
graph runningperc coloured(0,128,0) as "Running % Return"
graph annualreturn coloured(0,0,150) as " Last Years Annual % Return"
graph alltime coloured(128,145,150) as "All Time % Return"
graph annualaverage coloured(0,0,0) as "Annual Average %"
Thank you for sharing, I have added to here
Snippet Link Library