last ...
This commit is contained in:
@@ -5923,3 +5923,97 @@ struct XBoxZone
|
||||
};
|
||||
|
||||
//
|
||||
struct XDirectionShift
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
string type;
|
||||
datetime at;
|
||||
double after;
|
||||
double before;
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
ENUM_X_DIRECTION shiftTo;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XDirectionShift()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
at = NULL;
|
||||
after = 0;
|
||||
before = 0;
|
||||
type = NULL;
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
shiftTo = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
after > 0 &&
|
||||
IsValid(at) &&
|
||||
IsValid(type) &&
|
||||
after != before &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
HasDirection(shiftTo);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Same ...
|
||||
bool IsSameAs(XDirectionShift &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid() &&
|
||||
item.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
at == item.at &&
|
||||
type == item.type &&
|
||||
after == item.after &&
|
||||
before == item.before &&
|
||||
symbol == item.symbol &&
|
||||
period == item.period &&
|
||||
shiftTo == item.shiftTo
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
|
||||
@@ -135,6 +136,501 @@ struct XTriggerBlock
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
bool DetectTriggerBlock(
|
||||
XCPOIDrawer *drawer,
|
||||
XCX121XCatbHelper *helper,
|
||||
X121XCatbConditions &conditions,
|
||||
XTriggerBlock &tb,
|
||||
int barIndex = 0,
|
||||
int loopback = 10 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
tb.Clean();
|
||||
conditions.Clean();
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
loopback = NormalizeInt(loopback, 0);
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result = helper != NULL;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Market Conditions ...
|
||||
result = helper.GetConditions(
|
||||
conditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
tb.Clean();
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
int zIDX = 0;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int p2IDX = pIDX + 1;
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Detect Indicator Base Start Directional Movement ...
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
|
||||
//
|
||||
bool isSarBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current SAR is Directional ...
|
||||
conditions.isSarBullish &&
|
||||
//
|
||||
// Previous InDirectional Sar Exists ...
|
||||
helper.lastSarBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over previous Sar ...
|
||||
conditions.bars[cIDX].close > helper.lastSarBearish.after &&
|
||||
//
|
||||
// Before Close is not Over previous Sar ...
|
||||
conditions.bars[pIDX].close <= helper.lastSarBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSarBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current SAR is Directional ...
|
||||
conditions.isSarBearish &&
|
||||
//
|
||||
// Previous InDirectional Sar Exists ...
|
||||
helper.lastSarBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Under previous ...
|
||||
conditions.bars[cIDX].close < helper.lastSarBullish.after &&
|
||||
//
|
||||
// Before Close is not Under previous ...
|
||||
conditions.bars[pIDX].close >= helper.lastSarBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
|
||||
//
|
||||
bool isTrendBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current Trend is Directional ...
|
||||
conditions.isTrendBullish &&
|
||||
//
|
||||
// Previous InDirectiona; Trend Exists ...
|
||||
helper.lastTrendBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over previous ...
|
||||
conditions.bars[cIDX].close > helper.lastTrendBearish.after &&
|
||||
//
|
||||
// Before close is not Over previous ...
|
||||
conditions.bars[pIDX].close <= helper.lastTrendBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isTrendBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current Trend is Directional ...
|
||||
conditions.isTrendBearish &&
|
||||
//
|
||||
// Previous InDirectiona; Trend Exists ...
|
||||
helper.lastTrendBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Under previous ...
|
||||
conditions.bars[cIDX].close < helper.lastTrendBullish.after &&
|
||||
//
|
||||
// Before close is not Under previous ...
|
||||
conditions.bars[pIDX].close >= helper.lastTrendBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// ADX ...
|
||||
|
||||
//
|
||||
bool isADXBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// ADX Value is Switched to Strong ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxThreshold &&
|
||||
conditions.adxBuffer[pIDX] <= conditions.adxThreshold &&
|
||||
//
|
||||
// ADX must Up ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxBuffer[pIDX] &&
|
||||
//
|
||||
// ADX +DI is Bigger than -DI ...
|
||||
conditions.adxpBuffer[cIDX] > conditions.adxnBuffer[cIDX] &&
|
||||
//
|
||||
// ADX +DI is Up ...
|
||||
conditions.adxpBuffer[cIDX] > conditions.adxpBuffer[pIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isADXBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// ADX Value is Switched to Strong ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxThreshold &&
|
||||
conditions.adxBuffer[pIDX] <= conditions.adxThreshold &&
|
||||
//
|
||||
// ADX must Up ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxBuffer[pIDX] &&
|
||||
//
|
||||
// ADX -DI is Bigger than +DI ...
|
||||
conditions.adxnBuffer[cIDX] > conditions.adxpBuffer[cIDX] &&
|
||||
//
|
||||
// ADX -DI is Up ...
|
||||
conditions.adxnBuffer[cIDX] > conditions.adxnBuffer[pIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// DELTA ...
|
||||
|
||||
//
|
||||
bool isDeltaBullishStart =
|
||||
//
|
||||
// Check State ...
|
||||
(
|
||||
//
|
||||
// Delta is Up ...
|
||||
conditions.deltaBuffer[cIDX] > conditions.deltaBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Signal is Up ...
|
||||
conditions.deltaSignalBuffer[cIDX] > conditions.deltaSignalBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Crossed Over Delta Signal ...
|
||||
conditions.deltaBuffer[cIDX] > conditions.deltaSignalBuffer[cIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastDeltaBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over last ...
|
||||
conditions.bars[cIDX].close > helper.lastDeltaBearish.after &&
|
||||
//
|
||||
// Before Close is not Over last ...
|
||||
conditions.bars[pIDX].close <= helper.lastDeltaBearish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isDeltaBearishStart =
|
||||
//
|
||||
// Check State ...
|
||||
(
|
||||
//
|
||||
// Delta is Down ...
|
||||
conditions.deltaBuffer[cIDX] < conditions.deltaBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Signal is Down ...
|
||||
conditions.deltaSignalBuffer[cIDX] < conditions.deltaSignalBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Crossed Under Delta Signal ...
|
||||
conditions.deltaBuffer[cIDX] < conditions.deltaSignalBuffer[cIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastDeltaBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Under last ...
|
||||
conditions.bars[cIDX].close < helper.lastDeltaBullish.after &&
|
||||
//
|
||||
// Before Close is not Under last ...
|
||||
conditions.bars[pIDX].close >= helper.lastDeltaBullish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
|
||||
//
|
||||
bool isVolumeBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
//
|
||||
// Volume is Up ...
|
||||
conditions.bullishVolumeBuffer[1] > conditions.bullishVolumeBuffer[2] &&
|
||||
//
|
||||
// Volume Signal is Up ...
|
||||
conditions.bullishVolumeSignalBuffer[1] > conditions.bullishVolumeSignalBuffer[2] &&
|
||||
//
|
||||
// Volume Signals Crossed Over ...
|
||||
conditions.bullishVolumeSignalBuffer[1] > conditions.bearishVolumeSignalBuffer[1]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastVolumeBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over last ...
|
||||
conditions.bars[cIDX].close > helper.lastVolumeBearish.after &&
|
||||
//
|
||||
// Before Close is not Over last ...
|
||||
conditions.bars[pIDX].close <= helper.lastVolumeBearish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVolumeBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
//
|
||||
// Volume is Up ...
|
||||
conditions.bearishVolumeBuffer[1] > conditions.bearishVolumeBuffer[2] &&
|
||||
//
|
||||
// Volume Signal is Up ...
|
||||
conditions.bearishVolumeSignalBuffer[1] > conditions.bearishVolumeSignalBuffer[2] &&
|
||||
//
|
||||
// Volume Signals Crossed Over ...
|
||||
conditions.bearishVolumeSignalBuffer[1] > conditions.bullishVolumeSignalBuffer[1]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastVolumeBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over last ...
|
||||
conditions.bars[cIDX].close < helper.lastVolumeBullish.after &&
|
||||
//
|
||||
// Before Close is not Over last ...
|
||||
conditions.bars[pIDX].close >= helper.lastVolumeBullish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// SIGNAL Bar ...
|
||||
|
||||
//
|
||||
bool isSBarBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isSBarBullish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastSignalBarBearish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.sBarCloseBuffer[cIDX] > helper.lastSignalBarBearish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.sBarCloseBuffer[pIDX] <= helper.lastSignalBarBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSBarBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isSBarBearish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastSignalBarBullish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.sBarCloseBuffer[cIDX] < helper.lastSignalBarBullish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.sBarCloseBuffer[pIDX] >= helper.lastSignalBarBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// HKSIGNAL Bar ...
|
||||
|
||||
//
|
||||
bool isHKSBarBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isHKSBarBullish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastHKSignalBarBearish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.hkSBarCloseBuffer[cIDX] > helper.lastHKSignalBarBearish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.hkSBarCloseBuffer[pIDX] <= helper.lastHKSignalBarBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isHKSBarBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isHKSBarBearish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastHKSignalBarBullish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.hkSBarCloseBuffer[cIDX] < helper.lastHKSignalBarBullish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.hkSBarCloseBuffer[pIDX] >= helper.lastHKSignalBarBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Try to Summarize Conditions ...
|
||||
|
||||
//
|
||||
bool isBullishPassed =
|
||||
//
|
||||
//isSarBullishStart &&
|
||||
// isTrendBullishStart &&
|
||||
// isADXBullishStart &&
|
||||
isDeltaBullishStart &&
|
||||
isVolumeBullishStart &&
|
||||
isSBarBullishStart
|
||||
// &&
|
||||
// isHKSBarBullishStart
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBearishPassed =
|
||||
//
|
||||
// isSarBearishStart &&
|
||||
// isTrendBearishStart &&
|
||||
// isADXBearishStart &&
|
||||
isDeltaBearishStart &&
|
||||
isVolumeBearishStart &&
|
||||
isSBarBearishStart
|
||||
// &&
|
||||
// isHKSBarBearishStart
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Draw Line for Detect Conditions States on Chart ...
|
||||
if (isBullishPassed ||
|
||||
isBearishPassed)
|
||||
{
|
||||
//
|
||||
color iColor = isBullishPassed
|
||||
? clrAqua
|
||||
: clrMagenta;
|
||||
|
||||
//
|
||||
datetime iTime = conditions.bars[cIDX].time;
|
||||
|
||||
//
|
||||
string iName = "VL_" + ToFormatString(iTime);
|
||||
|
||||
//
|
||||
long chartID = drawer.ChartIdentification();
|
||||
int subWindow = drawer.SubWindowIdentification();
|
||||
|
||||
//
|
||||
CChartObjectVLine *iObj;
|
||||
iObj = new CChartObjectVLine();
|
||||
bool isDrawn = iObj.Create(
|
||||
chartID,
|
||||
iName,
|
||||
subWindow,
|
||||
iTime //
|
||||
);
|
||||
if (isDrawn)
|
||||
{
|
||||
//
|
||||
iObj.Color(iColor);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Summarizing result ...
|
||||
|
||||
//
|
||||
result = (isBullishPassed ||
|
||||
isBearishPassed);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
tb.Clean();
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Block ...
|
||||
bool DetectTriggerBlock(
|
||||
|
||||
Reference in New Issue
Block a user