1039 lines
22 KiB
Plaintext
1039 lines
22 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// 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 X121SMCStrategyXTWPVSignalConditions
|
|
{
|
|
//
|
|
// 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 point;
|
|
XPVPivot pivot;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXTWPVSignalConditions()
|
|
{
|
|
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()
|
|
{
|
|
//
|
|
point = 0;
|
|
pivot.Clean();
|
|
}
|
|
|
|
bool HasPivot()
|
|
{
|
|
return pivot.IsValid();
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXTWPVSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXTWPVSignalConditions &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 = verificationCycleHelper
|
|
// .DetectTrend(trend);
|
|
// bool hasBullishTrend = hasTrend &&
|
|
// IsBullish(trend);
|
|
// bool hasBearishTrend = hasTrend &&
|
|
// IsBearish(trend);
|
|
// result = hasBullishTrend ||
|
|
// hasBearishTrend;
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
//
|
|
// Retrieve Active Pivots ...
|
|
|
|
//
|
|
// Select Source Cycle Helper ...
|
|
XC121SMCCycleHelper *helper = analyseCycleHelper;
|
|
X121SMCCycleConditions helperConditions = analyseConditions;
|
|
XPOIState helperState = analyseState;
|
|
XOHCL helperCBar;
|
|
result = helper.GetBar(
|
|
cBar,
|
|
helperCBar //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XPVPivot peakPivot;
|
|
bool hasPeakPivot = helper
|
|
.GetActivePeakPivot(peakPivot);
|
|
|
|
//
|
|
XPVPivot valePivot;
|
|
bool hasValePivot = helper
|
|
.GetActiveValePivot(valePivot);
|
|
|
|
//
|
|
// Check Pivot ...
|
|
bool hasPivot = conditions.HasPivot();
|
|
if (!hasPivot)
|
|
{
|
|
//
|
|
if (hasPeakPivot && !hasValePivot)
|
|
{
|
|
conditions.pivot = peakPivot;
|
|
}
|
|
else if (hasValePivot && !hasPeakPivot)
|
|
{
|
|
conditions.pivot = valePivot;
|
|
}
|
|
else if (hasPeakPivot && hasValePivot)
|
|
{
|
|
//
|
|
if (peakPivot.from > valePivot.from)
|
|
{
|
|
conditions.pivot = peakPivot;
|
|
}
|
|
else if (valePivot.from > peakPivot.from)
|
|
{
|
|
conditions.pivot = valePivot;
|
|
}
|
|
}
|
|
|
|
//
|
|
hasPivot = conditions.HasPivot();
|
|
result = hasPivot;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Update Pivot States ...
|
|
if (hasPivot)
|
|
{
|
|
//
|
|
conditions.pivot.to = cTime;
|
|
helper.FillPivotState(conditions.pivot);
|
|
|
|
//
|
|
bool hasNewPivot =
|
|
//
|
|
(hasPeakPivot &&
|
|
peakPivot.from > conditions.pivot.from) ||
|
|
(hasValePivot &&
|
|
valePivot.from > conditions.pivot.from)
|
|
//
|
|
;
|
|
result = !hasNewPivot;
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.pivot.Clean();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Waits for new Peaks or Vales ...
|
|
|
|
//
|
|
double peak = helperConditions.x121Conditions.peaksBuffer[1];
|
|
bool isNewPeak = helperConditions.x121Conditions.isNewPeak;
|
|
bool isNewPeakOverLast = helperConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewPeakUnderLast = helperConditions.x121Conditions.isNewPeakUnderLast;
|
|
|
|
//
|
|
double vale = helperConditions.x121Conditions.valesBuffer[1];
|
|
bool isNewVale = helperConditions.x121Conditions.isNewVale;
|
|
bool isNewValeOverLast = helperConditions.x121Conditions.isNewValeOverLast;
|
|
bool isNewValeUnderLast = helperConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
result = isNewPeak ||
|
|
isNewVale;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Calculate Conditions ...
|
|
|
|
//
|
|
// Bullish ...
|
|
|
|
//
|
|
// Bearish ...
|
|
|
|
//
|
|
double bullishFib = GetFibonacciLevel(
|
|
helperCBar.high,
|
|
helperCBar.low,
|
|
GetFiboLevelValue(X_FIBO_LEVEL_382),
|
|
-1 //
|
|
);
|
|
|
|
//
|
|
double bearishFib = GetFibonacciLevel(
|
|
helperCBar.high,
|
|
helperCBar.low,
|
|
GetFiboLevelValue(X_FIBO_LEVEL_382),
|
|
1 //
|
|
);
|
|
|
|
//
|
|
bool isBearishFiboPassed = bullishFib <= conditions.pivot.lower;
|
|
|
|
//
|
|
// Bearish Conditions 1 ...
|
|
bool bearishConditions1 =
|
|
//
|
|
isNewValeUnderLast &&
|
|
isBearishFiboPassed &&
|
|
helperCBar.IsBearish() &&
|
|
conditions.pivot.lower > vale &&
|
|
conditions.pivot.lower < helperCBar.GetUp() &&
|
|
conditions.pivot.lower > helperCBar.GetDown()
|
|
//
|
|
;
|
|
if (bearishConditions1)
|
|
{
|
|
conditions.point = conditions.pivot.lower;
|
|
}
|
|
|
|
//
|
|
double donCloseUpper = helperConditions.x121Conditions.donCloseUpperBuffer[1];
|
|
double donCloseLower = helperConditions.x121Conditions.donCloseLowerBuffer[1];
|
|
|
|
//
|
|
double donOpenUpper = helperConditions.x121Conditions.donOpenUpperBuffer[1];
|
|
double donOpenLower = helperConditions.x121Conditions.donOpenLowerBuffer[1];
|
|
|
|
//
|
|
bool bearishConditions2 =
|
|
//
|
|
isNewPeakUnderLast &&
|
|
donCloseUpper > peak
|
|
//
|
|
;
|
|
if (bearishConditions2)
|
|
{
|
|
conditions.point = peak;
|
|
}
|
|
|
|
//
|
|
// Summary Conditions ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
bearishConditions1
|
|
// ||
|
|
// bearishConditions2
|
|
//
|
|
;
|
|
|
|
//
|
|
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 DetectX121SMCXTWPVSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXTWPVSignalConditions &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;
|
|
}
|
|
|
|
//
|
|
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 ...
|
|
|
|
// //
|
|
// isBullish =
|
|
// isBullish &&
|
|
// false;
|
|
|
|
// //
|
|
// isBearish =
|
|
// isBearish &&
|
|
// false;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Consolidation ...
|
|
XConsolidationZone consolidationZone;
|
|
bool hasConsolidationZone = triggerCycleHelper
|
|
.GetLastConsolidationZone(consolidationZone);
|
|
if (hasConsolidationZone)
|
|
{
|
|
//
|
|
hasConsolidationZone =
|
|
isBullish
|
|
? consolidationZone.upper <= conditions.point
|
|
: consolidationZone.lower >= conditions.point;
|
|
|
|
//
|
|
if (!hasConsolidationZone)
|
|
{
|
|
consolidationZone.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Detect Nearest Pivot Point ...
|
|
XPVPivotPoint pivotPoints[];
|
|
XPVPivotPoint nearestPivotPoint;
|
|
bool hasNearestPivotPoint = false;
|
|
int pivotPointsCount = triggerCycleHelper
|
|
.FillPivotPoints(pivotPoints);
|
|
if (IsValidSize(pivotPointsCount))
|
|
{
|
|
//
|
|
for (int i = 0; i < pivotPointsCount; i++)
|
|
{
|
|
//
|
|
XPVPivotPoint iPoint = pivotPoints[i];
|
|
|
|
//
|
|
bool canSet =
|
|
(isBullish
|
|
? iPoint.value < conditions.point
|
|
: iPoint.value > conditions.point)
|
|
//
|
|
&&
|
|
//
|
|
(!nearestPivotPoint.IsValid()
|
|
? true
|
|
: isBullish
|
|
? nearestPivotPoint.value > iPoint.value
|
|
: nearestPivotPoint.value < iPoint.value);
|
|
if (canSet)
|
|
{
|
|
nearestPivotPoint = iPoint;
|
|
}
|
|
}
|
|
|
|
//
|
|
hasNearestPivotPoint = nearestPivotPoint.IsValid();
|
|
}
|
|
|
|
//
|
|
// Detect Target ...
|
|
double target = CalculateTarget(
|
|
cBar,
|
|
analyseState,
|
|
setupDir //
|
|
);
|
|
if (target == 0)
|
|
{
|
|
//
|
|
target = CalculateTarget(
|
|
cBar,
|
|
verificationState,
|
|
setupDir //
|
|
);
|
|
}
|
|
|
|
//
|
|
double oppositTarget = CalculateTarget(
|
|
cBar,
|
|
analyseState,
|
|
Opposit(setupDir) //
|
|
);
|
|
|
|
//
|
|
double points = GetPoints(conditions.symbol);
|
|
|
|
//
|
|
double entry = GetEntry(
|
|
conditions.symbol,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
// Filling SL Candidates ...
|
|
double sls[];
|
|
if (hasConsolidationZone)
|
|
{
|
|
//
|
|
if (isBullish)
|
|
{
|
|
Add(
|
|
consolidationZone.lower,
|
|
sls //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
Add(
|
|
consolidationZone.upper,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
if (hasNearestPivotPoint)
|
|
{
|
|
Add(
|
|
nearestPivotPoint.value,
|
|
sls //
|
|
);
|
|
}
|
|
if (ArraySize(sls) == 0)
|
|
{
|
|
//
|
|
double pointsDiff = (10 * points);
|
|
double pointsPlus = conditions.point + pointsDiff;
|
|
double pointsMinus = conditions.point - pointsDiff;
|
|
|
|
//
|
|
// Force SL ...
|
|
Add(
|
|
conditions.point,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
pointsPlus,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
pointsMinus,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
oppositTarget,
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
double slsMin = GetMin(sls);
|
|
double slsMax = GetMax(sls);
|
|
|
|
//
|
|
double sl = isBullish
|
|
? slsMin
|
|
: slsMax;
|
|
double risk = MathAbs(entry - sl);
|
|
double targetDelta = 2 * (risk / 3);
|
|
if (target == 0)
|
|
{
|
|
//
|
|
// Force Target On Half Risk ...
|
|
target =
|
|
isBullish
|
|
? entry + targetDelta
|
|
: entry - targetDelta;
|
|
}
|
|
|
|
//
|
|
conditions.sl = sl;
|
|
conditions.target = target;
|
|
conditions.triggerTime = cTime;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|