1121 lines
26 KiB
Plaintext
1121 lines
26 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Class Library
|
|
// --------------------------------------
|
|
// Name: XCX121SMCTestStrategy
|
|
// Description: provides all based classes for use ...
|
|
//
|
|
//
|
|
// 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.base.strategy.class.mq5"
|
|
#include "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// XStrategy Class Implementation(s) ...
|
|
class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
void XCX121SMCTestStrategy(
|
|
//
|
|
// Base ...
|
|
string _symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES _period // Trading TimeFrame
|
|
)
|
|
: XCX121SMCBaseStrategy(_symbol, _period)
|
|
{
|
|
InitialHelpers();
|
|
}
|
|
|
|
//
|
|
// Deconstructur ...
|
|
void ~XCX121SMCTestStrategy()
|
|
{
|
|
}
|
|
|
|
//
|
|
// Overrides Actions ...
|
|
|
|
/**
|
|
* Destroy All Class Implementations ...
|
|
*/
|
|
void Destroy() override
|
|
{
|
|
//
|
|
delete mTriggerCycleHelper;
|
|
delete mDecisionCycleHelper;
|
|
delete mAnalyseCycleHelper;
|
|
delete mVerificationCycleHelper;
|
|
delete mConsolidationCycleHelper;
|
|
delete mVisionCycleHelper;
|
|
}
|
|
|
|
/**
|
|
* Check Conditions For Signal ...
|
|
*/
|
|
bool HasSignal(
|
|
XSignal &signal,
|
|
X121SMCStrategyConditions &conditions //
|
|
) override
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
signal.Clean();
|
|
conditions.Clean();
|
|
|
|
//
|
|
int pushers = 0;
|
|
|
|
//
|
|
double sl = 0;
|
|
double tp = 0;
|
|
double risk = 0;
|
|
double entry = 0;
|
|
double reward = 0;
|
|
double r2r = R2R();
|
|
string provider = "";
|
|
double volume = Volume();
|
|
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
|
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
|
|
|
//
|
|
bool hasLong = false;
|
|
bool hasShort = false;
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Start Calculations ...
|
|
|
|
//
|
|
// Retrieve Common Data ...
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
// Required Value For SL/TP Calculations ...
|
|
double points = GetPoints(symbol);
|
|
double pip = GetPipPrice(symbol);
|
|
double pip2 = 2 * pip;
|
|
|
|
//
|
|
// Retrieve and Fill Cycle Conditions ...
|
|
result = GetCyclesConditions(conditions);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Spread for Signalling Conditions ...
|
|
bool isSpreadPassed = IsSpreadPass();
|
|
result = isSpreadPassed;
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Signal Conditions ...
|
|
result = DetectConditions(conditions);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Combine all Signals Conditions ...
|
|
selectedSL = conditions.sl;
|
|
provider = conditions.provider;
|
|
|
|
//
|
|
hasLong =
|
|
//
|
|
IsBullish(conditions.marketStructureDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
hasShort =
|
|
//
|
|
IsBearish(conditions.marketStructureDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
result = hasLong ||
|
|
hasShort;
|
|
|
|
//
|
|
// Rmove Signal Condition ...
|
|
if (result)
|
|
{
|
|
//
|
|
// TYPE ...
|
|
type =
|
|
hasLong
|
|
? POSITION_TYPE_BUY
|
|
: POSITION_TYPE_SELL;
|
|
ENUM_X_POSITION_TYPES xType =
|
|
hasLong
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
entry = GetEntry(
|
|
conditions.symbol,
|
|
type //
|
|
);
|
|
|
|
//
|
|
sl =
|
|
hasLong
|
|
? selectedSL - pip2
|
|
: selectedSL + pip2;
|
|
|
|
//
|
|
// RISK Reward ...
|
|
risk =
|
|
hasLong
|
|
? entry - sl
|
|
: sl - entry;
|
|
reward = risk * r2r;
|
|
tp =
|
|
hasLong
|
|
? entry + reward
|
|
: entry - reward;
|
|
|
|
//
|
|
signal.sl = sl;
|
|
signal.tp = tp;
|
|
signal.type = type;
|
|
signal.mode = mode;
|
|
signal.entry = entry;
|
|
signal.volume = volume;
|
|
signal.symbol = symbol;
|
|
signal.period = period;
|
|
signal.pushers = pushers;
|
|
signal.provider = provider;
|
|
signal.time = TimeCurrent();
|
|
|
|
//
|
|
result = PrepareSignal(signal);
|
|
if (result)
|
|
{
|
|
//
|
|
Print("PRV: ", provider);
|
|
DrawSignal(signal);
|
|
}
|
|
|
|
//
|
|
hasLong = false;
|
|
hasShort = false;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Customize Strategy Identifier ...
|
|
*/
|
|
string GetTag() override
|
|
{
|
|
return X121SMCStrategyToken;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Trigger Order Flow ...
|
|
XPVPivot mOrderFlow[];
|
|
ENUM_X_DIRECTION mOrderFlowDir;
|
|
|
|
//
|
|
ENUM_X_CYCLE_EVENTS mTriggerCycleEvents[];
|
|
XC121SMCCycleHelper *mTriggerCycleHelper;
|
|
|
|
//
|
|
ENUM_X_CYCLE_EVENTS mDecisionCycleEvents[];
|
|
XC121SMCCycleHelper *mDecisionCycleHelper;
|
|
|
|
//
|
|
ENUM_X_CYCLE_EVENTS mAnalyseCycleEvents[];
|
|
XC121SMCCycleHelper *mAnalyseCycleHelper;
|
|
|
|
//
|
|
ENUM_X_CYCLE_EVENTS mVerificationCycleEvents[];
|
|
XC121SMCCycleHelper *mVerificationCycleHelper;
|
|
|
|
//
|
|
ENUM_X_CYCLE_EVENTS mConsolidationCycleEvents[];
|
|
XC121SMCCycleHelper *mConsolidationCycleHelper;
|
|
|
|
//
|
|
ENUM_X_CYCLE_EVENTS mVisionCycleEvents[];
|
|
XC121SMCCycleHelper *mVisionCycleHelper;
|
|
|
|
//
|
|
// Actions ...
|
|
|
|
/**
|
|
* Retrieve Cycles Conditions ...
|
|
*
|
|
* @param conditions: X121SMCStrategyConditions instance Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool GetCyclesConditions(
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
conditions.time = cTime;
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
int conditionsLoopback = 7;
|
|
|
|
//
|
|
// Fill Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
result = mTriggerCycleHelper.GetConditions(
|
|
mTriggerCycleEvents,
|
|
conditions.triggerConditions,
|
|
zIndex,
|
|
conditionsLoopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
conditions.triggerConditions.state = mTriggerState;
|
|
|
|
//
|
|
// Decision ...
|
|
result = mDecisionCycleHelper.GetConditions(
|
|
mDecisionCycleEvents,
|
|
conditions.decisionConditions,
|
|
zIndex,
|
|
conditionsLoopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
conditions.decisionConditions.state = mDecisionState;
|
|
|
|
//
|
|
// Analyse ...
|
|
result = mAnalyseCycleHelper.GetConditions(
|
|
mAnalyseCycleEvents,
|
|
conditions.analyseConditions,
|
|
zIndex,
|
|
conditionsLoopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
conditions.analyseConditions.state = mAnalyseState;
|
|
|
|
//
|
|
// Verification ...
|
|
result = mVerificationCycleHelper.GetConditions(
|
|
mVerificationCycleEvents,
|
|
conditions.verificationConditions,
|
|
zIndex,
|
|
conditionsLoopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
conditions.verificationConditions.state = mVerificationState;
|
|
|
|
//
|
|
// Consolidation ...
|
|
result = mConsolidationCycleHelper.GetConditions(
|
|
mConsolidationCycleEvents,
|
|
conditions.consolidationConditions,
|
|
zIndex,
|
|
conditionsLoopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
conditions.consolidationConditions.state = mConsolidationState;
|
|
|
|
//
|
|
// Vision ...
|
|
result = mVisionCycleHelper.GetConditions(
|
|
mVisionCycleEvents,
|
|
conditions.visionConditions,
|
|
zIndex,
|
|
conditionsLoopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
conditions.visionConditions.state = mVisionState;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect and Parse Market Conditions ...
|
|
*
|
|
* @param conditions: X121SMCStrategyConditions instance Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectConditions(
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string msg = NULL;
|
|
|
|
//
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
// Here We Select Cycles For Conditions Check ...
|
|
ENUM_X_CYCLES cycles[5] = {
|
|
X_CYCLE_TRIGGER,
|
|
X_CYCLE_DECISION,
|
|
X_CYCLE_ANALYSE,
|
|
X_CYCLE_VERIFICATION,
|
|
X_CYCLE_CONSOLIDATION //
|
|
};
|
|
bool hasSamePeaks = DetectSamePeaks(
|
|
cycles,
|
|
conditions //
|
|
);
|
|
bool hasSameVales = DetectSameVales(
|
|
cycles,
|
|
conditions //
|
|
);
|
|
result =
|
|
hasSamePeaks ||
|
|
hasSameVales;
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Sar State ...
|
|
ENUM_X_DIRECTION sarDir;
|
|
result = DetectSarState(
|
|
sarDir,
|
|
conditions //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check VWAP State ...
|
|
ENUM_X_DIRECTION vwapDir;
|
|
result = DetectVWapState(
|
|
vwapDir,
|
|
conditions //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Candlestic State ...
|
|
ENUM_X_DIRECTION candlesticDir;
|
|
result = DetectCandlestic(
|
|
candlesticDir,
|
|
conditions //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
Print("Has Same Peaks or Vales ...");
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect Where Cycles has Same Peaks ...
|
|
*
|
|
* @param cycles: ENUM_X_CYCLES members, Array ...
|
|
* @param conditions: X121SMCStrategyConditions instance, Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSamePeaks(
|
|
ENUM_X_CYCLES &cycles[],
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
int count = ArraySize(cycles);
|
|
result = IsValidSize(count);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double value = -1;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
ENUM_X_CYCLES iCycle = cycles[i];
|
|
|
|
//
|
|
double iValue = -1;
|
|
switch (iCycle)
|
|
{
|
|
//
|
|
case X_CYCLE_TRIGGER:
|
|
iValue = conditions.triggerConditions.x121Conditions.peaksBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_DECISION:
|
|
iValue = conditions.decisionConditions.x121Conditions.peaksBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_ANALYSE:
|
|
iValue = conditions.analyseConditions.x121Conditions.peaksBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_VERIFICATION:
|
|
iValue = conditions.verificationConditions.x121Conditions.peaksBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_CONSOLIDATION:
|
|
iValue = conditions.consolidationConditions.x121Conditions.peaksBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_VISION:
|
|
iValue = conditions.visionConditions.x121Conditions.peaksBuffer[0];
|
|
break;
|
|
}
|
|
|
|
//
|
|
if (iValue > 0)
|
|
{
|
|
//
|
|
if (value <= 0)
|
|
{
|
|
value = iValue;
|
|
}
|
|
|
|
//
|
|
result = value == iValue;
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect Where Cycles has Same Vales ...
|
|
*
|
|
* @param cycles: ENUM_X_CYCLES members, Array ...
|
|
* @param conditions: X121SMCStrategyConditions instance, Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSameVales(
|
|
ENUM_X_CYCLES &cycles[],
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
int count = ArraySize(cycles);
|
|
result = IsValidSize(count);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double value = -1;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
ENUM_X_CYCLES iCycle = cycles[i];
|
|
|
|
//
|
|
double iValue = -1;
|
|
switch (iCycle)
|
|
{
|
|
//
|
|
case X_CYCLE_TRIGGER:
|
|
iValue = conditions.triggerConditions.x121Conditions.valesBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_DECISION:
|
|
iValue = conditions.decisionConditions.x121Conditions.valesBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_ANALYSE:
|
|
iValue = conditions.analyseConditions.x121Conditions.valesBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_VERIFICATION:
|
|
iValue = conditions.verificationConditions.x121Conditions.valesBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_CONSOLIDATION:
|
|
iValue = conditions.consolidationConditions.x121Conditions.valesBuffer[0];
|
|
break;
|
|
|
|
//
|
|
case X_CYCLE_VISION:
|
|
iValue = conditions.visionConditions.x121Conditions.valesBuffer[0];
|
|
break;
|
|
}
|
|
|
|
//
|
|
if (iValue > 0)
|
|
{
|
|
//
|
|
if (value <= 0)
|
|
{
|
|
value = iValue;
|
|
}
|
|
|
|
//
|
|
result = value == iValue;
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect Sar State for Signalling ...
|
|
*
|
|
* @param dir: ENUM_X_DIRECTION member Reference ...
|
|
* @param conditions: X121SMCStrategyConditions instance, Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSarState(
|
|
ENUM_X_DIRECTION &dir,
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
bool isBullish =
|
|
//
|
|
// Check One of Verification or Consolidation Cycles Must be Sar Bullish ...
|
|
(conditions.verificationConditions.x121Conditions.isSarBullish ||
|
|
conditions.consolidationConditions.x121Conditions.isSarBullish)
|
|
//
|
|
&&
|
|
//
|
|
// Decision and Analyse Cycles Must be Bullish ...
|
|
(conditions.decisionConditions.x121Conditions.isSarBullish &&
|
|
conditions.analyseConditions.x121Conditions.isSarBullish)
|
|
//
|
|
&&
|
|
//
|
|
// Trigger State Must be Bearish ...
|
|
conditions.triggerConditions.x121Conditions.isSarBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearish =
|
|
//
|
|
// Check One of Verification or Consolidation Cycles Must be Sar Bearish ...
|
|
(conditions.verificationConditions.x121Conditions.isSarBearish ||
|
|
conditions.consolidationConditions.x121Conditions.isSarBearish)
|
|
//
|
|
&&
|
|
//
|
|
// Decision and Analyse Cycles Must be Bearish ...
|
|
(conditions.decisionConditions.x121Conditions.isSarBearish &&
|
|
conditions.analyseConditions.x121Conditions.isSarBearish)
|
|
//
|
|
&&
|
|
//
|
|
// Trigger State Must be Bullish ...
|
|
conditions.triggerConditions.x121Conditions.isSarBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect Sar State for Signalling ...
|
|
*
|
|
* @param dir: ENUM_X_DIRECTION member Reference ...
|
|
* @param conditions: X121SMCStrategyConditions instance, Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectVWapState(
|
|
ENUM_X_DIRECTION &dir,
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
bool isBullish =
|
|
//
|
|
// Trigger, Decision and Analyse Cycles Must be in Direction Order and State ...
|
|
//
|
|
// Orders ...
|
|
(conditions.triggerConditions.x121Conditions.isVWapBullishOrdered &&
|
|
conditions.decisionConditions.x121Conditions.isVWapBullishOrdered &&
|
|
conditions.analyseConditions.x121Conditions.isVWapBullishOrdered)
|
|
//
|
|
&&
|
|
//
|
|
// State ...
|
|
(conditions.triggerConditions.x121Conditions.isVWapBullishState &&
|
|
conditions.decisionConditions.x121Conditions.isVWapBullishState &&
|
|
conditions.analyseConditions.x121Conditions.isVWapBullishState)
|
|
//
|
|
&&
|
|
//
|
|
// One of Verification and Consolidation must Be in Direction State ...
|
|
(conditions.verificationConditions.x121Conditions.isVWapBullishState ||
|
|
conditions.consolidationConditions.x121Conditions.isVWapBullishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearish =
|
|
//
|
|
// Trigger, Decision and Analyse Cycles Must be in Direction Order and State ...
|
|
//
|
|
// Orders ...
|
|
(conditions.triggerConditions.x121Conditions.isVWapBearishOrdered &&
|
|
conditions.decisionConditions.x121Conditions.isVWapBearishOrdered &&
|
|
conditions.analyseConditions.x121Conditions.isVWapBearishOrdered)
|
|
//
|
|
&&
|
|
//
|
|
// State ...
|
|
(conditions.triggerConditions.x121Conditions.isVWapBearishState &&
|
|
conditions.decisionConditions.x121Conditions.isVWapBearishState &&
|
|
conditions.analyseConditions.x121Conditions.isVWapBearishState)
|
|
//
|
|
&&
|
|
//
|
|
// One of Verification and Consolidation must Be in Direction State ...
|
|
(conditions.verificationConditions.x121Conditions.isVWapBearishState ||
|
|
conditions.consolidationConditions.x121Conditions.isVWapBearishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool DetectCandlestic(
|
|
ENUM_X_DIRECTION &dir,
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
int cIndex = 1;
|
|
int pIndex = cIndex + 1;
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
symbol,
|
|
period,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION cBarMomentumDir;
|
|
bool isCBarMomentum = mTriggerCycleHelper.mBarAnalyser.
|
|
IsMomentumBar(
|
|
cBar,
|
|
cBarMomentumDir //
|
|
);
|
|
|
|
//
|
|
ENUM_X_DIRECTION cBarRejectionDir;
|
|
bool isCBarRejection = mTriggerCycleHelper.mBarAnalyser.
|
|
IsRejectionBar(
|
|
cBar,
|
|
cBarRejectionDir //
|
|
);
|
|
|
|
//
|
|
bool isBullish =
|
|
//
|
|
// pBar is Rejection and cBar is Momentum ...
|
|
// pBar is Momentum and cBar is Rejection ...
|
|
// cBar is Momentum and Rejection ...
|
|
//
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearish =
|
|
//
|
|
// pBar is Rejection and cBar is Momentum ...
|
|
// pBar is Momentum and cBar is Rejection ...
|
|
// cBar is Momentum and Rejection ...
|
|
//
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
|
|
/**
|
|
* Initial Required Indicators Helper ...
|
|
*/
|
|
void InitialHelpers()
|
|
{
|
|
//
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
// Short ...
|
|
ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
|
ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
|
|
|
//
|
|
// Medium ...
|
|
ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
// Long ...
|
|
ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
// Hind ...
|
|
ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
// XPV ...
|
|
X121Inputs x121Inputs;
|
|
|
|
//
|
|
x121Inputs.Default();
|
|
|
|
//
|
|
x121Inputs.scMethod = scMethod;
|
|
x121Inputs.scPeriod = scPeriod;
|
|
x121Inputs.mcMethod = mcMethod;
|
|
x121Inputs.mcPeriod = mcPeriod;
|
|
x121Inputs.lcMethod = lcMethod;
|
|
x121Inputs.lcPeriod = lcPeriod;
|
|
x121Inputs.hcMethod = hcMethod;
|
|
x121Inputs.hcPeriod = hcPeriod;
|
|
|
|
//
|
|
// Initialize Cycle Helpers ...
|
|
|
|
//
|
|
mTriggerCycleHelper = new XC121SMCCycleHelper();
|
|
mTriggerCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M1,
|
|
x121Inputs //
|
|
);
|
|
|
|
//
|
|
mDecisionCycleHelper = new XC121SMCCycleHelper();
|
|
mDecisionCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M5,
|
|
x121Inputs //
|
|
);
|
|
|
|
//
|
|
mAnalyseCycleHelper = new XC121SMCCycleHelper();
|
|
mAnalyseCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M15,
|
|
x121Inputs //
|
|
);
|
|
|
|
//
|
|
mVerificationCycleHelper = new XC121SMCCycleHelper();
|
|
mVerificationCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M30,
|
|
x121Inputs //
|
|
);
|
|
|
|
//
|
|
mConsolidationCycleHelper = new XC121SMCCycleHelper();
|
|
mConsolidationCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_H1,
|
|
x121Inputs //
|
|
);
|
|
|
|
//
|
|
mVisionCycleHelper = new XC121SMCCycleHelper();
|
|
mVisionCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_H4,
|
|
x121Inputs //
|
|
);
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |