last ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,7 @@
|
||||
//
|
||||
// Imports ...
|
||||
#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"
|
||||
|
||||
//
|
||||
@@ -122,6 +123,10 @@ input int valeArrowCode = 159; // Vales Arrow Code
|
||||
//
|
||||
string eaLogTag; // EA Log Prefix ...
|
||||
XCBackTesterEA *eaExpert; // EA Expert ...
|
||||
XCMarketPatternDetector *eaPatternDetector; // EA Pattern Detector ...
|
||||
|
||||
//
|
||||
XBarTracker eaBarTracker; // EA Bar Traker ...
|
||||
|
||||
//
|
||||
int eaHandler = INVALID_HANDLE; // Indicator Handler ...
|
||||
@@ -284,6 +289,23 @@ int OnInit()
|
||||
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 ...");
|
||||
return INIT_SUCCEEDED;
|
||||
@@ -313,6 +335,13 @@ void OnDeinit(const int reason)
|
||||
// De Init Indicator ...
|
||||
IndicatorRelease(eaHandler);
|
||||
|
||||
//
|
||||
eaBarTracker.Clean();
|
||||
|
||||
//
|
||||
delete eaPatternDetector;
|
||||
ZeroMemory(eaPatternDetector);
|
||||
|
||||
//
|
||||
delete eaExpert;
|
||||
ZeroMemory(eaExpert);
|
||||
@@ -322,7 +351,156 @@ void OnDeinit(const int reason)
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -1110,6 +1110,116 @@ bool GetTick(
|
||||
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 ...
|
||||
//
|
||||
|
||||
@@ -747,6 +747,10 @@ bool IsValid(ENUM_X_SWING_TYPE value)
|
||||
//
|
||||
return result;
|
||||
}
|
||||
bool IsXValid(ENUM_X_SWING_TYPE value)
|
||||
{
|
||||
return IsValid(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts To String ...
|
||||
|
||||
@@ -1339,6 +1339,171 @@ struct XOHCL
|
||||
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 ...
|
||||
string GetTag(string prefix = "")
|
||||
|
||||
Reference in New Issue
Block a user