INVITE-ONLY SCRIPT

TTP Grid Backtester

已更新
This pine script strategy allows to backtest Grid bots.

This initial version offers the following features:
- Set the top and bottom limits of the grid
- Plots the average position price, realised and unrealised profits
- Set the value to invest
- This script is a strategy so you can check each individual buy/sell, stats and all included with strategies


What does it do:
- Depending where is located the initial close price relative to the grid (above, below, inside) it will buy for as many levels are above the price.
- It will disable a level that recently filled an order (in the way grids bot do)
- When the grid starts it will disable the closest grid level
- It places limit orders in the active levels and many levels can be filled in a single candle
- You can activate recalculate on each order filled, which will allow to fill further needed orders if the price swings up and down crossing multiple times multiple grid levels but I have found that doing this can compromise the accuracy of the price used on those levels (there are minor gaps between the filled price and the original level price)

How to use it:
- When you add this strategy to the chart you will be asked to select the top and bottom limits of the grid
- Notice you can always select the strategy in the chart and drag and drop the limits to adjust the grid
- Once the grid is in place, you can use either lower chart timeframes for higher accuracy of the stats, or higher timeframes if you want to privilege longer periods of testing

How to set the correct "initial capital"
In order to prevent getting wrong stats you need to make sure you are using the correct initial capital. If you put less than what you are actually using your results will be over inflated. If you set an initial capital below what the bot requires, your results will be smaller than they should.

- If you want to use exactly 100% of the capital for the grid use then first select what amount per level you want to use. Set this value in the settings of the indicator (if you are trading BTCUSD pair, how much BTC you want to use per level, 0.01 for example).
- Once you have set this value, then open the TradingView "Data Window" to be able to visualise the calculation of cash required to run the grid that the strategy is giving you. In our example with BTCUSD this value will be given in USD.
- Enter this amount in the "Properties" tab, "Initial Capital". If you enter the exact amount you will be using all for the grid usage.
- The grid first action will be to buy 0.01 for each level that is above the current price in the first candle of the chart. If there are no levels above it won't do any initial investment.
- The rest of the cash will be use to buy levels below if the price goes to the lower range of the grid later

Intention of this script
I built this script to help me understand better how grid bots work.
Understanding the flow of realised vs unrealised profits in a grid can help me understand why sometimes even if you are in red on unrealised profits, you can still compensate with realised profits and many other tricky scenarios with grids.
Sometimes I'm running a grid bot and would like to simulate how much better (or worst) it would have been to run it using different limits.

Future work and ideas
Initially I'm focusing on confirming that the grid behaves correctly and that the stats are as accurate as possible.
That is the first priority.
Once I feel more confident with the accuracy I will consider adding some of the following ideas (not in any particular order):
- Table with stats including: price of each level, times the level filled an order, times it was use for selling/buying, etc. Time it took to become in realised profit. Comparison against profits from buy & hold.
- Trailing TP/SL
- Entry/exit price
- Trading time window: only trade between the specified dates/times
- Alerts
發行說明
- Added time window to restrict backtesting only within the given start and end dates/times
- Fixed issue that levels below initial price were trading with 0.01 ignoring the user parameter for funds per level
發行說明
- Improved accuracy
- Graphic stats plot buy and hold for easy comparison
- Grid profits are drawn above the top grid level to reduce overlap with price
- Overall color and layout improvements
- Once the strat reaches the end time it closes all positions (selling all unrealised profits)
- TradingView Data window shows further stats
發行說明
- Improved stats in the TradingView "data window" panel
- If period and levels are close to the entry price, disable level that is closer to the price (what a real grid bot does to prevent over buying a level)
- Extra chart and layout tweaks
- Remove plots from area outside the time trading window
發行說明
NEW mode: calculate amount per level: When this option is enabled the value of 'amount spent per level' will be ignored and we will calculate one based on the provided initial capital value, the number of levels and the initial price at the time the grid starts. By enabling this mode you are using 100% of the initial capital for the grid. The calculated amount per level is shown in the data window.

Fix bug: there was a bug that the grid would stop trading after two orders were filled in the previous candle: one above and one below the current price. If this happens now we assume the most recent to get filled was the one closer to the last close price. There's no way to guarantee this but its the best compromise solution.
發行說明
- Improved better calculation of levels needed
- Support for non-USD pairs, now you can use automated level calculation on pairs like ETHBTC
- PNL chart scale. Use this value to adjust the scale of the in-chart PNL plots so they are in a similar scale to the grid. This is very useful for pairs like ETHBTC where the value of the token is fractional and the profits are not causing the profits to be too large to be next to the grid. Now you can use this parameter to keep everything in visible range.
發行說明
Grid not starting when price above range issue was fixed.
發行說明
Added upper and lower stop loss matching the new grid features offered by 3commas.
Support for stop loss action: stop bot and buy/sell base.
發行說明
Show SL levels only when enabled.
You can drag and drop SL levels when enabled.
發行說明
- Fixed issue that was causing grid levels to become not visible in the chart
- Added option to customise the grid colors.
- Added instructions table (you can hide them from the script settings)
- Minor changes: start/end time moved towards top of the form, by default stats are disable to keep chart cleaner, fixed pine script 5 warnings.
backtestbacktesterbacktestingeducationalGRIDgridbotgridsgridtradingstrategy

僅限邀請腳本

僅限作者授權的用戶訪問此腳本,並且通常需要付費。您可以將其增加到收藏腳本中,但是只有在向作者請求並獲得許可之後,才能使用它。 請聯繫TheTradingParrot以了解更多信息,或按照下面作者的說明進行操作。

TradingView 不建議購買並使用此腳本,除非您 100% 信任其作者並了解腳本的工作原理。在許多情況下,您可以在我們的社群腳本中免費找到良好的開源替代方案。

作者的說明

You can get access to this strategy here: https://thetradingparrot.com/tiers

想在圖表上使用此腳本?

警告:請閱讀,然後再請求訪問權限。

Join our membership to gain access to the private scripts.
thetradingparrot.com
更多:

免責聲明