last works ...
This commit is contained in:
@@ -3790,6 +3790,245 @@ void ValidateBoxes(
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Bar to Pivot ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Specified Bar ...
|
||||
* @param pivot: XPivot, reference to holds result ...
|
||||
* @param forDir: ENUM_X_DIRECTION, specified Pivot Direction ...
|
||||
* @param prefix: string, Specified Pivot Prefix (used for Object Type) ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ToPivot(
|
||||
XOHCL &bar,
|
||||
XPivot &pivot,
|
||||
ENUM_X_DIRECTION forDir,
|
||||
string prefix = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
pivot.Clean();
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
HasDirection(forDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Direction ...
|
||||
bool isBullish = IsSpecifiedBullish(forDir);
|
||||
|
||||
//
|
||||
// Prepare Value of Pivot ...
|
||||
double iValue =
|
||||
isBullish
|
||||
? bar.low
|
||||
: bar.high;
|
||||
|
||||
//
|
||||
// Prepare Pivot Type ...
|
||||
ENUM_X_PIVOT_TYPE iType =
|
||||
isBullish
|
||||
? X_PIVOT_TYPE_VALE
|
||||
: X_PIVOT_TYPE_PEAK;
|
||||
|
||||
//
|
||||
// Initialize Pivot ...
|
||||
result = pivot.Init(
|
||||
iValue,
|
||||
bar.time,
|
||||
bar.symbol,
|
||||
forDir,
|
||||
bar.period,
|
||||
iType //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Set Prefix if Pivot initialized successfully ...
|
||||
pivot.prefix = prefix;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = pivot.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
pivot.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts POI Patterns to Box ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Specified Pattern ...
|
||||
* @param box: XBoxZone, reference to holds result ...
|
||||
* @param forDir: ENUM_X_DIRECTION, Specified Pattern Direction ...
|
||||
* @param prefix: string, Specified Pattern Type ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ToBox(
|
||||
XOHCL &bar,
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION forDir,
|
||||
string prefix = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
box.Clean();
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
HasDirection(forDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Flags for Patterns ...
|
||||
|
||||
//
|
||||
bool isStar =
|
||||
IsSpecifiedValid(prefix) &&
|
||||
prefix == "Star";
|
||||
|
||||
//
|
||||
bool isPiercing =
|
||||
IsSpecifiedValid(prefix) &&
|
||||
prefix == "Piercing";
|
||||
|
||||
//
|
||||
bool isRising =
|
||||
IsSpecifiedValid(prefix) &&
|
||||
prefix == "Rising";
|
||||
|
||||
//
|
||||
bool isFlag =
|
||||
IsSpecifiedValid(prefix) &&
|
||||
prefix == "Flag";
|
||||
|
||||
//
|
||||
bool isSignalKeyBar =
|
||||
IsSpecifiedValid(prefix) &&
|
||||
prefix == "SignalKeyBar";
|
||||
|
||||
//
|
||||
// Validate Pattern ...
|
||||
result = isStar ||
|
||||
isFlag ||
|
||||
isRising ||
|
||||
isPiercing ||
|
||||
isSignalKeyBar;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now Try to Initialized Box ...
|
||||
|
||||
//
|
||||
// Common Configs ...
|
||||
box.dir = forDir;
|
||||
box.type = prefix;
|
||||
box.at = bar.time;
|
||||
box.from = bar.time;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = bar.symbol;
|
||||
box.period = bar.period;
|
||||
|
||||
//
|
||||
double upper = 0;
|
||||
double lower = 0;
|
||||
datetime from = NULL;
|
||||
bool isBullish = IsSpecifiedBullish(forDir);
|
||||
|
||||
//
|
||||
int loopback = 0;
|
||||
ENUM_SERIESMODE uMode = MODE_HIGH;
|
||||
ENUM_SERIESMODE lMode = MODE_LOW;
|
||||
|
||||
//
|
||||
// Specified Configs ...
|
||||
if (isStar)
|
||||
{
|
||||
loopback = 2;
|
||||
}
|
||||
else if (isPiercing)
|
||||
{
|
||||
loopback = 1;
|
||||
}
|
||||
else if (isRising)
|
||||
{
|
||||
loopback = 5;
|
||||
}
|
||||
else if (isFlag)
|
||||
{
|
||||
loopback = 1;
|
||||
}
|
||||
else if (isSignalKeyBar)
|
||||
{
|
||||
loopback = 1;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidSize(loopback);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
from = GetBarTime(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
bar.Index() + loopback //
|
||||
);
|
||||
upper = bar.FindHighest(
|
||||
loopback,
|
||||
uMode //
|
||||
);
|
||||
lower = bar.FindLowest(
|
||||
loopback,
|
||||
lMode //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
box.from = from;
|
||||
box.upper = upper;
|
||||
box.lower = lower;
|
||||
|
||||
//
|
||||
// Validate result ...
|
||||
result = box.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
box.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Bar to Support Box ...
|
||||
*
|
||||
@@ -3921,8 +4160,8 @@ bool IsBreaked(
|
||||
// Check Break ...
|
||||
result =
|
||||
zone.IsBullish()
|
||||
? bar.close > zone.upper
|
||||
: bar.close < zone.lower;
|
||||
? bar.close < zone.lower
|
||||
: bar.close > zone.upper;
|
||||
|
||||
//
|
||||
// Apply Force Bar Edge ...
|
||||
@@ -3966,7 +4205,7 @@ bool IsTested(
|
||||
}
|
||||
|
||||
//
|
||||
// Check Break ...
|
||||
// Check Test ...
|
||||
result =
|
||||
zone.IsBullish()
|
||||
? bar.low < zone.upper
|
||||
@@ -3976,12 +4215,50 @@ bool IsTested(
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Specified Bar is Inside Specified Zone or not ...
|
||||
*
|
||||
* @param bar: Specified Bar ...
|
||||
* @param zone: Specified Zone ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsInside(
|
||||
XOHCL &bar,
|
||||
XBoxZone &zone //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
zone.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Inside ...
|
||||
result =
|
||||
zone.IsBullish()
|
||||
? bar.low < zone.upper &&
|
||||
bar.low > zone.lower
|
||||
: bar.high > zone.lower &&
|
||||
bar.high < zone.upper;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all Bars which Breakes Specified Zone ...
|
||||
*
|
||||
*
|
||||
* @param zone: reference to Specified Zone ...
|
||||
* @param dest: reference Collection to hold result ...
|
||||
*
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetBreakerBars(
|
||||
@@ -4051,6 +4328,156 @@ int GetBreakerBars(
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all Bars which Inside Specified Zone ...
|
||||
*
|
||||
* @param zone: reference to Specified Zone ...
|
||||
* @param dest: reference Collection to hold result ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetInsideBars(
|
||||
XBoxZone &zone,
|
||||
XOHCL &dest[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool has = zone.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
SpecifiedClean(dest);
|
||||
|
||||
//
|
||||
// Do Action ...
|
||||
XOHCL iBar;
|
||||
int start = zone.ToIndex();
|
||||
int end = zone.FromIndex();
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
//
|
||||
// Initialize indexed Bar ...
|
||||
has = iBar.Init(
|
||||
zone.symbol,
|
||||
zone.period,
|
||||
i //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
has = IsInside(
|
||||
iBar,
|
||||
zone //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
iBar,
|
||||
dest //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(dest);
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all Bars which Tested Specified Zone ...
|
||||
*
|
||||
* @param zone: reference to Specified Zone ...
|
||||
* @param dest: reference Collection to hold result ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetTesterBars(
|
||||
XBoxZone &zone,
|
||||
XOHCL &dest[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool has = zone.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
SpecifiedClean(dest);
|
||||
|
||||
//
|
||||
// Do Action ...
|
||||
XOHCL iBar;
|
||||
int start = zone.ToIndex();
|
||||
int end = zone.FromIndex();
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
//
|
||||
// Initialize indexed Bar ...
|
||||
has = iBar.Init(
|
||||
zone.symbol,
|
||||
zone.period,
|
||||
i //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
has = IsTested(
|
||||
iBar,
|
||||
zone //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
iBar,
|
||||
dest //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(dest);
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user