last works on XFIMA ...
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
@@ -125,6 +126,25 @@ class XCBaseHelper : public XCBase
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Handler Exists ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsXValid(mSymbol) &&
|
||||
IsXValid(mPeriod) &&
|
||||
mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Validated Zones ...
|
||||
*
|
||||
@@ -511,6 +531,110 @@ class XCBaseHelper : public XCBase
|
||||
// Indicator Handler ...
|
||||
int mHandler;
|
||||
|
||||
/**
|
||||
* Read Value of Specified Buffer ...
|
||||
*
|
||||
* @param bufferIndex: int, which handler buffer to read value ...
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ReadValue(
|
||||
int bufferIndex,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
int barsTotal = CountBars();
|
||||
barIndex = NormalizeInt(barIndex, 0, barsTotal - 1);
|
||||
bufferIndex = NormalizeInt(bufferIndex, 0);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double tmp[];
|
||||
int count = CopyBuffer(
|
||||
mHandler,
|
||||
bufferIndex,
|
||||
barIndex,
|
||||
1,
|
||||
tmp //
|
||||
);
|
||||
result = tmp[0];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Values of Specified Buffer ...
|
||||
*
|
||||
* @param buffer: double, reference collection to holds result ...
|
||||
* @param bufferIndex: int, which handler buffer to read value ...
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param count: int, number of items to read, 0 for WHOLE_ARRAY ...
|
||||
* @param asSeries: bool, set As Series Buffer or not ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ReadValues(
|
||||
double &buffer[],
|
||||
int bufferIndex,
|
||||
int barIndex = 0,
|
||||
int count = 0,
|
||||
bool asSeries = true //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
XClean(buffer);
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
int barsTotal = CountBars();
|
||||
count = NormalizeInt(count, 0);
|
||||
bufferIndex = NormalizeInt(bufferIndex, 0);
|
||||
barIndex = NormalizeInt(barIndex, 0, barsTotal - 1);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = CopyBuffer(
|
||||
mHandler,
|
||||
bufferIndex,
|
||||
barIndex,
|
||||
count,
|
||||
buffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Set As Series Flag ...
|
||||
ArraySetAsSeries(buffer, asSeries);
|
||||
|
||||
//
|
||||
result = ArraySize(buffer);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+426
-1829
File diff suppressed because it is too large
Load Diff
@@ -3493,6 +3493,66 @@ bool AddIfNotExists(
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Extract |
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
/**
|
||||
* Extract Specified Directional Items ...
|
||||
*
|
||||
* @param dest: reference collection to holds extracted items ...
|
||||
* @param source: reference collection to provides data source ...
|
||||
* @param forDir: Specified which direction to Extract items ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
template <typename T>
|
||||
int ExtractByDirection(
|
||||
T &dest[],
|
||||
T &source[],
|
||||
ENUM_X_DIRECTION forDir //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
XClean(dest);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool has = HasChild(source) &&
|
||||
HasDirection(forDir);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(source);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
has = source[i].dir == forDir;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
source[i],
|
||||
dest //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(dest);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
@@ -4255,11 +4315,11 @@ bool IsInside(
|
||||
|
||||
/**
|
||||
* Check a Bar is Inside a Zone or not ...
|
||||
*
|
||||
*
|
||||
* @param index: int, reference to holds detected index ...
|
||||
* @param bar: reference to Specified Bar ...
|
||||
* @param source: reference collection to provide source ...
|
||||
*
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasInside(
|
||||
@@ -4307,11 +4367,11 @@ bool HasInside(
|
||||
|
||||
/**
|
||||
* Extract all Items which Specified Bar is inside them ...
|
||||
*
|
||||
*
|
||||
* @param bar: reference to Specified Bar ...
|
||||
* @param dest: reference to result ...
|
||||
* @param source: reference collection to provide source ...
|
||||
*
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractInsides(
|
||||
|
||||
@@ -219,6 +219,220 @@ class XCXFIMABaseSignaller : public XCBaseSignaller
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Protected Actions ...
|
||||
|
||||
/**
|
||||
* Check Specified Bar has Pattern or not ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Specified Bar ...
|
||||
* @param name: string, reference to holds Detected Patterns Name ...
|
||||
* @param dir: ENUM_X_DIRECTION, reference to holds Detected Patterns Direction ...
|
||||
* @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasPattern(
|
||||
XOHCL &bar,
|
||||
string &patternName,
|
||||
ENUM_X_DIRECTION &patternDir,
|
||||
XFIMAMarketStructure &structure //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
patternName = NULL;
|
||||
patternDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Required Pattern Exists ...
|
||||
bool hasPinnedBar = HasDirection(structure.pinnedDir);
|
||||
bool hasEngulfedBar = HasDirection(structure.engulfedDir);
|
||||
bool hasFlagPattern = HasDirection(structure.flagPatternDir);
|
||||
bool hasStarPattern = HasDirection(structure.starPatternDir);
|
||||
bool hasRisingPattern = HasDirection(structure.risingPatternDir);
|
||||
bool hasPiercingPattern = HasDirection(structure.piercingPatternDir);
|
||||
bool hasSignalKeyBar = HasDirection(structure.signalKeyBarPatternDir);
|
||||
|
||||
//
|
||||
// Check Bar Pattern Exists ...
|
||||
// and Select Pattern Direction and Price and Price Type ...
|
||||
result = hasPinnedBar ||
|
||||
hasEngulfedBar ||
|
||||
hasFlagPattern ||
|
||||
hasStarPattern ||
|
||||
hasSignalKeyBar ||
|
||||
hasRisingPattern ||
|
||||
hasPiercingPattern;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
if (hasPinnedBar)
|
||||
{
|
||||
//
|
||||
patternDir = structure.pinnedDir;
|
||||
patternName = "XPinned_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasEngulfedBar)
|
||||
{
|
||||
//
|
||||
patternDir = structure.engulfedDir;
|
||||
patternName = "XEngulfed_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasFlagPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.flagPatternDir;
|
||||
patternName = "XFlag_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasStarPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.starPatternDir;
|
||||
patternName = "XStar_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasSignalKeyBar)
|
||||
{
|
||||
//
|
||||
patternDir = structure.risingPatternDir;
|
||||
patternName = "XRising_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasRisingPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.piercingPatternDir;
|
||||
patternName = "XPiercing_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasPiercingPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.signalKeyBarPatternDir;
|
||||
patternName = "XSignalKey_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
result &&
|
||||
IsXValid(patternName) &&
|
||||
HasDirection(patternDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a Pattern based on MA Band ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Pattern Bar ...
|
||||
* @param patternName: string, detected pattern's name ...
|
||||
* @param patternDir: ENUM_X_DIRECTION, detected pattern's direction ...
|
||||
* @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidatePatternBasedOnMABand(
|
||||
XOHCL &bar,
|
||||
string patternName,
|
||||
ENUM_X_DIRECTION patternDir,
|
||||
XFIMAConditions &fimaConditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
IsXValid(patternName) &&
|
||||
HasDirection(patternDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
double iPrice = EMPTY_VALUE;
|
||||
double iPriceEdge = EMPTY_VALUE;
|
||||
ENUM_X_PRICE iPriceType = X_PRICE_NONE;
|
||||
ENUM_X_PRICE iPriceEdgeType = X_PRICE_NONE;
|
||||
|
||||
//
|
||||
// Calculating Price and Price Types ...
|
||||
|
||||
//
|
||||
isBullish = IsXBullish(patternDir);
|
||||
isBearish = IsXBearish(patternDir);
|
||||
|
||||
//
|
||||
iPriceType = isBullish
|
||||
? X_PRICE_DOWN
|
||||
: X_PRICE_UP;
|
||||
|
||||
//
|
||||
iPriceEdgeType = isBullish
|
||||
? X_PRICE_LOW
|
||||
: X_PRICE_HIGH;
|
||||
|
||||
//
|
||||
iPrice = bar.GetPrice(iPriceType);
|
||||
iPriceEdge = bar.GetPrice(iPriceEdgeType);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result =
|
||||
NotEmptyZero(iPrice) &&
|
||||
IsXValid(iPriceType) &&
|
||||
NotEmptyZero(iPriceEdge) &&
|
||||
IsXValid(iPriceEdgeType) &&
|
||||
((isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish));
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Pattern based on MA Band ...
|
||||
|
||||
//
|
||||
// Retrieve MA Band for Validation ...
|
||||
double iMABandUpper = fimaConditions.maBandUpperBuffer[0];
|
||||
double iMABandLower = fimaConditions.maBandLowerBuffer[0];
|
||||
|
||||
//
|
||||
// Validate by Edge Price ...
|
||||
result =
|
||||
NotEmptyZero(iMABandUpper) &&
|
||||
NotEmptyZero(iMABandLower) &&
|
||||
(isBullish
|
||||
? iPriceEdge < iMABandLower
|
||||
: iPriceEdge > iMABandUpper);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
@@ -226,7 +440,7 @@ class XCXFIMABaseSignaller : public XCBaseSignaller
|
||||
};
|
||||
|
||||
//
|
||||
// XFIMA Strategy 1 Signaller Class ...
|
||||
// XFIMA Strategy 2 Signaller Class ...
|
||||
class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
{
|
||||
//
|
||||
@@ -234,7 +448,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
int fvgLookupLenght; // Maximum Lenght for Looking up FVG before Crosses
|
||||
XFIMAPatternDetectorConfig analyserConfig;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
@@ -255,317 +469,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
_defaultSignalRiskInPoint,
|
||||
_defaultSignalVolume //
|
||||
)
|
||||
{
|
||||
//
|
||||
fvgLookupLenght = 5;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
/**
|
||||
* Processing Tick ...
|
||||
*
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
*/
|
||||
virtual void ProcessTick(int barIndex = 0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Processing New Bar ...
|
||||
*
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
*/
|
||||
virtual void ProcessNewBar(int barIndex = 0)
|
||||
{
|
||||
//
|
||||
// Normalize ...
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
|
||||
//
|
||||
// Update Helper ...
|
||||
fimaHelper.Update(barIndex);
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
XSignal signal;
|
||||
bool has = false;
|
||||
int cIdx = barIndex + 1;
|
||||
int pIdx = cIdx + 1;
|
||||
ENUM_X_DIRECTION signalDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Initialize Bar as CBar ...
|
||||
has = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIdx //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
bar.Clean();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Conditions ...
|
||||
XFIMAConditions fimaConditions;
|
||||
has = fimaHelper.GetConditions(
|
||||
fimaConditions,
|
||||
barIndex,
|
||||
10 // Loopback ...
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
bar.Clean();
|
||||
fimaConditions.Clean();
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse Conditions for Finding Signal ...
|
||||
|
||||
//
|
||||
// TODO: Remove this ...
|
||||
|
||||
//
|
||||
bool isFastCrossedOverSlow =
|
||||
fimaConditions.maFastBuffer[cIdx] > fimaConditions.maSlowBuffer[cIdx] &&
|
||||
fimaConditions.maFastBuffer[pIdx] < fimaConditions.maSlowBuffer[pIdx];
|
||||
|
||||
//
|
||||
bool isFastCrossedUnderSlow =
|
||||
fimaConditions.maFastBuffer[cIdx] < fimaConditions.maSlowBuffer[cIdx] &&
|
||||
fimaConditions.maFastBuffer[pIdx] > fimaConditions.maSlowBuffer[pIdx];
|
||||
|
||||
//
|
||||
has =
|
||||
isFastCrossedOverSlow ||
|
||||
isFastCrossedUnderSlow;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Do Conditions Validating ...
|
||||
// TODO: Igmore All Validations for Testing Purposes ...
|
||||
|
||||
//
|
||||
// Validate MA Positions ...
|
||||
double iFastMa = fimaConditions.maFastBuffer[cIdx];
|
||||
double iSlowMa = fimaConditions.maSlowBuffer[cIdx];
|
||||
double iFiboUpper = fimaConditions.fiboUpperBuffer[cIdx];
|
||||
double iFiboLower = fimaConditions.fiboLowerBuffer[cIdx];
|
||||
|
||||
//
|
||||
// Checking Has FVG ...
|
||||
XBoxZone fvg;
|
||||
ENUM_X_DIRECTION fvgDir;
|
||||
bool hasFVG = patternDetector.HasFVG(
|
||||
bar,
|
||||
fvgDir,
|
||||
fvg,
|
||||
fvgLookupLenght //
|
||||
);
|
||||
|
||||
//
|
||||
// Checking Crossed On Shadow ...
|
||||
|
||||
//
|
||||
bool isCrossedOverHappensOnShadow =
|
||||
isFastCrossedOverSlow &&
|
||||
iFastMa <= bar.GetDown() &&
|
||||
iFastMa >= bar.low;
|
||||
|
||||
//
|
||||
bool isCrossedUnderHappensOnShadow =
|
||||
isFastCrossedUnderSlow &&
|
||||
iFastMa <= bar.high &&
|
||||
iFastMa >= bar.GetUp();
|
||||
|
||||
//
|
||||
// Bullish Validation ...
|
||||
bool isBullish =
|
||||
//
|
||||
// Has Cross ...
|
||||
isFastCrossedOverSlow
|
||||
//
|
||||
// &&
|
||||
// //
|
||||
// // Cross Places Based on Fibo ...
|
||||
// MathMax(iFastMa, iSlowMa) < iFiboLower
|
||||
// //
|
||||
// &&
|
||||
// //
|
||||
// (
|
||||
// //
|
||||
// // Checking FVG ...
|
||||
// (hasFVG &&
|
||||
// fvg.IsBullish())
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// // Checking Crossed Place ...
|
||||
// isCrossedOverHappensOnShadow
|
||||
// //
|
||||
// )
|
||||
// //
|
||||
;
|
||||
|
||||
//
|
||||
// Bearish Validation ...
|
||||
bool isBearish =
|
||||
//
|
||||
// Has Cross ...
|
||||
isFastCrossedUnderSlow
|
||||
//
|
||||
// &&
|
||||
// //
|
||||
// // Cross Places Based on Fibo ...
|
||||
// MathMin(iFastMa, iSlowMa) > iFiboUpper
|
||||
// //
|
||||
// &&
|
||||
// //
|
||||
// (
|
||||
// //
|
||||
// // Checking FVG ...
|
||||
// (hasFVG &&
|
||||
// fvg.IsBearish())
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// // Checking Crossed Place ...
|
||||
// isCrossedUnderHappensOnShadow
|
||||
// //
|
||||
// )
|
||||
// //
|
||||
;
|
||||
|
||||
//
|
||||
has =
|
||||
(isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
signalDir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Founded ...
|
||||
has = HasDirection(signalDir);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Prepare Founded Signal ...
|
||||
XTarget targets[];
|
||||
has = PrepareSignal(
|
||||
signal,
|
||||
signalDir,
|
||||
targets //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Notify On Signal Event ...
|
||||
NotifySignalEventListeners(signal);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
bar.Clean();
|
||||
signal.Clean();
|
||||
fimaConditions.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Guards Based on MarketConditions ...
|
||||
*
|
||||
* @param guards: XGuard[]
|
||||
* @param barIndex: int
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int virtual CheckForGuard(
|
||||
XGuard &guards[],
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
SpecifiedClean(guards);
|
||||
|
||||
//
|
||||
result = ArraySize(guards);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Lookup FVG ...
|
||||
bool LookupFVG(
|
||||
XOHCL &bar,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
XBoxZone &fvgBox //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// XFIMA Strategy 2 Signaller Class ...
|
||||
class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
XFIMAPatternDetectorConfig analyserConfig;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCXFIMAStrategy2Signaller(
|
||||
string _symbol, // Symbol ...
|
||||
ENUM_TIMEFRAMES _period, // Period ...
|
||||
XFIMAInputs &_fimaInputs, // XFIMAInputs ...
|
||||
bool _processAllTicks = false, // Process All Ticks ...
|
||||
double _defaultSignalR2R = 1.5, // Default Signal Risk To Reward Ratio ...
|
||||
double _defaultSignalRiskInPoint = 50, // Default Signal Risk In Point ...
|
||||
double _defaultSignalVolume = 0.01 // Default Signal Volume ...
|
||||
) : XCXFIMABaseSignaller("XFIMA2",
|
||||
_symbol,
|
||||
_period,
|
||||
_fimaInputs,
|
||||
_processAllTicks,
|
||||
_defaultSignalR2R,
|
||||
_defaultSignalRiskInPoint,
|
||||
_defaultSignalVolume //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Configure Detector ...
|
||||
@@ -579,7 +482,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCXFIMAStrategy2Signaller()
|
||||
~XCXFIMAStrategy1Signaller()
|
||||
{
|
||||
//
|
||||
Destroy();
|
||||
@@ -611,10 +514,6 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
||||
// Normalize ...
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
|
||||
//
|
||||
// Update Helper ...
|
||||
fimaHelper.Update(barIndex);
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
int count = 0;
|
||||
@@ -1160,6 +1059,9 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Collect Bar Support and Resistance (s) ...
|
||||
|
||||
//
|
||||
// Disable Signallers ...
|
||||
has = false;
|
||||
@@ -1274,217 +1176,6 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
||||
//
|
||||
// Implementing Strategies ...
|
||||
|
||||
/**
|
||||
* Check Specified Bar has Pattern or not ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Specified Bar ...
|
||||
* @param name: string, reference to holds Detected Patterns Name ...
|
||||
* @param dir: ENUM_X_DIRECTION, reference to holds Detected Patterns Direction ...
|
||||
* @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasPattern(
|
||||
XOHCL &bar,
|
||||
string &patternName,
|
||||
ENUM_X_DIRECTION &patternDir,
|
||||
XFIMAMarketStructure &structure //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
patternName = NULL;
|
||||
patternDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Required Pattern Exists ...
|
||||
bool hasPinnedBar = HasDirection(structure.pinnedDir);
|
||||
bool hasEngulfedBar = HasDirection(structure.engulfedDir);
|
||||
bool hasFlagPattern = HasDirection(structure.flagPatternDir);
|
||||
bool hasStarPattern = HasDirection(structure.starPatternDir);
|
||||
bool hasRisingPattern = HasDirection(structure.risingPatternDir);
|
||||
bool hasPiercingPattern = HasDirection(structure.piercingPatternDir);
|
||||
bool hasSignalKeyBar = HasDirection(structure.signalKeyBarPatternDir);
|
||||
|
||||
//
|
||||
// Check Bar Pattern Exists ...
|
||||
// and Select Pattern Direction and Price and Price Type ...
|
||||
result = hasPinnedBar ||
|
||||
hasEngulfedBar ||
|
||||
hasFlagPattern ||
|
||||
hasStarPattern ||
|
||||
hasSignalKeyBar ||
|
||||
hasRisingPattern ||
|
||||
hasPiercingPattern;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
if (hasPinnedBar)
|
||||
{
|
||||
//
|
||||
patternDir = structure.pinnedDir;
|
||||
patternName = "XPinned_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasEngulfedBar)
|
||||
{
|
||||
//
|
||||
patternDir = structure.engulfedDir;
|
||||
patternName = "XEngulfed_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasFlagPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.flagPatternDir;
|
||||
patternName = "XFlag_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasStarPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.starPatternDir;
|
||||
patternName = "XStar_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasSignalKeyBar)
|
||||
{
|
||||
//
|
||||
patternDir = structure.risingPatternDir;
|
||||
patternName = "XRising_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasRisingPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.piercingPatternDir;
|
||||
patternName = "XPiercing_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
else if (hasPiercingPattern)
|
||||
{
|
||||
//
|
||||
patternDir = structure.signalKeyBarPatternDir;
|
||||
patternName = "XSignalKey_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
result &&
|
||||
IsXValid(patternName) &&
|
||||
HasDirection(patternDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a Pattern based on MA Band ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Pattern Bar ...
|
||||
* @param patternName: string, detected pattern's name ...
|
||||
* @param patternDir: ENUM_X_DIRECTION, detected pattern's direction ...
|
||||
* @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidatePatternBasedOnMABand(
|
||||
XOHCL &bar,
|
||||
string patternName,
|
||||
ENUM_X_DIRECTION patternDir,
|
||||
XFIMAConditions &fimaConditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
IsXValid(patternName) &&
|
||||
HasDirection(patternDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
double iPrice = EMPTY_VALUE;
|
||||
double iPriceEdge = EMPTY_VALUE;
|
||||
ENUM_X_PRICE iPriceType = X_PRICE_NONE;
|
||||
ENUM_X_PRICE iPriceEdgeType = X_PRICE_NONE;
|
||||
|
||||
//
|
||||
// Calculating Price and Price Types ...
|
||||
|
||||
//
|
||||
isBullish = IsXBullish(patternDir);
|
||||
isBearish = IsXBearish(patternDir);
|
||||
|
||||
//
|
||||
iPriceType = isBullish
|
||||
? X_PRICE_DOWN
|
||||
: X_PRICE_UP;
|
||||
|
||||
//
|
||||
iPriceEdgeType = isBullish
|
||||
? X_PRICE_LOW
|
||||
: X_PRICE_HIGH;
|
||||
|
||||
//
|
||||
iPrice = bar.GetPrice(iPriceType);
|
||||
iPriceEdge = bar.GetPrice(iPriceEdgeType);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result =
|
||||
NotEmptyZero(iPrice) &&
|
||||
IsXValid(iPriceType) &&
|
||||
NotEmptyZero(iPriceEdge) &&
|
||||
IsXValid(iPriceEdgeType) &&
|
||||
((isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish));
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Pattern based on MA Band ...
|
||||
|
||||
//
|
||||
// Retrieve MA Band for Validation ...
|
||||
double iMABandUpper = fimaConditions.maBandUpperBuffer[0];
|
||||
double iMABandLower = fimaConditions.maBandLowerBuffer[0];
|
||||
|
||||
//
|
||||
// Validate by Edge Price ...
|
||||
result =
|
||||
NotEmptyZero(iMABandUpper) &&
|
||||
NotEmptyZero(iMABandLower) &&
|
||||
(isBullish
|
||||
? iPriceEdge < iMABandLower
|
||||
: iPriceEdge > iMABandUpper);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Bar Has Signal Based on Strategy 1 ...
|
||||
*
|
||||
@@ -1659,27 +1350,95 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
||||
// Detect Specified MA Cross ...
|
||||
result = HasDirection(structure.maCrossDir);
|
||||
|
||||
//
|
||||
// Collecting Bar Support and Resistances ...
|
||||
XBoxZone barZones[];
|
||||
int count = fimaHelper.ExtractBarZones(
|
||||
barZones,
|
||||
bar.Index(),
|
||||
analyserConfig.recentlyPatternsMaxAllowedCollecting, // Number of Zones ...
|
||||
analyserConfig.supportAndResistanceBreakeValidationLength, // Break Validation Length ...
|
||||
analyserConfig.supportAndResistanceBreakeValidationLength > 0, // Validate Fake Breaked Zones ...
|
||||
4, // Shadow Multiplier ...
|
||||
analyserConfig.minAllowdSupportAndResistanceStrength, // Validation Strength ...
|
||||
7, // Validation Length ...
|
||||
analyserConfig.supportAndResistanceMaxAllowedLoopback // Max Allowed Loopback ...
|
||||
);
|
||||
Copy(
|
||||
supports,
|
||||
barZones,
|
||||
false // Force Clean ...
|
||||
);
|
||||
Copy(
|
||||
resistances,
|
||||
barZones,
|
||||
false // Force Clean ...
|
||||
);
|
||||
|
||||
//
|
||||
// Validate Conditions ...
|
||||
XBoxZone fvg;
|
||||
ENUM_X_DIRECTION tmpDir;
|
||||
bool hasFVG = poiDetector.HasFVG(
|
||||
bar,
|
||||
tmpDir,
|
||||
fvg,
|
||||
3 // Max Loopback ...
|
||||
);
|
||||
|
||||
//
|
||||
// Validate result by FVG ...
|
||||
// result =
|
||||
// result &&
|
||||
// hasFVG &&
|
||||
// fvg.dir == structure.maCrossDir;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
XCBoxObject *iFVGObj;
|
||||
poiDrawer.DrawBox(
|
||||
fvg,
|
||||
iFVGObj //
|
||||
);
|
||||
|
||||
//
|
||||
// Draw Support or Resistances based on Direction of Cross ...
|
||||
CArrayObj *iZones;
|
||||
count = poiDrawer.DrawBoxes(
|
||||
barZones,
|
||||
iZones //
|
||||
);
|
||||
|
||||
//
|
||||
Print("Cross Happens ...");
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare iZone ...
|
||||
iZone.to = bar.time;
|
||||
iZone.from = GetBarTime(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
bar.Index() + 2 //
|
||||
);
|
||||
iZone.symbol = bar.symbol;
|
||||
iZone.period = bar.period;
|
||||
iZone.dir = structure.maCrossDir;
|
||||
iZone.lower = bar.FindLowest(2, MODE_LOW);
|
||||
iZone.upper = bar.FindHighest(2, MODE_HIGH);
|
||||
iZone.type = name + "_" + ToXString(structure.maCrossDir);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
iZone.to = bar.time;
|
||||
iZone.from = GetBarTime(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
bar.Index() + 2 //
|
||||
);
|
||||
iZone.symbol = bar.symbol;
|
||||
iZone.period = bar.period;
|
||||
iZone.dir = structure.maCrossDir;
|
||||
iZone.lower = bar.FindLowest(2, MODE_LOW);
|
||||
iZone.upper = bar.FindHighest(2, MODE_HIGH);
|
||||
iZone.type = name + "_" + ToXString(structure.maCrossDir);
|
||||
|
||||
//
|
||||
result = iZone.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Result ...
|
||||
result = iZone.IsValid();
|
||||
if (result)
|
||||
{
|
||||
iDir = structure.maCrossDir;
|
||||
@@ -1691,6 +1450,10 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
||||
{
|
||||
iZone.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
fvg.Clean();
|
||||
XClean(barZones);
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user