Net Positions (Net Longs & Net Shorts) - By LeviathanThis script is an experimental indicator that visualizes the entering and exiting of long and short positions in the market. It also includes other useful tools, such as NL/NS Profile, NL/NS Delta, NL/NS Ratio, Volume Heatmap, Divergence finder, Relative Strength Index of Net Longs and Net Shorts, EMAs and VWMAs and more.
To avoid misinterpretation, it's important to understand some basics. The “real” ratio between net long and net short positions in a given market is always 1:1. A futures contract is an agreement between two parties to buy or sell an underlying asset at an agreed-upon price. Each contract has a long side and a short side, with one party agreeing to buy (long) and the other party agreeing to sell (short) the asset at the agreed-upon price. The long position holder anticipates that the asset's price will rise, while the short position holder expects it to fall. Because every futures contract involves both a buyer and a seller, it is impossible to have more net longs than net shorts or vice versa (in terms of the net value). For every long position opened, there must be a corresponding short position taken by another market participant (and vice versa), thus maintaining the 1:1 ratio between longs and shorts. While there can be an imbalance in the number of traders/accounts holding long and short contracts, the net value of positions held on each side remains 1 to 1.
Open Interest (OI) is a metric that tracks the number of open (unsettled) contracts in a given market. For example, Open Interest of 100 BTC means that there are currently 100 BTC worth of longs and 100 BTC worth of shorts open in the market. There may be more traders on one side holding smaller positions, and fewer traders on the other side holding larger positions, but the net value of positions on one side is equal to the net value of positions on the other side → 100 BTC in longs and 100 BTC in shorts (1:1). Consider a scenario in which a trader decides to open a long position for 1 BTC at a price of HKEX:30 ,000. For this long order to be executed, a counterparty must take the opposite side of the contract by placing an order to short 1 BTC at the same price of HKEX:30 ,000. When both the long and short orders are matched and executed, the open interest increases by 1 BTC, reflecting the addition of this new contract to the market.
Changes in Open Interest essentially tell us 3 things:
- OI Increase - new positions entered the market (both longs and shorts!)
- OI Decrease - positions exited the market (both longs and shorts!)
- OI Flat - no change in open positions due to low activity or simply lots of transfers of contracts
However, different concepts can be used to analyze sentiment, aggressiveness, and activity in the market by analyzing data such as Open Interest, price, volume, etc. This indicator combines Open Interest data and price action to simplify the visualization of positions entering and exiting the market. It is based on the following concept:
Increase in Open Interest + Increase in price = Longs Opening
Decrease in Open Interest + Decrease in price = Longs Closing
Increase in Open Interest + Decrease in price = Shorts Opening
Decrease in Open Interest + Increase in price = Shorts Closing
When "Longs Opening" occurs, the OI Delta value is added to the running total of Net Longs, and when "Longs Closing" occurs, the OI Delta value is subtracted from the running total of Net Longs.
When "Shorts Opening" occurs, the OI Delta value is added to the running total of Net Shorts, and when "Shorts Closing" occurs, the OI Delta value is subtracted from the running total of Net Shorts.
To summarize:
Net Longs: Cumulative value of Longs Opening and Longs Closing (LO - LC)
Net Shorts: Cumulative value of Shorts Opening and Shorts Closing (SO - SC)
Net Delta: Net Longs - Net Shorts
Net Ratio: Net Longs / Net Shorts
This is the fundamental logic of how this script functions, but it also includes several other tools and options. Here is an overview of the settings:
Type:
- Net Positions (display values of Net Longs, Net Shorts, Net Delta, Net Ratio as described above)
- Relative Strength (display Net Longs, Net Shorts, Net Delta, Net Ratio in the form of a momentum oscillator that measures the speed and change of movements. Same logic as RSI for price)
Display as:
- Candles (display the data in the form of candlesticks)
- Lines (display the data in the form of candlesticks)
- Columns (display the data in the form of columns)
Cumulation:
- Visible Range (data is cumulated from the first visible bar on your chart)
- Full Data (data is cumulated from the beginning)
Quoted in:
- Base Currency (all data is presented in the pair’s base currency eg. BTC)
- Quote Currency (all data is presented in the pair’s quote currency eg USDT)
OI Sources
- Pick the sources from where the data is collected (if available).
Net Positions:
- NET LONGS (show/hide Net Longs plot, choose candle colors, choose line color)
- NET SHORTS (show/hide Net Shorts plot, choose candle colors, choose line color)
- NET DELTA (show/hide Net Delta plot, choose candle colors, choose line color)
- NET RATIO (show/hide Net Ratio plot, choose candle colors, choose line color)
Moving Averages:
- Type (choose between EMA and Volume Weighted Moving Average)
- NET LONGS (show/hide NL moving average plot, choose length, choose color)
- NET SHORTS (show/hide NS moving average plot, choose length, choose color)
- NET DELTA (show/hide ND moving average plot, choose length, choose color)
- NET RATIO (show/hide NR moving average plot, choose length, choose color)
Profile:
- Profile Data (choose the source data of the profile)
- Value Area % (set the percentage width of profile’s value area)
- Positions (set the position of the profile to left or right of the visible range)
- Node Size (set the relative size of nodes to make them appear smaller or larger)
- Rows (select the amount of rows displayed by the profile to control granularity)
- POC (show/hide POC- Point Of Control and select its color)
- VA (show/hide VA- Value Area and select its color)
Divergence finder
- Source (choose the source data used by the script to compare it with price pivot points)
- Maximum distance (the maximum distance between two divergent pivot points)
- Lookback Bars Left (the number of bars to the left of the current bar that the function will consider when looking for a pivot point)
- Lookback Bars Right (the number of bars to the right of the current bar that the function will consider when looking for a pivot point)
Stats:
- Show/Hide the Stats table
- Bars Back (choose the length of data analyzed for stats in number of bars)
- Position (choose the position of the Stats table)
- Select Data you want to display in the Stats table
Additional Settings:
- Volume Heatmap (show/hide volume heatmap and select its color)
- Label Offset (select how much the plot label is shifted to the right
- Position Relative Strength Length (select the length used in the calculation)
- Value Label (show/hide OI Delta values when candles are displayed)
- Plot Labels (show/hide the labels next to the plot)
- Wicks (show/hide wick when candles are displayed)
Code used for generating profiles is taken from @KioseffTrading's "Profile Any Indicator" script (used with author's permission)