liquidity level finder
This commit is contained in:
+13
-5
@@ -20,8 +20,16 @@ def load_candles(filepath: str) -> list[Candle]:
|
|||||||
|
|
||||||
return candles
|
return candles
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def resample_candles(candles, period=5):
|
||||||
candles = load_candles("data.csv")
|
resampled = []
|
||||||
print(f"Loaded {len(candles)} candles")
|
for i in range(0, len(candles) - period + 1, period):
|
||||||
print(f"First: {candles[0]}")
|
group = candles[i:i + period]
|
||||||
print(f"Last: {candles[-1]}")
|
resampled.append(Candle(
|
||||||
|
time_open=group[0].time_open,
|
||||||
|
open=group[0].open,
|
||||||
|
high=max(c.high for c in group),
|
||||||
|
low=min(c.low for c in group),
|
||||||
|
close=group[-1].close,
|
||||||
|
volume=sum(c.volume for c in group)
|
||||||
|
))
|
||||||
|
return resampled
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
def find_liquidity_levels(swings, tolerance=0.015, max_distance=100):
|
||||||
|
levels = []
|
||||||
|
highs = [s for s in swings if s["type"] == "high"]
|
||||||
|
lows = [s for s in swings if s["type"] == "low"]
|
||||||
|
|
||||||
|
used = set()
|
||||||
|
for i, h1 in enumerate(highs):
|
||||||
|
if i in used:
|
||||||
|
continue
|
||||||
|
cluster = [h1]
|
||||||
|
for j, h2 in enumerate(highs):
|
||||||
|
if j != i and j not in used:
|
||||||
|
if abs(h1["price"] - h2["price"]) <= tolerance and abs(h1["index"] - h2["index"]) <= max_distance:
|
||||||
|
cluster.append(h2)
|
||||||
|
used.add(j)
|
||||||
|
if len(cluster) >= 2:
|
||||||
|
avg_price = sum(s["price"] for s in cluster) / len(cluster)
|
||||||
|
levels.append({
|
||||||
|
"price": avg_price,
|
||||||
|
"type": "equal_highs",
|
||||||
|
"count": len(cluster),
|
||||||
|
"indexes": [s["index"] for s in cluster]
|
||||||
|
})
|
||||||
|
used.add(i)
|
||||||
|
|
||||||
|
used = set()
|
||||||
|
for i, l1 in enumerate(lows):
|
||||||
|
if i in used:
|
||||||
|
continue
|
||||||
|
cluster = [l1]
|
||||||
|
for j, l2 in enumerate(lows):
|
||||||
|
if j != i and j not in used:
|
||||||
|
if abs(h1["price"] - h2["price"]) <= tolerance and abs(h1["index"] - h2["index"]) <= max_distance:
|
||||||
|
cluster.append(l2)
|
||||||
|
used.add(j)
|
||||||
|
if len(cluster) >= 2:
|
||||||
|
avg_price = sum(s["price"] for s in cluster) / len(cluster)
|
||||||
|
levels.append({
|
||||||
|
"price": avg_price,
|
||||||
|
"type": "equal_lows",
|
||||||
|
"count": len(cluster),
|
||||||
|
"indexes": [s["index"] for s in cluster]
|
||||||
|
})
|
||||||
|
used.add(i)
|
||||||
|
|
||||||
|
return levels
|
||||||
+16
-5
@@ -1,12 +1,23 @@
|
|||||||
from data.loader import load_candles
|
from data.loader import load_candles
|
||||||
from indicators.market_structure import find_swing_points, detect_structure
|
from indicators.market_structure import find_swing_points, detect_structure
|
||||||
|
from indicators.liquidity import find_liquidity_levels
|
||||||
|
|
||||||
candles = load_candles("data/data.csv")
|
candles = load_candles("data/data.csv")
|
||||||
print(f"Loaded {len(candles)} candles")
|
print(f"Loaded {len(candles)} candles")
|
||||||
|
from data.loader import load_candles, resample_candles
|
||||||
|
|
||||||
swings = find_swing_points(candles)
|
candles_1m = load_candles("data/data.csv")
|
||||||
structure = detect_structure(swings)
|
candles_3m = resample_candles(candles_1m, period=3)
|
||||||
print(f"Structure points: {len(structure)}")
|
candles_5m = resample_candles(candles_1m, period=5)
|
||||||
|
|
||||||
|
print(f"1m: {len(candles_1m)} candles")
|
||||||
|
print(f"3m: {len(candles_3m)} candles")
|
||||||
|
print(f"5m: {len(candles_5m)} candles")
|
||||||
|
|
||||||
|
swings = find_swing_points(candles_5m)
|
||||||
|
levels = find_liquidity_levels(swings)
|
||||||
|
print(f"Swing points: {len(swings)}")
|
||||||
|
print(f"Liquidity levels: {len(levels)}")
|
||||||
|
for l in levels[:5]:
|
||||||
|
print(l)
|
||||||
|
|
||||||
for s in structure[:10]:
|
|
||||||
print(s)
|
|
||||||
Reference in New Issue
Block a user