Last Works on Validating Order Blocks ...
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
//
|
||||
double cPZoneUpper = 0;
|
||||
double cPZoneLower = 0;
|
||||
datetime cPZoneFrom = NULL;
|
||||
datetime cPZoneTo = NULL;
|
||||
result = consolidationPriceZone.GetBoxData(
|
||||
X_DIRECTION_ALL,
|
||||
cPZoneUpper,
|
||||
cPZoneLower,
|
||||
cPZoneFrom,
|
||||
cPZoneTo //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double aPZoneUpper = 0;
|
||||
double aPZoneLower = 0;
|
||||
datetime aPZoneFrom = NULL;
|
||||
datetime aPZoneTo = NULL;
|
||||
result = analysePriceZone.GetBoxData(
|
||||
X_DIRECTION_ALL,
|
||||
aPZoneUpper,
|
||||
aPZoneLower,
|
||||
aPZoneFrom,
|
||||
aPZoneTo //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
double rsi = decisionConditions.x121Conditions.rsiBuffer[1];
|
||||
|
||||
//
|
||||
bool isRSIOverBought = decisionConditions.x121Conditions.isRSIOverBought;
|
||||
bool isRSICrossedOverOverBought = decisionConditions.x121Conditions.isRSICrossedOverOverBought;
|
||||
bool isRSICrossedUnderOverBought = decisionConditions.x121Conditions.isRSICrossedUnderOverBought;
|
||||
|
||||
//
|
||||
bool isRSIOverSold = decisionConditions.x121Conditions.isRSIOverSold;
|
||||
bool isRSICrossedOverOverSold = decisionConditions.x121Conditions.isRSICrossedOverOverSold;
|
||||
bool isRSICrossedUnderOverSold = decisionConditions.x121Conditions.isRSICrossedUnderOverSold;
|
||||
|
||||
//
|
||||
// PV ...
|
||||
double peak = decisionConditions.x121Conditions.peaksBuffer[1];
|
||||
double vale = decisionConditions.x121Conditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
bool isNewPeak = decisionConditions.x121Conditions.isNewPeak;
|
||||
bool isNewPeakOverLast = decisionConditions.x121Conditions.isNewPeakOverLast;
|
||||
bool isNewPeakUnderLast = decisionConditions.x121Conditions.isNewPeakUnderLast;
|
||||
|
||||
//
|
||||
bool isNewVale = decisionConditions.x121Conditions.isNewVale;
|
||||
bool isNewValeOverLast = decisionConditions.x121Conditions.isNewValeOverLast;
|
||||
bool isNewValeUnderLast = decisionConditions.x121Conditions.isNewValeUnderLast;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
double str = decisionConditions.x121Conditions.strBuffer[1];
|
||||
|
||||
//
|
||||
bool isStrBullish = decisionConditions.x121Conditions.isStrBullish;
|
||||
bool isStrBearish = decisionConditions.x121Conditions.isStrBearish;
|
||||
|
||||
//
|
||||
bool isStrSwitchedToBullish = decisionConditions.x121Conditions.isStrSwitchedToBullish;
|
||||
bool isStrSwitchedToBearish = decisionConditions.x121Conditions.isStrSwitchedToBearish;
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
double atr = decisionConditions.x121Conditions.atrBuffer[1];
|
||||
double atrUpper = decisionConditions.x121Conditions.atrUpperBuffer[1];
|
||||
double atrLower = decisionConditions.x121Conditions.atrLowerBuffer[1];
|
||||
|
||||
//
|
||||
bool isCloseOverATRUpper = decisionConditions.x121Conditions.isCloseOverATRUpper;
|
||||
bool isCloseOverATRLower = decisionConditions.x121Conditions.isCloseOverATRLower;
|
||||
|
||||
//
|
||||
bool isCloseUnderATRUpper = decisionConditions.x121Conditions.isCloseUnderATRUpper;
|
||||
bool isCloseUnderATRLower = decisionConditions.x121Conditions.isCloseUnderATRLower;
|
||||
|
||||
//
|
||||
bool isRejectUpATRUpper = decisionConditions.x121Conditions.isRejectUpATRUpper;
|
||||
bool isRejectDownATRUpper = decisionConditions.x121Conditions.isRejectDownATRUpper;
|
||||
|
||||
//
|
||||
bool isRejectUpATRLower = decisionConditions.x121Conditions.isRejectUpATRLower;
|
||||
bool isRejectDownATRLower = decisionConditions.x121Conditions.isRejectDownATRLower;
|
||||
|
||||
//
|
||||
bool isBreakUpATRUpper = decisionConditions.x121Conditions.isBreakUpATRUpper;
|
||||
bool isBreakDownATRUpper = decisionConditions.x121Conditions.isBreakDownATRUpper;
|
||||
|
||||
//
|
||||
bool isBreakUpATRLower = decisionConditions.x121Conditions.isBreakUpATRLower;
|
||||
bool isBreakDownATRLower = decisionConditions.x121Conditions.isBreakDownATRLower;
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
double sar = decisionConditions.x121Conditions.sarBuffer[1];
|
||||
|
||||
//
|
||||
bool isSarBullish = decisionConditions.x121Conditions.isSarBullish;
|
||||
bool isSarBearish = decisionConditions.x121Conditions.isSarBearish;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish = decisionConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish = decisionConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
// DON ...
|
||||
|
||||
//
|
||||
double donOpenUpper = decisionConditions.x121Conditions.donOpenUpperBuffer[1];
|
||||
double donOpenLower = decisionConditions.x121Conditions.donOpenLowerBuffer[1];
|
||||
double donHighUpper = decisionConditions.x121Conditions.donHighUpperBuffer[1];
|
||||
double donHighLower = decisionConditions.x121Conditions.donHighLowerBuffer[1];
|
||||
double donLowUpper = decisionConditions.x121Conditions.donLowUpperBuffer[1];
|
||||
double donLowLower = decisionConditions.x121Conditions.donLowLowerBuffer[1];
|
||||
double donCloseUpper = decisionConditions.x121Conditions.donCloseUpperBuffer[1];
|
||||
double donCloseLower = decisionConditions.x121Conditions.donCloseLowerBuffer[1];
|
||||
|
||||
//
|
||||
bool isRejectDonOpenUpper = decisionConditions.x121Conditions.isRejectDonOpenUpper;
|
||||
bool isRejectDonHighUpper = decisionConditions.x121Conditions.isRejectDonHighUpper;
|
||||
bool isRejectDonLowUpper = decisionConditions.x121Conditions.isRejectDonLowUpper;
|
||||
bool isRejectDonCloseUpper = decisionConditions.x121Conditions.isRejectDonCloseUpper;
|
||||
|
||||
//
|
||||
bool isRejectDonOpenLower = decisionConditions.x121Conditions.isRejectDonOpenLower;
|
||||
bool isRejectDonHighLower = decisionConditions.x121Conditions.isRejectDonHighLower;
|
||||
bool isRejectDonLowLower = decisionConditions.x121Conditions.isRejectDonLowLower;
|
||||
bool isRejectDonCloseLower = decisionConditions.x121Conditions.isRejectDonCloseLower;
|
||||
|
||||
//
|
||||
bool isBreakDonOpenUpper = decisionConditions.x121Conditions.isBreakDonOpenUpper;
|
||||
bool isBreakDonHighUpper = decisionConditions.x121Conditions.isBreakDonHighUpper;
|
||||
bool isBreakDonLowUpper = decisionConditions.x121Conditions.isBreakDonLowUpper;
|
||||
bool isBreakDonCloseUpper = decisionConditions.x121Conditions.isBreakDonCloseUpper;
|
||||
|
||||
//
|
||||
bool isBreakDonOpenLower = decisionConditions.x121Conditions.isBreakDonOpenLower;
|
||||
bool isBreakDonHighLower = decisionConditions.x121Conditions.isBreakDonHighLower;
|
||||
bool isBreakDonLowLower = decisionConditions.x121Conditions.isBreakDonLowLower;
|
||||
bool isBreakDonCloseLower = decisionConditions.x121Conditions.isBreakDonCloseLower;
|
||||
|
||||
//
|
||||
// VWAP ...
|
||||
|
||||
//
|
||||
// COMPLEX ...
|
||||
// Complex Conditions ...
|
||||
|
||||
//
|
||||
bool isNewPeakOverATRUpper =
|
||||
isNewPeak &&
|
||||
peak > atrUpper;
|
||||
|
||||
//
|
||||
bool isNewValeUnderATRLower =
|
||||
isNewVale &&
|
||||
vale < atrLower;
|
||||
|
||||
//
|
||||
bool isDonHighUpperEqualsToPeak =
|
||||
donHighUpper == peak;
|
||||
|
||||
//
|
||||
bool isDonLowLowerEqualsToVale =
|
||||
donLowLower == vale;
|
||||
|
||||
//
|
||||
bool isBullishSign = (
|
||||
//
|
||||
triggerConditions.x121Conditions.isBreakUpATRLower ||
|
||||
triggerConditions.x121Conditions.isRejectUpATRLower ||
|
||||
triggerConditions.x121Conditions.isBreakDonHighLower ||
|
||||
triggerConditions.x121Conditions.isRejectDonHighLower ||
|
||||
triggerConditions.x121Conditions.isBreakDonCloseLower ||
|
||||
triggerConditions.x121Conditions.isRejectDonCloseLower
|
||||
//
|
||||
);
|
||||
bool isBearishSign = (
|
||||
//
|
||||
triggerConditions.x121Conditions.isBreakDownATRUpper ||
|
||||
triggerConditions.x121Conditions.isRejectDownATRUpper ||
|
||||
triggerConditions.x121Conditions.isBreakDonLowUpper ||
|
||||
triggerConditions.x121Conditions.isRejectDonLowUpper ||
|
||||
triggerConditions.x121Conditions.isBreakDonCloseUpper ||
|
||||
triggerConditions.x121Conditions.isRejectDonCloseUpper
|
||||
//
|
||||
);
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Check RSI in Over Bought or Over Sold ...
|
||||
|
||||
//
|
||||
bool isRSICrossedOverOverSold = consolidationConditions.x121Conditions.isRSICrossedOverOverSold;
|
||||
bool isRSICrossedUnderOverBought = consolidationConditions.x121Conditions.isRSICrossedUnderOverBought;
|
||||
|
||||
//
|
||||
result = isRSICrossedOverOverSold ||
|
||||
isRSICrossedUnderOverBought;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,957 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
datetime newPeakOverATRUpperAt;
|
||||
datetime newValeUnderATRLowerAt;
|
||||
|
||||
//
|
||||
datetime donHighUpperEqualsToPeakAt;
|
||||
datetime donLowLowerEqualsToValeAt;
|
||||
|
||||
//
|
||||
datetime closeOverATRUpperAt;
|
||||
datetime closeUnderATRLowerAt;
|
||||
|
||||
//
|
||||
datetime rsiOverSoldAt;
|
||||
datetime rsiOverBoughtAt;
|
||||
|
||||
//
|
||||
datetime newPeakOverLastAt;
|
||||
datetime newValeUnderLastAt;
|
||||
|
||||
//
|
||||
datetime bullishBarSignAt;
|
||||
datetime bearishBarSignAt;
|
||||
|
||||
//
|
||||
XPriceZones priceZone;
|
||||
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
//
|
||||
priceZone.Clean();
|
||||
|
||||
//
|
||||
newPeakOverATRUpperAt = NULL;
|
||||
newValeUnderATRLowerAt = NULL;
|
||||
|
||||
//
|
||||
donHighUpperEqualsToPeakAt = NULL;
|
||||
donLowLowerEqualsToValeAt = NULL;
|
||||
|
||||
//
|
||||
closeOverATRUpperAt = NULL;
|
||||
closeUnderATRLowerAt = NULL;
|
||||
|
||||
//
|
||||
rsiOverSoldAt = NULL;
|
||||
rsiOverBoughtAt = NULL;
|
||||
|
||||
//
|
||||
newPeakOverLastAt = NULL;
|
||||
newValeUnderLastAt = NULL;
|
||||
|
||||
//
|
||||
bullishBarSignAt = NULL;
|
||||
bearishBarSignAt = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Conditions Filled ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsFilled(ENUM_X_DIRECTION &fillDir)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
fillDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
bool hasNewPeakOverATRUpper = IsValid(newPeakOverATRUpperAt);
|
||||
bool hasNewValeUnderATRLower = IsValid(newValeUnderATRLowerAt);
|
||||
|
||||
//
|
||||
bool hasDonHighUpperEqualsToPeak = IsValid(donHighUpperEqualsToPeakAt);
|
||||
bool hasDonLowLowerEqualsToVale = IsValid(donLowLowerEqualsToValeAt);
|
||||
|
||||
//
|
||||
bool hasCloseOverATRUpper = IsValid(closeOverATRUpperAt);
|
||||
bool hasCloseUnderATRLower = IsValid(closeUnderATRLowerAt);
|
||||
|
||||
//
|
||||
bool hasRsiOverSold = IsValid(rsiOverSoldAt);
|
||||
bool hasRsiOverBought = IsValid(rsiOverBoughtAt);
|
||||
|
||||
//
|
||||
bool hasNewPeakOverLast = IsValid(newPeakOverLastAt);
|
||||
bool hasNewValeUnderLast = IsValid(newValeUnderLastAt);
|
||||
|
||||
//
|
||||
bool hasBullishBarSign = IsValid(bullishBarSignAt);
|
||||
bool hasBearishBarSign = IsValid(bearishBarSignAt);
|
||||
|
||||
//
|
||||
bool isBullish =
|
||||
(
|
||||
//
|
||||
hasRsiOverSold &&
|
||||
hasBullishBarSign &&
|
||||
hasNewValeUnderLast &&
|
||||
hasCloseUnderATRLower &&
|
||||
hasNewValeUnderATRLower &&
|
||||
hasDonLowLowerEqualsToVale
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
bool isBearish =
|
||||
(
|
||||
//
|
||||
hasRsiOverBought &&
|
||||
hasBearishBarSign &&
|
||||
hasNewPeakOverLast &&
|
||||
hasCloseOverATRUpper &&
|
||||
hasNewPeakOverATRUpper &&
|
||||
hasDonHighUpperEqualsToPeak
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
(isBullish || isBearish) &&
|
||||
!(isBullish && isBearish);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
fillDir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HasPriceZone()
|
||||
{
|
||||
return priceZone.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;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
// Setup Conditions ...
|
||||
|
||||
//
|
||||
result = analyseConditions.x121Conditions.isStrSwitchedToBullish ||
|
||||
analyseConditions.x121Conditions.isStrSwitchedToBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
// Trigger Conditions ...
|
||||
|
||||
//
|
||||
// Detect Bullish Conditions ...
|
||||
isBullish =
|
||||
isBullish &&
|
||||
cBar.IsBullish();
|
||||
|
||||
//
|
||||
// Detect Bearish Conditions ...
|
||||
isBearish =
|
||||
isBearish &&
|
||||
cBar.IsBearish();
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Cleanup Setup Conditions ...
|
||||
int setupAge = conditions.GetSetupAge();
|
||||
if (IsValidSize(setupAge) &&
|
||||
IsValidSize(maxAllowedSetupAge) &&
|
||||
setupAge >= maxAllowedSetupAge)
|
||||
{
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Nearest Pivot Point ...
|
||||
|
||||
//
|
||||
// Detect Target ...
|
||||
double target = CalculateTarget(
|
||||
cBar,
|
||||
analyseState,
|
||||
setupDir //
|
||||
);
|
||||
if (target == 0)
|
||||
{
|
||||
//
|
||||
target = CalculateTarget(
|
||||
cBar,
|
||||
verificationState,
|
||||
setupDir //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double oppositTarget = CalculateTarget(
|
||||
cBar,
|
||||
analyseState,
|
||||
Opposit(setupDir) //
|
||||
);
|
||||
|
||||
//
|
||||
double entry = GetEntry(
|
||||
conditions.symbol,
|
||||
setupDir //
|
||||
);
|
||||
|
||||
//
|
||||
// Filling SL Candidates ...
|
||||
|
||||
//
|
||||
double sls[];
|
||||
|
||||
//
|
||||
double atr = triggerConditions.x121Conditions.atrBuffer[1];
|
||||
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
||||
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale(vale);
|
||||
if (lowerVale > 0)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
lowerVale,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (isBearish)
|
||||
{
|
||||
//
|
||||
double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak(peak);
|
||||
if (higherPeak > 0)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
higherPeak,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (ArraySize(sls) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
double slsMin = GetMin(sls);
|
||||
double slsMax = GetMax(sls);
|
||||
|
||||
//
|
||||
double sl = isBullish
|
||||
? slsMin - atr
|
||||
: slsMax + atr;
|
||||
double risk = MathAbs(entry - sl);
|
||||
double targetDelta = 2 * (risk / 3);
|
||||
if (target == 0)
|
||||
{
|
||||
//
|
||||
int minTargetPint = 50;
|
||||
double minTargetPointValue = minTargetPint * points;
|
||||
if (targetDelta < minTargetPointValue)
|
||||
{
|
||||
targetDelta = minTargetPointValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Force Target On Half Risk ...
|
||||
target =
|
||||
isBullish
|
||||
? entry + targetDelta
|
||||
: entry - targetDelta;
|
||||
|
||||
//
|
||||
target = 0;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Ignore Target ...
|
||||
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;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Signal ...
|
||||
int DrawX121SMCXTWPVSiganl(
|
||||
X121SMCStrategyXTWPVSignalConditions &conditions,
|
||||
XCBaseObject *&drawnObjects[],
|
||||
XCPOIDrawer *drawer //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
Clean(drawnObjects);
|
||||
|
||||
//
|
||||
if (drawer == NULL)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isSetuped = conditions.IsSetuped();
|
||||
if (!isSetuped)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(conditions.dir);
|
||||
|
||||
//
|
||||
result = ArraySize(drawnObjects);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user