# Entanglement Pen

script name: Entanglement Pen
For left traders, how to accurately find the bottom and top is very important, and there are various methods. I have shared the bottom type script composed of three bars before, but this type of bottom type is effective in a small range. So, this script is sharing " Entanglement Pen ", which can help us determine bottoms and tops on a global scale.
However, this script uses an approximate reduction method rather than the orthodox solution of entanglement.
After roughly finding the bottom and top, how to determine that these are the bottom and top that meet the definition of entanglement theory?
The main 2 methods of "approximate reduction" are:
(1) The price difference between the top and the bottom is large enough, that is: the lowest price at the top > the highest price at the bottom.
(2) The stock price before the top has continued to rise, that is: both the highest point and the lowest point are rising. In the same way, the stock price before the bottom has a continuous decline, that is: both the high and the low point are falling.
A big disadvantage of this script is that it needs to use future data. This is because:
When multiple bars meet the top definition in a short period of time, only the last bar is used, which is defined as a big top. So, when you see a top appear, you don't know it's not a real top, because it might be followed by a bar that also matches the definition of the top.
When displayed on the graph, bars that meet the top definition have a gray label, which is the small top. Each small top is a big top (with a blue label) at the beginning, and when another small top appears after it, it becomes a gray small top.
Regarding the limit on the number of bars by TradingView:
The logic of calculating the small top and the small bottom is relatively simple, it does not need to use future data, and the amount of calculation is small, so it is the default TradingView limit. (The limit is 2000 in the script, but in practice TradingView won't let us use such many bars)
The calculation logic of the big top and the big bottom is more complicated, and it needs to use future data. The calculation amount is very large, and only the most recent 150 bars can be calculated. The user can try to enter a larger value, but TradingView may report an error. If an error occurs, please enter a lower value. When loading for the first time, it takes a long time, which is indeed not common in general TradingView scripts, but please be patient.
The next version may add the alert function, that is: when the top and bottom appear, the alert function is called. But this only applies to small tops and bottoms, because when the alert is sent,, none of us know what data will be in the future.

Introduction in Chinese:

“近似还原”的主要2个方法是：
（1）顶部与底部的价差足够大，即：顶部的最低价>底部的最高价。
（2）顶部之前的股价有持续的上涨，即：最高点和最低点都在上涨。同理，底部之前的股价有持续的下跌，即：最高点和最低点都在下跌。