Why does a simple Trailing Stop Loss in pinescript repaint this hugely?
I am doing some backtesting on ETH/USD, 1H on Tradingview using pinescript version 4. The complete script is shown below:
//@version=4
strategy(title="Simple SL script", shorttitle="Simple SL script", overlay = true, initial_capital=1000, currency="USD", commission_type=strategy.commission.percent, commission_value=0.1, slippage = 5, pyramiding=1, calc_on_every_tick=false)
risk = input(title='Risk %', defval=100.0, step=1.0)/100
//secScaler = secType == "Forex" ? 100000 : secType == "Metal Spot" ? 100 : secType == "Cryptocurrency" ? 10000 : secType == "Custom" ? contracts : 0
fixedSL = input(title="SL Points", defval=1000)*10000
fixedTP = input(title="TP Points", defval=10)*10000
//##############################################################################
//Trade Logic
//##############################################################################
balance = strategy.initial_capital + strategy.netprofit
if (balance > 0)
lots = (risk * balance)/close
strategy.entry("BUY", strategy.long, qty=lots)
strategy.exit("B.Exit", "BUY", qty_percent = 100, loss=fixedSL, trail_offset=20, trail_points=fixedTP)
Using normal backtesting or Replay I get the following results:
Which results in a plus $20.
Before the backtesting I let it run through realtime data and I got the following results:
Which resultet in a negative $6.
So a difference of $26.
I am using no security or other questionable solutions for the trailing stop loss - how can the results vary this much over a short timeframe of 6 bars (6 hours)?
I did try to set the calc_on_every_tick
to true but as expected I got a huge amount of buy and sell orders within the same candle.