Complete Detection of Swings ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+298
-213
@@ -25,6 +25,7 @@
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
|
||||
@@ -239,7 +240,10 @@ class XCPOIDetector : public XCBaseAlert
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
@@ -247,8 +251,8 @@ class XCPOIDetector : public XCBaseAlert
|
||||
//
|
||||
XOHCL zBar;
|
||||
bool isInited = zBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
@@ -259,8 +263,8 @@ class XCPOIDetector : public XCBaseAlert
|
||||
//
|
||||
XOHCL cBar;
|
||||
isInited = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
@@ -269,39 +273,79 @@ class XCPOIDetector : public XCBaseAlert
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
isInited = pBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
pIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
// POI Detecting ...
|
||||
bool isDetect = false;
|
||||
|
||||
//
|
||||
XOHCL ppBar;
|
||||
isInited = ppBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
ppIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
// Swings ...
|
||||
int swingRange = SwingRange();
|
||||
if (swingRange > 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
//
|
||||
XOHCL swingBar;
|
||||
isInited = swingBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex + swingRange //
|
||||
);
|
||||
if (isInited)
|
||||
{
|
||||
//
|
||||
// Swing High ...
|
||||
isDetect = DetectSwingHigh(swingBar);
|
||||
if (isDetect)
|
||||
{
|
||||
//
|
||||
ENUM_XPOI_EVENTS event = X_SWING_HIGH_DETECTED;
|
||||
XCSwing *param;
|
||||
bool hasItem = GetLastItem(
|
||||
param,
|
||||
mSwingHighs //
|
||||
);
|
||||
if (hasItem)
|
||||
{
|
||||
//
|
||||
NotifyEventListeners(
|
||||
event,
|
||||
param //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL zDayBar;
|
||||
isInited = zDayBar.Init(
|
||||
mSymbol,
|
||||
PERIOD_D1,
|
||||
zIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
return result;
|
||||
//
|
||||
Add(
|
||||
event,
|
||||
state //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Low ...
|
||||
isDetect = DetectSwingLow(swingBar);
|
||||
if (isDetect)
|
||||
{
|
||||
//
|
||||
ENUM_XPOI_EVENTS event = X_SWING_LOW_DETECTED;
|
||||
XCSwing *param;
|
||||
bool hasItem = GetLastItem(
|
||||
param,
|
||||
mSwingLows //
|
||||
);
|
||||
if (hasItem)
|
||||
{
|
||||
//
|
||||
NotifyEventListeners(
|
||||
event,
|
||||
param //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Add(
|
||||
event,
|
||||
state //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -355,6 +399,20 @@ class XCPOIDetector : public XCBaseAlert
|
||||
//
|
||||
// Event Listeners ...
|
||||
|
||||
/**
|
||||
* Add Event Listener ...
|
||||
*
|
||||
* @param listener: TOnPOIEvent instance ...
|
||||
*/
|
||||
void AddEventListener(TOnPOIEvent listener)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
listener,
|
||||
mEventListeners //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Destroy ...
|
||||
|
||||
@@ -363,6 +421,9 @@ class XCPOIDetector : public XCBaseAlert
|
||||
*/
|
||||
void DestroyPOIs()
|
||||
{
|
||||
//
|
||||
Clean(mSwingHighs);
|
||||
Clean(mSwingLows);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,6 +438,7 @@ class XCPOIDetector : public XCBaseAlert
|
||||
*/
|
||||
void DestroyEventListeners()
|
||||
{
|
||||
Clean(mEventListeners);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -463,10 +525,18 @@ class XCPOIDetector : public XCBaseAlert
|
||||
//
|
||||
// Swing Highs ...
|
||||
swingHighsCount = DetectRequiredSwingHighs(barIndex);
|
||||
if (swingHighsCount == requiredPOIs)
|
||||
{
|
||||
ArrayReverse(mSwingHighs);
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Lows ...
|
||||
swingLowsCount = DetectRequiredSwingLows(barIndex);
|
||||
if (swingHighsCount == requiredPOIs)
|
||||
{
|
||||
ArrayReverse(mSwingLows);
|
||||
}
|
||||
|
||||
//
|
||||
canContinue =
|
||||
@@ -486,10 +556,6 @@ class XCPOIDetector : public XCBaseAlert
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
swingHighsCount = ArraySize(mSwingHighs);
|
||||
swingLowsCount = ArraySize(mSwingLows);
|
||||
|
||||
//
|
||||
// Unlocking Detector ...
|
||||
Unlock();
|
||||
@@ -507,11 +573,11 @@ class XCPOIDetector : public XCBaseAlert
|
||||
return;
|
||||
}
|
||||
|
||||
// //
|
||||
//
|
||||
int swingHighsCount = ArraySize(mSwingHighs);
|
||||
int swingLowsCount = ArraySize(mSwingLows);
|
||||
// int tradingDaysCount = ArraySize(mTradingDays);
|
||||
// int marketSessionsCount = ArraySize(mMarketSessions);
|
||||
// int swingHighsCount = ArraySize(mSwingHighs);
|
||||
// int swingLowsCount = ArraySize(mSwingLows);
|
||||
// int momentumBarsCount = ArraySize(mMomentumBars);
|
||||
// int rejectionBarsCount = ArraySize(mRejectionBars);
|
||||
// int supportZonesCount = ArraySize(mSupportZones);
|
||||
@@ -523,11 +589,38 @@ class XCPOIDetector : public XCBaseAlert
|
||||
// int bullishFVGsCount = ArraySize(mBullishFVGs);
|
||||
// int bearishFVGsCount = ArraySize(mBearishFVGs);
|
||||
|
||||
// //
|
||||
// int from = 0;
|
||||
// int requiredPOIs = MaxNumberOfRequiredPOIs();
|
||||
// int count = maxAllowed - requiredPOIs;
|
||||
// int to = count - 1;
|
||||
//
|
||||
int from = 0;
|
||||
int requiredPOIs = MaxNumberOfRequiredPOIs();
|
||||
int count = maxAllowed - requiredPOIs;
|
||||
int to = count - 1;
|
||||
|
||||
//
|
||||
// Swings ...
|
||||
|
||||
//
|
||||
// Swing Highs ...
|
||||
if (swingHighsCount >= maxAllowed)
|
||||
{
|
||||
//
|
||||
ArrayRemove(
|
||||
mSwingHighs,
|
||||
from,
|
||||
count //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Lows ...
|
||||
if (swingLowsCount >= maxAllowed)
|
||||
{
|
||||
//
|
||||
ArrayRemove(
|
||||
mSwingLows,
|
||||
from,
|
||||
count //
|
||||
);
|
||||
}
|
||||
|
||||
// //
|
||||
// // Trading Days ...
|
||||
@@ -601,45 +694,6 @@ class XCPOIDetector : public XCBaseAlert
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Swing High and Low (s) ...
|
||||
|
||||
// //
|
||||
// // Swing Highs ...
|
||||
// if (swingHighsCount >= maxAllowed)
|
||||
// {
|
||||
// //
|
||||
// ArrayRemove(
|
||||
// mSwingHighs,
|
||||
// from,
|
||||
// count //
|
||||
// );
|
||||
|
||||
// //
|
||||
// mSwingHighObjects.DeleteRange(
|
||||
// from,
|
||||
// to //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Swing Lows ...
|
||||
// if (swingLowsCount >= maxAllowed)
|
||||
// {
|
||||
// //
|
||||
// ArrayRemove(
|
||||
// mSwingLows,
|
||||
// from,
|
||||
// count //
|
||||
// );
|
||||
|
||||
// //
|
||||
// mSwingLowObjects.DeleteRange(
|
||||
// from,
|
||||
// to //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Support and Resistance Zones ...
|
||||
|
||||
@@ -799,6 +853,35 @@ class XCPOIDetector : public XCBaseAlert
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Event Listeners ...
|
||||
*
|
||||
* @param event: ENUM_XPOI_EVENTS member, Specified Occured Event ...
|
||||
* @param param: XCBasePOI implementation, Specified Event Object ...
|
||||
*/
|
||||
void NotifyEventListeners(
|
||||
ENUM_XPOI_EVENTS event,
|
||||
XCBasePOI *param //
|
||||
)
|
||||
{
|
||||
//
|
||||
int count = ArraySize(mEventListeners);
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
mEventListeners[i](
|
||||
event,
|
||||
param //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void AddObjectIfNotExists(XCBaseObject *object)
|
||||
{
|
||||
//
|
||||
@@ -847,8 +930,12 @@ class XCPOIDetector : public XCBaseAlert
|
||||
int mMaxNumberOfRequiredPOIs; // Max Allowed Number of POI(s) which Must Find at Initializion Time ...
|
||||
|
||||
//
|
||||
CArrayObj mDrawnObjects; // Drawn Objects ...
|
||||
XBarTracker mBarTracker; // Market Bar Tracker ...
|
||||
CArrayObj mDrawnObjects; // Drawn Objects ...
|
||||
XBarTracker mBarTracker; // Market Bar Tracker ...
|
||||
XCBarAnalyser mBarAnalyser; // Bar Analyser ...
|
||||
|
||||
//
|
||||
TOnPOIEvent mEventListeners[]; // Event Listeners ...
|
||||
|
||||
//
|
||||
// POI Props ...
|
||||
@@ -865,8 +952,80 @@ class XCPOIDetector : public XCBaseAlert
|
||||
|
||||
//
|
||||
// Swing High ...
|
||||
|
||||
//
|
||||
XCSwing *mSwingHighs[]; // Holds Founded Swing Highs ...
|
||||
|
||||
/**
|
||||
* Detect Swing High ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectSwingHigh(XOHCL &bar)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int range = SwingRange();
|
||||
int barIndex = bar.Index();
|
||||
result = range > 0 &&
|
||||
barIndex >= range;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = mBarAnalyser.IsSwingHigh(
|
||||
bar,
|
||||
range //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
XCSwing *swing;
|
||||
swing = new XCSwing();
|
||||
result = swing.Init(
|
||||
bar,
|
||||
X_POI_SWING_HIGH //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
swing,
|
||||
mSwingHighs //
|
||||
);
|
||||
|
||||
//
|
||||
XCSwingHighObject *iObj;
|
||||
bool isCreated = mDrawer.CreateSwingHigh(
|
||||
swing,
|
||||
iObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
AddObjectIfNotExists(iObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Required Swing Highs ...
|
||||
*
|
||||
@@ -926,61 +1085,67 @@ class XCPOIDetector : public XCBaseAlert
|
||||
}
|
||||
|
||||
//
|
||||
bool isSwing = true;
|
||||
for (int i = 1; i <= range; i++)
|
||||
DetectSwingHigh(bar);
|
||||
|
||||
//
|
||||
result = ArraySize(mSwingHighs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Low ...
|
||||
|
||||
//
|
||||
XCSwing *mSwingLows[]; // Holds Founded Swing Lows ...
|
||||
|
||||
/**
|
||||
* Detect Swing Low ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectSwingLow(XOHCL &bar)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Prev Bar ...
|
||||
XOHCL iPrevBar;
|
||||
isInited = iPrevBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex + i //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
//
|
||||
isSwing = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Next Bar ...
|
||||
XOHCL iNextBar;
|
||||
isInited = iNextBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex - i //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
//
|
||||
isSwing = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
isSwing = bar.high >= iPrevBar.high &&
|
||||
bar.high >= iNextBar.high;
|
||||
if (!isSwing)
|
||||
{
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (isSwing)
|
||||
int range = SwingRange();
|
||||
int barIndex = bar.Index();
|
||||
result = range > 0 &&
|
||||
barIndex >= range;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = mBarAnalyser.IsSwingLow(
|
||||
bar,
|
||||
range //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
XCSwing *swing;
|
||||
swing = new XCSwing();
|
||||
isInited = swing.Init(
|
||||
result = swing.Init(
|
||||
bar,
|
||||
X_POI_SWING_HIGH //
|
||||
X_POI_SWING_LOW //
|
||||
);
|
||||
|
||||
//
|
||||
if (isInited)
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
@@ -989,8 +1154,8 @@ class XCPOIDetector : public XCBaseAlert
|
||||
);
|
||||
|
||||
//
|
||||
XCSwingHighObject *iObj;
|
||||
bool isCreated = mDrawer.CreateSwingHigh(
|
||||
XCSwingLowObject *iObj;
|
||||
bool isCreated = mDrawer.CreateSwingLow(
|
||||
swing,
|
||||
iObj //
|
||||
);
|
||||
@@ -1001,17 +1166,10 @@ class XCPOIDetector : public XCBaseAlert
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(mSwingHighs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Low ...
|
||||
XCSwing *mSwingLows[]; // Holds Founded Swing Lows ...
|
||||
|
||||
/**
|
||||
* Detect Required Swing Lows ...
|
||||
*
|
||||
@@ -1071,80 +1229,7 @@ class XCPOIDetector : public XCBaseAlert
|
||||
}
|
||||
|
||||
//
|
||||
bool isSwing = true;
|
||||
for (int i = 1; i <= range; i++)
|
||||
{
|
||||
//
|
||||
// Prev Bar ...
|
||||
XOHCL iPrevBar;
|
||||
isInited = iPrevBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex + i //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
//
|
||||
isSwing = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Next Bar ...
|
||||
XOHCL iNextBar;
|
||||
isInited = iNextBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex - i //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
//
|
||||
isSwing = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
isSwing = bar.low <= iPrevBar.low &&
|
||||
bar.low <= iNextBar.low;
|
||||
if (!isSwing)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (isSwing)
|
||||
{
|
||||
//
|
||||
XCSwing *swing;
|
||||
swing = new XCSwing();
|
||||
isInited = swing.Init(
|
||||
bar,
|
||||
X_POI_SWING_LOW //
|
||||
);
|
||||
|
||||
//
|
||||
if (isInited)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
swing,
|
||||
mSwingLows //
|
||||
);
|
||||
|
||||
//
|
||||
XCSwingLowObject *iObj;
|
||||
bool isCreated = mDrawer.CreateSwingLow(
|
||||
swing,
|
||||
iObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
AddObjectIfNotExists(iObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
DetectSwingLow(bar);
|
||||
|
||||
//
|
||||
result = ArraySize(mSwingHighs);
|
||||
|
||||
@@ -1411,14 +1411,14 @@ class XCPOIDrawer : public XCBase
|
||||
SubWindowIdentification(0);
|
||||
|
||||
//
|
||||
SwingLowWidth(1);
|
||||
SwingLowWidth(2);
|
||||
SwingLowArrow(108);
|
||||
SwingLowColor(clrLime);
|
||||
SwingLowColor(clrAqua);
|
||||
|
||||
//
|
||||
SwingHighWidth(1);
|
||||
SwingHighWidth(2);
|
||||
SwingHighArrow(108);
|
||||
SwingHighColor(clrRed);
|
||||
SwingHighColor(clrMagenta);
|
||||
|
||||
//
|
||||
BullishMomentumBarWidth(1);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2555,4 +2555,9 @@ string ToString(ENUM_XPOI_EVENTS value)
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
typedef void (*TOnPOIEvent)(ENUM_XPOI_EVENTS event,
|
||||
XCBasePOI *param //
|
||||
);
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user