995 lines
21 KiB
Plaintext
995 lines
21 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Lib
|
|
// -------------------------------------------------
|
|
// Name:
|
|
// Description: provide all Signalling functions ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXPVDPSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
double peak;
|
|
double vale;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXPVDPSignalConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
sl = 0;
|
|
target = 0;
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
type = X_POSITION_TYPE_NONE;
|
|
|
|
//
|
|
symbol = NULL;
|
|
period = NULL;
|
|
setupTime = NULL;
|
|
triggerTime = NULL;
|
|
|
|
//
|
|
ExtensionClean();
|
|
}
|
|
|
|
/**
|
|
* Check Condition is Setting Up ...
|
|
*
|
|
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsSetuped()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValid(setupTime) &&
|
|
HasDirection(dir);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Calculate Setup Age ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int GetSetupAge()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
if (!IsSetuped())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect How we Can Trigger Signal ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool CanTrigger()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
sl > 0 &&
|
|
IsValid(symbol) &&
|
|
IsValid(period) &&
|
|
IsValid(triggerTime) &&
|
|
type != X_POSITION_TYPE_ALL &&
|
|
type != X_POSITION_TYPE_NONE
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Extensions ...
|
|
|
|
/**
|
|
* Clean Additional Properties ...
|
|
*/
|
|
void ExtensionClean()
|
|
{
|
|
//
|
|
peak = 0;
|
|
vale = 0;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXPVDPSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXPVDPSignalConditions &conditions,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
// Detect Market Trend ...
|
|
ENUM_X_DIRECTION trend;
|
|
bool hasTrend = consolidationCycleHelper
|
|
.DetectTrend(trend);
|
|
bool hasBullishTrend = hasTrend &&
|
|
IsBullish(trend);
|
|
bool hasBearishTrend = hasTrend &&
|
|
IsBearish(trend);
|
|
result = hasBullishTrend ||
|
|
hasBearishTrend;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Select Source State ...
|
|
XPOIState state = decisionState;
|
|
|
|
//
|
|
// Detect High Equals to Peaks or Low Equals to Vale ...
|
|
|
|
//
|
|
// Peak ...
|
|
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
bool isNewPeak = triggerConditions.x121Conditions.isNewPeak;
|
|
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast;
|
|
|
|
//
|
|
// Vale ...
|
|
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
bool isNewVale = triggerConditions.x121Conditions.isNewVale;
|
|
bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast;
|
|
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
bool isHighEqualsToPeak =
|
|
isNewPeak &&
|
|
peak == cBar.high;
|
|
|
|
//
|
|
bool isLowEqualsToVale =
|
|
isNewVale &&
|
|
vale == cBar.low;
|
|
|
|
//
|
|
result = isHighEqualsToPeak ||
|
|
isLowEqualsToVale;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Now We Have To Check DONChain Status ...
|
|
|
|
//
|
|
double donCUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1];
|
|
double donCUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2];
|
|
|
|
//
|
|
double donCLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1];
|
|
double donCLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2];
|
|
|
|
//
|
|
double donOUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1];
|
|
double donOUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2];
|
|
|
|
//
|
|
double donOLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1];
|
|
double donOLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2];
|
|
|
|
//
|
|
bool isDonUpperBullish = donCUpper > donOUpper;
|
|
bool isDonUpperBullishPrev = donCUpperPrev > donOUpperPrev;
|
|
|
|
//
|
|
bool isDonUpperBearish = donCUpper < donOUpper;
|
|
bool isDonUpperBearishPrev = donCUpperPrev < donOUpperPrev;
|
|
|
|
//
|
|
bool isDonUpperSwitchedToBullish = isDonUpperBullish &&
|
|
!isDonUpperBullishPrev;
|
|
|
|
//
|
|
bool isDonUpperSwitchedToBearish = isDonUpperBearish &&
|
|
!isDonUpperBearishPrev;
|
|
|
|
//
|
|
bool isDonLowerBullish = donCLower > donOLower;
|
|
bool isDonLowerBullishPrev = donCLowerPrev > donOLowerPrev;
|
|
|
|
//
|
|
bool isDonLowerBearish = donCLower < donOLower;
|
|
bool isDonLowerBearishPrev = donCLowerPrev < donOLowerPrev;
|
|
|
|
//
|
|
bool isDonLowerSwitchedToBullish = isDonLowerBullish &&
|
|
!isDonLowerBullishPrev;
|
|
|
|
//
|
|
bool isDonLowerSwitchedToBearish = isDonLowerBearish &&
|
|
!isDonLowerBearishPrev;
|
|
|
|
//
|
|
// Calculate State ...
|
|
|
|
//
|
|
bool isDonInBullishState =
|
|
//
|
|
// Upper ...
|
|
(isDonUpperBullish ||
|
|
isDonUpperSwitchedToBullish)
|
|
//
|
|
&&
|
|
//
|
|
// Lower ...
|
|
(isDonLowerBullish ||
|
|
isDonLowerSwitchedToBullish)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDonInBearishState =
|
|
//
|
|
// Upper ...
|
|
(isDonUpperBearish ||
|
|
isDonUpperSwitchedToBearish)
|
|
//
|
|
&&
|
|
//
|
|
// Lower ...
|
|
(isDonLowerBearish ||
|
|
isDonLowerSwitchedToBearish)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Summary DonChain State ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
hasBullishTrend
|
|
//
|
|
&&
|
|
//
|
|
isDonInBullishState
|
|
//
|
|
&&
|
|
//
|
|
(isHighEqualsToPeak ||
|
|
isLowEqualsToVale)
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
hasBearishTrend
|
|
//
|
|
&&
|
|
//
|
|
isDonInBearishState
|
|
//
|
|
&&
|
|
//
|
|
(isHighEqualsToPeak ||
|
|
isLowEqualsToVale)
|
|
//
|
|
;
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check VWap Conditions ...
|
|
|
|
//
|
|
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
|
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
|
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
double vwaps[3] = {
|
|
vwapFast,
|
|
vwapMid,
|
|
vwapSlow,
|
|
};
|
|
double vwapMax = GetMax(vwaps);
|
|
double vwapMin = GetMin(vwaps);
|
|
|
|
//
|
|
bool isCloseOverVwapMax =
|
|
//
|
|
ask > vwapMax &&
|
|
bid > vwapMax &&
|
|
(cBar.low > vwapMax ||
|
|
cBar.close > vwapMax)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCloseUnderVwapMin =
|
|
//
|
|
ask < vwapMin &&
|
|
bid < vwapMin &&
|
|
(cBar.high < vwapMin ||
|
|
cBar.close < vwapMin)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish;
|
|
bool isVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish;
|
|
bool isVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish;
|
|
bool isVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish;
|
|
bool isVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish;
|
|
bool isVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish;
|
|
bool isVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid;
|
|
bool isVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow;
|
|
bool isVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid;
|
|
bool isVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isVwapBullishFormed =
|
|
//
|
|
// Order ...
|
|
(isVWapFastOverMid ||
|
|
isVWapMidOverSlow ||
|
|
(isVWapFastOverMid &&
|
|
isVWapMidOverSlow))
|
|
//
|
|
&&
|
|
// State ...
|
|
((isVWapFastBullish &&
|
|
isVWapMidBullish) ||
|
|
(isVWapMidBullish &&
|
|
isVWapSlowBullish) ||
|
|
(isVWapFastBullish &&
|
|
isVWapMidBullish &&
|
|
isVWapSlowBullish))
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVwapBearishFormed =
|
|
//
|
|
// Order ...
|
|
(isVWapFastUnderMid ||
|
|
isVWapMidUnderSlow ||
|
|
(isVWapFastUnderMid &&
|
|
isVWapMidUnderSlow))
|
|
//
|
|
&&
|
|
// State ...
|
|
((isVWapFastBearish &&
|
|
isVWapMidBearish) ||
|
|
(isVWapMidBearish &&
|
|
isVWapSlowBearish) ||
|
|
(isVWapFastBearish &&
|
|
isVWapMidBearish &&
|
|
isVWapSlowBearish))
|
|
//
|
|
;
|
|
|
|
//
|
|
// Summar VWap State ...
|
|
|
|
//
|
|
isBullish =
|
|
isBullish &&
|
|
isCloseOverVwapMax &&
|
|
isVwapBullishFormed;
|
|
|
|
//
|
|
isBearish =
|
|
isBearish &&
|
|
isCloseUnderVwapMin &&
|
|
isVwapBearishFormed;
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Sar State ...
|
|
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
|
|
|
//
|
|
bool isSarBullish = triggerConditions.x121Conditions.isSarBullish;
|
|
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
|
|
|
//
|
|
bool isSarBearish = triggerConditions.x121Conditions.isSarBearish;
|
|
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
|
|
|
//
|
|
// Summary Sar ...
|
|
|
|
//
|
|
bool isSarBullishFormed = isSarBullish ||
|
|
isSarSwitchedToBullish;
|
|
|
|
//
|
|
bool isSarBearishFormed = isSarBearish ||
|
|
isSarSwitchedToBearish;
|
|
|
|
//
|
|
isBullish =
|
|
isBullish &&
|
|
isSarBullishFormed;
|
|
|
|
//
|
|
isBearish =
|
|
isBearish &&
|
|
isSarBearishFormed;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCXPVDPSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXPVDPSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60 //
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = conditions.IsSetuped();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
datetime setupTime = conditions.setupTime;
|
|
ENUM_X_DIRECTION setupDir = conditions.dir;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
|
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
|
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
double vwaps[3] = {
|
|
vwapFast,
|
|
vwapMid,
|
|
vwapSlow,
|
|
};
|
|
double vwapMax = GetMax(vwaps);
|
|
double vwapMin = GetMin(vwaps);
|
|
|
|
//
|
|
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
IsBullish(setupDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
IsBearish(setupDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.triggerTime = cTime;
|
|
conditions.sl = isBullish
|
|
? MathMin(sar, vwapMin)
|
|
: MathMin(sar, vwapMax);
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
// |