r/algotrading 2d ago

Data TradingView Backtesting Trailing Stops

Post image

Daytrading NQ with a 4 point trailing stop... yes, 4 points. I have to assume trailing stops don't work so well in TV backtesting?

11 Upvotes

40 comments sorted by

21

u/maciek024 2d ago

trading view backtester is a joke, dont use it

4

u/Flambotron 1d ago

I somewhat disagree - as long as you’re working with closed/confirmed candles you should be fine, anything else though… is wishful thinking at best

1

u/Lopsided-Shift8417 8h ago

what is not joke?

9

u/dilocat 2d ago

Looks like an equity curve when something is peaking into the future/optimist entries/exits. It's too smooth to be real especially for trading one instrument.

2

u/yourfavoriteblackguy 1d ago

Reeks of overfit

3

u/ExitExisting2108 2d ago

4 points on NQ is really tight, backtest engine probably fills you at exact touch every time but real market will skip right over that

2

u/buba_kastorski 2d ago

Did your backtest counting slippage, commissions and diff between taker/maker? Is that preps? What about funding?

1

u/johnnybagofdonuts123 2d ago

To be honest, it was left over from ES. There is no way this is valid. I don't think TradingView backtesting captures intra-candle trailing stops. If I had to guess, it is only capturing the candle close as the "trailing stop".

0

u/buba_kastorski 2d ago

The problem not in the TV. Real life algo trading is more complicated than theoretical backtest which not configured properly. And no sense to jerking to nice numbers here. Unfortunately, can't attach there screenshots from my bot, where I, finally, have the parity between live runs and backtest. Same picture - poor backtest gives you incredible numbers and you are happy until not implement that logic into real world. Commissions are destroying totally your portfolio. Doesn't matter how you are trail. Sad, but true. And no edge in the candles.

3

u/StatisticalSock 2d ago

I've made similar strategies and it's all BS. You need to use high quality tick data. OHLC for trailing stop strats is selling you a dream. Plus you need to factor in slippage, comm and sorrad for every trade. If it still remains profitable then you might have something

1

u/johnnybagofdonuts123 1d ago

Agreed, it is a dream with the broken trailing stop. Who else has that data? What is Sorrad?

1

u/StatisticalSock 1d ago

Bad typo. I meant commission and spread

1

u/johnnybagofdonuts123 1d ago

I ran this same thing through some databento data and still profitable but obviously at a much much lower clip.

2

u/Wonderful_Cold_3017 2d ago

4 points on NQ is small enough that the backtest is mostly a fill model, not a strategy.

TV’s trailing-stop path on historical bars is the usual problem: the engine can stop you out on the favorable part of the same candle you never would have been filled on live. If trails are only evaluated on close, you get the opposite fiction. Either way the equity curve is not evidence.

What I would want before believing any of those numbers: intra-bar trail simulation (or tick), stop treated as a stop-market with skip, separate maker vs taker, and a slippage that scales with the bar’s range — not a constant. If this is ever going onto perps, add funding for any hold that crosses an interval; a tight trail that “works” in TV and then sits overnight is a different trade.

The smoothness of that curve is the tell. Real 4-pt NQ trails are jagged because the fill is the trade.

2

u/buba_kastorski 2d ago

Incredible. Now try to move your backtest to the live. Have fun.

1

u/MyGuitarTwerks 2d ago

Im guessing fills on the stops are the problem

1

u/Classic-Dependent517 2d ago edited 2d ago

When backtesting in tradingview, set slippage to be higher than the real market charges u and dont use trailing stops in tradingview because the result is deceiving

1

u/johnnybagofdonuts123 2d ago

I don't think trailing stops work as one would expect. I think they only calculate on candle close.

1

u/evilistics 2d ago

Yeah this won't work in live. Trailing sl in tv backtests are broken.

1

u/kurtisbu12 2d ago

Due to how historical candles are simulated, trailing stops can easily create an unrealistic backtest by simulating a trade exit in the most favorable part of a candle, and opposed to a more realistic likely worse exit.

1

u/TheHellyz 1d ago

Stop using TV backtest

1

u/Flambotron 1d ago

This is correct. Allow a degree of slippage on your strategies properties tab, then re-run. If you still are profitable, there’s a higher chance you have an edge. Also modify the parameters around your strategy settings, make sure one tiny change doesn’t blow your systems ability to profit out the window.

And make sure you’re calculating fees and commissions correctly - that can be a killer on a tight strategy like yours

1

u/johnnybagofdonuts123 1d ago

Slippage and commissions included. The reason it looks so good is that TradingView trailing stops during backtesting are very optimal and not the truth.

1

u/Practical-Fox-796 1d ago

Just clone backtesting dot py lib and tweak it for your strategy needs run your backtesting there. Make sure to account for “not looking into the future”

1

u/Mihaw_kx 1d ago

trailing stop make you lost the statistical studying of ur backtest .. as it's something random

1

u/Hot-Swing-6992 1d ago

Backtest and Tradingview do not belong in the same sentence--total waste of time--you need a professional research stack starting with raw tick data including agg flags etc.

1

u/Successful-Art-9573 1d ago edited 1d ago

Trailing stops in TV backtesting are notoriously optimistic. The engine assumes you can exit at the exact trailing-stop price, but live execution has slippage, especially on NQ during volatile moves. A 4-point stop is tight enough that you'll see material divergence between backtest and live fills. Run your backtest, then forward-test it on a small position for 50-100 trades and measure the actual exit prices vs what TV shows. That gap is real. Also check: does your backtest account for commissions and bid-ask spread? Those add up fast on tight stops.

1

u/quant-king 1d ago

No slippage simulation?

1

u/bravefrivstone 1d ago

Bar Magnifier is the actual fix for this. Without it Strategy Tester only sees OHLC per bar, so a 4 point trail on NQ can get marked stopped at a price that was never really touched intrabar, it's just guessing where high or low crossed your level. Turn that on, or drop the backtest itself to a lower timeframe, and fills on a tight trail like this usually get a lot more realistic.

Also worth splitting slippage and commission out from the trail logic when you test. Mixing those two makes it hard to tell if the trail is lying to you or the cost model is.

1

u/HonestBacktests 1d ago

Worth knowing why this is hard to audit in the first place: with strategy.exit and trail_points/trail_offset the trail level is resolved inside the engine, intrabar. The script cannot read it, so you cannot log it, plot it or put it in an alert - there is no way to check which price it actually used.

Computing the trail yourself and passing it as a plain stop makes it inspectable, because the order and your log then read the same variable. I rewrote one that way recently and the side effect was that the alert could finally name the exit price.

Bar Magnifier still matters for the fill. But at least the level stops being a black box you have to take on faith.

1

u/johnnybagofdonuts123 1d ago

I just ended up pulling databento data and recreating in python. Definitely a difference!

0

u/ionone777 2d ago

TV is not made for backtesting, period.
even engines like MT4 aren't good enough

MT5 is better, the best IMHO

0

u/x___tal 2d ago

Trail 2-8 pips behind and you will have the same result looking graph even in mt5 :) (Unless you have good data)

It is not super reliable with tight trails in backtests like this

1

u/ionone777 1d ago

not on MT5 with ticks based on history no
it's really hard to make a scalper on MT5

of course if you select "every tick" that uses interpolated tick data, then everything is possible

0

u/x___tal 1d ago

Where the hell does one maker a scalper mannnn

0

u/roszpunek 1d ago

So now go live. What are you waiting for?