I want to make stock screener through trading view pine script code . 

So chat gpt you have to write trading view pine script code stock screener for Multi Timeframe and Multi Symbol analysis based on Supply and Demand zone 
  


Important Definition

Unfilled Boring/Base candle: A candle where body of candle is less than 50% of the total length of the candle. Also the TR of this candle will be less than the ATR of this candle. ATR calculation is taken of last 14 candles. If multiple consecutive boring candles are present then rules will be applicable on all of those.

Filled Leg-in candle: Candle that comes just before the first Boring Candle, its Body should be more than 50% of its own total length and its TR should be greater than its ATR. ATR calculation is taken of last 14 candles. It should be bigger than the Boring candles that come just after it.

Filled Leg-out candle: Candle that comes just after the last Boring Candle(if there are multiple Boring candles then), its Body should be more than 50% of its own total length and its TR should be greater than its ATR. ATR calculation is taken of last 14 candles. It should be bigger than the Boring candles that come just before it. The length of the Filled Leg-out starts from the close price of the last boring candle and ends at the close price of the Single leg out(high for Demand zone buy trade and low for Supply zone Sell trade) candle or ends at the close price of the 3rd legout candle if 3 consecutive green/red candles are present.

User Inputs options in code:

👉 Point 1. Candlestick Timeframe Selection: 1 Min, 2 Min, 3 Min, 5 Min, 15 Min,30 Min, 1 Hr, 2 HR, 3 Hr, 4 Hr, 8 HR, 1 Day, 1 Week, 1 Month. Multiple Selection checkbox.

👉 Point 2. Symbol Selection: Comma separate list of Symbols to be accepted as Input. Multiple Symbols can be entered.

👉 Point 3. Ratio of Base/Boring Candle to Legin Candle: example 1:2, 1:3 etc accept the ratio in textbox, If there are multiple Boring candles all should adhere to this ratio.

👉 Point 4. Ratio of Base/Boring Candle to Legout Candle: example 1:4, 1:5 etc accept the ratio in textbox

, If there are multiple Boring candles all should adhere to this ratio.


👉 Point 5. Maximum Number of Base/Boring Candles Allowed: Textbox that allows Number from 1 to 4

👉 Point 6.  Minimum Leg In Body To its own HighLow % : Accept percentage as a number so if we enter 60 then it means the body of the candle should be atleast 60% of the total length of that candle including the wick(high and low also). Optional paramter. Leg in candle is the Candle which is just before the Base/Boring Candle(s). If there are multiple boring/base candles then the candle which comes just before the first boring candle is called as Leg in Candle.

👉 Point 7. Minimum Leg Out Body To its own HighLow % : Accept percentage as a number so if we enter 60 then it means the body of the candle should be atleast 60% of the total length of that candle including the wick(high and low also). Optional paramter.  Leg out candle is the Candle which is just after the Base/Boring Candle(s). If there are multiple boring/base candles then the candle which comes after the last boring candle is called as Leg out Candle.



👉 Point 8. Number of consecutive candles to consider for Leg-out length calculation: Optional Parameter that accepts a number. Suppose if we select 3 then that means after the Boring candle or the last of the boring candles  if 3 consecutive green or red candles are created those would be considered as a single leg out candle and the length of the legout candle will be considered as the total of these 3 candles. If this parameter is selected then point 8 calculation will also consider this as the total length for its calculation.


Zone patterns
(1) demand zone pattern 
1.1 DBR: Drop-base-rally 
Proximal price line for DBR- highest body in boring candle
Distal price line for DBR- lowest low in pattern 

1.2 RBR: Rally-base-rally
Proximal price line for RBR- highest body in boring candle
Distal price line for RBR- lowest low in pattern excluding legin 


(2) Supply zone pattern
2.1 DBD: Drop-base-drop
Proximal price line for DBD- lowest body in boring candle
Distal price line for DBD- highest high  in pattern excluding legin 

2.2 RBD: Rally-base-Drop 
Proximal price line for RBD- lowest body in boring candle
Distal price line for RBD- highest high in pattern


Objective & Logic for writing code:  our code will detect if any of the 4 patterns mentioned above have been created by candles that have closed earlier 

The Area or zone between the Proximal and Distal price should not be tested by Price after it has been created. If price has already come between this zone earlier after this zone was created then ignore this pattern.. Only when the zone is fresh and untested can be considered valid.  Remember that the Legout candle is excluded from this check as it can come within this zone also. But all the candles that are created after Legout should not have come within this Area zone in between the Proximal price and the Distal Price. The candle that comes just after legout candle should not cover more than 50% of the Legout candle.


Other rules

THERE SHOULD BE NO GAP IN LEG-IN AND BORING CANDLE(s)




. Generated code should be modular and well documented in each block. In the code you will be attached to any 1 single Indian stock symbol chart but it will run all the symbols and timeframes that are specified in the Input. 

Each Timeframe(s) and Symbol combination will have a separate and unique magic number. That number and  timeframe combination and symbol and pattern name (DBR, RBR, DBD, RBD) should be displayed on the screen in the table as a summary with legin and legout candle date of latest pattern for both demand zone and supply zone. Chart will use candlestick chart.