add support for FVG and Order Blocks in along side Support and Resistance ...

This commit is contained in:
2024-07-25 19:21:49 +03:30
parent cd04299a2a
commit 8525704eb1
3 changed files with 563 additions and 53 deletions
+2 -2
View File
@@ -371,8 +371,8 @@ bool InitialEA()
eaIgnoreSL, eaIgnoreSL,
eaAllowLong, eaAllowLong,
eaAllowShort, eaAllowShort,
eaMaxAllowedLongs, // Max Longs 1, // eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts 1 // eaMaxAllowedShorts // Max Shorts
); );
eurusdXCHKMStrategy.SetAlertLogAlerts(true); eurusdXCHKMStrategy.SetAlertLogAlerts(true);
eurusdXCHKMStrategy.SetAlertEnableAlerts(true); eurusdXCHKMStrategy.SetAlertEnableAlerts(true);
+210
View File
@@ -1663,6 +1663,216 @@ struct XOHCL
return result; return result;
} }
//
bool HasBullishPressure(
int _loopback = 7 //
)
{
//
bool result = false;
//
if (_loopback < 0)
{
_loopback = 7;
}
//
double bullishPressure = GetBullishPressure(_loopback);
double bearishPressure = GetBearishPressure(_loopback);
//
result =
//
bullishPressure > 0 &&
bearishPressure >= 0 &&
bullishPressure > bearishPressure
//
;
//
return result;
}
//
bool HasBearishPressure(
int _loopback = 7 //
)
{
//
bool result = false;
//
if (_loopback < 0)
{
_loopback = 7;
}
//
double bullishPressure = GetBullishPressure(_loopback);
double bearishPressure = GetBearishPressure(_loopback);
//
result =
//
bearishPressure > 0 &&
bullishPressure >= 0 &&
bearishPressure > bullishPressure
//
;
//
return result;
}
//
// Retrieve Bullish Power ...
double GetBullishPower(
int _loopback = 7 //
)
{
//
double result = 0;
//
if (!IsValid())
{
return result;
}
//
XOHCL bars[];
int barsCount = GetBars(
bars,
symbol,
period,
Index(),
_loopback //
);
if (!IsValidSize(barsCount))
{
return result;
}
//
for (int i = 0; i < barsCount; i++)
{
//
if (bars[i].IsBullish())
{
result += bars[i].GetBody();
}
}
//
return result;
}
//
// Retrieve Bearish Pressure ...
double GetBearishPower(
int _loopback = 7 //
)
{
//
double result = 0;
//
if (!IsValid())
{
return result;
}
//
XOHCL bars[];
int barsCount = GetBars(
bars,
symbol,
period,
Index(),
_loopback //
);
if (!IsValidSize(barsCount))
{
return result;
}
//
for (int i = 0; i < barsCount; i++)
{
//
if (bars[i].IsBearish())
{
result += bars[i].GetBody();
}
}
//
return result;
}
//
bool HasBullishPower(
int _loopback = 7 //
)
{
//
bool result = false;
//
if (_loopback < 0)
{
_loopback = 7;
}
//
double bullishPressure = GetBullishPower(_loopback);
double bearishPressure = GetBearishPower(_loopback);
//
result =
//
bullishPressure > 0 &&
bearishPressure >= 0 &&
bullishPressure > bearishPressure
//
;
//
return result;
}
//
bool HasBearishPower(
int _loopback = 7 //
)
{
//
bool result = false;
//
if (_loopback < 0)
{
_loopback = 7;
}
//
double bullishPressure = GetBullishPower(_loopback);
double bearishPressure = GetBearishPower(_loopback);
//
result =
//
bearishPressure > 0 &&
bullishPressure >= 0 &&
bearishPressure > bullishPressure
//
;
//
return result;
}
// //
// Touches ... // Touches ...
+351 -51
View File
@@ -270,6 +270,9 @@ public:
MODE_LOW // MODE_LOW //
); );
//
// Support nad Resistance ...
// //
// Check Support Exists or Find ... // Check Support Exists or Find ...
bool hasSupport = support.IsValid(); bool hasSupport = support.IsValid();
@@ -322,6 +325,118 @@ public:
} }
} }
//
// Order Blocks ...
//
bool hasBullishOB = bullishOB.IsValid();
if (!hasBullishOB)
{
//
hasBullishOB =
//
cBar.HasBullishOrderBlock(bullishOB)
//
;
//
if (hasBullishOB)
{
//
DrawBullishOrderBlock(
bullishOB,
ChartID() //
);
//
bullishOBTime = cBar.time;
}
}
//
bool hasBearishOB = bearishOB.IsValid();
if (!hasBearishOB)
{
//
hasBearishOB =
//
cBar.HasBearishOrderBlock(bearishOB)
//
;
//
if (hasBearishOB)
{
//
DrawBearishOrderBlock(
bearishOB,
ChartID() //
);
//
bearishOBTime = cBar.time;
}
}
//
// FVG ...
//
bool hasBullishFVG = bullishFVG.IsValid();
if (!hasBullishFVG)
{
//
hasBullishFVG =
//
cBar.HasBullishFVG(bullishFVGUpper, bullishFVGLower)
//
;
//
if (hasBullishFVG)
{
//
bullishFVG = cBar;
DrawBullishFVG(
bullishFVG,
bullishFVGUpper,
bullishFVGLower,
ChartID() //
);
//
bullishFVGTime = cBar.time;
}
}
//
bool hasBearishFVG = bearishFVG.IsValid();
if (!hasBearishFVG)
{
//
hasBearishFVG =
//
cBar.HasBearishFVG(bearishFVGUpper, bearishFVGLower)
//
;
//
if (hasBearishFVG)
{
//
bearishFVG = cBar;
DrawBearishFVG(
bearishFVG,
bearishFVGUpper,
bearishFVGLower,
ChartID() //
);
//
bearishFVGTime = cBar.time;
}
}
// //
// For Trend ... // For Trend ...
XOHCL tmpHSW[]; XOHCL tmpHSW[];
@@ -332,7 +447,9 @@ public:
// //
// Bullish ... // Bullish ...
bool hasBullishPower = cBar.HasBullishPower();
bool hasBullishPattern = HasBullishPattern(cBar); bool hasBullishPattern = HasBullishPattern(cBar);
bool hasBullishPressure = cBar.HasBullishPressure();
bool isBullishTrend = cBar.HasBullishTrend( bool isBullishTrend = cBar.HasBullishTrend(
tmpHSW, tmpHSW,
tmpLSW, tmpLSW,
@@ -341,7 +458,9 @@ public:
// //
// Bearish ... // Bearish ...
bool hasBearishPower = cBar.HasBearishPower();
bool hasBearishPattern = HasBearishPattern(cBar); bool hasBearishPattern = HasBearishPattern(cBar);
bool hasBearishPressure = cBar.HasBearishPressure();
bool isBearishTrend = cBar.HasBearishTrend( bool isBearishTrend = cBar.HasBearishTrend(
tmpHSW, tmpHSW,
tmpLSW, tmpLSW,
@@ -1086,7 +1205,7 @@ public:
// Bullish Conclusion ... // Bullish Conclusion ...
// //
bool isCHSTRCBullish = bool isCHSTRBullish =
// //
( (
// //
@@ -1294,7 +1413,7 @@ public:
// //
// Preparing Signals for Execution ... // Preparing Signals for Execution ...
bool allowCHMSignals = false; bool allowCHMSignals = false;
bool allowCHHKSignals = true; bool allowCHHKSignals = false;
bool allowCHSTRSignals = false; bool allowCHSTRSignals = false;
// //
@@ -1362,9 +1481,15 @@ public:
// //
hasLong = hasLong =
// //
isCHHKBullish && false
hasBullishPattern && //
chhkDistanceDiffInPoint <= pressureDistance // isCHMBullish &&
// isCHHKBullish &&
// isCHSTRBullish &&
// hasBullishPower &&
// hasBullishPressure &&
// hasBullishPattern &&
// chhkDistanceDiffInPoint <= pressureDistance
// //
; ;
@@ -1373,7 +1498,7 @@ public:
{ {
// //
type = POSITION_TYPE_BUY; type = POSITION_TYPE_BUY;
sl = chhkLowMax; sl = chhkLowMin;
} }
} }
@@ -1383,9 +1508,15 @@ public:
// //
hasShort = hasShort =
// //
isCHHKBearish && false
hasBearishPattern && //
chhkDistanceDiffInPoint <= pressureDistance // isCHMBearish &&
// isCHHKBearish &&
// isCHSTRBearish &&
// hasBearishPower &&
// hasBearishPressure &&
// hasBearishPattern &&
// chhkDistanceDiffInPoint <= pressureDistance
// //
; ;
@@ -1394,7 +1525,7 @@ public:
{ {
// //
type = POSITION_TYPE_SELL; type = POSITION_TYPE_SELL;
sl = chhkHighMin; sl = chhkHighMax;
} }
} }
} }
@@ -1406,6 +1537,9 @@ public:
{ {
} }
//
// Checking Long Conditions ...
// //
// forceCloseLongs = isCHHKBullishBreaked; // forceCloseLongs = isCHHKBullishBreaked;
// forceCloseShorts = isCHHKBearishBreaked; // forceCloseShorts = isCHHKBearishBreaked;
@@ -1447,6 +1581,16 @@ public:
// //
CheckSupportValidation(); CheckSupportValidation();
CheckResistanceValidation(); CheckResistanceValidation();
//
CheckBullishOBValidation();
CheckBearishOBValidation();
//
CheckBullishFVGValidation();
CheckBearishFVgValidation();
//
return result; return result;
} }
@@ -1470,6 +1614,46 @@ public:
resistance.Clean(); resistance.Clean();
} }
//
if (hasBullishOB)
{
//
bullishOBTime = NULL;
RemoveBullishOrderBlock(bullishOB);
bullishOB.Clean();
}
//
if (hasBearishOB)
{
//
bearishOBTime = NULL;
RemoveBearishOrderBlock(bearishOB);
bearishOB.Clean();
}
//
if (hasBullishFVG)
{
//
bullishFVGUpper = 0;
bullishFVGLower = 0;
bullishFVGTime = NULL;
RemoveBullishFVG(bullishFVG);
bullishFVG.Clean();
}
//
if (hasBearishFVG)
{
//
bearishFVGUpper = 0;
bearishFVGLower = 0;
bearishFVGTime = NULL;
RemoveBullishFVG(bearishFVG);
bearishFVG.Clean();
}
// //
// Retrieve Entry Price based on Position Type ... // Retrieve Entry Price based on Position Type ...
entry = GetEntry(mSymbol, type); entry = GetEntry(mSymbol, type);
@@ -1512,6 +1696,18 @@ protected:
// //
XOHCL support; XOHCL support;
XOHCL resistance; XOHCL resistance;
XOHCL bullishOB;
XOHCL bearishOB;
//
double bullishFVGUpper;
double bullishFVGLower;
XOHCL bullishFVG;
//
double bearishFVGUpper;
double bearishFVGLower;
XOHCL bearishFVG;
// //
// XPV ... // XPV ...
@@ -1557,6 +1753,26 @@ private:
resistanceTime = NULL; resistanceTime = NULL;
isResistanceTested = false; isResistanceTested = false;
//
// Short ...
ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
ENUM_TIMEFRAMES scPeriod = NULL; // PERIOD_M20; // Time Period
//
// Medium ...
ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
ENUM_TIMEFRAMES mcPeriod = NULL; // PERIOD_M30; // Time Period
//
// Long ...
ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
ENUM_TIMEFRAMES lcPeriod = NULL; // PERIOD_H1; // Time Period
//
// Hind ...
ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
ENUM_TIMEFRAMES hcPeriod = NULL; // PERIOD_H2; // Time Period
// //
// XPV ... // XPV ...
@@ -1564,14 +1780,14 @@ private:
pvInputs.Default(); pvInputs.Default();
// //
pvInputs.scMethod = X_PERIOD_MANUALLY; pvInputs.scMethod = scMethod;
pvInputs.scPeriod = PERIOD_M10; pvInputs.scPeriod = scPeriod;
pvInputs.mcMethod = X_PERIOD_MANUALLY; pvInputs.mcMethod = mcMethod;
pvInputs.mcPeriod = PERIOD_M15; pvInputs.mcPeriod = mcPeriod;
pvInputs.lcMethod = X_PERIOD_MANUALLY; pvInputs.lcMethod = lcMethod;
pvInputs.lcPeriod = PERIOD_M20; pvInputs.lcPeriod = lcPeriod;
pvInputs.hcMethod = X_PERIOD_MANUALLY; pvInputs.hcMethod = hcMethod;
pvInputs.hcPeriod = PERIOD_M30; pvInputs.hcPeriod = hcPeriod;
// //
pvInputs.showPeaksAndVales = true; pvInputs.showPeaksAndVales = true;
@@ -1598,10 +1814,10 @@ private:
cheInputs.Default(); cheInputs.Default();
// //
cheInputs.showLongExit1Line = false; cheInputs.showLongExit1Line = true;
cheInputs.showShortExit1Line = false; cheInputs.showShortExit1Line = true;
cheInputs.showLongExit2Line = false; cheInputs.showLongExit2Line = true;
cheInputs.showShortExit2Line = false; cheInputs.showShortExit2Line = true;
// //
cheHelper = new XSCXCHEHelper(); cheHelper = new XSCXCHEHelper();
@@ -1618,14 +1834,14 @@ private:
chmInputs.Default(); chmInputs.Default();
// //
chmInputs.scMethod = X_PERIOD_MANUALLY; chmInputs.scMethod = scMethod;
chmInputs.scPeriod = PERIOD_M10; chmInputs.scPeriod = scPeriod;
chmInputs.mcMethod = X_PERIOD_MANUALLY; chmInputs.mcMethod = mcMethod;
chmInputs.mcPeriod = PERIOD_M15; chmInputs.mcPeriod = mcPeriod;
chmInputs.lcMethod = X_PERIOD_MANUALLY; chmInputs.lcMethod = lcMethod;
chmInputs.lcPeriod = PERIOD_M20; chmInputs.lcPeriod = lcPeriod;
chmInputs.hcMethod = X_PERIOD_MANUALLY; chmInputs.hcMethod = hcMethod;
chmInputs.hcPeriod = PERIOD_M30; chmInputs.hcPeriod = hcPeriod;
// //
chmInputs.showFast = true; chmInputs.showFast = true;
@@ -1656,21 +1872,21 @@ private:
chhkInputs.Default(); chhkInputs.Default();
// //
chhkInputs.scMethod = X_PERIOD_MANUALLY; chhkInputs.scMethod = scMethod;
chhkInputs.scPeriod = PERIOD_M10; chhkInputs.scPeriod = scPeriod;
chhkInputs.mcMethod = X_PERIOD_MANUALLY; chhkInputs.mcMethod = mcMethod;
chhkInputs.mcPeriod = PERIOD_M15; chhkInputs.mcPeriod = mcPeriod;
chhkInputs.lcMethod = X_PERIOD_MANUALLY; chhkInputs.lcMethod = lcMethod;
chhkInputs.lcPeriod = PERIOD_M20; chhkInputs.lcPeriod = lcPeriod;
chhkInputs.hcMethod = X_PERIOD_MANUALLY; chhkInputs.hcMethod = hcMethod;
chhkInputs.hcPeriod = PERIOD_M30; chhkInputs.hcPeriod = hcPeriod;
// //
chhkInputs.showCurrent = false; chhkInputs.showCurrent = false;
chhkInputs.showShort = false; chhkInputs.showShort = false;
chhkInputs.showMedium = false; chhkInputs.showMedium = false;
chhkInputs.showLong = false; chhkInputs.showLong = false;
chhkInputs.showHind = false; chhkInputs.showHind = true;
// //
chhkHelper = new XSCXCHHKHelper(); chhkHelper = new XSCXCHHKHelper();
@@ -1687,20 +1903,20 @@ private:
chstrInputs.Default(); chstrInputs.Default();
// //
chstrInputs.scMethod = X_PERIOD_MANUALLY; chstrInputs.scMethod = scMethod;
chstrInputs.scPeriod = PERIOD_M10; chstrInputs.scPeriod = scPeriod;
chstrInputs.mcMethod = X_PERIOD_MANUALLY; chstrInputs.mcMethod = mcMethod;
chstrInputs.mcPeriod = PERIOD_M15; chstrInputs.mcPeriod = mcPeriod;
chstrInputs.lcMethod = X_PERIOD_MANUALLY; chstrInputs.lcMethod = lcMethod;
chstrInputs.lcPeriod = PERIOD_M20; chstrInputs.lcPeriod = lcPeriod;
chstrInputs.hcMethod = X_PERIOD_MANUALLY; chstrInputs.hcMethod = hcMethod;
chstrInputs.hcPeriod = PERIOD_M30; chstrInputs.hcPeriod = hcPeriod;
// //
chstrInputs.showCurrent = true; chstrInputs.showCurrent = false;
chstrInputs.showShort = true; chstrInputs.showShort = false;
chstrInputs.showMedium = true; chstrInputs.showMedium = false;
chstrInputs.showLong = true; chstrInputs.showLong = false;
chstrInputs.showHind = true; chstrInputs.showHind = true;
// //
@@ -1829,6 +2045,90 @@ private:
resistanceTime = NULL; resistanceTime = NULL;
resistance.Clean(); resistance.Clean();
} }
//
datetime bullishOBTime;
void CheckBullishOBValidation()
{
//
if (!IsValid(bullishOBTime))
{
return;
}
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishOBTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
bullishOBTime = NULL;
RemoveBullishOrderBlock(bullishOB);
bullishOB.Clean();
}
}
//
datetime bearishOBTime;
void CheckBearishOBValidation()
{
//
if (!IsValid(bearishOBTime))
{
return;
}
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishOBTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
bearishOBTime = NULL;
RemoveBearishOrderBlock(bearishOB);
bearishOB.Clean();
}
}
//
datetime bullishFVGTime;
void CheckBullishFVGValidation()
{
//
if (!IsValid(bullishFVGTime))
{
return;
}
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishFVGTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
bullishFVGTime = NULL;
RemoveBullishFVG(bullishFVG);
bullishFVG.Clean();
}
}
//
datetime bearishFVGTime;
void CheckBearishFVgValidation()
{
//
if (!IsValid(bearishFVGTime))
{
return;
}
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishFVGTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
bearishFVGTime = NULL;
RemoveBearishFVG(bearishFVG);
bearishFVG.Clean();
}
}
}; };
// //