fvg and ob indicators
Front-end start
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from data.loader import load_candles, resample_candles
|
||||
from indicators.market_structure import find_swing_points, detect_structure
|
||||
from indicators.liquidity import find_liquidity_levels
|
||||
from indicators.fvg import find_fvgs
|
||||
from indicators.order_blocks import find_order_blocks
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@app.get("/api/candles")
|
||||
def get_candles(timeframe: int = 5):
|
||||
candles_1m = load_candles("data/data.csv")
|
||||
candles = resample_candles(candles_1m, period=timeframe)
|
||||
|
||||
return {
|
||||
"candles": [
|
||||
{
|
||||
"time": c.time_open.isoformat(),
|
||||
"open": c.open,
|
||||
"high": c.high,
|
||||
"low": c.low,
|
||||
"close": c.close
|
||||
}
|
||||
for c in candles
|
||||
]
|
||||
}
|
||||
|
||||
@app.get("/api/indicators")
|
||||
def get_indicators(timeframe: int = 5):
|
||||
candles_1m = load_candles("data/data.csv")
|
||||
candles = resample_candles(candles_1m, period=timeframe)
|
||||
|
||||
swings = find_swing_points(candles)
|
||||
structure = detect_structure(swings)
|
||||
levels = find_liquidity_levels(swings)
|
||||
fvgs = find_fvgs(candles)
|
||||
obs = find_order_blocks(candles, structure)
|
||||
|
||||
return {
|
||||
"swings": swings,
|
||||
"structure": structure,
|
||||
"liquidity": levels,
|
||||
"fvgs": fvgs,
|
||||
"order_blocks": obs
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
def find_fvgs(candles):
|
||||
fvgs = []
|
||||
|
||||
for i in range(2, len(candles)):
|
||||
c1 = candles[i - 2]
|
||||
c2 = candles[i - 1]
|
||||
c3 = candles[i]
|
||||
|
||||
# Bullish
|
||||
if c1.high < c3.low:
|
||||
fvgs.append({
|
||||
"index": i - 1,
|
||||
"type": "bullish",
|
||||
"top": c3.low,
|
||||
"bottom": c1.high
|
||||
})
|
||||
|
||||
# bearish
|
||||
elif c1.low > c3.high:
|
||||
fvgs.append({
|
||||
"index": i - 1,
|
||||
"type": "bearish",
|
||||
"top": c1.low,
|
||||
"bottom": c3.high
|
||||
})
|
||||
|
||||
return fvgs
|
||||
@@ -0,0 +1,31 @@
|
||||
def find_order_blocks(candles, structure, min_impulse=0.10):
|
||||
obs = []
|
||||
|
||||
for point in structure:
|
||||
if point["label"] == "HH":
|
||||
# Bullish break of structure, look back for last bearish candle
|
||||
idx = point["index"]
|
||||
for j in range(idx - 1, max(idx - 20, 0), -1):
|
||||
if candles[j].close < candles[j].open:
|
||||
obs.append({
|
||||
"index": j,
|
||||
"type": "bullish",
|
||||
"top": candles[j].open,
|
||||
"bottom": candles[j].close
|
||||
})
|
||||
break
|
||||
|
||||
elif point["label"] == "LL":
|
||||
# Bearish break of structure, look back for last bullish candle
|
||||
idx = point["index"]
|
||||
for j in range(idx - 1, max(idx - 20, 0), -1):
|
||||
if candles[j].close > candles[j].open:
|
||||
obs.append({
|
||||
"index": j,
|
||||
"type": "bearish",
|
||||
"top": candles[j].close,
|
||||
"bottom": candles[j].open
|
||||
})
|
||||
break
|
||||
|
||||
return obs
|
||||
+14
-9
@@ -1,10 +1,8 @@
|
||||
from data.loader import load_candles
|
||||
from data.loader import load_candles, resample_candles
|
||||
from indicators.market_structure import find_swing_points, detect_structure
|
||||
from indicators.liquidity import find_liquidity_levels
|
||||
|
||||
candles = load_candles("data/data.csv")
|
||||
print(f"Loaded {len(candles)} candles")
|
||||
from data.loader import load_candles, resample_candles
|
||||
from indicators.fvg import find_fvgs
|
||||
from indicators.order_blocks import find_order_blocks
|
||||
|
||||
candles_1m = load_candles("data/data.csv")
|
||||
candles_3m = resample_candles(candles_1m, period=3)
|
||||
@@ -15,9 +13,16 @@ print(f"3m: {len(candles_3m)} candles")
|
||||
print(f"5m: {len(candles_5m)} candles")
|
||||
|
||||
swings = find_swing_points(candles_5m)
|
||||
structure = detect_structure(swings)
|
||||
levels = find_liquidity_levels(swings)
|
||||
print(f"Swing points: {len(swings)}")
|
||||
print(f"Liquidity levels: {len(levels)}")
|
||||
for l in levels[:5]:
|
||||
print(l)
|
||||
fvgs = find_fvgs(candles_5m)
|
||||
obs = find_order_blocks(candles_5m, structure)
|
||||
|
||||
print(f"Swing points: {len(swings)}")
|
||||
print(f"Structure points: {len(structure)}")
|
||||
print(f"Liquidity levels: {len(levels)}")
|
||||
print(f"FVGs: {len(fvgs)}")
|
||||
print(f"Order blocks: {len(obs)}")
|
||||
|
||||
for o in obs[:5]:
|
||||
print(o)
|
||||
Reference in New Issue
Block a user