I want to plot the equity curve on the price, to compare the strategy to simple buy and hold. To make the graph useful, the equity curve could either start on the initial equity, or in line with the first price on the graph or no equity curve at all depending on manual input.
Using the code below, I get this:
line xx: Cannot use 'plot' in local scope.
line xx: Cannot use 'plot' in local scope.
equitycurvetype = input(defval="No", title='Equity Curve Type', options=["No","Yes","Yes same start"])
if equitycurvetype == "Yes"
plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
if equitycurvetype == "Yes same start"
plot(strategy.equity * close[bar_index]/strategy.initial_capital, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
plot(Trailingsl, title = "SuperTrend", color = linecolor , linewidth = 2, transp = showSuperTrend ? 0 : 100)
Workaround:
transp = showSuperTrend ? 0 : 100
Can't plot from if
blocks. Also, while using close[bar_index]
is syntactically correct, it will throw runtime error because of far away referencing in the past, so this code saves first bar's close in firstClose
variable:
//@version=4
strategy("")
equitycurvetype = input(defval="No", title='Equity Curve Type', options=["No","Yes","Yes same start"])
// Save close of 1st bar in dataset using "var" to initialize only once.
var firstClose = close
float equity = na
if equitycurvetype == "Yes"
equity := strategy.equity
else
if equitycurvetype == "Yes same start"
equity := strategy.equity * firstClose / strategy.initial_capital
plot(equity, title="Equity", color=color.red, linewidth=2, style=plot.style_areabr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With