1984 lines
44 KiB
Plaintext
1984 lines
44 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// Name: X
|
|
// 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 "../../Libraries/x-trade.lib"
|
|
#include "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXSignalConditions
|
|
{
|
|
//
|
|
// 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 pivot;
|
|
double point;
|
|
|
|
//
|
|
double higherPeak;
|
|
datetime higherPeakTime;
|
|
|
|
//
|
|
double lowerVale;
|
|
datetime lowerValeTime;
|
|
|
|
//
|
|
XPVPivot pivotZone;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXSignalConditions()
|
|
{
|
|
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()
|
|
{
|
|
//
|
|
pivot = 0;
|
|
point = 0;
|
|
|
|
//
|
|
pivotZone.Clean();
|
|
|
|
//
|
|
higherPeak = 0;
|
|
higherPeakTime = NULL;
|
|
|
|
//
|
|
lowerVale = 0;
|
|
lowerValeTime = NULL;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Signaller Data Sources ...
|
|
X121SMCStrategyXSignalConditions mXConditions;
|
|
X121SMCStrategyXSignalConditions mXConditionsCollection[];
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXSignalConditions &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 = decisionCycleHelper.GetBar(
|
|
zBar,
|
|
zIndex //
|
|
);
|
|
// zBar.Init(
|
|
// symbol,
|
|
// period,
|
|
// zIndex //
|
|
// );
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = decisionCycleHelper.GetBar(
|
|
cBar,
|
|
cIndex //
|
|
);
|
|
// cBar.Init(
|
|
// symbol,
|
|
// period,
|
|
// cIndex //
|
|
// );
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = decisionCycleHelper.GetBar(
|
|
pBar,
|
|
pIndex //
|
|
);
|
|
// pBar.Init(
|
|
// symbol,
|
|
// period,
|
|
// pIndex //
|
|
// );
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
double points = GetPoints(symbol);
|
|
|
|
//
|
|
int swingLoopback = 3;
|
|
double ll = cBar.FindLowest(swingLoopback, MODE_LOW);
|
|
double hh = cBar.FindHighest(swingLoopback, MODE_HIGH);
|
|
double llDown = cBar.FindLowesttDown(swingLoopback);
|
|
double hhUp = cBar.FindHighestUp(swingLoopback);
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
// Cycle X121Conditions ...
|
|
X121Conditions triggerXConditions = triggerConditions.x121Conditions;
|
|
X121Conditions decisionXConditions = decisionConditions.x121Conditions;
|
|
X121Conditions analyseXConditions = analyseConditions.x121Conditions;
|
|
X121Conditions verificationXConditions = verificationConditions.x121Conditions;
|
|
X121Conditions consolidationXConditions = consolidationConditions.x121Conditions;
|
|
X121Conditions visionXConditions = visionConditions.x121Conditions;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
// Detect Trend ...
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_X_DIRECTION consolidationTrendDir;
|
|
bool hasConsolidationTrend =
|
|
consolidationCycleHelper
|
|
.DetectMarketStructure(
|
|
consolidationTrendDir //
|
|
);
|
|
bool hasConsolidationBullishTrend =
|
|
hasConsolidationTrend &&
|
|
IsBullish(consolidationTrendDir);
|
|
bool hasConsolidationBearishTrend =
|
|
hasConsolidationTrend &&
|
|
IsBearish(consolidationTrendDir);
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_X_DIRECTION verificationTrendDir;
|
|
bool hasVerificationTrend =
|
|
verificationCycleHelper
|
|
.DetectMarketStructure(
|
|
verificationTrendDir //
|
|
);
|
|
bool hasVerificationBullishTrend =
|
|
hasVerificationTrend &&
|
|
IsBullish(verificationTrendDir);
|
|
bool hasVerificationBearishTrend =
|
|
hasVerificationTrend &&
|
|
IsBearish(verificationTrendDir);
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_X_DIRECTION analyseTrendDir;
|
|
bool hasAnalyseTrend =
|
|
analyseCycleHelper
|
|
.DetectMarketStructure(
|
|
analyseTrendDir //
|
|
);
|
|
bool hasAnalyseBullishTrend =
|
|
hasAnalyseTrend &&
|
|
IsBullish(analyseTrendDir);
|
|
bool hasAnalyseBearishTrend =
|
|
hasAnalyseTrend &&
|
|
IsBearish(analyseTrendDir);
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_X_DIRECTION decisionTrendDir;
|
|
bool hasDecisionTrend =
|
|
decisionCycleHelper
|
|
.DetectMarketStructure(
|
|
decisionTrendDir //
|
|
);
|
|
bool hasDecisionBullishTrend =
|
|
hasDecisionTrend &&
|
|
IsBullish(decisionTrendDir);
|
|
bool hasDecisionBearishTrend =
|
|
hasDecisionTrend &&
|
|
IsBearish(decisionTrendDir);
|
|
|
|
//
|
|
// Detect Bar State ...
|
|
|
|
//
|
|
// PinBar ...
|
|
ENUM_X_DIRECTION cBarPinDir;
|
|
bool isCBarPin = decisionCycleHelper
|
|
.mBarAnalyser
|
|
.IsPinBar(
|
|
cBar,
|
|
cBarPinDir,
|
|
1 //
|
|
);
|
|
bool isCBarBullishPin =
|
|
isCBarPin &&
|
|
IsBullish(cBarPinDir);
|
|
bool isCBarBearishPin =
|
|
isCBarPin &&
|
|
IsBearish(cBarPinDir);
|
|
|
|
//
|
|
// Engulf ...
|
|
ENUM_X_DIRECTION cBarEngulfDir;
|
|
bool isCBarEngulfed = decisionCycleHelper
|
|
.mBarAnalyser
|
|
.IsEngulfBar(
|
|
cBar,
|
|
cBarEngulfDir,
|
|
0 // Extended ...
|
|
);
|
|
bool isCBarBullishEngulfed =
|
|
isCBarEngulfed &&
|
|
IsBullish(cBarEngulfDir);
|
|
bool isCBarBearishEngulfed =
|
|
isCBarEngulfed &&
|
|
IsBearish(cBarEngulfDir);
|
|
|
|
//
|
|
// Momentum ...
|
|
ENUM_X_DIRECTION cBarMomentumDir;
|
|
bool isCBarMomentum = decisionCycleHelper
|
|
.mBarAnalyser
|
|
.IsMomentumBar(
|
|
cBar,
|
|
cBarMomentumDir,
|
|
0 // Extended ...
|
|
);
|
|
bool isCBarBullishMomentum =
|
|
isCBarMomentum &&
|
|
IsBullish(cBarMomentumDir);
|
|
bool isCBarBearishMomentum =
|
|
isCBarMomentum &&
|
|
IsBearish(cBarMomentumDir);
|
|
|
|
//
|
|
// Reject ...
|
|
ENUM_X_DIRECTION cBarRejectDir;
|
|
bool isCBarRejected = decisionCycleHelper
|
|
.mBarAnalyser
|
|
.IsRejectionBar(
|
|
cBar,
|
|
cBarRejectDir,
|
|
0 // Extended ...
|
|
);
|
|
bool isCBarBullishRejected =
|
|
isCBarRejected &&
|
|
IsBullish(cBarRejectDir);
|
|
bool isCBarBearishRejected =
|
|
isCBarRejected &&
|
|
IsBearish(cBarRejectDir);
|
|
|
|
//
|
|
// Pull Back ...
|
|
ENUM_X_DIRECTION cBarPullbackDir;
|
|
bool isCBarPullbacked =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasPullBack(
|
|
cBarPullbackDir,
|
|
cBar //
|
|
);
|
|
bool isCBarBullishPullbacked =
|
|
isCBarPullbacked &&
|
|
IsBullish(cBarPullbackDir);
|
|
bool isCBarBearishPullbacked =
|
|
isCBarPullbacked &&
|
|
IsBearish(cBarPullbackDir);
|
|
|
|
//
|
|
// HH/LL Break ...
|
|
|
|
//
|
|
bool isCBarBreaksUpHH = IsBarBreak(
|
|
hh,
|
|
X_DIRECTION_BULLISH,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
bool isCBarBreaksDownLL = IsBarBreak(
|
|
hh,
|
|
X_DIRECTION_BEARISH,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
// Bars Pattern and Power and Pressures ...
|
|
|
|
//
|
|
bool hasCBarBullishPattern =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasBullishPattern(
|
|
cBar,
|
|
2 //
|
|
);
|
|
|
|
//
|
|
bool hasCBarBearishPattern =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasBearishPattern(
|
|
cBar,
|
|
2 //
|
|
);
|
|
|
|
//
|
|
bool isCBarHasBullishPower =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasBullishPower(
|
|
cBar,
|
|
2 //
|
|
);
|
|
|
|
//
|
|
bool isCBarHasBearishPower =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasBearishPower(
|
|
cBar,
|
|
2 //
|
|
);
|
|
|
|
//
|
|
bool isCBarHasBullishPressure =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasBullishPressure(
|
|
cBar,
|
|
2 //
|
|
);
|
|
|
|
//
|
|
bool isCBarHasBearishPressure =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasBearishPressure(
|
|
cBar,
|
|
2 //
|
|
);
|
|
|
|
//
|
|
// Bar Checking Summary ...
|
|
|
|
//
|
|
// Bullish ...
|
|
bool isCBarBullishFormed =
|
|
//
|
|
(
|
|
//
|
|
hasCBarBullishPattern &&
|
|
isCBarHasBullishPower &&
|
|
isCBarHasBullishPressure
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
isCBarBullishPin ||
|
|
isCBarBreaksUpHH ||
|
|
isCBarBullishEngulfed ||
|
|
isCBarBullishMomentum ||
|
|
isCBarBullishRejected
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish ...
|
|
bool isCBarBearishFormed =
|
|
//
|
|
(
|
|
//
|
|
hasCBarBearishPattern &&
|
|
isCBarHasBearishPower &&
|
|
isCBarHasBearishPressure
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
isCBarBearishPin ||
|
|
isCBarBreaksDownLL ||
|
|
isCBarBearishEngulfed ||
|
|
isCBarBearishMomentum ||
|
|
isCBarBearishRejected
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Set Higher Peak and Lowe Vale ...
|
|
|
|
//
|
|
XOHCL higherPeakBar;
|
|
bool hasHigherPeak =
|
|
conditions.higherPeak > 0 &&
|
|
IsValid(conditions.higherPeakTime);
|
|
bool isHigherPeakBreaked = false;
|
|
bool isHigherPeakRejected = false;
|
|
|
|
//
|
|
if (!hasHigherPeak)
|
|
{
|
|
//
|
|
int higherPeakIDX = -1;
|
|
double higherPeak =
|
|
decisionCycleHelper
|
|
.mX121Helper
|
|
.xpvHelper
|
|
.GetHigherPeak(
|
|
higherPeakIDX,
|
|
decisionXConditions.peaksBuffer[1],
|
|
cIndex //
|
|
);
|
|
|
|
//
|
|
if (higherPeak > 0 &&
|
|
IsValidIndex(higherPeakIDX))
|
|
{
|
|
//
|
|
bool hasHigherPeak = higherPeakBar.Init(
|
|
symbol,
|
|
period,
|
|
higherPeakIDX //
|
|
);
|
|
|
|
//
|
|
if (hasHigherPeak)
|
|
{
|
|
//
|
|
conditions.higherPeakTime = cTime;
|
|
conditions.higherPeak = higherPeak;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasHigherPeak)
|
|
{
|
|
//
|
|
isHigherPeakBreaked = IsBarBreak(
|
|
conditions.higherPeak,
|
|
X_DIRECTION_BULLISH,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
isHigherPeakRejected = IsBarReject(
|
|
conditions.higherPeak,
|
|
X_DIRECTION_BEARISH,
|
|
cBar //
|
|
);
|
|
}
|
|
|
|
//
|
|
XOHCL lowerValeBar;
|
|
bool hasLowerVale =
|
|
conditions.lowerVale > 0 &&
|
|
IsValid(conditions.lowerValeTime);
|
|
bool isLowerValeBreaked = false;
|
|
bool isLowerValeRejected = false;
|
|
|
|
//
|
|
if (!hasLowerVale)
|
|
{
|
|
//
|
|
int lowerValeIDX = -1;
|
|
double lowerVale =
|
|
decisionCycleHelper
|
|
.mX121Helper
|
|
.xpvHelper
|
|
.GetLowerVale(
|
|
lowerValeIDX,
|
|
decisionXConditions.valesBuffer[1],
|
|
cIndex //
|
|
);
|
|
|
|
//
|
|
if (lowerVale > 0 &&
|
|
IsValidIndex(lowerValeIDX))
|
|
{
|
|
//
|
|
hasLowerVale = lowerValeBar.Init(
|
|
symbol,
|
|
period,
|
|
lowerValeIDX //
|
|
);
|
|
|
|
//
|
|
if (hasLowerVale)
|
|
{
|
|
//
|
|
conditions.lowerVale = lowerVale;
|
|
conditions.lowerValeTime = cTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasLowerVale)
|
|
{
|
|
//
|
|
isLowerValeBreaked = IsBarBreak(
|
|
conditions.lowerVale,
|
|
X_DIRECTION_BEARISH,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
isLowerValeRejected = IsBarReject(
|
|
conditions.lowerVale,
|
|
X_DIRECTION_BULLISH,
|
|
cBar //
|
|
);
|
|
}
|
|
|
|
//
|
|
double pivotMid = 0;
|
|
bool isPivotToUpRejected = false;
|
|
bool isPivotToDownRejected = false;
|
|
bool isPivotToUpBreaked = false;
|
|
bool isPivotToDownBreaked = false;
|
|
bool hasPivot = conditions.pivotZone.IsValid();
|
|
|
|
//
|
|
if (!hasPivot)
|
|
{
|
|
//
|
|
bool isSamePeaks = decisionXConditions.peaksBuffer[1] ==
|
|
decisionXConditions.peaksBuffer[2] &&
|
|
decisionXConditions.peaksBuffer[2] ==
|
|
decisionXConditions.peaksBuffer[3];
|
|
bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] ==
|
|
analyseXConditions.peaksBuffer[1] &&
|
|
analyseXConditions.peaksBuffer[1] ==
|
|
verificationXConditions.peaksBuffer[1];
|
|
bool hasPeakPivot =
|
|
// isSamePeaks &&
|
|
hasHigherPeak &&
|
|
isSameCyclePeaks &&
|
|
(isHigherPeakBreaked ||
|
|
isHigherPeakRejected);
|
|
|
|
//
|
|
bool isSameVales = decisionXConditions.valesBuffer[1] ==
|
|
decisionXConditions.valesBuffer[2] &&
|
|
decisionXConditions.valesBuffer[2] ==
|
|
decisionXConditions.valesBuffer[3];
|
|
bool isSameCycleVales = decisionXConditions.valesBuffer[1] ==
|
|
analyseXConditions.valesBuffer[1] &&
|
|
analyseXConditions.valesBuffer[1] ==
|
|
verificationXConditions.valesBuffer[1];
|
|
bool hasValePivot =
|
|
// isSameVales &&
|
|
hasLowerVale &&
|
|
isSameCycleVales &&
|
|
(isLowerValeBreaked ||
|
|
isLowerValeRejected);
|
|
|
|
//
|
|
bool hasPivot = hasPeakPivot ||
|
|
hasValePivot;
|
|
if (hasPivot)
|
|
{
|
|
//
|
|
XPVPivot pivot;
|
|
|
|
//
|
|
pivot.symbol = symbol;
|
|
pivot.period = period;
|
|
|
|
//
|
|
pivot.upper = decisionXConditions.peaksBuffer[1];
|
|
pivot.lower = decisionXConditions.valesBuffer[1];
|
|
|
|
//
|
|
pivot.to = cTime;
|
|
pivot.from = cTime;
|
|
pivot.repetition = 3;
|
|
|
|
//
|
|
pivot.type =
|
|
hasPeakPivot
|
|
? XPV_PEAK
|
|
: XPV_VALE;
|
|
|
|
//
|
|
hasPivot = pivot.IsValid();
|
|
if (hasPivot)
|
|
{
|
|
conditions.pivotZone = pivot;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasPivot)
|
|
{
|
|
//
|
|
pivotMid = conditions
|
|
.pivotZone
|
|
.CalculateMid();
|
|
|
|
//
|
|
isPivotToUpRejected = IsBarReject(
|
|
pivotMid,
|
|
X_DIRECTION_BULLISH,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
isPivotToDownRejected = IsBarReject(
|
|
pivotMid,
|
|
X_DIRECTION_BEARISH,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
isPivotToUpBreaked = IsBarBreak(
|
|
pivotMid,
|
|
X_DIRECTION_BULLISH,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
isPivotToDownBreaked = IsBarBreak(
|
|
pivotMid,
|
|
X_DIRECTION_BEARISH,
|
|
cBar //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Sar Conditions ...
|
|
|
|
//
|
|
bool isSarBullishFormed =
|
|
(
|
|
//
|
|
(
|
|
//
|
|
decisionXConditions.isBreakedUpPrevSar &&
|
|
(decisionXConditions.isSarBullish ||
|
|
decisionXConditions.isSarSwitchedToBullish)
|
|
//
|
|
)
|
|
//
|
|
);
|
|
|
|
//
|
|
bool isSarBearishFormed =
|
|
(
|
|
//
|
|
(
|
|
//
|
|
decisionXConditions.isBreakedDownPrevSar &&
|
|
(decisionXConditions.isSarBearish ||
|
|
decisionXConditions.isSarSwitchedToBearish)
|
|
//
|
|
)
|
|
//
|
|
);
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Summarize Conditions ...
|
|
|
|
//
|
|
bool isCondition1Bullish =
|
|
//
|
|
hasPivot &&
|
|
//
|
|
isCBarBullishFormed &&
|
|
(isPivotToUpRejected ||
|
|
isPivotToUpBreaked) &&
|
|
conditions.pivotZone.IsPeak() &&
|
|
//
|
|
// SAR ...
|
|
isSarBullishFormed &&
|
|
// //
|
|
// // STR ...
|
|
// !(decisionXConditions.isStrBearish) &&
|
|
// //
|
|
// // VWAP ...
|
|
// !(decisionXConditions.isVWapBearishState ||
|
|
// decisionXConditions.isVWapBearishOrdered) &&
|
|
//
|
|
true
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCondition1Bearish =
|
|
//
|
|
hasPivot &&
|
|
//
|
|
isCBarBearishFormed &&
|
|
(isPivotToDownRejected ||
|
|
isPivotToDownBreaked) &&
|
|
conditions.pivotZone.IsVale() &&
|
|
//
|
|
// SAR ...
|
|
isSarBearishFormed &&
|
|
// //
|
|
// // STR ...
|
|
// !(decisionXConditions.isStrBullish) &&
|
|
// //
|
|
// // VWAP ...
|
|
// !(decisionXConditions.isVWapBullishState ||
|
|
// decisionXConditions.isVWapBullishOrdered) &&
|
|
//
|
|
true
|
|
//
|
|
;
|
|
|
|
//
|
|
bool hasCondition1 = isCondition1Bullish ||
|
|
isCondition1Bearish;
|
|
if (hasCondition1)
|
|
{
|
|
//
|
|
ENUM_X_DIRECTION pzDir =
|
|
isCondition1Bullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
double point = GetEntry(
|
|
conditions.symbol,
|
|
pzDir //
|
|
);
|
|
|
|
//
|
|
// Manipulate Conditions Point ...
|
|
|
|
//
|
|
conditions.point = pivotMid;
|
|
|
|
//
|
|
// Manipulate Conditions Pivot ...
|
|
|
|
//
|
|
conditions.pivot =
|
|
isCondition1Bullish
|
|
? conditions.pivotZone.upper
|
|
: conditions.pivotZone.lower;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
// false
|
|
isCondition1Bullish
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
// false
|
|
isCondition1Bearish
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Arrays ...
|
|
ArrayFree(triggerPoiEvents);
|
|
ArrayFree(triggerCycleEvents);
|
|
ArrayFree(decisionPoiEvents);
|
|
ArrayFree(decisionCycleEvents);
|
|
ArrayFree(analysePoiEvents);
|
|
ArrayFree(analyseCycleEvents);
|
|
ArrayFree(verificationPoiEvents);
|
|
ArrayFree(verificationCycleEvents);
|
|
ArrayFree(consolidationPoiEvents);
|
|
ArrayFree(consolidationCycleEvents);
|
|
ArrayFree(visionPoiEvents);
|
|
ArrayFree(visionCycleEvents);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
// Cleanup Arrays ...
|
|
ArrayFree(triggerPoiEvents);
|
|
ArrayFree(triggerCycleEvents);
|
|
ArrayFree(decisionPoiEvents);
|
|
ArrayFree(decisionCycleEvents);
|
|
ArrayFree(analysePoiEvents);
|
|
ArrayFree(analyseCycleEvents);
|
|
ArrayFree(verificationPoiEvents);
|
|
ArrayFree(verificationCycleEvents);
|
|
ArrayFree(consolidationPoiEvents);
|
|
ArrayFree(consolidationCycleEvents);
|
|
ArrayFree(visionPoiEvents);
|
|
ArrayFree(visionCycleEvents);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCXSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXSignalConditions &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 = IsBullish(setupDir);
|
|
bool isBearish = IsBearish(setupDir);
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
symbol,
|
|
period,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
double points = GetPoints(symbol);
|
|
|
|
//
|
|
int swingLoopback = 9;
|
|
double ll = cBar.FindLowest(swingLoopback, MODE_LOW);
|
|
double hh = cBar.FindHighest(swingLoopback, MODE_HIGH);
|
|
double llDown = cBar.FindLowesttDown(swingLoopback);
|
|
double hhUp = cBar.FindHighestUp(swingLoopback);
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
// Cycle X121Conditions ...
|
|
X121Conditions triggerXConditions = triggerConditions.x121Conditions;
|
|
X121Conditions decisionXConditions = decisionConditions.x121Conditions;
|
|
X121Conditions analyseXConditions = analyseConditions.x121Conditions;
|
|
X121Conditions verificationXConditions = verificationConditions.x121Conditions;
|
|
X121Conditions consolidationXConditions = consolidationConditions.x121Conditions;
|
|
X121Conditions visionXConditions = visionConditions.x121Conditions;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
// SAR ...
|
|
double sar = decisionXConditions.sarBuffer[1];
|
|
|
|
//
|
|
// STR ...
|
|
double str = decisionXConditions.strBuffer[1];
|
|
|
|
//
|
|
// CHE ...
|
|
double le1 = decisionXConditions.le1Buffer[1];
|
|
double le2 = decisionXConditions.le2Buffer[1];
|
|
double se1 = decisionXConditions.se1Buffer[1];
|
|
double se2 = decisionXConditions.se2Buffer[1];
|
|
|
|
//
|
|
// ATR ...
|
|
double atrUpper = decisionXConditions.atrUpperBuffer[1];
|
|
double atrLower = decisionXConditions.atrLowerBuffer[1];
|
|
|
|
//
|
|
// PV ...
|
|
double peak = decisionXConditions.peaksBuffer[1];
|
|
double vale = decisionXConditions.valesBuffer[1];
|
|
|
|
//
|
|
int higherPeakIDX = -1;
|
|
double higherPeak = decisionCycleHelper
|
|
.mX121Helper
|
|
.xpvHelper.GetHigherPeak(
|
|
higherPeakIDX,
|
|
peak //
|
|
);
|
|
|
|
//
|
|
int lowerValeIDX = -1;
|
|
double lowerVale = decisionCycleHelper
|
|
.mX121Helper
|
|
.xpvHelper.GetLowerVale(
|
|
lowerValeIDX,
|
|
vale //
|
|
);
|
|
|
|
//
|
|
// Slopes ...
|
|
|
|
//
|
|
bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish;
|
|
bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish;
|
|
bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish;
|
|
bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish;
|
|
bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish;
|
|
bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish;
|
|
bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish;
|
|
|
|
//
|
|
bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish;
|
|
bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish;
|
|
bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish;
|
|
bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish;
|
|
bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish;
|
|
bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish;
|
|
bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish;
|
|
|
|
//
|
|
bool isSlopesBullish =
|
|
isRsiSlopeBullish &&
|
|
isStrSlopeBullish &&
|
|
isAtrUpperSlopeBullish &&
|
|
isAtrLowerSlopeBullish &&
|
|
isVwapFastSlopeBullish &&
|
|
isVwapMidSlopeBullish &&
|
|
isVwapSlowSlopeBullish;
|
|
|
|
//
|
|
bool isSlopesBearish =
|
|
isRsiSlopeBearish &&
|
|
isStrSlopeBearish &&
|
|
isAtrUpperSlopeBearish &&
|
|
isAtrLowerSlopeBearish &&
|
|
isVwapFastSlopeBearish &&
|
|
isVwapMidSlopeBearish &&
|
|
isVwapSlowSlopeBearish;
|
|
|
|
//
|
|
double point = conditions.point;
|
|
bool isPointBreaked =
|
|
isBullish
|
|
? ask > point && bid > point
|
|
: ask < point && bid < point;
|
|
// bool isPointBreaked = IsBarBreak(
|
|
// point,
|
|
// setupDir,
|
|
// cBar //
|
|
// );
|
|
|
|
//
|
|
// Summary ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
isBullish &&
|
|
// isPointBreaked &&
|
|
// isSlopesBullish &&
|
|
cBar.IsBullish()
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isBearish &&
|
|
// isPointBreaked &&
|
|
// isSlopesBearish &&
|
|
cBar.IsBearish()
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
// Cleanup Arrays ...
|
|
ArrayFree(triggerPoiEvents);
|
|
ArrayFree(triggerCycleEvents);
|
|
ArrayFree(decisionPoiEvents);
|
|
ArrayFree(decisionCycleEvents);
|
|
ArrayFree(analysePoiEvents);
|
|
ArrayFree(analyseCycleEvents);
|
|
ArrayFree(verificationPoiEvents);
|
|
ArrayFree(verificationCycleEvents);
|
|
ArrayFree(consolidationPoiEvents);
|
|
ArrayFree(consolidationCycleEvents);
|
|
ArrayFree(visionPoiEvents);
|
|
ArrayFree(visionCycleEvents);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Nearest Pivot Point ...
|
|
|
|
//
|
|
// Detect Target ...
|
|
double target = CalculateTarget(
|
|
cBar,
|
|
decisionState,
|
|
setupDir //
|
|
);
|
|
if (target == 0)
|
|
{
|
|
//
|
|
target = CalculateTarget(
|
|
cBar,
|
|
analyseState,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
if (target == 0)
|
|
{
|
|
//
|
|
target = CalculateTarget(
|
|
cBar,
|
|
verificationState,
|
|
setupDir //
|
|
);
|
|
}
|
|
}
|
|
target = 0;
|
|
|
|
//
|
|
double entry = GetEntry(
|
|
conditions.symbol,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
// Filling SL Candidates ...
|
|
double momentumBarPointsDif = 30 * points;
|
|
|
|
//
|
|
// Bullish Momentum Bar Selection ...
|
|
XOHCL bullishMomentumBar;
|
|
int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars();
|
|
if (IsValidSize(bullishMomentumBarsCount))
|
|
{
|
|
//
|
|
for (int i = 0; i < bullishMomentumBarsCount; i++)
|
|
{
|
|
//
|
|
XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iMomentum.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif;
|
|
if (!isValidDistane)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool isIndexPassed = iBar.Index() <= 5;
|
|
if (!isIndexPassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool canSet =
|
|
!bullishMomentumBar.IsValid() ||
|
|
(bullishMomentumBar.IsValid() &&
|
|
bullishMomentumBar.low < entry &&
|
|
bullishMomentumBar.Index() > iBar.Index());
|
|
if (canSet)
|
|
{
|
|
bullishMomentumBar = iBar;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Bearish Momentum Bar Selection ...
|
|
XOHCL bearishMomentumBar;
|
|
int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars();
|
|
if (IsValidSize(bearishMomentumBarsCount))
|
|
{
|
|
//
|
|
for (int i = 0; i < bearishMomentumBarsCount; i++)
|
|
{
|
|
//
|
|
XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iMomentum.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif;
|
|
if (!isValidDistane)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool isIndexPassed = iBar.Index() <= 5;
|
|
if (!isIndexPassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool canSet =
|
|
!bearishMomentumBar.IsValid() ||
|
|
(bearishMomentumBar.IsValid() &&
|
|
bearishMomentumBar.high > entry &&
|
|
bearishMomentumBar.Index() > iBar.Index());
|
|
if (canSet)
|
|
{
|
|
bearishMomentumBar = iBar;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
double sls[];
|
|
Add(
|
|
sar,
|
|
sls //
|
|
);
|
|
Add(
|
|
str,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
Add(
|
|
atrLower,
|
|
sls //
|
|
);
|
|
|
|
// //
|
|
// Add(
|
|
// vale,
|
|
// sls //
|
|
// );
|
|
|
|
//
|
|
if (bullishMomentumBar.IsValid())
|
|
{
|
|
//
|
|
Add(
|
|
bullishMomentumBar.low,
|
|
sls //
|
|
);
|
|
}
|
|
|
|
// //
|
|
// if (IsValidIndex(lowerValeIDX))
|
|
// {
|
|
// //
|
|
// Add(
|
|
// lowerVale,
|
|
// sls //
|
|
// );
|
|
// }
|
|
|
|
//
|
|
if (le1 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
le1,
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
if (le2 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
le2,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
Add(
|
|
atrUpper,
|
|
sls //
|
|
);
|
|
|
|
// //
|
|
// Add(
|
|
// peak,
|
|
// sls //
|
|
// );
|
|
|
|
//
|
|
if (bearishMomentumBar.IsValid())
|
|
{
|
|
//
|
|
Add(
|
|
bearishMomentumBar.high,
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
// if (IsValidIndex(higherPeakIDX))
|
|
// {
|
|
// //
|
|
// Add(
|
|
// higherPeak,
|
|
// sls //
|
|
// );
|
|
// }
|
|
|
|
//
|
|
if (se1 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
se1,
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
if (se2 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
se2,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
double iAtr = decisionConditions.x121Conditions.atrBuffer[1];
|
|
iAtr *= 2.5;
|
|
|
|
//
|
|
double slsMin = GetMin(sls);
|
|
double slsMax = GetMax(sls);
|
|
|
|
//
|
|
double sl = isBullish
|
|
? slsMin - iAtr
|
|
: slsMax + iAtr;
|
|
double risk = MathAbs(entry - sl);
|
|
double riskInPoints = risk / points;
|
|
if (riskInPoints >= 150)
|
|
{
|
|
//
|
|
target =
|
|
isBullish
|
|
? entry + (points * 200)
|
|
: entry - (points * 200);
|
|
|
|
//
|
|
target = 0;
|
|
}
|
|
|
|
//
|
|
// Filling Conditions Props ...
|
|
conditions.sl = sl;
|
|
conditions.target = target;
|
|
conditions.triggerTime = cTime;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
// Cleanup Arrays ...
|
|
ArrayFree(triggerPoiEvents);
|
|
ArrayFree(triggerCycleEvents);
|
|
ArrayFree(decisionPoiEvents);
|
|
ArrayFree(decisionCycleEvents);
|
|
ArrayFree(analysePoiEvents);
|
|
ArrayFree(analyseCycleEvents);
|
|
ArrayFree(verificationPoiEvents);
|
|
ArrayFree(verificationCycleEvents);
|
|
ArrayFree(consolidationPoiEvents);
|
|
ArrayFree(consolidationCycleEvents);
|
|
ArrayFree(visionPoiEvents);
|
|
ArrayFree(visionCycleEvents);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool DetectX121SMCXGuards(
|
|
X121SMCGuard &guards[],
|
|
const XPosition &positions[],
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
string provider = ToString(X_121_SMC_PROVIDER_X);
|
|
|
|
//
|
|
// result = DetectX121SMCGuards(
|
|
// provider,
|
|
// guards,
|
|
// positions,
|
|
// triggerCycleHelper,
|
|
// decisionCycleHelper,
|
|
// analyseCycleHelper,
|
|
// verificationCycleHelper,
|
|
// consolidationCycleHelper,
|
|
// visionCycleHelper //
|
|
// );
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int AddX121SMCXConditionsIfNotExists(
|
|
X121SMCStrategyXSignalConditions &item,
|
|
X121SMCStrategyXSignalConditions &items[],
|
|
int maxAllowed = 10 //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
bool isSetuped = IsValid(item.setupTime) &&
|
|
HasDirection(item.dir);
|
|
if (!isSetuped)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int count = ArraySize(items);
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
// Copy Original Items ...
|
|
X121SMCStrategyXSignalConditions tmpItems[];
|
|
Copy(
|
|
items,
|
|
tmpItems //
|
|
);
|
|
|
|
//
|
|
// Prese Item Data ...
|
|
bool isBullish = IsBullish(item.dir);
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
X121SMCStrategyXSignalConditions iItem = tmpItems[i];
|
|
|
|
//
|
|
bool canRemove = item.dir == iItem.dir &&
|
|
item.pivot == iItem.pivot;
|
|
if (canRemove)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
items,
|
|
i,
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpItems);
|
|
}
|
|
|
|
//
|
|
AddRef(
|
|
item,
|
|
items //
|
|
);
|
|
|
|
//
|
|
// Remove Olds ...
|
|
CleanupArray(
|
|
items,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
result = ArraySize(items);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int DrawX121SMCXConditions(
|
|
X121SMCStrategyXSignalConditions &conditions,
|
|
XCBaseObject *&drawnObjects[],
|
|
XCPOIDrawer *drawer //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
Clean(drawnObjects);
|
|
|
|
//
|
|
if (drawer == NULL)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isSetuped = conditions.IsSetuped();
|
|
if (!isSetuped)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|