Last works ...
This commit is contained in:
@@ -1393,6 +1393,15 @@ class XCXFIMAHelper : public XCBaseHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Fibo Push Exists or not ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION, reference to hold result ...
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param validationLength: int, Validation Length ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasFiboPush(
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int barIndex = 0,
|
||||
@@ -2946,6 +2955,236 @@ class XCXFIMAHelper : public XCBaseHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Zones (Support / Resistance) based on XFIMA Validators ...
|
||||
*
|
||||
* @param zones: XBoxZone, reference to Collection for holding Detected Zones ...
|
||||
* @param barIndex: int, Specified Start Looking Bar Index ...
|
||||
* @param requiredNumberOfZones: int, Specified how many zones looking for ...
|
||||
* @param shadowMultiplier: double, a valid zone's Shadow side multiplier ...
|
||||
* @param maxAllowedLoopbackLength: int, Specified Max Allowed Looping back trhough Bars for Detection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int DetectXFIMAZones(
|
||||
XBoxZone &zones[],
|
||||
int barIndex = 0,
|
||||
bool onlyValidZones = false,
|
||||
int requiredNumberOfZones = 50,
|
||||
double shadowMultiplier = 4,
|
||||
int validationLength = 7,
|
||||
int maxAllowedLoopbackLength = 1500 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
XClean(zones);
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
barIndex = NormalizeBarIndex(barIndex);
|
||||
validationLength = NormalizeInt(validationLength, 3);
|
||||
shadowMultiplier = NormalizeDouble(shadowMultiplier, 2);
|
||||
requiredNumberOfZones = NormalizeInt(requiredNumberOfZones, 5);
|
||||
maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
XOHCL bar;
|
||||
bool has = IsValid() &&
|
||||
bar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex + 1 //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
XOHCL iBar;
|
||||
XBoxZone iBox;
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
double iUpper = EMPTY_VALUE;
|
||||
double iLower = EMPTY_VALUE;
|
||||
double iHKUpper = EMPTY_VALUE;
|
||||
double iHKLower = EMPTY_VALUE;
|
||||
double iMAUpper = EMPTY_VALUE;
|
||||
double iMALower = EMPTY_VALUE;
|
||||
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Create a Loop to Detect Zones ...
|
||||
int start = barIndex;
|
||||
int idx = start - 1;
|
||||
int end = start + maxAllowedLoopbackLength;
|
||||
while (ArraySize(zones) < requiredNumberOfZones && idx < end)
|
||||
{
|
||||
//
|
||||
idx++;
|
||||
|
||||
//
|
||||
// Initialize Indexed Bar ...
|
||||
has = bar.BarAt(idx, iBar);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Bars ...
|
||||
iMAUpper = GetMABondUpper(idx);
|
||||
iMALower = GetMABondLower(idx);
|
||||
iHKUpper = GetHKBondUpper(idx);
|
||||
iHKLower = GetHKBondLower(idx);
|
||||
|
||||
//
|
||||
iUpper = MathMax(iMAUpper, iHKUpper);
|
||||
iLower = MathMin(iMALower, iHKLower);
|
||||
|
||||
//
|
||||
// Check Bar State ...
|
||||
has =
|
||||
NotEmptyZero(iUpper) &&
|
||||
NotEmptyZero(iLower);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Direction of Zone ...
|
||||
isBullish = iBar.low < iLower;
|
||||
isBearish = iBar.high > iUpper;
|
||||
has = (isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Price Based on Bar ...
|
||||
// Validate Shadow Multiplier ...
|
||||
has =
|
||||
isBullish
|
||||
? iBar.low < bar.low
|
||||
: iBar.high > bar.high;
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? iBar.GetLowShadow() > iBar.GetHighShadow() * shadowMultiplier
|
||||
: iBar.GetHighShadow() > iBar.GetLowShadow() * shadowMultiplier);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
iDir = isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
// Fill Bax ...
|
||||
iBox.dir = iDir;
|
||||
iBox.symbol = mSymbol;
|
||||
iBox.period = mPeriod;
|
||||
iBox.upper =
|
||||
isBullish
|
||||
? iBar.GetDown()
|
||||
: iBar.high;
|
||||
iBox.lower =
|
||||
isBullish
|
||||
? iBar.low
|
||||
: iBar.GetUp();
|
||||
iBox.type =
|
||||
(isBullish ? "XFIMSup" : "XFIMARes") + "_" +
|
||||
ToXString(NormalizePrice(iBox.upper, iBox.symbol)) + "_" +
|
||||
ToXString(NormalizePrice(iBox.lower, iBox.symbol));
|
||||
|
||||
//
|
||||
iBox.at = iBar.time;
|
||||
iBox.to = bar.time;
|
||||
|
||||
//
|
||||
// Loopback to Detect From Time ...
|
||||
XOHCL pBar;
|
||||
datetime fromTime = NULL;
|
||||
has = iBar.GetPreviousBar(pBar);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
while (!IsXValid(fromTime))
|
||||
{
|
||||
//
|
||||
// Check Price Inside ...
|
||||
has =
|
||||
isBullish
|
||||
? pBar.GetDown() < iBox.lower
|
||||
: pBar.GetUp() > iBox.upper;
|
||||
if (has)
|
||||
{
|
||||
fromTime = pBar.time;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve PrevBar ...
|
||||
has = pBar.GetPreviousBar(pBar);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
has = IsXValid(fromTime);
|
||||
if (has)
|
||||
{
|
||||
iBox.from = fromTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Zone Length ...
|
||||
has = iBox.IsValid() &&
|
||||
(iBox.FromIndex() - iBox.AtIndex() >= validationLength);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
iBox,
|
||||
zones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
iBar.Clean();
|
||||
pBar.Clean();
|
||||
iBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(zones);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
if (!result)
|
||||
{
|
||||
XClean(zones);
|
||||
}
|
||||
iBar.Clean();
|
||||
iBox.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Values Retrievers ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user