1368 lines
37 KiB
Plaintext
1368 lines
37 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Class Library
|
|
// --------------------------------------
|
|
// Name: XCX121SMCStrategy
|
|
// 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"
|
|
|
|
//
|
|
#include "../Signals/x-121.smc.xobs.signal.lib.mq5"
|
|
#include "../Signals/x-121.smc.xsupdemobs.signal.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// XStrategy Class Implementation(s) ...
|
|
class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
bool useXOBSSignal;
|
|
bool useXSupDemOBSSignal;
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
void XCX121SMCStrategy(
|
|
//
|
|
// Base ...
|
|
string _symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES _period // Trading TimeFrame
|
|
)
|
|
: XCX121SMCBaseStrategy(_symbol, _period)
|
|
{
|
|
InitialHelpers();
|
|
}
|
|
|
|
//
|
|
// Deconstructur ...
|
|
void ~XCX121SMCStrategy()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
//
|
|
// Getter(s) / Setter(s) ...
|
|
|
|
/**
|
|
* Get Max Allowed Required POI(s) to Find ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int MaxAllowedRequiredPOIs()
|
|
{
|
|
return mMaxAllowedRequiredPOIs;
|
|
}
|
|
|
|
/**
|
|
* Set Max Allowed Required POI(s) to Find ...
|
|
*
|
|
* @param value: number of Required POIs
|
|
*/
|
|
void MaxAllowedRequiredPOIs(int value)
|
|
{
|
|
//
|
|
if (value < 10)
|
|
{
|
|
value = 10;
|
|
}
|
|
|
|
//
|
|
mMaxAllowedRequiredPOIs = value;
|
|
}
|
|
|
|
//
|
|
// Overrides Actions ...
|
|
|
|
/**
|
|
* Destroy All Class Implementations ...
|
|
*/
|
|
void Destroy() override
|
|
{
|
|
//
|
|
Clean(mX121SMCXOBSConditionsCollection);
|
|
Clean(mX121SMCXSupDemOBSConditionsCollection);
|
|
|
|
//
|
|
ZeroMemory(mTriggerCycleHelper);
|
|
ZeroMemory(mDecisionCycleHelper);
|
|
ZeroMemory(mAnalyseCycleHelper);
|
|
ZeroMemory(mVerificationCycleHelper);
|
|
ZeroMemory(mConsolidationCycleHelper);
|
|
ZeroMemory(mVisionCycleHelper);
|
|
|
|
//
|
|
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();
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
// Required Value For SL/TP Calculations ...
|
|
double points = GetPoints(symbol);
|
|
double pip = GetPipPrice(symbol);
|
|
double pip2 = 2 * pip;
|
|
|
|
//
|
|
conditions.time = cTime;
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
// Check Spread for Signalling Conditions ...
|
|
// TODO: Uncomment this ...
|
|
// bool isSpreadPassed = IsSpreadPass();
|
|
// result = isSpreadPassed;
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// conditions.Clean();
|
|
// return result;
|
|
// }
|
|
|
|
//
|
|
// Detect Signal Conditions ...
|
|
bool hasSignal = false;
|
|
|
|
//
|
|
bool hasXOBSSignal = false;
|
|
bool hasXSupDemOBSSignal = false;
|
|
|
|
//
|
|
// XOBS Signal ...
|
|
if (useXOBSSignal && !hasSignal)
|
|
{
|
|
//
|
|
hasXOBSSignal = DetectXOBSSignal(conditions);
|
|
hasSignal = hasXOBSSignal;
|
|
}
|
|
|
|
//
|
|
// XSupDemOBS Signal ...
|
|
if (useXSupDemOBSSignal && !hasSignal)
|
|
{
|
|
//
|
|
hasXSupDemOBSSignal = DetectXSupDemOBSSignal(conditions);
|
|
hasSignal = hasXSupDemOBSSignal;
|
|
}
|
|
|
|
//
|
|
result = hasSignal;
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Combine all Signals Conditions ...
|
|
selectedSL = conditions.sl;
|
|
provider = conditions.provider;
|
|
|
|
//
|
|
hasLong =
|
|
//
|
|
IsBullish(conditions.signalDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
hasShort =
|
|
//
|
|
IsBearish(conditions.signalDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
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 //
|
|
);
|
|
|
|
//
|
|
double slAddition = 0;
|
|
sl =
|
|
hasLong
|
|
? selectedSL - slAddition
|
|
: selectedSL + slAddition;
|
|
|
|
//
|
|
// 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();
|
|
signal.target = conditions.target;
|
|
|
|
//
|
|
bool canReplaceTarget =
|
|
signal.target > 0 &&
|
|
(hasLong
|
|
? signal.target > signal.tp
|
|
: signal.target < signal.tp);
|
|
if (canReplaceTarget)
|
|
{
|
|
//
|
|
signal.tp = conditions.target;
|
|
signal.target = tp;
|
|
}
|
|
|
|
//
|
|
result = PrepareSignal(signal);
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
// Configure Signal Protector ...
|
|
// if (useXSTRPVSignal)
|
|
// {
|
|
// //
|
|
// signal.trailSL = false;
|
|
// signal.fullTPLevel = r2r;
|
|
// signal.partialCloseOnTPLevel = 2;
|
|
// signal.partialCloseMultiplier = 0.5;
|
|
// signal.trailSLStartOnReachTPLevel = 2;
|
|
// }
|
|
|
|
//
|
|
// TODO: Remove this ...
|
|
// XCSignalObject *iObj;
|
|
// mPOIDrawer.DrawSignal(signal, iObj);
|
|
// Print("");
|
|
}
|
|
|
|
//
|
|
hasLong = false;
|
|
hasShort = false;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check for any Guard Actions ...
|
|
*/
|
|
bool CheckGuard(
|
|
X121SMCGuard &guards[],
|
|
const XPosition &positions[] //
|
|
) override
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(guards);
|
|
|
|
//
|
|
int count = ArraySize(positions);
|
|
result = IsValidSize(count);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// XOBS Guard Detection ...
|
|
if (useXOBSSignal)
|
|
{
|
|
//
|
|
bool hasGuard = DetectX121SMCXOBSGuards(
|
|
guards,
|
|
positions,
|
|
mTriggerCycleHelper,
|
|
mDecisionCycleHelper,
|
|
mAnalyseCycleHelper,
|
|
mVerificationCycleHelper,
|
|
mConsolidationCycleHelper,
|
|
mVisionCycleHelper //
|
|
);
|
|
}
|
|
|
|
//
|
|
// XSupDemOBS Guard Detection ...
|
|
if (useXSupDemOBSSignal)
|
|
{
|
|
//
|
|
bool hasGuard = DetectX121SMCXSupDemOBSGuards(
|
|
guards,
|
|
positions,
|
|
mTriggerCycleHelper,
|
|
mDecisionCycleHelper,
|
|
mAnalyseCycleHelper,
|
|
mVerificationCycleHelper,
|
|
mConsolidationCycleHelper,
|
|
mVisionCycleHelper //
|
|
);
|
|
}
|
|
|
|
//
|
|
count = ArraySize(guards);
|
|
result = IsValidSize(count);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Customize Strategy Identifier ...
|
|
*/
|
|
string GetTag() override
|
|
{
|
|
return X121SMCStrategyToken;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
XC121SMCCycleHelper *mTriggerCycleHelper;
|
|
XC121SMCCycleHelper *mDecisionCycleHelper;
|
|
XC121SMCCycleHelper *mAnalyseCycleHelper;
|
|
XC121SMCCycleHelper *mVerificationCycleHelper;
|
|
XC121SMCCycleHelper *mConsolidationCycleHelper;
|
|
XC121SMCCycleHelper *mVisionCycleHelper;
|
|
|
|
//
|
|
// Actions ...
|
|
|
|
//
|
|
// Signalling Functions ...
|
|
|
|
//
|
|
// XOBS Signal ...
|
|
bool DetectXOBSSignal(
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
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 cLL = cBar.FindLowest(7, MODE_LOW);
|
|
double cHH = cBar.FindHighest(7, MODE_HIGH);
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XOBS;
|
|
string providerStr = ToString(provider);
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
datetime setupTime = mX121SMCXOBSConditions.setupTime;
|
|
bool isSetuped = mX121SMCXOBSConditions.IsSetuped();
|
|
ENUM_X_DIRECTION setupDir = mX121SMCXOBSConditions.dir;
|
|
if (!isSetuped)
|
|
{
|
|
//
|
|
// Detect Signal Setup ...
|
|
isSetuped = DetectX121SMCXOBSSignalSetup(
|
|
symbol,
|
|
period,
|
|
mX121SMCXOBSConditions,
|
|
mTriggerCycleHelper,
|
|
mDecisionCycleHelper,
|
|
mAnalyseCycleHelper,
|
|
mVerificationCycleHelper,
|
|
mConsolidationCycleHelper,
|
|
mVisionCycleHelper //
|
|
);
|
|
|
|
//
|
|
setupDir = mX121SMCXOBSConditions.dir;
|
|
setupTime = mX121SMCXOBSConditions.setupTime;
|
|
|
|
//
|
|
if (isSetuped)
|
|
{
|
|
//
|
|
int items = AddX121SMCXOBSConditionsIfNotExists(
|
|
mX121SMCXOBSConditions,
|
|
mX121SMCXOBSConditionsCollection //
|
|
);
|
|
|
|
//
|
|
mX121SMCXOBSConditions.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
int conditionsCount = ArraySize(mX121SMCXOBSConditionsCollection);
|
|
result = IsValidSize(conditionsCount);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Looking For Conditions ...
|
|
int selectedIndex = 0;
|
|
X121SMCStrategyXOBSSignalConditions mTmpConditions[];
|
|
Copy(
|
|
mX121SMCXOBSConditionsCollection,
|
|
mTmpConditions //
|
|
);
|
|
X121SMCStrategyXOBSSignalConditions mConditions;
|
|
for (int i = 0; i < conditionsCount; i++)
|
|
{
|
|
//
|
|
// Check Triggers ...
|
|
bool canTrigger = mTmpConditions[i].CanTrigger();
|
|
datetime triggerTime = mTmpConditions[i].triggerTime;
|
|
if (!canTrigger)
|
|
{
|
|
//
|
|
// Detect Signal Trigger ...
|
|
canTrigger = DetectX121SMCXOBSSignalTrigger(
|
|
mTmpConditions[i],
|
|
symbol,
|
|
period,
|
|
mTriggerCycleHelper,
|
|
mDecisionCycleHelper,
|
|
mAnalyseCycleHelper,
|
|
mVerificationCycleHelper,
|
|
mConsolidationCycleHelper,
|
|
mVisionCycleHelper //
|
|
);
|
|
|
|
//
|
|
result = canTrigger;
|
|
if (!result)
|
|
{
|
|
//
|
|
bool isISetuped = mTmpConditions[i].IsSetuped();
|
|
if (!isISetuped)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
mX121SMCXOBSConditionsCollection,
|
|
i,
|
|
1 //
|
|
);
|
|
}
|
|
continue;
|
|
}
|
|
|
|
//
|
|
triggerTime = mTmpConditions[i].triggerTime;
|
|
}
|
|
|
|
//
|
|
if (canTrigger)
|
|
{
|
|
//
|
|
selectedIndex = i;
|
|
mConditions = mTmpConditions[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = IsValid(mConditions.setupTime) &&
|
|
HasDirection(mConditions.dir);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Remove Selected Index from Main Collection ...
|
|
ArrayRemove(
|
|
mX121SMCXOBSConditionsCollection,
|
|
selectedIndex,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Check Signal Direction ...
|
|
isBullish = IsBullish(mConditions.dir);
|
|
isBearish = IsBearish(mConditions.dir);
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Issues Signal on Conditions ...
|
|
conditions.sl = mConditions.sl;
|
|
conditions.provider = providerStr;
|
|
conditions.signalDir = mConditions.dir;
|
|
conditions.target = mConditions.target;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// XSupDemOBS Signal ...
|
|
bool DetectXSupDemOBSSignal(
|
|
X121SMCStrategyConditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
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 cLL = cBar.FindLowest(7, MODE_LOW);
|
|
double cHH = cBar.FindHighest(7, MODE_HIGH);
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XSUPDEMOBS;
|
|
string providerStr = ToString(provider);
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
datetime setupTime = mX121SMCXSupDemOBSConditions.setupTime;
|
|
bool isSetuped = mX121SMCXSupDemOBSConditions.IsSetuped();
|
|
ENUM_X_DIRECTION setupDir = mX121SMCXSupDemOBSConditions.dir;
|
|
if (!isSetuped)
|
|
{
|
|
//
|
|
// Detect Signal Setup ...
|
|
isSetuped = DetectX121SMCXSupDemOBSSignalSetup(
|
|
symbol,
|
|
period,
|
|
mX121SMCXSupDemOBSConditions,
|
|
mTriggerCycleHelper,
|
|
mDecisionCycleHelper,
|
|
mAnalyseCycleHelper,
|
|
mVerificationCycleHelper,
|
|
mConsolidationCycleHelper,
|
|
mVisionCycleHelper //
|
|
);
|
|
|
|
//
|
|
setupDir = mX121SMCXSupDemOBSConditions.dir;
|
|
setupTime = mX121SMCXSupDemOBSConditions.setupTime;
|
|
|
|
//
|
|
if (isSetuped)
|
|
{
|
|
//
|
|
int items = AddX121SMCXSupDemOBSConditionsIfNotExists(
|
|
mX121SMCXSupDemOBSConditions,
|
|
mX121SMCXSupDemOBSConditionsCollection //
|
|
);
|
|
|
|
//
|
|
mX121SMCXSupDemOBSConditions.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
int conditionsCount = ArraySize(mX121SMCXSupDemOBSConditionsCollection);
|
|
result = IsValidSize(conditionsCount);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Looking For Conditions ...
|
|
int selectedIndex = 0;
|
|
X121SMCStrategyXSupDemOBSSignalConditions mTmpConditions[];
|
|
Copy(
|
|
mX121SMCXSupDemOBSConditionsCollection,
|
|
mTmpConditions //
|
|
);
|
|
X121SMCStrategyXSupDemOBSSignalConditions mConditions;
|
|
for (int i = 0; i < conditionsCount; i++)
|
|
{
|
|
//
|
|
// Check Triggers ...
|
|
bool canTrigger = mTmpConditions[i].CanTrigger();
|
|
datetime triggerTime = mTmpConditions[i].triggerTime;
|
|
if (!canTrigger)
|
|
{
|
|
//
|
|
// Detect Signal Trigger ...
|
|
canTrigger = DetectX121SMCXSupDemOBSSignalTrigger(
|
|
mTmpConditions[i],
|
|
symbol,
|
|
period,
|
|
mTriggerCycleHelper,
|
|
mDecisionCycleHelper,
|
|
mAnalyseCycleHelper,
|
|
mVerificationCycleHelper,
|
|
mConsolidationCycleHelper,
|
|
mVisionCycleHelper //
|
|
);
|
|
|
|
//
|
|
result = canTrigger;
|
|
if (!result)
|
|
{
|
|
//
|
|
bool isISetuped = mTmpConditions[i].IsSetuped();
|
|
if (!isISetuped)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
mX121SMCXSupDemOBSConditionsCollection,
|
|
i,
|
|
1 //
|
|
);
|
|
}
|
|
continue;
|
|
}
|
|
|
|
//
|
|
triggerTime = mTmpConditions[i].triggerTime;
|
|
}
|
|
|
|
//
|
|
if (canTrigger)
|
|
{
|
|
//
|
|
selectedIndex = i;
|
|
mConditions = mTmpConditions[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = IsValid(mConditions.setupTime) &&
|
|
HasDirection(mConditions.dir);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Remove Selected Index from Main Collection ...
|
|
ArrayRemove(
|
|
mX121SMCXSupDemOBSConditionsCollection,
|
|
selectedIndex,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Check Signal Direction ...
|
|
isBullish = IsBullish(mConditions.dir);
|
|
isBearish = IsBearish(mConditions.dir);
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Issues Signal on Conditions ...
|
|
conditions.sl = mConditions.sl;
|
|
conditions.provider = providerStr;
|
|
conditions.signalDir = mConditions.dir;
|
|
conditions.target = mConditions.target;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
int mMaxAllowedRequiredPOIs; // Max Allowed Required POI(s) to Find ...
|
|
|
|
/**
|
|
* Initial Required Indicators Helper ...
|
|
*/
|
|
void InitialHelpers()
|
|
{
|
|
//
|
|
useXOBSSignal = false;
|
|
useXSupDemOBSSignal = true;
|
|
|
|
//
|
|
string symbol = GetSymbol();
|
|
ENUM_TIMEFRAMES period = GetPeriod();
|
|
|
|
//
|
|
if (mMaxAllowedRequiredPOIs <= 0)
|
|
{
|
|
mMaxAllowedRequiredPOIs = 50;
|
|
}
|
|
|
|
//
|
|
// 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();
|
|
|
|
//
|
|
bool showAll = false;
|
|
|
|
//
|
|
x121Inputs.showRSI = false;
|
|
|
|
//
|
|
bool isInited = false;
|
|
|
|
//
|
|
// XPV ...
|
|
|
|
//
|
|
x121Inputs.xpvInputs.scMethod = scMethod;
|
|
x121Inputs.xpvInputs.scPeriod = scPeriod;
|
|
x121Inputs.xpvInputs.mcMethod = mcMethod;
|
|
x121Inputs.xpvInputs.mcPeriod = mcPeriod;
|
|
x121Inputs.xpvInputs.lcMethod = lcMethod;
|
|
x121Inputs.xpvInputs.lcPeriod = lcPeriod;
|
|
x121Inputs.xpvInputs.hcMethod = hcMethod;
|
|
x121Inputs.xpvInputs.hcPeriod = hcPeriod;
|
|
|
|
//
|
|
x121Inputs.xhkInputs.xhkIgnoreSmoothingShadows = true;
|
|
|
|
//
|
|
x121Inputs.xatrInputs.atrMultiplier = 1.5;
|
|
x121Inputs.xatrInputs.atrSmoothingMode = X_MA_MODE_EMA;
|
|
|
|
//
|
|
// XPV ...
|
|
x121Inputs.xpvInputs.showSar = showAll || false;
|
|
x121Inputs.xpvInputs.showPeaks = showAll || false;
|
|
x121Inputs.xpvInputs.showVales = showAll || false;
|
|
|
|
//
|
|
// XHK ...
|
|
|
|
//
|
|
x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false;
|
|
x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || false;
|
|
|
|
//
|
|
// XATR ...
|
|
x121Inputs.xatrInputs.showATRUpper = showAll || false;
|
|
x121Inputs.xatrInputs.showATRLower = showAll || false;
|
|
|
|
//
|
|
// XSTR ...
|
|
x121Inputs.xstrInputs.showStr = showAll || false;
|
|
x121Inputs.xstrInputs.showStrUpper = showAll || false;
|
|
x121Inputs.xstrInputs.showStrLower = showAll || false;
|
|
|
|
//
|
|
// XCHE ...
|
|
x121Inputs.xcheInputs.showLE1 = showAll || false;
|
|
x121Inputs.xcheInputs.showLE2 = showAll || false;
|
|
x121Inputs.xcheInputs.showSE1 = showAll || false;
|
|
x121Inputs.xcheInputs.showSE2 = showAll || false;
|
|
|
|
//
|
|
// XDON ...
|
|
x121Inputs.xdonInputs.showOpen = showAll || false;
|
|
x121Inputs.xdonInputs.showClose = showAll || false;
|
|
x121Inputs.xdonInputs.showLow = showAll || false;
|
|
x121Inputs.xdonInputs.showHigh = showAll || false;
|
|
|
|
//
|
|
// XVWAP ...
|
|
x121Inputs.xvwapInputs.showVWapFast = showAll || false;
|
|
x121Inputs.xvwapInputs.showVWapMedium = showAll || false;
|
|
x121Inputs.xvwapInputs.showVWapSlow = showAll || false;
|
|
|
|
//
|
|
// Initialize Cycle Helpers ...
|
|
|
|
//
|
|
int requiredPOIS = MaxAllowedRequiredPOIs();
|
|
|
|
//
|
|
// Trigger Cycle ...
|
|
mTriggerCycleHelper = new XC121SMCCycleHelper();
|
|
isInited = mTriggerCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M1,
|
|
x121Inputs,
|
|
requiredPOIS //
|
|
);
|
|
if (isInited)
|
|
{
|
|
//
|
|
// Configure POI Drawer ...
|
|
color bullishColor = clrYellowGreen;
|
|
color bearishColor = clrChocolate;
|
|
|
|
//
|
|
// Bars ...
|
|
mTriggerCycleHelper.mPOIDrawer.BarBullishColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.BarBearishColor(bearishColor);
|
|
|
|
//
|
|
// Swings ...
|
|
mTriggerCycleHelper.mPOIDrawer.SwingLowColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.SwingHighColor(bearishColor);
|
|
|
|
//
|
|
// Momentum ...
|
|
mTriggerCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor);
|
|
|
|
//
|
|
// Rejection ...
|
|
mTriggerCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor);
|
|
|
|
//
|
|
// Support and Resistance ...
|
|
mTriggerCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor);
|
|
|
|
//
|
|
// Demand and Supply ...
|
|
mTriggerCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor);
|
|
|
|
//
|
|
// Order Blocks ...
|
|
mTriggerCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
mTriggerCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor);
|
|
mTriggerCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor);
|
|
}
|
|
|
|
//
|
|
// Decision Cycle ...
|
|
mDecisionCycleHelper = new XC121SMCCycleHelper();
|
|
isInited = mDecisionCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M5,
|
|
x121Inputs,
|
|
requiredPOIS //
|
|
);
|
|
if (isInited)
|
|
{
|
|
//
|
|
// Configure POI Drawer ...
|
|
color bullishColor = clrDodgerBlue;
|
|
color bearishColor = clrSienna;
|
|
|
|
//
|
|
// Bars ...
|
|
mDecisionCycleHelper.mPOIDrawer.BarBullishColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.BarBearishColor(bearishColor);
|
|
|
|
//
|
|
// Swings ...
|
|
mDecisionCycleHelper.mPOIDrawer.SwingLowColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.SwingHighColor(bearishColor);
|
|
|
|
//
|
|
// Momentum ...
|
|
mDecisionCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor);
|
|
|
|
//
|
|
// Rejection ...
|
|
mDecisionCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor);
|
|
|
|
//
|
|
// Support and Resistance ...
|
|
mDecisionCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor);
|
|
|
|
//
|
|
// Demand and Supply ...
|
|
mDecisionCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor);
|
|
|
|
//
|
|
// Order Blocks ...
|
|
mDecisionCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
mDecisionCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor);
|
|
mDecisionCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor);
|
|
}
|
|
|
|
//
|
|
// Analyse Cycle ...
|
|
mAnalyseCycleHelper = new XC121SMCCycleHelper();
|
|
isInited = mAnalyseCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M15,
|
|
x121Inputs,
|
|
requiredPOIS //
|
|
);
|
|
if (isInited)
|
|
{
|
|
//
|
|
// Configure POI Drawer ...
|
|
color bullishColor = clrMediumSeaGreen;
|
|
color bearishColor = clrBlueViolet;
|
|
|
|
//
|
|
// Bars ...
|
|
mAnalyseCycleHelper.mPOIDrawer.BarBullishColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.BarBearishColor(bearishColor);
|
|
|
|
//
|
|
// Swings ...
|
|
mAnalyseCycleHelper.mPOIDrawer.SwingLowColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.SwingHighColor(bearishColor);
|
|
|
|
//
|
|
// Momentum ...
|
|
mAnalyseCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor);
|
|
|
|
//
|
|
// Rejection ...
|
|
mAnalyseCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor);
|
|
|
|
//
|
|
// Support and Resistance ...
|
|
mAnalyseCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor);
|
|
|
|
//
|
|
// Demand and Supply ...
|
|
mAnalyseCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor);
|
|
|
|
//
|
|
// Order Blocks ...
|
|
mAnalyseCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
mAnalyseCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor);
|
|
mAnalyseCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor);
|
|
}
|
|
|
|
//
|
|
// Verification Cycle ...
|
|
mVerificationCycleHelper = new XC121SMCCycleHelper();
|
|
isInited = mVerificationCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_M30,
|
|
x121Inputs,
|
|
requiredPOIS //
|
|
);
|
|
if (isInited)
|
|
{
|
|
//
|
|
// Configure POI Drawer ...
|
|
color bullishColor = clrOliveDrab;
|
|
color bearishColor = clrSteelBlue;
|
|
|
|
//
|
|
// Bars ...
|
|
mVerificationCycleHelper.mPOIDrawer.BarBullishColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.BarBearishColor(bearishColor);
|
|
|
|
//
|
|
// Swings ...
|
|
mVerificationCycleHelper.mPOIDrawer.SwingLowColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.SwingHighColor(bearishColor);
|
|
|
|
//
|
|
// Momentum ...
|
|
mVerificationCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor);
|
|
|
|
//
|
|
// Rejection ...
|
|
mVerificationCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor);
|
|
|
|
//
|
|
// Support and Resistance ...
|
|
mVerificationCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor);
|
|
|
|
//
|
|
// Demand and Supply ...
|
|
mVerificationCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor);
|
|
|
|
//
|
|
// Order Blocks ...
|
|
mVerificationCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
mVerificationCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor);
|
|
mVerificationCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor);
|
|
}
|
|
|
|
//
|
|
// Consolidation Cycle ...
|
|
mConsolidationCycleHelper = new XC121SMCCycleHelper();
|
|
isInited = mConsolidationCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_H1,
|
|
x121Inputs,
|
|
requiredPOIS //
|
|
);
|
|
if (isInited)
|
|
{
|
|
//
|
|
// Configure POI Drawer ...
|
|
color bullishColor = clrLime;
|
|
color bearishColor = clrRed;
|
|
|
|
//
|
|
// Bars ...
|
|
mConsolidationCycleHelper.mPOIDrawer.BarBullishColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.BarBearishColor(bearishColor);
|
|
|
|
//
|
|
// Swings ...
|
|
mConsolidationCycleHelper.mPOIDrawer.SwingLowColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.SwingHighColor(bearishColor);
|
|
|
|
//
|
|
// Momentum ...
|
|
mConsolidationCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor);
|
|
|
|
//
|
|
// Rejection ...
|
|
mConsolidationCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor);
|
|
|
|
//
|
|
// Support and Resistance ...
|
|
mConsolidationCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor);
|
|
|
|
//
|
|
// Demand and Supply ...
|
|
mConsolidationCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor);
|
|
|
|
//
|
|
// Order Blocks ...
|
|
mConsolidationCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
mConsolidationCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor);
|
|
mConsolidationCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor);
|
|
}
|
|
|
|
//
|
|
// Vision Cycle ...
|
|
mVisionCycleHelper = new XC121SMCCycleHelper();
|
|
isInited = mVisionCycleHelper.Init(
|
|
symbol,
|
|
PERIOD_H4,
|
|
x121Inputs,
|
|
requiredPOIS //
|
|
);
|
|
if (isInited)
|
|
{
|
|
//
|
|
// Configure POI Drawer ...
|
|
color bullishColor = clrAqua;
|
|
color bearishColor = clrMagenta;
|
|
|
|
//
|
|
// Bars ...
|
|
mVisionCycleHelper.mPOIDrawer.BarBullishColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.BarBearishColor(bearishColor);
|
|
|
|
//
|
|
// Swings ...
|
|
mVisionCycleHelper.mPOIDrawer.SwingLowColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.SwingHighColor(bearishColor);
|
|
|
|
//
|
|
// Momentum ...
|
|
mVisionCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor);
|
|
|
|
//
|
|
// Rejection ...
|
|
mVisionCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor);
|
|
|
|
//
|
|
// Support and Resistance ...
|
|
mVisionCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor);
|
|
|
|
//
|
|
// Demand and Supply ...
|
|
mVisionCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor);
|
|
|
|
//
|
|
// Order Blocks ...
|
|
mVisionCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
mVisionCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor);
|
|
mVisionCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor);
|
|
}
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |