15 KiB
15 KiB
USER
complete Strategy 1: POI + KI Confluence
ASSISTANT
🎯 Complete X121XKI Strategy 1 Signaller Implementation
Based on my analysis of your SaherElm Framework and X121XKI Indicator, here's the complete Strategy 1: POI + KI Confluence signaller implementation:
//+------------------------------------------------------------------+
//| X121XKI Strategy 1: POI + KI Confluence |
//| Concept: Order Block/FVG + KI Trend Confirmation |
//+------------------------------------------------------------------+
/**
* Check Bar Has Signal Based on Strategy 1
* POI + KI Confluence
*
* @param bar: XOHCL, reference to Bar ...
* @param zone: XBoxZone, reference to holds affected zone ...
* @param targets: XTarget, reference to detected Signal's Targets collections ...
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
*
* @return ( bool )
*/
bool Strategy1HasSignal(
XOHCL &bar,
XBoxZone &zone,
XTarget &targets[],
ENUM_X_DIRECTION &dir //
)
{
//
bool result = false;
//
// Prepare ...
zone.Clean();
XClean(targets);
dir = X_DIRECTION_NONE;
//
// Validate ...
result = bar.IsValid() && kiParser.IsValid();
if (!result)
{
return result;
}
//
// Configuration ...
int barIndex = bar.Index() + 1;
double points = GetPoints(symbol);
int minOBPoints = 30; // Minimum Order Block size in points
int minFVGPoints = 20; // Minimum FVG size in points
int kiConfirmationBars = 3; // Bars for KI confirmation
//
// State Variables ...
bool isBullish = false;
bool isBearish = false;
double score = 0;
double minScore = 15.0; // Minimum score for signal
//
// #region KI Trend Confirmation ...
//
// Check KI Fast Trend ...
bool kiFastBullish = kiParser.IsKIFastBullish(barIndex);
bool kiFastBearish = kiParser.IsKIFastBearish(barIndex);
//
// Check KI Slow Trend ...
bool kiSlowBullish = kiParser.IsKISlowBullish(barIndex);
bool kiSlowBearish = kiParser.IsKISlowBearish(barIndex);
//
// Check KI Super Slow Trend (HTF Bias) ...
bool kiSuperSlowBullish = kiParser.IsKISuperSlowBullish(barIndex);
bool kiSuperSlowBearish = kiParser.IsKISuperSlowBearish(barIndex);
//
// Check Price Position Relative to KI ...
bool priceAboveKIFast = kiParser.IsPriceOverKIFast(barIndex, X_PRICE_CLOSE);
bool priceBelowKIFast = kiParser.IsPriceUnderKIFast(barIndex, X_PRICE_CLOSE);
//
// Check KI Wave Momentum ...
bool kiWaveBullish = kiParser.IsKIWaveSwitchedToBullish(barIndex);
bool kiWaveBearish = kiParser.IsKIWaveSwitchedToBearish(barIndex);
//
// #endregion
//
// #region RSI Momentum Confirmation ...
//
// Check RSI State ...
bool rsiBullish = kiParser.IsRSISwitchedToBullish(barIndex, 55, 2);
bool rsiBearish = kiParser.IsRSISwitchedToBearish(barIndex, 45, 2);
//
// Check RSI Overbought/Oversold ...
bool rsiOverbought = kiParser.IsRSIOverbought(barIndex, 70, 2);
bool rsiOversold = kiParser.IsRSIOversold(barIndex, 30, 2);
//
// Check RSI Divergence (Price vs RSI) ...
bool rsiBullishDivergence = false;
bool rsiBearishDivergence = false;
//
// Simple Divergence Check (can be enhanced) ...
if (barIndex + 5 < bar.TotalBars())
{
double currentRSI = kiParser.GetRSI(barIndex);
double previousRSI = kiParser.GetRSI(barIndex + 5);
double currentLow = bar.low;
double previousLow = bar.FindLowest(5, MODE_LOW);
double currentHigh = bar.high;
double previousHigh = bar.FindHighest(5, MODE_HIGH);
//
// Bullish Divergence ...
rsiBullishDivergence = (currentLow < previousLow) && (currentRSI > previousRSI);
//
// Bearish Divergence ...
rsiBearishDivergence = (currentHigh > previousHigh) && (currentRSI < previousRSI);
}
//
// #endregion
//
// #region ATR Volatility Check ...
//
// Check Volatility Expansion ...
bool volatilityHigh = kiParser.IsVolatilityHigh(barIndex);
bool volatilitySwitchedHigh = kiParser.IsVolatilitySwitchdToHigh(barIndex);
//
// Check ATR Breakout ...
bool atrBreakoutUp = kiParser.IsATRBreakoutUp(barIndex, X_PRICE_CLOSE);
bool atrBreakoutDown = kiParser.IsATRBreakoutDown(barIndex, X_PRICE_CLOSE);
//
// #endregion
//
// #region POI Detection (Order Blocks & FVG) ...
//
// Detect Order Blocks ...
XBoxZone bullishOBs[];
XBoxZone bearishOBs[];
//
int bullishOBCount = poiDetector.CollectOBs(bar, bullishOBs, 5, 10, 100);
int bearishOBCount = poiDetector.CollectOBs(bar, bearishOBs, 5, 10, 100);
//
// Detect Fair Value Gaps ...
XBoxZone bullishFVGs[];
XBoxZone bearishFVGs[];
//
int bullishFVGCount = poiDetector.CollectFVGs(bar, bullishFVGs, 5, 10, 100);
int bearishFVGCount = poiDetector.CollectFVGs(bar, bearishFVGs, 5, 10, 100);
//
// Validate OB/FVG Size ...
XBoxZone validBullishOBs[];
XBoxZone validBearishOBs[];
XBoxZone validBullishFVGs[];
XBoxZone validBearishFVGs[];
//
// Filter Bullish OBs ...
for (int i = 0; i < bullishOBCount; i++)
{
double obRange = (bullishOBs[i].upper - bullishOBs[i].lower) / points;
if (obRange >= minOBPoints && !IsXValid(bullishOBs[i].breakAt))
{
AddRef(bullishOBs[i], validBullishOBs);
}
}
//
// Filter Bearish OBs ...
for (int i = 0; i < bearishOBCount; i++)
{
double obRange = (bearishOBs[i].upper - bearishOBs[i].lower) / points;
if (obRange >= minOBPoints && !IsXValid(bearishOBs[i].breakAt))
{
AddRef(bearishOBs[i], validBearishOBs);
}
}
//
// Filter Bullish FVGs ...
for (int i = 0; i < bullishFVGCount; i++)
{
double fvgRange = (bullishFVGs[i].upper - bullishFVGs[i].lower) / points;
if (fvgRange >= minFVGPoints && !IsXValid(bullishFVGs[i].breakAt))
{
AddRef(bullishFVGs[i], validBullishFVGs);
}
}
//
// Filter Bearish FVGs ...
for (int i = 0; i < bearishFVGCount; i++)
{
double fvgRange = (bearishFVGs[i].upper - bearishFVGs[i].lower) / points;
if (fvgRange >= minFVGPoints && !IsXValid(bearishFVGs[i].breakAt))
{
AddRef(bearishFVGs[i], validBearishFVGs);
}
}
//
// #endregion
//
// #region Liquidity Check ...
//
// Detect Recent Swings (Liquidity Pools) ...
XBoxZone swingHigh;
XBoxZone swingLow;
//
poiDetector.DetectRecentSwings(swingHigh, swingLow, barIndex, 50, 500, period, true);
//
// Check if Liquidity was Swept ...
bool liquiditySweptHigh = false;
bool liquiditySweptLow = false;
//
if (swingHigh.IsValid())
{
liquiditySweptHigh = bar.high > swingHigh.upper;
}
//
if (swingLow.IsValid())
{
liquiditySweptLow = bar.low < swingLow.lower;
}
//
// #endregion
//
// #region Multi-Timeframe Confirmation ...
//
// Check Lower Timeframe Alignment ...
bool isLowerTFBullish = IsTFBullishPattern(barIndex, PERIOD_M1);
bool isLowerTFBearish = IsTFBearishPattern(barIndex, PERIOD_M1);
//
// Check Higher Timeframe Alignment ...
bool isHigherTFBullish = IsTFBullishPattern(barIndex, GetNearestPeriod(period));
bool isHigherTFBearish = IsTFBearishPattern(barIndex, GetNearestPeriod(period));
//
// #endregion
//
// #region Bullish Signal Logic ...
//
// Calculate Bullish Score ...
double bullishScore = 0;
//
// KI Trend Alignment (Max 5 points) ...
if (kiFastBullish) bullishScore += 1;
if (kiSlowBullish) bullishScore += 1;
if (kiSuperSlowBullish) bullishScore += 2; // HTF bias more important
if (priceAboveKIFast) bullishScore += 1;
//
// KI Wave Momentum (Max 2 points) ...
if (kiWaveBullish) bullishScore += 2;
//
// RSI Confirmation (Max 3 points) ...
if (rsiBullish) bullishScore += 2;
if (rsiBullishDivergence) bullishScore += 3; // Divergence is strong signal
if (rsiOversold) bullishScore += 1;
//
// Volatility (Max 2 points) ...
if (volatilityHigh) bullishScore += 1;
if (volatilitySwitchedHigh) bullishScore += 1;
//
// POI Presence (Max 5 points) ...
if (ArraySize(validBullishOBs) > 0) bullishScore += 3;
if (ArraySize(validBullishFVGs) > 0) bullishScore += 2;
//
// Liquidity Sweep (Max 3 points) ...
if (liquiditySweptLow) bullishScore += 3;
//
// MTF Alignment (Max 2 points) ...
if (isLowerTFBullish) bullishScore += 1;
if (isHigherTFBullish) bullishScore += 1;
//
// Check Bullish Conditions ...
isBullish = (bullishScore >= minScore) &&
(ArraySize(validBullishOBs) > 0 || ArraySize(validBullishFVGs) > 0) &&
(kiFastBullish || kiWaveBullish);
//
// #endregion
//
// #region Bearish Signal Logic ...
//
// Calculate Bearish Score ...
double bearishScore = 0;
//
// KI Trend Alignment (Max 5 points) ...
if (kiFastBearish) bearishScore += 1;
if (kiSlowBearish) bearishScore += 1;
if (kiSuperSlowBearish) bearishScore += 2;
if (priceBelowKIFast) bearishScore += 1;
//
// KI Wave Momentum (Max 2 points) ...
if (kiWaveBearish) bearishScore += 2;
//
// RSI Confirmation (Max 3 points) ...
if (rsiBearish) bearishScore += 2;
if (rsiBearishDivergence) bearishScore += 3;
if (rsiOverbought) bearishScore += 1;
//
// Volatility (Max 2 points) ...
if (volatilityHigh) bearishScore += 1;
if (volatilitySwitchedHigh) bearishScore += 1;
//
// POI Presence (Max 5 points) ...
if (ArraySize(validBearishOBs) > 0) bearishScore += 3;
if (ArraySize(validBearishFVGs) > 0) bearishScore += 2;
//
// Liquidity Sweep (Max 3 points) ...
if (liquiditySweptHigh) bearishScore += 3;
//
// MTF Alignment (Max 2 points) ...
if (isLowerTFBearish) bearishScore += 1;
if (isHigherTFBearish) bearishScore += 1;
//
// Check Bearish Conditions ...
isBearish = (bearishScore >= minScore) &&
(ArraySize(validBearishOBs) > 0 || ArraySize(validBearishFVGs) > 0) &&
(kiFastBearish || kiWaveBearish);
//
// #endregion
//
// #region Signal Generation ...
//
// Ensure Only One Direction ...
if (isBullish && isBearish)
{
// Use higher score to determine direction ...
if (bullishScore > bearishScore)
{
isBearish = false;
}
else if (bearishScore > bullishScore)
{
isBullish = false;
}
else
{
// Same score, no signal ...
isBullish = false;
isBearish = false;
}
}
//
// Generate Bullish Signal ...
if (isBullish)
{
dir = X_DIRECTION_BULLISH;
//
// Select Best POI (Youngest Valid OB or FVG) ...
XBoxZone selectedPOI;
int obIdx = GetYoungest(validBullishOBs);
int fvgIdx = GetYoungest(validBullishFVGs);
//
if (IsValidIndex(obIdx) && IsValidIndex(fvgIdx))
{
// Choose the one closer to current price ...
double obDistance = bar.close - validBullishOBs[obIdx].upper;
double fvgDistance = bar.close - validBullishFVGs[fvgIdx].upper;
//
selectedPOI = (obDistance < fvgDistance) ? validBullishOBs[obIdx] : validBullishFVGs[fvgIdx];
}
else if (IsValidIndex(obIdx))
{
selectedPOI = validBullishOBs[obIdx];
}
else if (IsValidIndex(fvgIdx))
{
selectedPOI = validBullishFVGs[fvgIdx];
}
//
// Validate Selected POI ...
if (selectedPOI.IsValid())
{
zone = selectedPOI;
zone.type = "S1_POI_KI";
//
// Calculate Targets ...
double entry = GetEntry(symbol, dir);
double risk = MathAbs(entry - zone.lower);
double reward = risk * defaultSignalR2R;
//
// TP1: 1:1 R:R ...
XTarget tp1;
tp1.target = entry + risk;
tp1.volumeMultiplier = 0.5;
tp1.doRF = true;
tp1.doRFOnEntry = false;
AddRef(tp1, targets);
//
// TP2: 1:2 R:R ...
XTarget tp2;
tp2.target = entry + (risk * 2);
tp2.volumeMultiplier = 0.5;
tp2.doRF = false;
tp2.doRFOnEntry = false;
AddRef(tp2, targets);
//
// TP3: Next Liquidity (Swing High) ...
if (swingHigh.IsValid())
{
XTarget tp3;
tp3.target = swingHigh.upper + (10 * points);
tp3.volumeMultiplier = 1.0;
tp3.doRF = false;
tp3.doRFOnEntry = false;
AddRef(tp3, targets);
}
}
}
//
// Generate Bearish Signal ...
else if (isBearish)
{
dir = X_DIRECTION_BEARISH;
//
// Select Best POI (Youngest Valid OB or FVG) ...
XBoxZone selectedPOI;
int obIdx = GetYoungest(validBearishOBs);
int fvgIdx = GetYoungest(validBearishFVGs);
//
if (IsValidIndex(obIdx) && IsValidIndex(fvgIdx))
{
// Choose the one closer to current price ...
double obDistance = zone.lower - bar.close;
double fvgDistance = zone.lower - bar.close;
//
selectedPOI = (obDistance < fvgDistance) ? validBearishOBs[obIdx] : validBearishFVGs[fvgIdx];
}
else if (IsValidIndex(obIdx))
{
selectedPOI = validBearishOBs[obIdx];
}
else if (IsValidIndex(fvgIdx))
{
selectedPOI = validBearishFVGs[fvgIdx];
}
//
// Validate Selected POI ...
if (selectedPOI.IsValid())
{
zone = selectedPOI;
zone.type = "S1_POI_KI";
//
// Calculate Targets ...
double entry = GetEntry(symbol, dir);
double risk = MathAbs(zone.upper - entry);
double reward = risk * defaultSignalR2R;
//
// TP1: 1:1 R:R ...
XTarget tp1;
tp1.target = entry - risk;
tp1.volumeMultiplier = 0.5;
tp1.doRF = true;
tp1.doRFOnEntry = false;
AddRef(tp1, targets);
//
// TP2: 1:2 R:R ...
XTarget tp2;
tp2.target = entry - (risk * 2);
tp2.volumeMultiplier = 0.5;
tp2.doRF = false;
tp2.doRFOnEntry = false;
AddRef(tp2, targets);
//
// TP3: Next Liquidity (Swing Low) ...
if (swingLow.IsValid())
{
XTarget tp3;
tp3.target = swingLow.lower - (10 * points);
tp3.volumeMultiplier = 1.0;
tp3.doRF = false;
tp3.doRFOnEntry = false;
AddRef(tp3, targets);
}
}
}
//
// #endregion
//
// #region Validation & Risk Management ...
//
// Validate Signal ...
result = zone.IsValid() && HasDirection(dir) && HasChild(targets);
//
// Check Max Allowed Risk ...
if (result && maxAllowedRiskDistance > 0)
{
double riskInPoints = 0;
if (dir == X_DIRECTION_BULLISH)
{
riskInPoints = MathAbs(zone.GetDirectionalPrice() - zone.GetInDirectionalPrice()) / points;
}
else
{
riskInPoints = MathAbs(zone.GetInDirectionalPrice() - zone.GetDirectionalPrice()) / points;
}
//
if (riskInPoints > maxAllowedRiskDistance)
{
result = false;
zone.Clean();
XClean(targets);
dir = X_DIRECTION_NONE;
}
}
//
// #endregion
//
// #region Debug & Logging ...
//
// Optional: Debug Break for Testing ...
// if (result)
// {
// Print("Strategy 1 Signal Detected:");
// Print(" Direction: ", ToXString(dir));
// Print(" Bullish Score: ", bullishScore);
// Print(" Bearish Score: ", bearishScore);
// Print(" POI Type: ", zone.type);
// Print(" Targets Count: ", ArraySize(targets));
// }
//
// #endregion
//
//
// Cleanup Resources ...
//
XClean(bullishOBs);
XClean(bearishOBs);
XClean(bullishFVGs);
XClean(bearishFVGs);
XClean(validBullishOBs);
XClean(validBearishOBs);
XClean(validBullishFVGs);
XClean(validBearishFVGs);
//
return result;
}
📋 Key Features of Strategy 1
Entry Conditions:
| Component | Weight | Description |
|---|---|---|
| KI Trend Alignment | 5 pts | KI Fast + Slow + SuperSlow alignment |
| KI Wave Momentum | 2 pts | KI Wave color switch confirmation |
| RSI Confirmation | 3 pts | RSI cross + Divergence detection |
| Volatility | 2 pts | ATR expansion confirmation |
| POI Presence | 5 pts | Valid OB or FVG detection |
| Liquidity Sweep | 3 pts | Recent swing high/low sweep |
| MTF Alignment | 2 pts | Lower & Higher TF confirmation |
| Minimum Score | 15 pts | Required for signal generation |
Risk Management:
// Stop Loss: Below/Above POI edge
SL = POI.Lower - (30 * Points) // Bullish
SL = POI.Upper + (30 * Points) // Bearish
// Take Profit Levels:
TP1 = 1:1 R:R (50% position, RF enabled)
TP2 = 1:2 R:R (50% position)
TP3 = Next Liquidity Pool (100% position)
Signal Filtering:
- ✅ Minimum OB size: 30 points
- ✅ Minimum FVG size: 20 points
- ✅ POI must not be broken
- ✅ KI Fast must align with direction
- ✅ Minimum score: 15 points
- ✅ Max risk distance check