B008
commission or slippage is negative
Severity Error
commission and slippage model trading costs and must not be negative; a negative value would turn costs into income and make the backtest look better than any real account. Maker rebates are not modelled through negative commission.
Use zero or a positive value. Slippage is given in ticks.
Failing example
script "Cost model"
strategy (
commission = commission.percent(-0.01)
slippage = 1
)
data chart = subscribe(data.ohlcv)
on chart.close {
if ta.crossover(chart.close, ta.ema(chart.close, 50)) {
strategy.entry("Long", direction.long)
}
if ta.crossunder(chart.close, ta.ema(chart.close, 50)) {
strategy.close("Long")
}
}Fixed example
script "Cost model"
strategy (
commission = commission.percent(0.02)
slippage = 1
)
data chart = subscribe(data.ohlcv)
on chart.close {
let ema = ta.ema(chart.close, 50)
if ta.crossover(chart.close, ema) {
strategy.entry("Long", direction.long)
}
if ta.crossunder(chart.close, ema) {
strategy.close("Long")
}
}