This commit is contained in:
2025-09-16 10:55:50 +03:30
parent 5dd58eec74
commit 83ef415ca2
5 changed files with 1530 additions and 4 deletions
File diff suppressed because it is too large Load Diff
+180 -2
View File
@@ -24,6 +24,7 @@
// //
// Imports ... // Imports ...
#include "../Classes/x-saherelm.x-backtester.expert.class.mq5" #include "../Classes/x-saherelm.x-backtester.expert.class.mq5"
#include "../Classes/x-saherelm.x-market.pattern.class.mq5"
#include "../Helpers/x-saherelm.xom1.helper.mq5" #include "../Helpers/x-saherelm.xom1.helper.mq5"
// //
@@ -120,8 +121,12 @@ input int valeArrowCode = 159; // Vales Arrow Code
// Define Local Variables ... // Define Local Variables ...
// //
string eaLogTag; // EA Log Prefix ... string eaLogTag; // EA Log Prefix ...
XCBackTesterEA *eaExpert; // EA Expert ... XCBackTesterEA *eaExpert; // EA Expert ...
XCMarketPatternDetector *eaPatternDetector; // EA Pattern Detector ...
//
XBarTracker eaBarTracker; // EA Bar Traker ...
// //
int eaHandler = INVALID_HANDLE; // Indicator Handler ... int eaHandler = INVALID_HANDLE; // Indicator Handler ...
@@ -284,6 +289,23 @@ int OnInit()
return INIT_FAILED; return INIT_FAILED;
} }
//
// Initialize Bar Tracker ...
isInited = eaBarTracker.Init(
_Symbol,
_Period //
);
if (!isInited)
{
//
Print(ShortName, ": Initialization Failed ...");
return INIT_FAILED;
}
//
// Instantiate Market Pattern Detector ...
eaPatternDetector = new XCMarketPatternDetector();
// //
Print(ShortName, ": Initialized Successfully ..."); Print(ShortName, ": Initialized Successfully ...");
return INIT_SUCCEEDED; return INIT_SUCCEEDED;
@@ -313,6 +335,13 @@ void OnDeinit(const int reason)
// De Init Indicator ... // De Init Indicator ...
IndicatorRelease(eaHandler); IndicatorRelease(eaHandler);
//
eaBarTracker.Clean();
//
delete eaPatternDetector;
ZeroMemory(eaPatternDetector);
// //
delete eaExpert; delete eaExpert;
ZeroMemory(eaExpert); ZeroMemory(eaExpert);
@@ -322,7 +351,156 @@ void OnDeinit(const int reason)
// On Tick Handler ... // On Tick Handler ...
void OnTick() void OnTick()
{ {
//
eaExpert.HandleOnTick(); eaExpert.HandleOnTick();
//
bool isNewBar = eaBarTracker.IsNewBar();
if (isNewBar)
{
//
// Initialize 1 Indexed Bar ...
XOHCL cBar;
bool has = cBar.Init(
_Symbol,
_Period,
1 //
);
if (has)
{
//
// Do Analysis ...
//
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
//
// Checking Momentum Bar ...
bool isMomentum = eaPatternDetector.IsMomentumBar(
cBar,
iDir //
);
bool isBullishMomentum = isMomentum &&
IsSpecifiedBullish(iDir);
bool isBearishMomentum = isMomentum &&
IsSpecifiedBearish(iDir);
if (isMomentum)
{
Print(ToXString(iDir), " Momentum Bar: ", cBar.time);
}
//
// Checking Engulfed Bar ...
bool isEngulfed = eaPatternDetector.IsEngulfedBar(
cBar,
iDir //
);
bool isBullishEngulfed = isEngulfed &&
IsSpecifiedBullish(iDir);
bool isBearishEngulfed = isEngulfed &&
IsSpecifiedBearish(iDir);
if (isEngulfed)
{
Print(ToXString(iDir), " Engulfed Bar: ", cBar.time);
}
//
// Checking TruGaped Bar ...
bool isTrueGaped = eaPatternDetector.IsTrueGapedBar(
cBar,
iDir //
);
bool isBullishTrueGaped = isTrueGaped &&
IsSpecifiedBullish(iDir);
bool isBearishTrueGaped = isTrueGaped &&
IsSpecifiedBearish(iDir);
if (isTrueGaped)
{
Print(ToXString(iDir), " TrueGapped Bar: ", cBar.time);
}
//
// Checking Pinned Bar ...
bool isPinned = eaPatternDetector.IsPinnedBar(
cBar,
iDir //
);
bool isBullishPinned = isPinned &&
IsSpecifiedBullish(iDir);
bool isBearishPinned = isPinned &&
IsSpecifiedBearish(iDir);
if (isPinned)
{
Print(ToXString(iDir), " Pinned Bar: ", cBar.time);
}
//
// Checking Star Pattern ...
bool isStarPattern = eaPatternDetector.IsStartPattern(
cBar,
iDir //
);
bool isBullishStarPattern = isStarPattern &&
IsSpecifiedBullish(iDir);
bool isBearishStarPattern = isStarPattern &&
IsSpecifiedBearish(iDir);
if (isStarPattern)
{
Print(ToXString(iDir), " Star Pattern: ", cBar.time);
}
//
// Checking Piercing Pattern ...
bool isPiercingPattern = eaPatternDetector.IsPiercingPattern(
cBar,
iDir //
);
bool isBullishPiercingPattern = isPiercingPattern &&
IsSpecifiedBullish(iDir);
bool isBearishPiercingPattern = isPiercingPattern &&
IsSpecifiedBearish(iDir);
if (isPiercingPattern)
{
Print(ToXString(iDir), " Piercing Pattern: ", cBar.time);
}
//
// Checking Rising Pattern ...
bool isRisingPattern = eaPatternDetector.IsRisingPattern(
cBar,
iDir //
);
bool isBullishRisingPattern = isRisingPattern &&
IsSpecifiedBullish(iDir);
bool isBearishRisingPattern = isRisingPattern &&
IsSpecifiedBearish(iDir);
if (isRisingPattern)
{
Print(ToXString(iDir), " Rising Pattern: ", cBar.time);
}
//
// Checking Flag Pattern ...
XOHCL swingBar;
bool isFlagPattern = eaPatternDetector.IsFlagPattern(
cBar,
iDir,
swingBar //
);
bool isBullishFlagPattern = isFlagPattern &&
IsSpecifiedBullish(iDir);
bool isBearishFlagPattern = isFlagPattern &&
IsSpecifiedBearish(iDir);
if (isFlagPattern)
{
Print(ToXString(iDir), " Flag Pattern: ", cBar.time, ", Swing: ", swingBar.time);
}
swingBar.Clean();
}
//
cBar.Clean();
}
} }
// //
+112 -2
View File
@@ -862,9 +862,9 @@ double GetXSpread(
/** /**
* Get SPecified Symbols Volume Step ... * Get SPecified Symbols Volume Step ...
* *
* @param mSymbol: string ... * @param mSymbol: string ...
* *
* @return ( double ) * @return ( double )
*/ */
double GetVolumeStep( double GetVolumeStep(
@@ -1110,6 +1110,116 @@ bool GetTick(
return SymbolInfoTick(mSymbol, tick); return SymbolInfoTick(mSymbol, tick);
} }
//
// Peak and Vales ...
int FindXSwing(
ENUM_X_SWING_TYPE mType,
string mSymbol = NULL,
ENUM_TIMEFRAMES mPeriod = NULL,
int mFromIndex = 0,
int mShoulders = 5 //
)
{
//
int result = -1;
//
// Validate ...
if (!IsXValid(mType))
{
return result;
}
//
result = mFromIndex;
int foundedIDX = FindXNextSwing(
mType,
mSymbol,
mPeriod,
result - mShoulders,
mShoulders * 2 + 1 //
);
while (foundedIDX != result)
{
//
result = FindXNextSwing(
mType,
mSymbol,
mPeriod,
result + 1,
mShoulders //
);
//
foundedIDX = FindXNextSwing(
mType,
mSymbol,
mPeriod,
result - mShoulders,
mShoulders * 2 + 1 //
);
}
//
return result;
}
int FindXNextSwing(
ENUM_X_SWING_TYPE mType,
string mSymbol = NULL,
ENUM_TIMEFRAMES mPeriod = NULL,
int mFromIndex = 0,
int mShoulders = 5 //
)
{
//
int result = -1;
//
if (mFromIndex < 0)
{
mShoulders += mFromIndex;
}
//
// Normalize ...
mSymbol = NormalizeSymbol(mSymbol);
mPeriod = NormalizePeriod(mPeriod);
mFromIndex = NormalizeInt(mFromIndex, 0);
mShoulders = NormalizeInt(mShoulders, 3);
//
// Validate ....
if (!IsXValid(mType))
{
return result;
}
//
// Converts Swing Type to Series Mode ...
ENUM_SERIESMODE mode = ToSeriesMode(mType);
result =
mode == MODE_HIGH
? iHighest(
mSymbol,
mPeriod,
mode,
mShoulders,
mFromIndex //
)
: iLowest(
mSymbol,
mPeriod,
mode,
mShoulders,
mFromIndex //
);
//
return result;
}
// //
// END Position ... // END Position ...
// //
+4
View File
@@ -747,6 +747,10 @@ bool IsValid(ENUM_X_SWING_TYPE value)
// //
return result; return result;
} }
bool IsXValid(ENUM_X_SWING_TYPE value)
{
return IsValid(value);
}
/** /**
* Converts To String ... * Converts To String ...
+165
View File
@@ -1339,6 +1339,171 @@ struct XOHCL
return result; return result;
} }
//
// Swing Detection ...
//
int FindSwing(
ENUM_X_SWING_TYPE type,
int shoulders = 3 //
)
{
//
int result = -1;
//
// Validate ...
bool isValid = IsValid() &&
IsXValid(type);
if (!isValid)
{
return result;
}
//
// Find Next Swing ...
result = FindXSwing(
type,
symbol,
period,
Index(),
shoulders //
);
//
return result;
}
//
int FindNextSwing(
ENUM_X_SWING_TYPE type,
int shoulders = 3 //
)
{
//
int result = -1;
//
// Validate ...
bool isValid = IsValid() &&
IsXValid(type);
if (!isValid)
{
return result;
}
//
// Find Next Swing ...
result = FindXSwing(
type,
symbol,
period,
Index() + 1,
shoulders //
);
//
return result;
}
//
bool FindSwingBar(
ENUM_X_SWING_TYPE type,
XOHCL &swingBar,
int shoulders = 3 //
)
{
//
bool result = false;
//
// Prepare ...
swingBar.Clean();
//
// Validate ...
result = IsValid() &&
IsXValid(type);
if (!result)
{
return result;
}
//
// Find Next Swing ...
int idx = FindXSwing(
type,
symbol,
period,
Index(),
shoulders //
);
result = IsValidIndex(idx);
if (!result)
{
return result;
}
//
result = swingBar.Init(
symbol,
period,
idx //
);
//
return result;
}
//
bool FindNextSwingBar(
ENUM_X_SWING_TYPE type,
XOHCL &swingBar,
int shoulders = 3 //
)
{
//
bool result = false;
//
// Prepare ...
swingBar.Clean();
//
// Validate ...
result = IsValid() &&
IsXValid(type);
if (!result)
{
return result;
}
//
// Find Next Swing ...
int idx = FindXSwing(
type,
symbol,
period,
Index() + 1,
shoulders //
);
result = IsValidIndex(idx);
if (!result)
{
return result;
}
//
result = swingBar.Init(
symbol,
period,
idx //
);
//
return result;
}
// //
// Other ... // Other ...
string GetTag(string prefix = "") string GetTag(string prefix = "")