A new member was asking about the accuracy of the TTP grid pine script.
It is an amazing script, although, I think there are bugs in the grid backtesting script-
1) In spot trading, if you buy something or some amount on the lower grid, the average price ALWAYS goes DOWN. In your script, the orange line (GRID AVERAGE POSITION) sometimes goes UP even if we buy down. And vice versa.
2) In grid trading, the “realised profit” should never go down unless you stop the bot or intervene manually. The worst-case scenario is that the bot will buy coins and go down (like DCA) and HOLD. But NEVER sell at a loss (unless intervened manually). In your script, the bot is sometimes selling coins on the lower grid that are purchased at a higher price (on the upper grid). In reality, the grid bot always sells the number of coins that were purchased at the lower grid.
These two points are known issues caused by a limitation with pyramiding with TradingView: it cannot handle properly simultaneous long and short positions. This affects the accuracy of the realised PNL and the average grid position during the time range the grid is executing.
The positive side is that even though those two calculations can be wrong the overall PNL once the grid closes all the positions should be still correct.
Why is the realised PNL going down in some parts of the chart?
If you open the “strategy tester -> list of trades” panel you will notice that TV is matching each of the sells randomly with a buy order filled before. This causes TV to believe that there was a loss. This is compensated by larger wins in later trades giving a final PNL that averages all deals giving a final PNL that is still accurate.
What matters is that when you zoom in the chart you see the grid taking the right longs and shorts: timing, direction and position size should be correct. If any of these were wrong then the final PNL accuracy will be compromised.
In the chart below you can see that around August realised profit goes down once. In the results you can see a loss. That’s because TV matched that sell with a corresponding buy that occurred when the price was higher. This only affects the partial PNL up until that point due to TV matching those two trades. But later there will be other trades that will end up compensating with a relatively larger win.


Can’t this issues be fixed?
We have reported the issue and we’ve been looking for alternatives but for as long as pyramiding does not allow to sell a partial size from the on going long positions then it won’t be possible to show 100% accurate results of avg position and intermediate PNL stats.
What causes this issues?
Tv does not allow to use pyramiding in the way a grid requires it.
An example of what a grid can do:
- Buy 2 shares at $2
- Buy 1 share at $1 – when price goes down to the next level below
- Sell 1 share at $3
When using strategy.entry(qty=1, limit=3) to execute the first sell and pyramiding TV will close all longs and enter also a short of size 1. This is not what we want, we want to only sell $1.
We need pyramiding to properly calculate intermediate stats.
If instead of using entry(), we use strategy.order(qty=1, limit=3) then pyramiding is disabled but we are able to sell only $1 which is what we needed but this alternative messes up the intermediate stats.
Is the Grid backtester still useful then?
I believe so. The impact of this issue is only intermediate stats. It does not affect the final results.
Strategic suggested solution
TV should support pyramiding long/short strategies. A strategy should allow to both buy and sell in any order and any amount.