@@ -46,6 +46,7 @@ pip install pyindicators
4646 * [ Golden Zone] ( #golden-zone )
4747 * [ Golden Zone Signal] ( #golden-zone-signal )
4848 * [ Fair Value Gap (FVG)] ( #fair-value-gap-fvg )
49+ * [ Order Blocks] ( #order-blocks )
4950* [ Pattern recognition] ( #pattern-recognition )
5051 * [ Detect Peaks] ( #detect-peaks )
5152 * [ Detect Bullish Divergence] ( #detect-bullish-divergence )
@@ -1018,6 +1019,77 @@ The `fvg_filled` function detects when FVGs have been mitigated:
10181019
10191020![ FAIR_VALUE_GAP] ( https://github.com/coding-kitties/PyIndicators/blob/main/static/images/indicators/fair_value_gap.png )
10201021
1022+ #### Order Blocks
1023+
1024+ Order Blocks are zones where institutional traders (banks, hedge funds) placed large orders, causing significant price moves. They represent areas of supply and demand imbalance that often act as support/resistance when price returns.
1025+
1026+ ** Bullish Order Block:** The last bearish candle before a strong upward move. When price returns to this zone, it often bounces up (support).
1027+
1028+ ** Bearish Order Block:** The last bullish candle before a strong downward move. When price returns to this zone, it often reverses down (resistance).
1029+
1030+ ** Breaker Blocks:** When an Order Block is broken (invalidated), it becomes a breaker block and may act as the opposite type of support/resistance.
1031+
1032+ ``` python
1033+ def order_blocks (
1034+ data : Union[PdDataFrame, PlDataFrame],
1035+ swing_length : int = 10 ,
1036+ use_body : bool = False ,
1037+ high_column : str = ' High' ,
1038+ low_column : str = ' Low' ,
1039+ open_column : str = ' Open' ,
1040+ close_column : str = ' Close' ,
1041+ bullish_ob_column : str = ' bullish_ob' ,
1042+ bearish_ob_column : str = ' bearish_ob' ,
1043+ bullish_ob_top_column : str = ' bullish_ob_top' ,
1044+ bullish_ob_bottom_column : str = ' bullish_ob_bottom' ,
1045+ bearish_ob_top_column : str = ' bearish_ob_top' ,
1046+ bearish_ob_bottom_column : str = ' bearish_ob_bottom' ,
1047+ bullish_breaker_column : str = ' bullish_breaker' ,
1048+ bearish_breaker_column : str = ' bearish_breaker'
1049+ ) -> Union[PdDataFrame, PlDataFrame]:
1050+ ```
1051+
1052+ Example
1053+
1054+ ``` python
1055+ import pandas as pd
1056+ from pyindicators import order_blocks, ob_signal, get_active_order_blocks
1057+
1058+ # Create sample OHLC data
1059+ df = pd.DataFrame({
1060+ ' Open' : [100 , 102 , 101 , 105 , 110 , 108 , 112 , 115 , 113 , 118 ],
1061+ ' High' : [103 , 104 , 106 , 112 , 115 , 112 , 118 , 120 , 117 , 122 ],
1062+ ' Low' : [99 , 100 , 100 , 104 , 108 , 106 , 110 , 113 , 111 , 116 ],
1063+ ' Close' : [102 , 101 , 105 , 110 , 108 , 110 , 115 , 113 , 116 , 120 ]
1064+ })
1065+
1066+ # Detect Order Blocks
1067+ df = order_blocks(df, swing_length = 5 )
1068+ print (df[[' bullish_ob' , ' bearish_ob' , ' bullish_ob_top' , ' bullish_ob_bottom' ]])
1069+
1070+ # Generate signals when price enters an OB zone
1071+ df = ob_signal(df)
1072+ print (df[' ob_signal' ]) # 1 = in bullish zone, -1 = in bearish zone, 0 = outside
1073+
1074+ # Get currently active Order Blocks
1075+ active = get_active_order_blocks(df, max_bullish = 3 , max_bearish = 3 )
1076+ print (f " Active bullish OBs: { len (active[' bullish' ])} " )
1077+ print (f " Active bearish OBs: { len (active[' bearish' ])} " )
1078+ ```
1079+
1080+ The function returns columns for:
1081+ - ` bullish_ob ` / ` bearish_ob ` : 1 when Order Block is detected, 0 otherwise
1082+ - ` bullish_ob_top ` / ` bullish_ob_bottom ` : Zone boundaries for bullish OBs
1083+ - ` bearish_ob_top ` / ` bearish_ob_bottom ` : Zone boundaries for bearish OBs
1084+ - ` bullish_breaker ` / ` bearish_breaker ` : 1 when OB is broken (becomes breaker block)
1085+
1086+ The ` ob_signal ` function generates signals:
1087+ - ** 1** : Price is within a bullish OB zone (potential long entry)
1088+ - ** -1** : Price is within a bearish OB zone (potential short entry)
1089+ - ** 0** : Price is outside any OB zone
1090+
1091+ ![ ORDER_BLOCKS] ( https://github.com/coding-kitties/PyIndicators/blob/main/static/images/indicators/order_blocks.png )
1092+
10211093### Pattern Recognition
10221094
10231095#### Detect Peaks
0 commit comments