Find out how your trading strategy would have performed with real market data.
Would you like to test your Gunbot strategy without risking your money?
Introducing the Gunbot Backtesting Addon
The Gunbot Backtesting Addon allows you to check your strategy on Tradingview, so you can fine-tune the different parameters and make sure it will be profitable before you go live on the exchange.
In this article, you will learn how to use this add-on to adjust your strategy so you can Maximize your Profits with Gunbot.
But first, you need to know that the Gunbot Backtesting Addon is a paid feature that you can get included with the Gunbot Pro and Ultimate Licenses, or buy it separately here in the Gunbot Store.
You also have to be aware that Backtesting is the general method for seeing how well a strategy would have done in the past, and while we like to believe that history repeats itself…
You should understand that past performance does not guarantee future gains.
That been said, should you choose to use the Gunbot backtesting addon, here are some of its main advantages.
Gunbot Backtesting Addon Benefits
How can you benefit from the Gunbot backtesting add-on? Top 3 Backtesting Advantages
- You will learn fast and understand how Gunbot sees your strategies and how it will execute them.
- You will be able to fine-tune the settings in your Gunbot strategy without the risk of losing your money.
- You will receive the Gunbot Deluxe Tuners Black Edition, a set of pine scripts with the buy and sell strategies along with extra conditions and trail options.
Alternatively, if you own the Gunbot Tradingview addon, you will be able to trade on alerts sent from your custom strategies on Tradingview.
If you wish to receive instant notification in TradingView whenever an update to backtesting addon scripts is released, please visit the Allanster Tradingview Profile and click the Follow button.
Thank You, Allanster, for this wonderful tool!
How to Update the Gunbot Backtesting Addon
Here are the 3 steps you have to take; if you own the Gunbot backtesting addon, Deluxe BE, or the original backtesting script Deluxe and wish to update to the latest version.
- Remove existing Deluxe BE or Deluxe indicator(s) from the chart.
- Refresh browser page
- Load Deluxe BE or Deluxe indicator(s) onto the chart.
The newly loaded indicator(s) will recompile from the latest published update.
Updates are pushed to overwrite existing indicator(s), but the updates do not take effect on indicator(s) that were already active on the chart(s) before the update.
TradingView sometimes pushes system updates that can cause compatibility errors with Pine scripts.
TradingView’s system updates also do not seem to affect indicator(s) loaded before their updates.
For this reason, leave your indicator(s) loaded on your chart even when not in use (it is okay to hide them), as it may take some time to refactor code for indicator(s) when one of their system updates causes an issue.
Keeping indicator(s) loaded on the chart may help avoid not accessing them when something breaks.
Gunbot Backtesting Addon FAQ
Over the years, our users have asked many questions about this add-on, and all of them have been answered mostly by Allanster. You can find them by searching our Gunthy Elite Telegram Group.
First, let me tell you about these known issues:
The TradingView indicators are a centralized library that runs over historical data collected over years of trading. Some value of some indicators might get different value compared to your Gunbot PERIOD selection and CANDLES_LENGHT settings.
Other indicators (for example, ADX or STOCH_RSI) are using a different legacy formula, so those values will never match TradingView.
For references about the indicator’s formula Gunbot uses, you can read the Tulip Indicators Index.
Here are the Answers to Backtesting Frequently Asked Questions
- Indicator Discrepancy: Why I see Differences in the indicator Values between Gunbot and TradingView Charts?
- Matching Gunbot Trades: Why Gunbot doesn’t trade exactly as I see on TradingView with Backtesting
- Leverage: How to setup leverage on Margin trading backtesting?
- Prices A and Prices B: Baktesting the PingPong strategy
- Pyramid: Why is the calculation wrong when Pyramiding?
- Stop Limit: Why can’t I use decimals on Stop Limit when backtesting?
- TrailMe logic: What is the Logic used on the trail-me strategy?
This guide will answer all those questions below; keep reading…
There is a slight difference in RSI calculations between Exchange, TradingView, and Gunbot, where one used the last 14 CLOSE prices and the other used the last 13 CLOSE prices and the current in-candle price.
Also, sometimes (rare) Tulip library uses different formulas than TradingView.
You have to look at the previous candle on TradingView, and they will only match if the pair cycled exactly on the close of that candle.
Gunbot and TradingView Indicator Discrepancy Example
Notice in this example Gunbot 08:23:00 and TradingView 08:22:00
Gunbot buys in the middle of a candle. Is there an indicator that waits for the end of it?
Gunbot does what it is told to do. It is important to understand that a key difference between Gunbot and traditional charting is how Gunbot handles indicators.
Normal calculation of indicators is done after the close, but Gunbot uses the current price as the last “close” when the pair cycles and samples that instrument’s price.
As an example, if LTC-USD prices were:
A = $94 now
B = $92 last close
C = $90 previous close before that
D = $88 previous close before that
SMA 3 = (D + C + B) / 3
SMA 3 = (88 + 90 + 92) / 3 = $90
But Gunbot is more reactive, it sees:
SMA 3 = (C + B + A) / 3
SMA 3 = (90 + 92 + 94) / 3 = $92
So you must consider this when adjusting the settings in the Gunbot backtesting addon.
Gunbot Backtesting Addon Matching Trades
The logic is the same in the script as it is in Gunbot.
This screenshot shows a default SMACROSS setting with disabled DOUBLE_CHECK_GAIN and enabled BTC_PND_PROTECTION, so you can see where buying ceased each time MFI dipped below 35 in the script.
To determine if there was a discrepancy in the BTC_PND_PROTECTION MFI value between Gunbot and the scripts.
You would need to compare at that time the Gunbot log entry with the BTC_PND_PROTECTION MFI value of the Gunbot Backtesting Addon (uses same code) in TradingView’s Data Window.
You would also need to ensure that you have set the “BTC_PND Exchange =” setting in the scripts to the correct exchange for the pair you are using in Gunbot.
It is also unlikely that the Gunbot backtesting addon window would have entries and exits in sync with Gunbot.
Gunbot is reading the ticker prices which are all up and down the length of the candle.
TradingView pine scripts read the candle’s single price at the (high+low) / 2 price (known as HL2).
The Deluxe versions of the script give users the ability to sweep a range of candle prices instead of using just that single HL2 price.
This is why you see the Prices A and Prices B fields at the bottom in the tuner settings because they represent percentages up and down the candle’s length.
Setting them at 50/50 = HL2/HL2, which is the default.
Setting them at Prices A = 100 and Prices B = 0 represents Prices A = High and Prices B = Low sources.
Setting Prices A equal to Prices B allows you to use it as a single source or range point.
Prices A = 0-100
Prices B = 0-100
Low = 0
You have the choice of using this percentage range OR using conventional source choices like “close.”
Is important to take all of these concepts into consideration.
You are just opening the “window” of the range of prices to simulate Gunbot pair cycling and sampling various points along with the candle.
Gunbot itself isn’t truly watching the candle’s entire price range, though; it is “sampling” a point each time the pair cycles.
The reality is that depending on which strategy, period, settings you are using, some tuner strats may more closely mimic Gunbot than others.
Many users get hung up that they don’t always exactly match, but firing up 2 Gunbot instances and comparing them to each other won’t match.
The 2 Gunbot instances will cycle pairs at different times and sample at different points of the candle. As soon as one of the Gunbot instances buys, then the disparity will compound between the 2 Gunbot instances.
Remember that Gunbot may pair cycle and sample at the extreme bottom of the candle, or the middle, or the top.
So you are still never going to match exactly. Neither would 2 Gunbot instances.
Imagine a 15min candle… that candle is 15 minutes worth of ticker prices; say Gunbot is running 50 pairs, might be 5 minutes in between each time that pair cycles, and reads one of those 15 minutes of ticker prices.
Another Gunbot would be cycling randomly, reading 3 different samples of that 15min candle, and they will NOT match.
With the Gunbot Backtesting Addon, You have to focus on optimizing levels.
If you are using GAIN to buy at x% below lowest ema and you have your buy_level set at 3%, but the pair never dips below 2%, then you will never buy.
You should NOT be concerned about “matching” exact buys and sells; you SHOULD be concerned that your Buy-Level is not set so low that it never buys, etc.
What you want to do with the tuner is focus on dialing in your levels and ranges to achieve optimal stats.
You are tuning for “potential,” not trying and matching every buy and sell in a single unique instance of Gunbot running.
Here’s Another Scenario…
You have a good setup from backtesting and run it, but a week later, you see only 1 complete trade out of 12 that should have happened, so Gunbot shows only 1 complete trade.
Gunbot uses real-time ask/bid ticker prices which Pine scripts are not capable of using in an accurate manner during backtesting.
Pine allows reading them useful with live testing, but scripts should only use candle prices for backtests.
But even if Pine could perfectly match Gunbot’s ask/bid prices, they wouldn’t sync.
If you didn’t start Gunbot at exactly 00:01:00 on the same date with only that pair running, Gunbot or the script might buy at different times.
Without using the tuner script, you could set to buy at a dip of 3% and never realize that particular pair’s candles never dip 3%; maybe they only dip 2% below the lowest EMA.
But by using a tuner, you can visually see that “okay, these levels are realistic” or “okay, these levels are way off.”
The idea is that it allows you to visually set your levels to optimize “potential” for returns.
But it is never going to synchronize 100% with Gunbot exactly.
Gunbot Backtesting Addon Leverage
How to setup ROI percent in margin trading with the Gunbot backtesting addon?
Tip: If you ask how to approximate leverage, you will set Order Size equal to leverage multiple Initial Capital.
Check the picture with an example of Leverage at 5X.
The percentage fees are based on the type of order and how much leverage you use, plus the funding rate percentage, which isn’t static.
Gunbot has the luxury of reading the real-time ROE from the exchange API. So Gunbot doesn’t have to calculate it or liquidation levels etc.
Since Pine scripts lack the ability to communicate through API, there is no way for the tuner to poll the funding rate, real-time ROE, or liquidation levels.
Neither Gunbot nor the tuner scripts take leverage into account for the ROE setting. The percent settings for ROE in the script and Gunbot are based on no leverage.
The Leverage setting in Gunbot tells the exchange what leverage you want to use. I did not include Leverage setting in the script because there is no point; it does not talk to the exchange.
With the backtest script, when using leverage, all you can really do is a tune for optimal performance based on no leverage or take the time to calculate manually what that factor would be multiplied by the percent returns shown.
If you used to leverage and won the trade, you would have more profit, and if you lost, you would have more loss.
You can manually calculate the fees to enter the script based on what leverage you are using and adding a “guesstimate” of the funding rate by looking up and averaging the funding rate over the backtest window.
You could also calculate the liquidation level and place your stop_limit there to see how often wrong leverage would liquidate you.
For more explanation of the formulas for calculating leverage read this article:
Gunbot Backtesting Addon PingPong Strategy
The PingPong strategy doesn’t backtest correctly because of the candle open/close?
It works the same. Gunbot cycles through pairs, and if at that moment in time when you have cycled onto that pair…
Price ATM <= PP_BUY it buys
Price ATM >= PP_SELL it sells
The back-tester looks at as narrow or as wide a range of candle prices as you tell it to through Prices A and Prices B…
Price in Candle Range <= PP_BUY it buys
Price in Candle Range >= PP_SELL it sells
Gunbot PingPong strategy buys and sells examples.
You could set…
Prices A: 100
Prices B: 0
And then the back-tester would sweep the entire range of candle prices. But even Gunbot does not do that.
Backtesting is extremely useful for setting levels and ranges, you are flying blind without it.
But will it buy and sell at the same time as Gunbot and the same price?
The answer is more complex than just saying “no.” The answer to that question would be, “Which Gunbot?”
The Gunbot you started at 12:00 with 13 pairs or the Gunbot you started at 12:07 with 9 pairs?
Because neither of these matches precisely either, they will pair cycle at different times and read different prices when in sync that pair was cycled.
Gubot Backtesting Addon Pyramid Trading
Here’s an example using MACD-TSSL strategy in backtesting; it shows high % returns but due to lots of consecutive buys without sell using the minimum amount for trade-limit.
Is the percentage in the script in sync with my trade-limit?
TradingView calculates Net Profit against total fund (Initial Capital) like this:
(Order Size Sell – Order Size Buy) / Initial Capital
This is not the same as Net Profit against trading limit (Order Size) like this:
(Order Size Sell – Order Size Buy) / Order Size buy
Pyramid in Gunbot terms is the ability to buy more than once.
Pyramiding should be checked (true).
The script will automatically Pyramid when needed.
TradingView will allow you to use 100% of your total fund on each buy for multiple buys, but this is impossible in reality.
When you have Properties properly set, you will only see Pyramid take place on the strats that allow it.
But on those strategies, you will see profits that are wildly exaggerated due to the way that TradingView calculates Net Profit against Total Fund instead of against pair.
For non Pyramid strategies, Initial Capital needs to be set equal to Order Size to calculate Net Profit per pair properly.
But when using Pyramid starts, something like this happens…
BTC price is $4k
Script has an Initial Capital of $8k
Script has an Order Size of $8k
Script buys 2 BTC for $8k
Script buys another 2 BTC for $8k
BTC price rises from $4k to $5k
Script sells 4 BTC for $20k
Net Profit = ($20k – $16k) / $8k = 50% (this is wrong)
In reality, you couldn’t have bought $16k worth if your Initial Capital (total fund) was only $8k.
But TradingView will let you do it anyway. So when using Pyramid strategies, you need to manually lower the Order Size to a fraction of the Initial Capital to avoid seeing this inflated Net Profit percentage.
This Net Profit will no longer be showing the same thing as non Pyramid strats because you are now comparing trading limit increase against total fund instead of trading limit increase against the trading limit for that pair.
In the Pyramid strat example above, if you knew the strat was only going to buy twice before sell, you would halve the Order Size (in reality, you don’t know how many buys will occur)
BTC price is $4k
Script has an Initial Capital of $8k
Script has an Order Size of $4k
Script buys 1 BTC for $4k
Script buys another 1 BTC for $4k
BTC price rises from $4k to $5k
Script sells 2 BTC for $10k
NetProfit = ($10k – $8k) / $8k = 25% (this is right)
All you can do is set a small fraction that you think will allow the strat to buy as many times as it might buy, and then take into account when viewing Net Profit for Pyramid strats it is not the same thing as viewing Net Profit for non Pyramid strats.
But in both instances, Pyramiding should be left on; when you start using Pyramid, Gunbot should reduce your Order Size.
Gunbot Backtesting Addon Stop Limit
Gunbot does take the decimals, but backtesting and TV Alerts won’t take the decimals in the STOP-LIMIT?
From Allanster: A couple of users have asked about this, and it is an oversight on my part. I have made a note to change from integer to float.
Please note that this will make little difference in the behavior because Pine scripts trade on the next candle’s open after the trigger.
So whether you trigger a stop at 1% or 0.9%, it will not change the instrument’s price.
In the real Gunbot setting a stop-limit at 0.9% doesn’t necessarily mean you will always exit at that exact price either.
Gunbot Backtesting Addon TrailMe Logic
When using Trail Me Sell, it works after the conditions are met. What’s the experience?
At the moment the parent strategy conditions are met, instead of executing a position, trailing begins.
Once the price reverses direction and crosses your TrailMe stop, then TrailMe checks with the “parent strat” at that moment to see if its conditions are still met. If not, then TrailMe does not trade.
So one aspect to consider when using TrailMe is you may want to “relax” your parent strat settings to allow TrailMe some “breathing room”.
For example, you are running BB; then this is your “parent strat.”
If you normally ran BB conservatively at 5/5 levels, this may not give TrailMe much further room to travel or hit stop while still within that range.
In this instance, you might want to make BB levels less strict, like 15/15, to allow there to be some room for trailing.
Gunbot TrailMe Strategy Logic example
This illustration first shows how TrailMe Buy would work without checking the parent (which is not an option), then it shows where it would have actually bought.
The settings in this picture were with BB levels 45/45, which is extremely aggressive but illustrates the “breathing room” concept mentioned above.
I hope you got most of your Questions about the Gunbot Backtesting Addon Answered in this article.
For a comprehensive user guide, check out our Gunbot Wiki Backetesting Getting Started Guide.
Remember to bookmark this page for future reference, and do not hesitate to contact @allanster on Telegram if your question has not been answered.