last ...
This commit is contained in:
@@ -30,13 +30,24 @@
|
||||
|
||||
XCAlert *eaAlert;
|
||||
XCPOIDrawer *eaDrawer;
|
||||
CArrayObj eaDrawnObjects;
|
||||
XCPivotDetector *eaPivotDetector;
|
||||
XCSessionDetector *eaSessionDetector;
|
||||
|
||||
//
|
||||
XCPivotDetector *eaMajorPivotDetector;
|
||||
XCPivotDetector *eaMinorPivotDetector;
|
||||
|
||||
//
|
||||
// Last Processing Pivots Time ...
|
||||
datetime eaLastPivotProcessing = NULL;
|
||||
bool eaDrawMajorPivots = true;
|
||||
bool eaDrawMinorPivots = true;
|
||||
XPOIDrawConfig eaMajorPivotsDrawConfig;
|
||||
XPOIDrawConfig eaMinorPivotsDrawConfig;
|
||||
datetime eaLastMajorPivotProcessing = NULL;
|
||||
datetime eaLastMinorPivotProcessing = NULL;
|
||||
XPOIDrawConfig eaPointedMajorPivotsDrawConfig;
|
||||
XPOIDrawConfig eaPointedMinorPivotsDrawConfig;
|
||||
ENUM_X_DIRECTION eaMajorBias = X_DIRECTION_NONE;
|
||||
ENUM_X_DIRECTION eaMinorBias = X_DIRECTION_NONE;
|
||||
// #endregion
|
||||
|
||||
// #region Global Event Handlers ...
|
||||
@@ -84,12 +95,19 @@ void OnDeinit(const int reason)
|
||||
// Destroy Timer ...
|
||||
// If Initialized ...
|
||||
|
||||
//
|
||||
eaMajorPivotsDrawConfig.Clean();
|
||||
eaMinorPivotsDrawConfig.Clean();
|
||||
eaPointedMajorPivotsDrawConfig.Clean();
|
||||
eaPointedMinorPivotsDrawConfig.Clean();
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
ZeroMemory(eaAlert);
|
||||
ZeroMemory(eaDrawer);
|
||||
ZeroMemory(eaPivotDetector);
|
||||
ZeroMemory(eaSessionDetector);
|
||||
ZeroMemory(eaMajorPivotDetector);
|
||||
ZeroMemory(eaMinorPivotDetector);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +121,12 @@ void OnTick()
|
||||
|
||||
//
|
||||
// Process Pivot Detector ...
|
||||
HandleProcessPviots();
|
||||
HandleProcessMajorPviots();
|
||||
HandleProcessMinorPviots();
|
||||
|
||||
//
|
||||
// Detecting Bias ...
|
||||
HanldeBiasDetection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,8 +165,8 @@ bool InitializeRequirements()
|
||||
// Initialize Alert ...
|
||||
eaAlert = new XCAlert(
|
||||
ShortName,
|
||||
true, // Enable Alert ...
|
||||
true, // Log Alert ...
|
||||
false, // Enable Alert ...
|
||||
false, // Log Alert ...
|
||||
false, // Terminal Alert ...
|
||||
false, // Mail Alert ...
|
||||
false, // Push Alerts ...
|
||||
@@ -179,20 +202,82 @@ bool InitializeRequirements()
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Pivot Detector ...
|
||||
eaPivotDetector = new XCPivotDetector(
|
||||
eaAlert // Alert ...
|
||||
// Initialize Major Pivot Detector ...
|
||||
eaMajorPivotDetector = new XCPivotDetector(
|
||||
eaAlert, // Alert ...
|
||||
"X121SDTMajor", // Pivot Prefix ...
|
||||
false, // Support Inverted Zones ...
|
||||
0 // Processable Zones ...
|
||||
);
|
||||
|
||||
//
|
||||
// Register Event Handlers ...
|
||||
eaPivotDetector.AddOnPeakBreakedHandler(OnPeakBreakedHandler);
|
||||
eaPivotDetector.AddOnValeBreakedHandler(OnValeBreakedHandler);
|
||||
eaPivotDetector.AddOnPeakDetectedHandler(OnPeakDetectedHandler);
|
||||
eaPivotDetector.AddOnValeDetectedHandler(OnValeDetectedHandler);
|
||||
eaMajorPivotDetector.AddOnPeakBreakedHandler(OnMajorPeakBreakedHandler);
|
||||
eaMajorPivotDetector.AddOnValeBreakedHandler(OnMajorValeBreakedHandler);
|
||||
eaMajorPivotDetector.AddOnPeakDetectedHandler(OnMajorPeakDetectedHandler);
|
||||
eaMajorPivotDetector.AddOnValeDetectedHandler(OnMajorValeDetectedHandler);
|
||||
|
||||
//
|
||||
result = eaPivotDetector != NULL;
|
||||
// Pivot Draw Config ...
|
||||
eaMajorPivotsDrawConfig.zonesWidth = 2;
|
||||
eaMajorPivotsDrawConfig.zonesFill = false;
|
||||
eaMajorPivotsDrawConfig.ignoreZonesAt = true;
|
||||
eaMajorPivotsDrawConfig.zonesStyle = STYLE_SOLID;
|
||||
eaMajorPivotsDrawConfig.bullishColor = clrAqua;
|
||||
eaMajorPivotsDrawConfig.bearishColor = clrMagenta;
|
||||
|
||||
//
|
||||
// Pointed Pivot Draw Config ...
|
||||
eaPointedMajorPivotsDrawConfig.zonesWidth = 2;
|
||||
eaPointedMajorPivotsDrawConfig.zonesFill = false;
|
||||
eaPointedMajorPivotsDrawConfig.ignoreZonesAt = true;
|
||||
eaPointedMajorPivotsDrawConfig.zonesStyle = STYLE_SOLID;
|
||||
eaPointedMajorPivotsDrawConfig.bullishColor = clrYellow;
|
||||
eaPointedMajorPivotsDrawConfig.bearishColor = clrOrange;
|
||||
|
||||
//
|
||||
result = eaMajorPivotDetector != NULL;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Minor Pivot Detector ...
|
||||
eaMinorPivotDetector = new XCPivotDetector(
|
||||
eaAlert, // Alert ...
|
||||
"X121SDTMinor", // Pivot Prefix ...
|
||||
false, // Support Inverted Zones ...
|
||||
0 // Processable Zones ...
|
||||
);
|
||||
|
||||
//
|
||||
// Register Event Handlers ...
|
||||
eaMinorPivotDetector.AddOnPeakBreakedHandler(OnMinorPeakBreakedHandler);
|
||||
eaMinorPivotDetector.AddOnValeBreakedHandler(OnMinorValeBreakedHandler);
|
||||
eaMinorPivotDetector.AddOnPeakDetectedHandler(OnMinorPeakDetectedHandler);
|
||||
eaMinorPivotDetector.AddOnValeDetectedHandler(OnMinorValeDetectedHandler);
|
||||
|
||||
//
|
||||
// Pivot Draw Config ...
|
||||
eaMinorPivotsDrawConfig.zonesWidth = 1;
|
||||
eaMinorPivotsDrawConfig.zonesFill = false;
|
||||
eaMinorPivotsDrawConfig.ignoreZonesAt = true;
|
||||
eaMinorPivotsDrawConfig.bearishColor = clrRed;
|
||||
eaMinorPivotsDrawConfig.bullishColor = clrLime;
|
||||
eaMinorPivotsDrawConfig.zonesStyle = STYLE_DASHDOT;
|
||||
|
||||
//
|
||||
// Pointed Pivot Draw Config ...
|
||||
eaPointedMinorPivotsDrawConfig.zonesWidth = 2;
|
||||
eaPointedMinorPivotsDrawConfig.zonesFill = false;
|
||||
eaPointedMinorPivotsDrawConfig.ignoreZonesAt = true;
|
||||
eaPointedMinorPivotsDrawConfig.bearishColor = clrOrange;
|
||||
eaPointedMinorPivotsDrawConfig.bullishColor = clrYellow;
|
||||
eaPointedMinorPivotsDrawConfig.zonesStyle = STYLE_DASHDOT;
|
||||
|
||||
//
|
||||
result = eaMinorPivotDetector != NULL;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
@@ -205,7 +290,7 @@ bool InitializeRequirements()
|
||||
/**
|
||||
* Process Pivots ...
|
||||
*/
|
||||
void HandleProcessPviots()
|
||||
void HandleProcessMajorPviots()
|
||||
{
|
||||
//
|
||||
// Initialize Pivot Processing Bar ...
|
||||
@@ -213,7 +298,7 @@ void HandleProcessPviots()
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
PERIOD_H4,
|
||||
1 // Last Completed 4H Bar ...
|
||||
1 // Last Completed Bar ...
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
@@ -223,15 +308,18 @@ void HandleProcessPviots()
|
||||
//
|
||||
// Validate Passing Bar ...
|
||||
has =
|
||||
!IsXValid(eaLastPivotProcessing) ||
|
||||
bar.time > eaLastPivotProcessing;
|
||||
!IsXValid(eaLastMajorPivotProcessing) ||
|
||||
bar.time > eaLastMajorPivotProcessing;
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
eaPivotDetector.Process(
|
||||
eaLastMajorPivotProcessing = bar.time;
|
||||
|
||||
//
|
||||
eaMajorPivotDetector.Process(
|
||||
bar, // XOHCL Bar ...
|
||||
2, // Pivot Approvation Length ...
|
||||
20 // Loopback ...
|
||||
@@ -239,30 +327,141 @@ void HandleProcessPviots()
|
||||
|
||||
//
|
||||
// Handle Draw Pivots ...
|
||||
if (!eaDrawMajorPivots)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone tmps[];
|
||||
CArrayObj *objects;
|
||||
FillNotExists(
|
||||
tmps, // Dest ...
|
||||
eaPivotDetector.peaks, // Source ...
|
||||
false // Force Clean ...
|
||||
tmps, // Dest ...
|
||||
eaMajorPivotDetector.peaks, // Source ...
|
||||
false // Force Clean ...
|
||||
);
|
||||
FillNotExists(
|
||||
tmps, // Dest ...
|
||||
eaPivotDetector.vales, // Source ...
|
||||
false // Force Clean ...
|
||||
tmps, // Dest ...
|
||||
eaMajorPivotDetector.vales, // Source ...
|
||||
false // Force Clean ...
|
||||
);
|
||||
if (HasChild(tmps))
|
||||
{
|
||||
eaDrawer.DrawBoxes(
|
||||
tmps, // Boxes ...
|
||||
objects, // Objects to Hold ...
|
||||
false // Ignore Type Name ...
|
||||
eaDrawer.DrawZones(
|
||||
tmps, // Boxes ...
|
||||
eaMajorPivotsDrawConfig // Draw Config ...
|
||||
);
|
||||
}
|
||||
XClean(tmps);
|
||||
AddObjects(objects, eaDrawnObjects);
|
||||
if (eaDrawnObjects.Total() > 0) {
|
||||
DebugBreak();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Pivots ...
|
||||
*/
|
||||
void HandleProcessMinorPviots()
|
||||
{
|
||||
//
|
||||
// Initialize Pivot Processing Bar ...
|
||||
XOHCL bar;
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
PERIOD_M15,
|
||||
1 // Last Completed Bar ...
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Passing Bar ...
|
||||
has =
|
||||
!IsXValid(eaLastMinorPivotProcessing) ||
|
||||
bar.time > eaLastMinorPivotProcessing;
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
eaLastMinorPivotProcessing = bar.time;
|
||||
|
||||
//
|
||||
eaMinorPivotDetector.Process(
|
||||
bar, // XOHCL Bar ...
|
||||
5, // Pivot Approvation Length ...
|
||||
40 // Loopback ...
|
||||
);
|
||||
|
||||
//
|
||||
// Handle Draw Pivots ...
|
||||
if (!eaDrawMinorPivots)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone tmps[];
|
||||
FillNotExists(
|
||||
tmps, // Dest ...
|
||||
eaMinorPivotDetector.peaks, // Source ...
|
||||
false // Force Clean ...
|
||||
);
|
||||
FillNotExists(
|
||||
tmps, // Dest ...
|
||||
eaMinorPivotDetector.vales, // Source ...
|
||||
false // Force Clean ...
|
||||
);
|
||||
if (HasChild(tmps))
|
||||
{
|
||||
eaDrawer.DrawZones(
|
||||
tmps, // Boxes ...
|
||||
eaMinorPivotsDrawConfig // Draw Config ...
|
||||
);
|
||||
}
|
||||
XClean(tmps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Bias based on Pivots ...
|
||||
*/
|
||||
void HanldeBiasDetection()
|
||||
{
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Major Bias ...
|
||||
has =
|
||||
eaMajorPivotDetector.HasPeaks() &&
|
||||
eaMajorPivotDetector.HasVales();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
int youngestPeakIDX = eaMajorPivotDetector.GetYoungestPeak();
|
||||
int youngestValeIDX = eaMajorPivotDetector.GetYoungestVale();
|
||||
has =
|
||||
IsValidIndex(youngestPeakIDX) &&
|
||||
IsValidIndex(youngestValeIDX);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
eaMajorBias =
|
||||
eaMajorPivotDetector.peaks[youngestPeakIDX].from > eaMajorPivotDetector.vales[youngestValeIDX].from
|
||||
? X_DIRECTION_BEARISH
|
||||
: eaMajorPivotDetector.vales[youngestValeIDX].from > eaMajorPivotDetector.peaks[youngestPeakIDX].from
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (HasDirection(eaMajorBias))
|
||||
{
|
||||
Comment("Major Bias: ", ToXString(eaMajorBias));
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment("");
|
||||
}
|
||||
}
|
||||
// #endregion
|
||||
@@ -275,7 +474,7 @@ void HandleProcessPviots()
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnPeakBreakedHandler(XBoxZone &box)
|
||||
void OnMajorPeakBreakedHandler(XBoxZone &box)
|
||||
{
|
||||
// DebugBreak();
|
||||
}
|
||||
@@ -285,7 +484,7 @@ void OnPeakBreakedHandler(XBoxZone &box)
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnValeBreakedHandler(XBoxZone &box)
|
||||
void OnMajorValeBreakedHandler(XBoxZone &box)
|
||||
{
|
||||
// DebugBreak();
|
||||
}
|
||||
@@ -295,9 +494,16 @@ void OnValeBreakedHandler(XBoxZone &box)
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnPeakDetectedHandler(XBoxZone &box)
|
||||
void OnMajorPeakDetectedHandler(XBoxZone &box)
|
||||
{
|
||||
// DebugBreak();
|
||||
//
|
||||
eaDrawer.DrawZone(
|
||||
box, //
|
||||
eaPointedMajorPivotsDrawConfig //
|
||||
);
|
||||
|
||||
//
|
||||
DebugBreak();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,10 +511,71 @@ void OnPeakDetectedHandler(XBoxZone &box)
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnValeDetectedHandler(XBoxZone &box)
|
||||
void OnMajorValeDetectedHandler(XBoxZone &box)
|
||||
{
|
||||
//
|
||||
eaDrawer.DrawZone(
|
||||
box, //
|
||||
eaPointedMajorPivotsDrawConfig //
|
||||
);
|
||||
|
||||
//
|
||||
DebugBreak();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls when a Peak Breaked ...
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnMinorPeakBreakedHandler(XBoxZone &box)
|
||||
{
|
||||
// DebugBreak();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls when a Vale Breaked ...
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnMinorValeBreakedHandler(XBoxZone &box)
|
||||
{
|
||||
// DebugBreak();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls when a New Peak Detected ...
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnMinorPeakDetectedHandler(XBoxZone &box)
|
||||
{
|
||||
//
|
||||
eaDrawer.DrawZone(
|
||||
box, //
|
||||
eaPointedMinorPivotsDrawConfig //
|
||||
);
|
||||
|
||||
//
|
||||
DebugBreak();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls when a New Vale Detected ...
|
||||
*
|
||||
* @param box: XBoxZone instance ...
|
||||
*/
|
||||
void OnMinorValeDetectedHandler(XBoxZone &box)
|
||||
{
|
||||
//
|
||||
eaDrawer.DrawZone(
|
||||
box, //
|
||||
eaPointedMinorPivotsDrawConfig //
|
||||
);
|
||||
|
||||
//
|
||||
DebugBreak();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Session Detector Event Handlers ...
|
||||
|
||||
Reference in New Issue
Block a user