700 lines
19 KiB
Plaintext
700 lines
19 KiB
Plaintext
|
|
/**
|
|
* Check Market Conditions for Pattern Detection ...
|
|
*/
|
|
void DetectPatterns()
|
|
{
|
|
//
|
|
if (!eaIsNewBar)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Initialize 1 Indexed Bar ...
|
|
XOHCL cBar;
|
|
bool has = cBar.Init(
|
|
_Symbol,
|
|
_Period,
|
|
1 //
|
|
);
|
|
if (!has)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Do Analysis ...
|
|
|
|
//
|
|
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
// Define Detection Flags ...
|
|
|
|
//
|
|
bool detectPinned = false;
|
|
bool detectMomentum = false;
|
|
bool detectEngulfed = false;
|
|
bool detectTrueGaped = false;
|
|
|
|
//
|
|
bool detectStarPattern = false;
|
|
bool detectFlagPattern = false;
|
|
bool detectRisingPattern = false;
|
|
bool detectPiercingPattern = false;
|
|
bool detectSignalKeyBarPattern = false;
|
|
|
|
//
|
|
bool detectSwingTrend = false;
|
|
bool detectSwingTrendBreakes = false;
|
|
|
|
//
|
|
bool detectSupports = false;
|
|
bool detectResistance = false;
|
|
|
|
//
|
|
// XFIMA Patetrns ...
|
|
bool detectFIMAPatterns = true;
|
|
//
|
|
bool detectFIMAPVPatterns = false;
|
|
bool detectFIMAMAPatterns = false;
|
|
bool detectFIMASARPatterns = false;
|
|
bool detectFIMAZigZagPatterns = false;
|
|
//
|
|
bool analyseFIMAPVPivots = true;
|
|
bool analyseFIMAMAPivots = true;
|
|
bool analyseFIMASARPivots = true;
|
|
bool analyseFIMAZigZagPivots = true;
|
|
|
|
//
|
|
// Required Pivots ...
|
|
int numberOfRequiredPivots = 15;
|
|
|
|
//
|
|
// Checking Momentum Bar ...
|
|
if (detectMomentum)
|
|
{
|
|
//
|
|
bool isMomentum = fima2Signaller.poiDetector.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 ...
|
|
if (detectEngulfed)
|
|
{
|
|
//
|
|
bool isEngulfed = fima2Signaller.poiDetector.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 ...
|
|
if (detectTrueGaped)
|
|
{
|
|
//
|
|
bool isTrueGaped = fima2Signaller.poiDetector.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 ...
|
|
if (detectPinned)
|
|
{
|
|
bool isPinned = fima2Signaller.poiDetector.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 ...
|
|
if (detectStarPattern)
|
|
{
|
|
bool isStarPattern = fima2Signaller.poiDetector.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 ...
|
|
if (detectPiercingPattern)
|
|
{
|
|
//
|
|
bool isPiercingPattern = fima2Signaller.poiDetector.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 ...
|
|
if (detectRisingPattern)
|
|
{
|
|
//
|
|
bool isRisingPattern = fima2Signaller.poiDetector.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 ...
|
|
if (detectFlagPattern)
|
|
{
|
|
//
|
|
XOHCL swingBar;
|
|
bool isFlagPattern = fima2Signaller.poiDetector.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();
|
|
}
|
|
|
|
//
|
|
// Detect SignalKey Bar Pattern ...
|
|
if (detectSignalKeyBarPattern)
|
|
{
|
|
//
|
|
bool isSignalKeyBar = fima2Signaller.poiDetector.IsSignalKeyBarPattern(
|
|
cBar,
|
|
iDir //
|
|
);
|
|
bool isBullishSignalKeyBar = isSignalKeyBar &&
|
|
IsSpecifiedBullish(iDir);
|
|
bool isBearishSignalKeyBar = isSignalKeyBar &&
|
|
IsSpecifiedBearish(iDir);
|
|
if (isSignalKeyBar)
|
|
{
|
|
Print(ToXString(iDir), " SignalKey Bar Pattern: ", cBar.time);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Detect Swing Trend ...
|
|
if (detectSwingTrend)
|
|
{
|
|
//
|
|
XOHCL swings[];
|
|
bool hasSwingTrend = fima2Signaller.poiDetector.HasSwingTrend(
|
|
cBar,
|
|
iDir,
|
|
swings //
|
|
);
|
|
bool hasBullishSwingTrend = hasSwingTrend &&
|
|
IsSpecifiedBullish(iDir);
|
|
bool hasBearishSwingTrend = hasSwingTrend &&
|
|
IsSpecifiedBearish(iDir);
|
|
if (hasSwingTrend)
|
|
{
|
|
//
|
|
Print(ToXString(iDir), " Swing Trend: ", cBar.time);
|
|
|
|
//
|
|
CChartObjectTrend *iObj;
|
|
has = fima2Signaller.poiDrawer.DrawSwingTrend(
|
|
swings,
|
|
iDir,
|
|
iObj,
|
|
true // Ray Right ...
|
|
);
|
|
if (has)
|
|
{
|
|
eaDraws.Add(iObj);
|
|
}
|
|
}
|
|
SpecifiedClean(swings);
|
|
}
|
|
|
|
//
|
|
// Swing Trend Breakes ...
|
|
if (detectSwingTrendBreakes)
|
|
{
|
|
//
|
|
XOHCL swings[];
|
|
bool hasSwingTrend = fima2Signaller.poiDetector.HasSwingTrend(
|
|
cBar,
|
|
iDir,
|
|
swings //
|
|
);
|
|
bool hasBullishSwingTrend = hasSwingTrend &&
|
|
IsSpecifiedBullish(iDir);
|
|
bool hasBearishSwingTrend = hasSwingTrend &&
|
|
IsSpecifiedBearish(iDir);
|
|
if (hasSwingTrend)
|
|
{
|
|
//
|
|
if (!HasDirection(trendDir))
|
|
{
|
|
trendDir = iDir;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Breaked Detection ...
|
|
if (trendDir != iDir)
|
|
{
|
|
//
|
|
Print("Trend Dir Breaked to: ", ToXString(iDir));
|
|
trendDir = iDir;
|
|
}
|
|
|
|
//
|
|
SpecifiedClean(swings);
|
|
}
|
|
|
|
//
|
|
// Detect Supports ...
|
|
if (detectSupports)
|
|
{
|
|
//
|
|
XOHCL support;
|
|
bool hasSupport = fima2Signaller.poiDetector.HasSupport(
|
|
cBar,
|
|
support //
|
|
);
|
|
if (hasSupport)
|
|
{
|
|
//
|
|
XBoxZone supportBox;
|
|
has = ToSupportBox(support, supportBox);
|
|
if (has)
|
|
{
|
|
//
|
|
// Draw Box ...
|
|
XCBoxObject *iObj;
|
|
has = fima2Signaller.poiDrawer.DrawBox(
|
|
supportBox,
|
|
iObj //
|
|
);
|
|
if (has)
|
|
{
|
|
eaDraws.Add(iObj);
|
|
}
|
|
|
|
//
|
|
ZeroMemory(iObj);
|
|
}
|
|
|
|
//
|
|
supportBox.Clean();
|
|
}
|
|
support.Clean();
|
|
}
|
|
|
|
//
|
|
// Detect Resistance ...
|
|
if (detectResistance)
|
|
{
|
|
//
|
|
XOHCL resistance;
|
|
bool hasResistance = fima2Signaller.poiDetector.HasResistance(
|
|
cBar,
|
|
resistance //
|
|
);
|
|
if (hasResistance)
|
|
{
|
|
//
|
|
XBoxZone resistanceBox;
|
|
has = ToResistanceBox(resistance, resistanceBox);
|
|
if (has)
|
|
{
|
|
//
|
|
// Draw Box ...
|
|
XCBoxObject *iObj;
|
|
has = fima2Signaller.poiDrawer.DrawBox(
|
|
resistanceBox,
|
|
iObj //
|
|
);
|
|
if (has)
|
|
{
|
|
eaDraws.Add(iObj);
|
|
}
|
|
|
|
//
|
|
ZeroMemory(iObj);
|
|
}
|
|
|
|
//
|
|
resistanceBox.Clean();
|
|
}
|
|
resistance.Clean();
|
|
}
|
|
|
|
//
|
|
// Detecting FIMA Patterns ...
|
|
if (detectFIMAPatterns)
|
|
{
|
|
//
|
|
// Check For PV Pivots ...
|
|
if (detectFIMAPVPatterns)
|
|
{
|
|
//
|
|
XPivot pivots[];
|
|
int pivotsCount = fima2Signaller.poiDetector.ExtractPVPivots(
|
|
pivots, // Result ...
|
|
cBar.Index(), // Bar Index ...
|
|
numberOfRequiredPivots, // Required Number of Pivots ...
|
|
1500, // Max Allowed Loopback ...
|
|
10 // Validation Length ...
|
|
);
|
|
has = IsValidSize(pivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
CArrayObj *drawnPivots = new CArrayObj();
|
|
int drawnPivotsCount = fima2Signaller.poiDrawer.DrawPivots(
|
|
pivots,
|
|
drawnPivots //
|
|
);
|
|
has = IsValidSize(drawnPivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
AddObjects(
|
|
drawnPivots,
|
|
eaDraws //
|
|
);
|
|
|
|
//
|
|
// Print("Pivots Extracted ...");
|
|
}
|
|
|
|
//
|
|
ZeroMemory(drawnPivots);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check for MA Patterns ...
|
|
if (detectFIMAMAPatterns)
|
|
{
|
|
//
|
|
XPivot pivots[];
|
|
int pivotsCount = fima2Signaller.poiDetector.ExtractMAPivots(
|
|
pivots, // Result ...
|
|
cBar.Index(), // Bar Index ...
|
|
numberOfRequiredPivots, // Required Number of Pivots ...
|
|
1500, // Max Allowed Loopback ...
|
|
0 // Validation Length ...
|
|
);
|
|
has = IsValidSize(pivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
CArrayObj *drawnPivots = new CArrayObj();
|
|
int drawnPivotsCount = fima2Signaller.poiDrawer.DrawPivots(
|
|
pivots,
|
|
drawnPivots //
|
|
);
|
|
has = IsValidSize(drawnPivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
AddObjects(
|
|
drawnPivots,
|
|
eaDraws //
|
|
);
|
|
|
|
//
|
|
// Print("Pivots Extracted ...");
|
|
}
|
|
|
|
//
|
|
ZeroMemory(drawnPivots);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check for SAR Pivots ...
|
|
if (detectFIMASARPatterns)
|
|
{
|
|
//
|
|
XPivot pivots[];
|
|
int pivotsCount = fima2Signaller.poiDetector.ExtractSARPivots(
|
|
pivots, // Result ...
|
|
cBar.Index(), // Bar Index ...
|
|
numberOfRequiredPivots, // Required Number of Pivots ...
|
|
1500 // Max Allowed Loopback ...
|
|
);
|
|
has = IsValidSize(pivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
CArrayObj *drawnPivots = new CArrayObj();
|
|
int drawnPivotsCount = fima2Signaller.poiDrawer.DrawPivots(
|
|
pivots,
|
|
drawnPivots //
|
|
);
|
|
has = IsValidSize(drawnPivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
AddObjects(
|
|
drawnPivots,
|
|
eaDraws //
|
|
);
|
|
|
|
//
|
|
// Print("Pivots Extracted ...");
|
|
}
|
|
|
|
//
|
|
ZeroMemory(drawnPivots);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check for ZigZag Pivots ...
|
|
if (detectFIMAZigZagPatterns)
|
|
{
|
|
//
|
|
XPivot pivots[];
|
|
int pivotsCount = fima2Signaller.poiDetector.ExtractZigZagPivots(
|
|
pivots,
|
|
cBar.Index(),
|
|
numberOfRequiredPivots,
|
|
1500 //
|
|
);
|
|
has = IsValidSize(pivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
CArrayObj *drawnPivots = new CArrayObj();
|
|
int drawnPivotsCount = fima2Signaller.poiDrawer.DrawPivots(
|
|
pivots,
|
|
drawnPivots //
|
|
);
|
|
has = IsValidSize(drawnPivotsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
AddObjects(
|
|
drawnPivots,
|
|
eaDraws //
|
|
);
|
|
|
|
//
|
|
// Print("Pivots Extracted ...");
|
|
}
|
|
|
|
//
|
|
ZeroMemory(drawnPivots);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Analysers ...
|
|
|
|
//
|
|
// Analyse Based on PV ...
|
|
if (analyseFIMAPVPivots)
|
|
{
|
|
//
|
|
XPivotAnalysis analysis;
|
|
has = fima2Signaller.poiDetector.AnalysePVPivots(
|
|
analysis, // Result ...
|
|
cBar.Index(), // Bar Index ...
|
|
numberOfRequiredPivots, // Required Number of Pivots ...
|
|
1500, // Max Allowed Loopback ...
|
|
10 // Validation Length ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// Draw Analysis ...
|
|
DestroyObject(pvAnalysisObject);
|
|
has = fima2Signaller.poiDrawer.DrawPivotAnalysis(
|
|
analysis,
|
|
pvAnalysisObject,
|
|
true // Draw Pivots ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// eaDraws.Add(iObj);
|
|
|
|
//
|
|
// Print("FIMA PV Pivots Analysed ...");
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Analyse Based on MA ...
|
|
if (analyseFIMAMAPivots)
|
|
{
|
|
//
|
|
XPivotAnalysis analysis;
|
|
has = fima2Signaller.poiDetector.AnalyseMAPivots(
|
|
analysis, // Result ...
|
|
cBar.Index(), // Bar Index ...
|
|
numberOfRequiredPivots, // Required Number of Pivots ...
|
|
1500, // Max Allowed Loopback ...
|
|
0 // Validation Length ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// Draw Analysis ...
|
|
DestroyObject(maAnalysisObject);
|
|
has = fima2Signaller.poiDrawer.DrawPivotAnalysis(
|
|
analysis,
|
|
maAnalysisObject,
|
|
true // Draw Pivots ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// eaDraws.Add(iObj);
|
|
|
|
//
|
|
// Print("FIMA MA Pivots Analysed ...");
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Analyse Based on SAR ...
|
|
if (analyseFIMASARPivots)
|
|
{
|
|
//
|
|
XPivotAnalysis analysis;
|
|
has = fima2Signaller.poiDetector.AnalyseSARPivots(
|
|
analysis, // Result ...
|
|
cBar.Index(), // Bar Index ...
|
|
numberOfRequiredPivots, // Required Number of Pivots ...
|
|
1500 // Max Allowed Loopback ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// Draw Analysis ...
|
|
DestroyObject(sarAnalysisObject);
|
|
has = fima2Signaller.poiDrawer.DrawPivotAnalysis(
|
|
analysis,
|
|
sarAnalysisObject,
|
|
true // Draw Pivots ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// eaDraws.Add(iObj);
|
|
|
|
//
|
|
// Print("FIMA Sar Pivots Analysed ...");
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Analyse Based on ZigZag ...
|
|
if (analyseFIMAZigZagPivots)
|
|
{
|
|
//
|
|
XPivotAnalysis analysis;
|
|
has = fima2Signaller.poiDetector.AnalyseZigZagPivots(
|
|
analysis, // Result ...
|
|
cBar.Index(), // Bar Index ...
|
|
numberOfRequiredPivots, // Required Number of Pivots ...
|
|
1500 // Max Allowed Loopback ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// Draw Analysis ...
|
|
DestroyObject(zigzagAnalysisObject);
|
|
has = fima2Signaller.poiDrawer.DrawPivotAnalysis(
|
|
analysis,
|
|
zigzagAnalysisObject,
|
|
true // Draw Pivots ...
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
// eaDraws.Add(iObj);
|
|
|
|
//
|
|
// Print("FIMA ZigZag Pivots Analysed ...");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
cBar.Clean();
|
|
}
|