This is a simple script that aggregates the USDTUSD pairs available on TradingView and shows the average price of (USDTUSD - 1).
Heavy buying of BTC on USD exchanges (read: Coinbase) will result in a positive USDT premium
Heavy selling of BTC on USD exchanges (read: Coinbase) will result in a negative USDT premium
Heavy buying of BTC on USDT exchanges result in a negative USDT premium
Heavy selling of BTC on USDT exchanges will result in a positive USDT premium
Here is a quote about USDT premiums from Zhao Dong, one of China's largest OTC traders, from the article "Chinese Bitcoin Billionaire Argues USDT Premium is Caused by USD Inflow, Not Tether Inflation":
"So let me tell you a little bit about where the plus or minus premium for usdt comes from. Right
The biggest exchange in America is coinbase, which trades in dollars. In addition to coinbase, most exchanges with large trading volume are usdt trading. Since BTC and usdt can flow freely between exchanges, the price difference is very small.
Assuming that the market is stable, there is no difference between the prices of usd and usdt. Btcusd = btcusdt
At some point the market starts to recover, goes up, and the otc money starts to come into the market. Coinbase is a compliance exchange, so the usd deposit is very smooth, while the usd deposit through usdt needs to be converted into usdt first and then deposited into the exchange, so the usdt will be slightly delayed in price transmission, so the usd exchange price is higher than the usdt exchange price. If there is a lot of dollars to buy, coinbase goes up first and usdt goes up later.
At this point, the coinbase price is higher than the usdt exchange price. If btcusd>btcusdt, because BTC is free flowing, that means usdt is in a positive premium to usd.
This arbitrage space will prompt the brick moving party to sell BTC from coinbase to usd, and then use usd to buy usdt, thus facilitating the issuance of usdt.
A negative usdt premium would prompt Tether to take back the usdt and destroy it."
Includes an option for repainting -- default value is true, meaning the script will repaint the current bar.
False = Not Repainting = Value for the current bar is not repainted, but all past values are offset by 1 bar.
True = Repainting = Value for the current bar is repainted, but all past values are correct and not offset by 1 bar.
In both cases, all of the historical values are correct, it is just a matter of whether you prefer the current bar to be realistically painted and the historical bars offset by 1, or the current bar to be repainted and the historical data to match their respective price bars.
As explained by TradingView,`f_security()` is for coders who want to offer their users a repainting/no-repainting version of the HTF data.