This commit is contained in:
2025-02-24 00:24:13 +03:30
parent 8e34ef9c94
commit 0f9ab4b61a
7 changed files with 1548 additions and 282 deletions
+405 -18
View File
@@ -23,19 +23,11 @@
// Definitions ...
//
enum ENUM_XWZ_REJECTION_TYPES
{
XWZ_REJECTION_BAR, // Only Bar Reject
XWZ_REJECTION_STRONG_BAR, // Directional Bar Reject
XWZ_REJECTION_PRESSURED_BAR, // Bar Reject using Pressure
XWZ_REJECTION_STRONG_PRESSURED_BAR, // Strong Bar Reject using Pressure
};
//
#define ShortName "X121 XWZ"
#define ShortName "X121_XWZ"
//
// Includes Common Library ...
#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.common.lib.mq5"
@@ -59,14 +51,21 @@ input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
//
input group "ATR StopLoss";
input int atrLength = 14; // ATR Length
input int atrMultiplier = 2; // ATR Multiplier
input int atrLength = 14; // ATR Length
input double atrMultiplier = 2; // ATR Multiplier
//
input group "ADX Detection";
input int adxLength = 14; // ADX Length
input double adxThreshold = 25; // ADX Threshold for Strong Trends
//
input group "Alert";
input bool mXWZEnableAlerts = true; // Enable Alerts
input bool mXWZPushAlerts = false; // Push Alerts
input bool mXWZMailAlerts = false; // Mail Alerts
input bool mXWZTerminalAlerts = false; // Terminal Alerts
//
// Presentation ...
input group "Presentation";
@@ -85,7 +84,7 @@ input bool showRejection = true; // Show Rejection Bars
//
input group "POI Presentation";
input bool showPOIs = true; // Show POI(s)
input bool showPOIs = false; // Show POI(s)
input bool showActivatedPOIs = true; // Show Activated POI(s)
input bool showOrderBlocks = true; // Show Order Blocks
input bool showFairValueGaps = true; // Show Fair Value Gaps
@@ -308,6 +307,7 @@ int atrHandler = INVALID_HANDLE;
int adxHandler = INVALID_HANDLE;
//
XCAlert *mXWZAlert;
CArrayObj mXWZDrawnObjects;
XCPOIDrawer *mXWZPOIDrawer;
XCBarAnalyser *mXWZBarAnalyser;
@@ -316,17 +316,21 @@ XCBarAnalyser *mXWZBarAnalyser;
datetime lastBullishTrend = NULL;
datetime lastBearishTrend = NULL;
//
datetime lastCrossedOverMA = NULL;
datetime lastCrossedUnderMA = NULL;
//
// POI(s) ...
//
bool mXWZDetectOrderBlocks = true;
bool mXWZDetectFairValueGaps = true;
bool mXWZDetectSupportZones = true;
bool mXWZDetectResistanceZones = true;
bool mXWZDetectFairValueGaps = false;
bool mXWZDetectSupportZones = false;
bool mXWZDetectResistanceZones = false;
//
bool filterPOIsUsingMa = true; // Filter POI(s) Using MA
bool filterPOIsUsingMa = false; // Filter POI(s) Using MA
bool filterPOIsUsingZones = false; // Filter POI(s) Using Zones
//
@@ -436,6 +440,10 @@ int OnInit()
mXWZPOIDrawer = new XCPOIDrawer();
ConfigurePOIDrawer();
//
mXWZAlert = new XCAlert();
ConfigureAlert();
//
mXWZBarAnalyser = new XCBarAnalyser();
@@ -472,6 +480,7 @@ void OnDeinit(const int reason)
mXWZDrawnObjects.Clear();
//
ZeroMemory(mXWZAlert);
ZeroMemory(mXWZPOIDrawer);
ZeroMemory(mXWZBarAnalyser);
@@ -1112,6 +1121,7 @@ void CalculateValues(
pBar.Clean();
return;
}
int pIndex = pBar.Index();
//
// Calculate Applied Price ...
@@ -1126,6 +1136,7 @@ void CalculateValues(
//
double iMa = maBuffer[bar_index];
double iMaPrev = maBuffer[pIndex];
double iAtr = atrBuffer[bar_index];
double iAdx = adxBuffer[bar_index];
double iAppliedAtr = iAtr * atrMultiplier;
@@ -1157,6 +1168,33 @@ void CalculateValues(
bool hasLastResistance = lastResistance != NULL &&
lastResistance.IsValid();
//
// Calculate Crossing Over / Under Ma ...
bool isCrossedOverMA =
//
iBar.low > iMa &&
(pBar.low <= iMaPrev &&
(pBar.GetUp() <= iMaPrev ||
pBar.GetDown() <= iMaPrev))
//
;
bool isCrossedUnderMA =
//
iBar.high < iMa &&
(pBar.high >= iMaPrev &&
(pBar.GetUp() >= iMaPrev ||
pBar.GetDown() >= iMaPrev))
//
;
lastCrossedOverMA =
isCrossedOverMA
? iBar.time
: lastCrossedOverMA;
lastCrossedUnderMA =
isCrossedUnderMA
? iBar.time
: lastCrossedUnderMA;
//
// SL Buffers ...
@@ -1594,7 +1632,7 @@ void CalculateValues(
: iSwingLowValue < iMa
? iSwingLowValue
: 0;
}
}
//
if (isSwingHigh)
@@ -1629,6 +1667,22 @@ void CalculateValues(
swingHighBuffer[bar_index] = iSwingHighValue;
}
//
//
//
//
DetectSignals(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Cleanup Resources ...
@@ -1637,6 +1691,339 @@ void CalculateValues(
pBar.Clean();
}
//
void ConfigureAlert()
{
//
mXWZAlert.SetPrefix(ShortName);
//
mXWZAlert.SetPushAlerts(mXWZPushAlerts);
mXWZAlert.SetMailAlerts(mXWZMailAlerts);
mXWZAlert.SetEnableAlerts(mXWZEnableAlerts);
mXWZAlert.SetTerminalAlerts(mXWZTerminalAlerts);
}
//
void DetectSignals(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Calculate Signals ...
//
XOHCL bar;
XOHCL pBar;
XOHCL ppBar;
bool isInited = bar.Init(
_Symbol,
_Period,
barIndex //
);
if (!isInited)
{
return;
}
//
isInited = bar.GetPreviousBar(pBar);
if (!isInited)
{
return;
}
//
isInited = pBar.GetPreviousBar(ppBar);
if (!isInited)
{
return;
}
//
int pIDX = pBar.Index();
int ppIDX = ppBar.Index();
//
// Reading Buffers ...
//
double ma = maBuffer[barIndex];
double maPrev = maBuffer[pIDX];
double maPPrev = maBuffer[ppIDX];
//
// Pin Bar ...
bool isBullisPinned = bullishPinBuffer[pIDX] > 0;
bool isBearisPinned = bearishPinBuffer[pIDX] > 0;
//
// Engulf Bar ...
bool isBullisEngulfed = bullishEngulfBuffer[pIDX] > 0;
bool isBearisEngulfed = bearishEngulfBuffer[pIDX] > 0;
//
// Rejection Bar ...
bool isBullishRejected = bullishRejectionBuffer[pIDX] > 0;
bool isBearishRejected = bearishRejectionBuffer[pIDX] > 0;
//
// Momentum Bar ...
bool isBullishMomentum = bullishMomentumBuffer[pIDX] > 0;
bool isBearishMomentum = bearishMomentumBuffer[pIDX] > 0;
//
// Checking Pullback ...
ENUM_X_DIRECTION pullbackDir;
bool hasPullback = mXWZBarAnalyser.HasPullBack(
pullbackDir,
bar //
);
bool hasBullishPullback =
hasPullback &&
IsBullish(pullbackDir);
bool hasBearishPullback =
hasPullback &&
IsBearish(pullbackDir);
//
// Order Block Parsing ...
// //
// bool isMACrossedOverBullishOB =
// //
// lastBullOB != NULL &&
// lastBullOB.IsValid() &&
// //
// IsInside(
// maPPrev,
// lastBullOB //
// ) &&
// //
// IsAbove(
// maPrev,
// lastBullOB //
// )
// //
// ;
// //
// bool isMACrossedUnderBearishOB =
// //
// lastBearOB != NULL &&
// lastBearOB.IsValid() &&
// //
// IsInside(
// maPPrev,
// lastBearOB //
// ) &&
// //
// IsBelow(
// maPrev,
// lastBearOB //
// )
// //
// ;
//
// Bullish ...
// --------------
// -[] a Bullish Wave Which Crossed Over MA ...
// -[] Trend is Bullish ...
// -[] PullBack to MA ...
// -[] Has a Bllish Rejection ...
bool hasBullishSignal =
//
pBar.IsBullish() &&
pBar.low < maPrev &&
pBar.GetDown() >= maPrev &&
//
bar.open >= ma &&
//
hasBearishPullback &&
//
false
//
;
//
// Bearish ...
// --------------
// -[] a Bearish Wave Which Crossed Under MA ...
// -[] Trend is Bearish ...
// -[] PullBack to MA ...
// -[] Has a Bearish Rejection ...
bool hasBearishSignal =
//
false
// pBar.IsBearish() &&
// pBar.high > maPrev &&
// pBar.GetUp() <= maPrev &&
// //
// bar.open <= ma &&
// //
// true
//
;
//
// Draw ...
//
//
long chartID = mXWZPOIDrawer.ChartIdentification();
int window = mXWZPOIDrawer.SubWindowIdentification();
// //
// if (isMACrossedOverBullishOB)
// {
// //
// string name =
// "Bullish_" +
// ToMD5(ToFormatString(pBar.time));
// //
// CChartObjectVLine *iLine;
// iLine = new CChartObjectVLine();
// bool isCreated = iLine.Create(
// chartID,
// name,
// window,
// pBar.time //
// );
// if (isCreated)
// {
// //
// iLine.Color(clrAqua);
// //
// mXWZDrawnObjects.Add(iLine);
// }
// }
// //
// if (isMACrossedUnderBearishOB)
// {
// //
// string name =
// "Bearish_" +
// ToMD5(ToFormatString(pBar.time));
// //
// CChartObjectVLine *iLine;
// iLine = new CChartObjectVLine();
// bool isCreated = iLine.Create(
// chartID,
// name,
// window,
// pBar.time //
// );
// if (isCreated)
// {
// //
// iLine.Color(clrMagenta);
// //
// mXWZDrawnObjects.Add(iLine);
// }
// }
//
bool hasSignal =
(hasBullishSignal ||
hasBearishSignal);
if (hasSignal)
{
//
long chartID = mXWZPOIDrawer.ChartIdentification();
int window = mXWZPOIDrawer.SubWindowIdentification();
string name =
(hasBullishSignal
? "Bullish_"
: "Bearish_") +
"Signal_" + ToMD5(ToFormatString(bar.time));
color signalColor =
hasBullishSignal
? clrYellow
: clrOrange;
//
CChartObjectVLine *iSignal;
iSignal = new CChartObjectVLine();
bool isCreated = iSignal.Create(
chartID,
name,
window,
bar.time //
);
if (isCreated)
{
//
iSignal.Color(signalColor);
//
mXWZDrawnObjects.Add(iSignal);
}
//
bool drawRR = false;
if (drawRR)
{
//
XRR iSigRR;
ENUM_X_POSITION_TYPES type =
hasBullishSignal
? X_POSITION_TYPE_LONG
: X_POSITION_TYPE_SHORT;
double sl = hasBullishSignal
? longSLBuffer[barIndex]
: shortSLBuffer[barIndex];
//
isCreated = iSigRR.Init(
_Symbol,
_Period,
sl,
bar.open,
type,
ShortName //
);
if (!isCreated)
{
return;
}
//
iSigRR.time = pBar.NextAt();
//
XCRRObject *iObj;
isCreated = mXWZPOIDrawer.CreateRR(
iSigRR,
iObj //
);
if (isCreated)
{
mXWZDrawnObjects.Add(iObj);
}
//
iSigRR.Clean();
}
}
//
bar.Clean();
pBar.Clean();
}
//
// POIS Functions ...