last works ...
Resolve all XPOI XPivot and XPivotAnalysis Refactoring Side Affects on XFIMA ...
This commit is contained in:
@@ -56,277 +56,6 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector
|
||||
//
|
||||
// Actions and Tools ...
|
||||
|
||||
/**
|
||||
* Get Specified Number of Recent ZigZag Points ...
|
||||
*
|
||||
* @param bar: XOHCL, Specified Bar for Start ...
|
||||
* @param fimaHelper: XCXFIMAHelper, instance of XFIMA Helper ...
|
||||
* @param zigzagPoints: XZigZagPoint, Array of Founded Points ...
|
||||
* @param numberOfRequiredPivots: int, Specified Number of required ZigZag Points ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetZigZagPivot(
|
||||
XOHCL &bar,
|
||||
XCXFIMAHelper *&fimaHelper,
|
||||
XZigZagPivot &zigzagPivots[],
|
||||
int numberOfRequiredPivots = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
SpecifiedClean(zigzagPivots);
|
||||
numberOfRequiredPivots = NormalizeInt(numberOfRequiredPivots, 3);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
bar.symbol == fimaHelper.GetSymbol() &&
|
||||
bar.period == fimaHelper.GetPeriod();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Update Fima Helper ...
|
||||
int index = bar.Index();
|
||||
fimaHelper.Update(index);
|
||||
|
||||
//
|
||||
// Start Reading ZigZag Values ...
|
||||
double iZG = 0;
|
||||
double iPZG = 0;
|
||||
int iZGIdx = -1;
|
||||
int iPZGIdx = -1;
|
||||
bool has = false;
|
||||
int start = index;
|
||||
XZigZagPivot iZGPoint;
|
||||
datetime iZGTime = NULL;
|
||||
datetime iPZGTime = NULL;
|
||||
int lastZGDetected = start;
|
||||
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
|
||||
ENUM_X_ZIGZAG_POINT_TYPE iType = X_ZIGZAG_PIVOT_TYPE_NONE;
|
||||
while (ArraySize(zigzagPivots) < numberOfRequiredPivots)
|
||||
{
|
||||
//
|
||||
// Reading Last two ZigZag Value ...
|
||||
|
||||
//
|
||||
// Detect Last ZG Value ...
|
||||
has = GetZigZagValue(lastZGDetected, iZG, iZGIdx, iZGTime, fimaHelper);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
iZG = 0;
|
||||
iPZG = 0;
|
||||
iZGIdx = -1;
|
||||
iPZGIdx = -1;
|
||||
iZGTime = NULL;
|
||||
iPZGTime = NULL;
|
||||
iZGPoint.Clean();
|
||||
iDir = X_DIRECTION_NONE;
|
||||
iType = X_ZIGZAG_PIVOT_TYPE_NONE;
|
||||
|
||||
//
|
||||
start++;
|
||||
lastZGDetected++;
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Previous ZG Value ...
|
||||
has = GetZigZagValue(lastZGDetected + 1, iPZG, iPZGIdx, iPZGTime, fimaHelper);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
iZG = 0;
|
||||
iPZG = 0;
|
||||
iZGIdx = -1;
|
||||
iPZGIdx = -1;
|
||||
iZGTime = NULL;
|
||||
iPZGTime = NULL;
|
||||
iZGPoint.Clean();
|
||||
iDir = X_DIRECTION_NONE;
|
||||
iType = X_ZIGZAG_PIVOT_TYPE_NONE;
|
||||
|
||||
//
|
||||
start++;
|
||||
lastZGDetected++;
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Direction ...
|
||||
iDir =
|
||||
(iZG > iPZG)
|
||||
? X_DIRECTION_BULLISH
|
||||
: (iZG < iPZG)
|
||||
? X_DIRECTION_BEARISH
|
||||
: X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Check Point Type ...
|
||||
iType =
|
||||
IsSpecifiedBullish(iDir)
|
||||
? X_ZIGZAG_PIVOT_TYPE_PEAK
|
||||
: IsSpecifiedBearish(iDir)
|
||||
? X_ZIGZAG_PIVOT_TYPE_VALE
|
||||
: X_ZIGZAG_PIVOT_TYPE_NONE;
|
||||
has =
|
||||
IsXValid(iType) &&
|
||||
HasDirection(iDir);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
iZG = 0;
|
||||
iPZG = 0;
|
||||
iZGIdx = -1;
|
||||
iPZGIdx = -1;
|
||||
iZGTime = NULL;
|
||||
iPZGTime = NULL;
|
||||
iZGPoint.Clean();
|
||||
iDir = X_DIRECTION_NONE;
|
||||
iType = X_ZIGZAG_PIVOT_TYPE_NONE;
|
||||
|
||||
//
|
||||
start++;
|
||||
lastZGDetected++;
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize ZigZag Point ...
|
||||
has = iZGPoint.Init(
|
||||
iZG,
|
||||
iZGTime,
|
||||
bar.symbol,
|
||||
iDir,
|
||||
bar.period,
|
||||
iType //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iZGPoint.AddIfNotExists(zigzagPivots);
|
||||
lastZGDetected = iZGIdx + 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset Resources ...
|
||||
iZG = 0;
|
||||
iPZG = 0;
|
||||
iZGIdx = -1;
|
||||
iPZGIdx = -1;
|
||||
iZGTime = NULL;
|
||||
iPZGTime = NULL;
|
||||
iZGPoint.Clean();
|
||||
iDir = X_DIRECTION_NONE;
|
||||
iType = X_ZIGZAG_PIVOT_TYPE_NONE;
|
||||
|
||||
//
|
||||
start++;
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(zigzagPivots);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool AnalyseMarketUsingZigZag(
|
||||
XOHCL &bar,
|
||||
ENUM_TIMEFRAMES forPeriod,
|
||||
XCXFIMAHelper *&fimaHelper,
|
||||
XZigZagAnalysis &analysis,
|
||||
int numberOfRequiredPivots = 20 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
analysis.Clean();
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
numberOfRequiredPivots = NormalizeInt(numberOfRequiredPivots, 5);
|
||||
if (!IsSpecifiedValid(forPeriod))
|
||||
{
|
||||
forPeriod = bar.period;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading XZigZag Points ...
|
||||
XOHCL iPeriodBar;
|
||||
result = iPeriodBar.Init(
|
||||
bar.symbol,
|
||||
forPeriod,
|
||||
bar.Index() //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
iPeriodBar.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Required Pivots ...
|
||||
XZigZagPivot pivots[];
|
||||
int pivotsCount = GetZigZagPivot(
|
||||
iPeriodBar,
|
||||
fimaHelper,
|
||||
pivots,
|
||||
numberOfRequiredPivots //
|
||||
);
|
||||
result = IsValidSize(pivotsCount);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
analysis.Clean();
|
||||
iPeriodBar.Clean();
|
||||
SpecifiedClean(pivots);
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Analysis Model ...
|
||||
result = analysis.Analyse(
|
||||
bar,
|
||||
pivots //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
analysis.Clean();
|
||||
iPeriodBar.Clean();
|
||||
SpecifiedClean(pivots);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
@@ -349,102 +78,6 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector
|
||||
//
|
||||
// Tools / Actions ...
|
||||
|
||||
/**
|
||||
* Read Specified Value of ZigZag ...
|
||||
*
|
||||
* @param fromBarIndex: int, Specified Start Bar Index ...
|
||||
* @param value: double, reference to Hold ZigZag Value ...
|
||||
* @param index: int, reference to Hold ZigZag Value's Bar Index ...
|
||||
* @param time: datetime, reference to Hold ZigZag Value's Time ...
|
||||
* @param maxAllowedLoopback: int, Maximum Allowe Loopback to Detect Specified Point ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetZigZagValue(
|
||||
int fromBarIndex,
|
||||
double &value,
|
||||
int &index,
|
||||
datetime &time,
|
||||
XCXFIMAHelper *&fimaHelper,
|
||||
int maxAllowedLoopback = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
fromBarIndex = NormalizeInt(fromBarIndex, 0);
|
||||
maxAllowedLoopback = NormalizeInt(maxAllowedLoopback, 10, 100);
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
value = 0;
|
||||
index = -1;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = fimaHelper != NULL;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int start = fromBarIndex;
|
||||
int end = start + maxAllowedLoopback;
|
||||
while (start < end)
|
||||
{
|
||||
//
|
||||
fimaHelper.Update(start);
|
||||
|
||||
//
|
||||
value = fimaHelper.GetZigZag(start);
|
||||
result = value > 0 && value != EMPTY_VALUE;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
time = GetBarTime(
|
||||
fimaHelper.GetSymbol(),
|
||||
fimaHelper.GetPeriod(),
|
||||
start //
|
||||
);
|
||||
|
||||
//
|
||||
index = start;
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
value = 0;
|
||||
index = -1;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
start++;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
value > 0 &&
|
||||
IsValidIndex(index) &&
|
||||
value != EMPTY_VALUE &&
|
||||
IsSpecifiedValid(time);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
value = 0;
|
||||
index = -1;
|
||||
time = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
|
||||
@@ -33,179 +33,6 @@ class XCXFIMAPOIDrawer : public XCPOIDrawer
|
||||
public:
|
||||
//
|
||||
|
||||
/**
|
||||
* Draw Specified XZigZagMarketStyle on Chart ...
|
||||
*
|
||||
* @param object: XCZigZagAnalysisObject, pointer reference to Drawn Object ...
|
||||
* @param model: XZigZagAnalysis, reference to Model ...
|
||||
* @param numberOfPivots: int, required number of pivots for Draw Trends ...
|
||||
* @param rayRight: bool, Ray To Right ...
|
||||
* @param rayLeft: bool, Ray To Left ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DrawZigZagMarketAnalysisByPV(
|
||||
XCZigZagAnalysisObject *&object,
|
||||
XZigZagAnalysis &model,
|
||||
bool rayRight = false,
|
||||
bool rayLeft = false,
|
||||
int numberOfPivots = 2 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
object = NULL;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = model.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
object = new XCZigZagAnalysisObject();
|
||||
result = object.CreateByPV(
|
||||
ChartIdentification(),
|
||||
SubWindowIdentification(),
|
||||
model //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Apply Style ...
|
||||
bool isBullish = model.IsBullish();
|
||||
|
||||
//
|
||||
XPOIStyle style;
|
||||
if (isBullish)
|
||||
{
|
||||
style = defaultBullishStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
style = defaultBearishStyle;
|
||||
}
|
||||
|
||||
//
|
||||
ApplyZigZagMarketAnalysisStyle(
|
||||
object,
|
||||
style,
|
||||
true, // Ray Right ...
|
||||
false // Ray Left ...
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw Specified XZigZagMarketStyle on Chart ...
|
||||
*
|
||||
* @param object: XCZigZagAnalysisObject, pointer reference to Drawn Object ...
|
||||
* @param model: XZigZagAnalysis, reference to Model ...
|
||||
* @param numberOfPivots: int, required number of pivots for Draw Trends ...
|
||||
* @param rayRight: bool, Ray To Right ...
|
||||
* @param rayLeft: bool, Ray To Left ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DrawZigZagMarketAnalysisByRecent(
|
||||
XCZigZagAnalysisObject *&object,
|
||||
XZigZagAnalysis &model,
|
||||
bool rayRight = false,
|
||||
bool rayLeft = false,
|
||||
int numberOfPivots = 2 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
object = NULL;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = model.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
object = new XCZigZagAnalysisObject();
|
||||
result = object.CreateByRecent(
|
||||
ChartIdentification(),
|
||||
SubWindowIdentification(),
|
||||
model,
|
||||
numberOfPivots //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Apply Style ...
|
||||
bool isBullish = model.IsBullish();
|
||||
|
||||
//
|
||||
XPOIStyle style;
|
||||
if (isBullish)
|
||||
{
|
||||
style = defaultBullishStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
style = defaultBearishStyle;
|
||||
}
|
||||
|
||||
//
|
||||
ApplyZigZagMarketAnalysisStyle(
|
||||
object,
|
||||
style,
|
||||
true, // Ray Right ...
|
||||
false // Ray Left ...
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Specified Style to Object ...
|
||||
*/
|
||||
void ApplyZigZagMarketAnalysisStyle(
|
||||
XCZigZagAnalysisObject *&object,
|
||||
XPOIStyle &style,
|
||||
bool rayRight = false,
|
||||
bool rayLeft = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool has = object != NULL;
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
object.UpperColor(style.clr);
|
||||
object.LowerColor(style.clr);
|
||||
object.UpperWidth(style.width);
|
||||
object.UpperRayLeft(rayLeft);
|
||||
object.UpperRayRight(rayRight);
|
||||
object.LowerWidth(style.width);
|
||||
object.UpperStyle(style.style);
|
||||
object.LowerStyle(style.style);
|
||||
object.LowerRayLeft(rayLeft);
|
||||
object.LowerRayRight(rayRight);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user