# BUY — grid level fires only while the longer trend is intact
# second half is your grid level - Sma(60)*0.995 stands in so this parses
if Price > Sma(3600) and Price <= Sma(60) * 0.995:
Buy()This costs you the bottom of every real dip, which is exactly where the best grid entries are. That's the trade. You are paying a real price for not being loaded up at the start of a decline, and whether that's worth it depends entirely on how often your market trends versus oscillates.
Measure that on your own instrument before deciding. Mine oscillates more than I assumed and the filter cost me more than it saved.A trend filter in front of the grid
The failure mode is always the same: the grid is fine until the range stops being a range. So put something in front of it that notices.
The simplest version I've tested: only allow new buy levels to fire while price is above a long moving average. When it falls below, existing levels still sell as price recovers, but no new buying happens. The grid winds down instead of loading up into a decline.