| sigperform |
sigperform(x, signal):
x: an array of numbers representing, in most cases, close prices,
signal: an array of numbers containing 1, -1, 0, where 1 stands for buy signals, -1 for sell signals and 0 for no trading activity.
return gain/loss percentage numbers as the performance of signal.
|
# compare performance with S&P 500 Index
polyline(1, 0), colorblack;
valid := sgn(barssince(isfirstbar)+1);
sig := valid;
performance : sigperform(close, sig), linethick2;
sp500: sigperform("^gspc$ochl.c", sig);
|
# compare performance with buy-and-hold strategy
polyline(1, 0), colorblack;
v1 := ma(close, 30);
valid := sgn(barssince(isfirstbar)+1);
buy_hold_signal := valid;
signal := if(close > v1, 1, if(close < v1, -1, 0)) * valid;
performance : sigperform(close, signal);
buy_hold: sigperform(close, buy_hold_signal);
|