TradingView
Wilson-IV
Sep 1, 2021 5:55 PM

Rebalancing 

Bitcoin / TetherUSBinance

Description

This script gives you an approximation of the APR you can get when using the technique of Rebalancing.
Further discription are embeded in the script.

HOW TO USE:
- Start date: Choose start date
- Settings: Change settings to your own needs
- Base currency: Select Base currency
- Portfolio: Select the coins (MAX 9 pcs.) you want to use in your portfolio for the rebalancing algoritm
- Click "Data Window" to see the APR (appr.)

Markets:
It can be used to all markets.

NOTE:
Some Exchanges don't go very far back in the past and for this reason this may have impact on this Indicator.
Make sure the coins you selected are available at the Exchange you select in the settings section. If you dont do this, the script generates an error.

Release Notes

Updates:
- Amount of coins reduced to 2 to make rebalancing with Exchanges easier
- Rebalance momentum is now visible (yellow arrowup)
- Rebalance happnes only when the value of the trade is equal or greater then $10
- Placing orders (will be later activated)

Release Notes

Changes:
- Showing the Initial Rebalancing moment
- Rebalancing when goes LONG/SHORT
- Minor Layout fixes

Release Notes

Updates:
- Invest more after a rebalance took place (Reserve Investment)
This seems to have a (huge) impact on the APR
- Pay back the money you inbest during rebalancing
- APR shown in a table on the chart
- Minor Lay-out changes.

Release Notes

BTC as base currency is now available.

Release Notes

Updates:
- Upgrade to version 5
- Rebalance Modes available: Periodic or Treshold

Release Notes

Version 1.1
- Pyramiding set to 25
- Using the correct qty now in List of trades

Release Notes

Version 1.1
- Pyramiding set to 25
- Using the correct qty now in List of trades

Release Notes

Update: FTX Exchange added

Release Notes

Update:
- Main currencie as variable (no need to select currency from list anymore)
Comments
Canundo
Hello, I like the script but I don't understand the numbers. When changing the initial investment it stops working but even with the initial investment and starting at this month the stats claim a portfolio of a couple million USD. Also not sure where the 5000 pyramiding can come in.
Wilson-IV
@Canundo, Thank you for your fedback.
The 5000 pyramiding is there because in some cases the strategy needs to go Long several times after each other. I agree, 5000 is too much, maybe 10, 25 is better (note: it's not an advise).
Wilson-IV
@Canundo, Bug fixed. Thank you for your feedback.
Canundo
@Wilson-IV, thank you, it worked. Numbers make sense now. I guess below 1 hour timeframe rebalancing doesn't make much sense?
Wilson-IV
@Canundo, That is true imho. The price need to move enough for the rebalance to take place. And that happen when you use the 1 hour timeframe for this script. No advice but always backtest your strategy.
AkariAkaza
Hi Wilson-IV, thank you for sharing such nice and organized codes. It really helped me with thinking of rebalanceing programing.
I tried your codes, but cannot get it run on BTC/USD from Coinbase. It worked for 1h BTC/USDT from Binance.
Another question: is there a way to rebalance 3 target at the same time? E.g. 50%USDT; 25%BTCUP; 25%BTCDOWN.
Wilson-IV
@AkariAkaza, Thank you!
BTC/USD from Coinbase or do you mean BTC/USDT from Coinbase ?
For BTC/USDT from Coinbase you need to select it from the Exchange dropdown.
But if you realy need USD insead of USDT, then it need to be implemented in the code, because i only used USDT and not USD in the code.

Is it possible to rebalance more then 2 coins?
Yes, it is possible. I only used 2 coins in this script just to make it easy for other users.
If you need this code for more then 2 coins, please let me know. More needs to be done to get this rebalancing script working for more then 2 coins.
AkariAkaza
@Wilson-IV, Thank you for your reply!
Some one told me a stragety where they held BTCx3long & BTCx3short at the same time with 50% USDT aside, and then rebalance these three as 1:1:2 everyday to gain high return. I'd like to try this stragety but don't know how to do.
Threre are people also claim that buy BTCx3long & BTCx3short, Oilx3long & Oilx3short, Real Estate x3Bull & Real Estate x3Bear and finally China stock index x3long & China stock index x3short together and rebalancing them monthly 1:1 could out perform the Ray Dalio all weather portfolio fund. Is there a way to rebalance these 8 by tradingview easily?
Wilson-IV
@AkariAkaza, To do this let we just look at an example of 3 coins(BTC, ETH and USDT).
If we can do this with 3 coins(can also be stocks if your bots supports trading stocks) then we can also do this with 8 coins or more.

Asume you want to use this settings:
BTC 25% | ETH 25 % | USDT 50 %

Then you need 4 bots :
- LONG bot -> BTCUSDT and ETHUSDT
- SHORT bot -> BTCUSDT and ETHUSDT

Also the script needs to be updated for handling 3 or more coins with the settings above.
More