Files
MQL5Data/Strategies/x-saherelm.xchkm.strategy.mq5
T

1834 lines
43 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXCHKMStrategy
// 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 ...
//
// Import(s) Helper(s) ...
#include "../Helpers/x-saherelm.xpv.helper.mq5"
#include "../Helpers/x-saherelm.xche.helper.mq5"
#include "../Helpers/x-saherelm.xchm.helper.mq5"
#include "../Helpers/x-saherelm.xchhk.helper.mq5"
#include "../Helpers/x-saherelm.xchstr.helper.mq5"
//
// Base Classes ...
#include "../Classes/x-saherelm.xstrategy.class.mq5"
//
// Specific Identifier(s) of XStrategy ...
string XCHKMStartegyToken = "XCHKM";
//
// XStrategy Class Implementation(s) ...
class XSCXCHKMStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXCHKMStrategy(
//
// Base ...
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period, // Trading TimeFrame
double _volume, // Voluem
double _r2r, // Risk/Reward Ratio
int _slippage, // Trader Slippage
long _magicNumber, // Trader Magic Number
bool _ignoreSignalExecution = false, // Ignore Signal Execution
bool _useTPSLAsPoint = false, // Converts TP and SL by Provided Points
bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points
double _tpPoint = 0, // TP As Point
double _slPoint = 0, // SL As Point
bool _ignoreTP = false, // TP set to 0
bool _ignoreSL = false, // SL set to 0
bool _allowLong = true,
bool _allowShort = true,
int _maxAllowedLongs = 0,
int _maxAllowedShorts = 0 //
) : XSCBaseStrategy(_symbol,
_period,
_volume,
_r2r,
_slippage,
_magicNumber,
_ignoreSignalExecution,
_useTPSLAsPoint,
_forceMaxTPSLAsPoint,
_tpPoint,
_slPoint,
_ignoreTP,
_ignoreSL,
_allowLong,
_allowShort,
_maxAllowedLongs,
_maxAllowedShorts //
)
{
//
SetAlertPrefix(GetTag());
//
PrepareRequirements();
}
//
// Deconstructor ...
void ~XSCXCHKMStrategy()
{
//
delete pvHelper;
delete cheHelper;
//
delete chmHelper;
delete chhkHelper;
delete chstrHelper;
}
//
// Getter / Setter (s) ...
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XCHKMStartegyToken;
}
//
// Check Conditions For Signal ...
bool HasSignal(
XSignal &signal //
) override
{
//
bool result = false;
//
signal.Clean();
//
double sl = 0;
double tp = 0;
double risk = 0;
double entry = 0;
double reward = 0;
double r2r = R2R();
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
//
bool hasLong = false;
bool hasShort = false;
//
bool forceCloseLongs = false;
bool forceCloseShorts = false;
//
// Retrieve Conditions ...
//
// XPV ...
XPVConditions pvConditions;
result = pvHelper.GetConditions(pvConditions);
if (!result)
{
return result;
}
//
// XCHE ...
XCHEConditions cheConditions;
result = cheHelper.GetConditions(cheConditions);
if (!result)
{
return result;
}
//
// XCHM ...
XCHMConditions chmConditions;
result = chmHelper.GetConditions(chmConditions);
if (!result)
{
return result;
}
//
// XCHHK ...
XCHHKConditions chhkConditions;
result = chhkHelper.GetConditions(chhkConditions);
if (!result)
{
return result;
}
//
// XCHSTR ...
XCHSTRConditions chstrConditions;
result = chstrHelper.GetConditions(chstrConditions);
if (!result)
{
return result;
}
//
// Start Calculations ...
//
double points = GetPoints(mSymbol);
//
int zIndex = 0;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
// Retrieve Bars ...
//
// Last Bar ...
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
cIndex //
);
if (!result)
{
return result;
}
//
// Previous Bar of Last Bar ...
XOHCL pBar;
result = cBar.GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
// Last Swing Low Bar ...
XOHCL lastSwingLow;
result = cBar.FindLastSwingLow(lastSwingLow);
if (!result)
{
return result;
}
//
// Last Swing High Bar ...
XOHCL lastSwingHigh;
result = cBar.FindLastSwingHigh(lastSwingHigh);
if (!result)
{
return result;
}
//
// Retrieve Highest High(s) and Lowest Low(s) ...
//
// Highest High ...
double hh5 = cBar.FindHighest(
5,
MODE_HIGH //
);
//
// Lowest Low ...
double ll5 = cBar.FindLowest(
5,
MODE_LOW //
);
//
// Check Support Exists or Find ...
bool hasSupport = support.IsValid();
if (!hasSupport)
{
//
hasSupport =
//
cBar.HasSupport(support)
//
;
//
if (hasSupport)
{
//
DrawSupport(
support,
ChartID() //
);
//
supportTime = cBar.time;
}
}
//
// Check Resistance Exists or Find ...
bool hasResistance = resistance.IsValid();
if (!hasResistance)
{
//
hasResistance =
//
cBar.HasResistance(resistance)
//
;
//
if (hasResistance)
{
//
DrawResistance(
resistance,
ChartID() //
);
//
resistanceTime = cBar.time;
}
}
//
// For Trend ...
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
// Detect Bullish/Bearish Patterns and Trends ...
//
// Bullish ...
bool hasBullishPattern = HasBullishPattern(cBar);
bool isBullishTrend = cBar.HasBullishTrend(
tmpHSW,
tmpLSW,
true //
);
//
// Bearish ...
bool hasBearishPattern = HasBearishPattern(cBar);
bool isBearishTrend = cBar.HasBearishTrend(
tmpHSW,
tmpLSW,
false //
);
//
// XCHM ...
// Detect XCHMbased Conditions ...
//
// Bullish ...
//
bool isCHMHSwithedToBullish =
//
(
//
chmConditions.isHFastCrossedOverSlow &&
chmConditions.isLFastOverSlow &&
chmConditions.isMFastOverSlow &&
chmConditions.isSFastOverSlow &&
chmConditions.isCFastOverSlow
//
)
//
;
//
bool isCHMLSwithedToBullish =
//
(
//
chmConditions.isLFastCrossedOverSlow &&
chmConditions.isHFastOverSlow &&
chmConditions.isMFastOverSlow &&
chmConditions.isSFastOverSlow &&
chmConditions.isCFastOverSlow
//
)
//
;
//
bool isCHMMSwithedToBullish =
//
(
//
chmConditions.isMFastCrossedOverSlow &&
chmConditions.isHFastOverSlow &&
chmConditions.isLFastOverSlow &&
chmConditions.isSFastOverSlow &&
chmConditions.isCFastOverSlow
//
)
//
;
//
bool isCHMSSwithedToBullish =
//
(
//
chmConditions.isSFastCrossedOverSlow &&
chmConditions.isHFastOverSlow &&
chmConditions.isLFastOverSlow &&
chmConditions.isMFastOverSlow &&
chmConditions.isCFastOverSlow
//
)
//
;
//
bool isCHMCSwithedToBullish =
//
(
//
chmConditions.isCFastCrossedOverSlow &&
chmConditions.isHFastOverSlow &&
chmConditions.isLFastOverSlow &&
chmConditions.isMFastOverSlow &&
chmConditions.isSFastOverSlow
//
)
//
;
//
// Bullish Conclusion ...
//
bool isCHMBullish =
//
(
//
chmConditions.isHFastOverSlow &&
chmConditions.isLFastOverSlow &&
chmConditions.isMFastOverSlow &&
chmConditions.isSFastOverSlow &&
chmConditions.isCFastOverSlow
//
)
//
;
//
bool isCHMSwitchedToBullish =
//
isCHMHSwithedToBullish
//
||
//
isCHMLSwithedToBullish
//
||
//
isCHMMSwithedToBullish
//
||
//
isCHMSSwithedToBullish
//
||
//
isCHMCSwithedToBullish
//
;
//
// Bearish ...
//
bool isCHMCHSwitchedToBearish =
//
(
//
chmConditions.isHFastCrossedUnderSlow &&
chmConditions.isLFastUnderSlow &&
chmConditions.isMFastUnderSlow &&
chmConditions.isSFastUnderSlow &&
chmConditions.isCFastUnderSlow
//
)
//
;
//
bool isCHMCLSwitchedToBearish =
//
(
//
chmConditions.isLFastCrossedUnderSlow &&
chmConditions.isHFastUnderSlow &&
chmConditions.isMFastUnderSlow &&
chmConditions.isSFastUnderSlow &&
chmConditions.isCFastUnderSlow
//
)
//
;
//
bool isCHMCMSwitchedToBearish =
//
(
//
chmConditions.isMFastCrossedUnderSlow &&
chmConditions.isHFastUnderSlow &&
chmConditions.isLFastUnderSlow &&
chmConditions.isSFastUnderSlow &&
chmConditions.isCFastUnderSlow
//
)
//
;
//
bool isCHMCSSwitchedToBearish =
//
(
//
chmConditions.isSFastCrossedUnderSlow &&
chmConditions.isHFastUnderSlow &&
chmConditions.isLFastUnderSlow &&
chmConditions.isMFastUnderSlow &&
chmConditions.isCFastUnderSlow
//
)
//
;
//
bool isCHMCCSwitchedToBearish =
//
(
//
chmConditions.isCFastCrossedUnderSlow &&
chmConditions.isHFastUnderSlow &&
chmConditions.isLFastUnderSlow &&
chmConditions.isMFastUnderSlow &&
chmConditions.isSFastUnderSlow
//
)
//
;
//
// Bearish Conclusion ...
//
bool isCHMBearish =
//
(
//
chmConditions.isHFastUnderSlow &&
chmConditions.isLFastUnderSlow &&
chmConditions.isMFastUnderSlow &&
chmConditions.isSFastUnderSlow &&
chmConditions.isCFastUnderSlow
//
)
//
;
//
bool isCHMSwitchedToBearish =
//
isCHMCHSwitchedToBearish
//
||
//
isCHMCLSwitchedToBearish
//
||
//
isCHMCMSwitchedToBearish
//
||
//
isCHMCSSwitchedToBearish
//
||
//
isCHMCCSwitchedToBearish
//
;
//
// Max ...
double chmMax = MathMax(
chmConditions.cFast[cIndex],
chmConditions.cSlow[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.sFast[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.sSlow[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.mFast[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.mSlow[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.lFast[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.lSlow[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.hFast[cIndex] //
);
chmMax = MathMax(
chmMax,
chmConditions.hSlow[cIndex] //
);
//
// Min ...
double chmMin = MathMin(
chmConditions.cFast[cIndex],
chmConditions.cSlow[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.sFast[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.sSlow[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.mFast[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.mSlow[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.lFast[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.lSlow[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.hFast[cIndex] //
);
chmMin = MathMin(
chmMin,
chmConditions.hSlow[cIndex] //
);
//
double chmDistanceDiffInPoint =
//
(chmMax - chmMin) / points
//
;
//
// XCHHK ...
// Detect XCHHK Conditions ...
//
// Bullish ...
//
bool isCHHKCSwitchedToBullish =
//
(
//
chhkConditions.isCSwitchedToBullish &&
chhkConditions.isSBullish &&
chhkConditions.isMBullish &&
chhkConditions.isLBullish &&
chhkConditions.isHBullish
//
)
//
;
//
bool isCHHKSSwitchedToBullish =
//
(
//
chhkConditions.isSSwitchedToBullish &&
chhkConditions.isCBullish &&
chhkConditions.isMBullish &&
chhkConditions.isLBullish &&
chhkConditions.isHBullish
//
)
//
;
//
bool isCHHKMSwitchedToBullish =
//
(
//
chhkConditions.isMSwitchedToBullish &&
chhkConditions.isCBullish &&
chhkConditions.isSBullish &&
chhkConditions.isLBullish &&
chhkConditions.isHBullish
//
)
//
;
//
bool isCHHKLSwitchedToBullish =
//
(
//
chhkConditions.isLSwitchedToBullish &&
chhkConditions.isCBullish &&
chhkConditions.isSBullish &&
chhkConditions.isMBullish &&
chhkConditions.isHBullish
//
)
//
;
//
bool isCHHKHSwitchedToBullish =
//
(
//
chhkConditions.isHSwitchedToBullish &&
chhkConditions.isCBullish &&
chhkConditions.isSBullish &&
chhkConditions.isMBullish &&
chhkConditions.isLBullish
//
)
//
;
//
// Bullish Conclusion ...
//
bool isCHHKBullish =
//
(
//
chhkConditions.isHBullish &&
chhkConditions.isCBullish &&
chhkConditions.isSBullish &&
chhkConditions.isMBullish &&
chhkConditions.isLBullish
//
)
//
;
//
bool isCHHKSwitchedBullish =
//
isCHHKCSwitchedToBullish
//
||
//
isCHHKSSwitchedToBullish
//
||
//
isCHHKMSwitchedToBullish
//
||
//
isCHHKLSwitchedToBullish
//
||
//
isCHHKHSwitchedToBullish
//
;
//
// Bearish ...
//
bool isCHHKCSwitchedToBearish =
//
(
//
chhkConditions.isCSwitchedToBearish &&
chhkConditions.isSBearish &&
chhkConditions.isMBearish &&
chhkConditions.isLBearish &&
chhkConditions.isHBearish
//
)
//
;
//
bool isCHHKSSwitchedToBearish =
//
(
//
chhkConditions.isSSwitchedToBearish &&
chhkConditions.isCBearish &&
chhkConditions.isMBearish &&
chhkConditions.isLBearish &&
chhkConditions.isHBearish
//
)
//
;
//
bool isCHHKMSwitchedToBearish =
//
(
//
chhkConditions.isMSwitchedToBearish &&
chhkConditions.isCBearish &&
chhkConditions.isSBearish &&
chhkConditions.isLBearish &&
chhkConditions.isHBearish
//
)
//
;
//
bool isCHHKLSwitchedToBearish =
//
(
//
chhkConditions.isLSwitchedToBearish &&
chhkConditions.isCBearish &&
chhkConditions.isSBearish &&
chhkConditions.isMBearish &&
chhkConditions.isHBearish
//
)
//
;
//
bool isCHHKHSwitchedToBearish =
//
(
//
chhkConditions.isHSwitchedToBearish &&
chhkConditions.isCBearish &&
chhkConditions.isSBearish &&
chhkConditions.isMBearish &&
chhkConditions.isLBearish
//
)
//
;
//
// Bearish Conclusion ...
//
bool isCHHKBearish =
//
(
//
chhkConditions.isHBearish &&
chhkConditions.isCBearish &&
chhkConditions.isSBearish &&
chhkConditions.isMBearish &&
chhkConditions.isLBearish
//
)
//
;
//
bool isCHHKSwitchedToBearish =
//
isCHHKCSwitchedToBearish
//
||
//
isCHHKSSwitchedToBearish
//
||
//
isCHHKMSwitchedToBearish
//
||
//
isCHHKLSwitchedToBearish
//
||
//
isCHHKHSwitchedToBearish
//
;
//
// Max High ...
double chhkHighMax = MathMax(
chhkConditions.cBars[cIndex].high,
chhkConditions.sBars[cIndex].high //
);
chhkHighMax = MathMax(
chhkHighMax,
chhkConditions.mBars[cIndex].high //
);
chhkHighMax = MathMax(
chhkHighMax,
chhkConditions.lBars[cIndex].high //
);
chhkHighMax = MathMax(
chhkHighMax,
chhkConditions.hBars[cIndex].high //
);
//
// Min High ...
double chhkHighMin = MathMin(
chhkConditions.cBars[cIndex].high,
chhkConditions.sBars[cIndex].high //
);
chhkHighMin = MathMin(
chhkHighMin,
chhkConditions.mBars[cIndex].high //
);
chhkHighMin = MathMin(
chhkHighMin,
chhkConditions.lBars[cIndex].high //
);
chhkHighMin = MathMin(
chhkHighMin,
chhkConditions.hBars[cIndex].high //
);
//
// Max Low ...
double chhkLowMax = MathMax(
chhkConditions.cBars[cIndex].low,
chhkConditions.sBars[cIndex].low //
);
chhkLowMax = MathMax(
chhkLowMax,
chhkConditions.mBars[cIndex].low //
);
chhkLowMax = MathMax(
chhkLowMax,
chhkConditions.lBars[cIndex].low //
);
chhkLowMax = MathMax(
chhkLowMax,
chhkConditions.hBars[cIndex].low //
);
//
// Min Low ...
double chhkLowMin = MathMin(
chhkConditions.cBars[cIndex].low,
chhkConditions.sBars[cIndex].low //
);
chhkLowMin = MathMin(
chhkLowMin,
chhkConditions.mBars[cIndex].low //
);
chhkLowMin = MathMin(
chhkLowMin,
chhkConditions.lBars[cIndex].low //
);
chhkLowMin = MathMin(
chhkLowMin,
chhkConditions.hBars[cIndex].low //
);
//
double chhkDistanceDiffInPoint =
//
(chhkHighMax - chhkLowMin) / points
//
;
//
// XCHSTR ...
// Detect XCHSTR Conditions ...
//
// Bullish ...
//
bool isCHSTRHSwitchedToBullish =
//
(
//
chstrConditions.isHSwitchedToBullish &&
chstrConditions.isLBullish &&
chstrConditions.isMBullish &&
chstrConditions.isSBullish &&
chstrConditions.isCBullish
//
)
//
;
//
bool isCHSTRLSwitchedToBullish =
//
(
//
chstrConditions.isLSwitchedToBullish &&
chstrConditions.isHBullish &&
chstrConditions.isMBullish &&
chstrConditions.isSBullish &&
chstrConditions.isCBullish
//
)
//
;
//
bool isCHSTRMSwitchedToBullish =
//
(
//
chstrConditions.isMSwitchedToBullish &&
chstrConditions.isHBullish &&
chstrConditions.isLBullish &&
chstrConditions.isSBullish &&
chstrConditions.isCBullish
//
)
//
;
//
bool isCHSTRSSwitchedToBullish =
//
(
//
chstrConditions.isSSwitchedToBullish &&
chstrConditions.isHBullish &&
chstrConditions.isLBullish &&
chstrConditions.isMBullish &&
chstrConditions.isCBullish
//
)
//
;
//
bool isCHSTRCSwitchedToBullish =
//
(
//
chstrConditions.isCSwitchedToBullish &&
chstrConditions.isHBullish &&
chstrConditions.isLBullish &&
chstrConditions.isMBullish &&
chstrConditions.isSBullish
//
)
//
;
//
// Bullish Conclusion ...
//
bool isCHSTRCBullish =
//
(
//
chstrConditions.isCBullish &&
chstrConditions.isHBullish &&
chstrConditions.isLBullish &&
chstrConditions.isMBullish &&
chstrConditions.isSBullish
//
)
//
;
//
bool isCHMSTRBullish =
//
isCHSTRHSwitchedToBullish
//
||
//
isCHSTRLSwitchedToBullish
//
||
//
isCHSTRMSwitchedToBullish
//
||
//
isCHSTRSSwitchedToBullish
//
||
//
isCHSTRCSwitchedToBullish
//
;
//
// Bearish ...
//
bool isCHSTRHSwitchedToBearish =
//
(
//
chstrConditions.isHSwitchedToBearish &&
chstrConditions.isLBearish &&
chstrConditions.isMBearish &&
chstrConditions.isSBearish &&
chstrConditions.isCBearish
//
)
//
;
//
bool isCHSTRLSwitchedToBearish =
//
(
//
chstrConditions.isLSwitchedToBearish &&
chstrConditions.isHBearish &&
chstrConditions.isMBearish &&
chstrConditions.isSBearish &&
chstrConditions.isCBearish
//
)
//
;
//
bool isCHSTRMSwitchedToBearish =
//
(
//
chstrConditions.isMSwitchedToBearish &&
chstrConditions.isHBearish &&
chstrConditions.isLBearish &&
chstrConditions.isSBearish &&
chstrConditions.isCBearish
//
)
//
;
//
bool isCHSTRSSwitchedToBearish =
//
(
//
chstrConditions.isSSwitchedToBearish &&
chstrConditions.isHBearish &&
chstrConditions.isLBearish &&
chstrConditions.isMBearish &&
chstrConditions.isCBearish
//
)
//
;
//
bool isCHSTRCSwitchedToBearish =
//
(
//
chstrConditions.isCSwitchedToBearish &&
chstrConditions.isHBearish &&
chstrConditions.isLBearish &&
chstrConditions.isMBearish &&
chstrConditions.isSBearish
//
)
//
;
//
// Bearish Conclusion ...
//
bool isCHSTRBearish =
//
(
//
chstrConditions.isCBearish &&
chstrConditions.isHBearish &&
chstrConditions.isLBearish &&
chstrConditions.isMBearish &&
chstrConditions.isSBearish
//
)
//
;
//
bool isCHSTRSwitchedToBearish =
//
isCHSTRHSwitchedToBearish
//
||
//
isCHSTRLSwitchedToBearish
//
||
//
isCHSTRMSwitchedToBearish
//
||
//
isCHSTRSSwitchedToBearish
//
||
//
isCHSTRCSwitchedToBearish
//
;
//
// Max ...
double chstrMax = MathMax(
chstrConditions.cTrend[cIndex],
chstrConditions.sTrend[cIndex] //
);
chstrMax = MathMax(
chstrMax,
chstrConditions.mTrend[cIndex] //
);
chstrMax = MathMax(
chstrMax,
chstrConditions.lTrend[cIndex] //
);
chstrMax = MathMax(
chstrMax,
chstrConditions.hTrend[cIndex] //
);
//
// Min ...
double chstrMin = MathMin(
chstrConditions.cTrend[cIndex],
chstrConditions.sTrend[cIndex] //
);
chstrMin = MathMin(
chstrMin,
chstrConditions.mTrend[cIndex] //
);
chstrMin = MathMin(
chstrMin,
chstrConditions.lTrend[cIndex] //
);
chstrMin = MathMin(
chstrMin,
chstrConditions.hTrend[cIndex] //
);
//
double chstrDistanceDiffInPoint =
//
(chstrMax - chstrMin) / points
//
;
//
// Signalling ...
// Looking for Signals Based on Conditions ...
//
// Preparing Signals for Execution ...
bool allowCHMSignals = false;
bool allowCHHKSignals = true;
bool allowCHSTRSignals = false;
//
// Check Signals based on:
// XCHMA ...
if (allowCHMSignals)
{
//
double pressureDistance = 200;
//
if (isCHMBullish)
{
//
hasLong =
//
isCHMBullish &&
hasBullishPattern &&
chmDistanceDiffInPoint <= pressureDistance
//
;
//
if (hasLong)
{
//
type = POSITION_TYPE_SELL;
sl = chmMin;
}
}
//
if (isCHMBearish)
{
//
hasShort =
//
isCHMBearish &&
hasBearishPattern &&
chmDistanceDiffInPoint <= pressureDistance
//
;
//
if (hasShort)
{
//
type = POSITION_TYPE_SELL;
sl = chmMin;
}
}
}
//
// Check Signals based on:
// XCHHK ...
if (allowCHHKSignals)
{
//
double pressureDistance = 200;
//
if (isCHHKSwitchedBullish)
{
//
hasLong =
//
isCHHKBullish &&
hasBullishPattern &&
chhkDistanceDiffInPoint <= pressureDistance
//
;
//
if (hasLong)
{
//
type = POSITION_TYPE_BUY;
sl = chhkLowMax;
}
}
//
if (isCHHKSwitchedToBearish)
{
//
hasShort =
//
isCHHKBearish &&
hasBearishPattern &&
chhkDistanceDiffInPoint <= pressureDistance
//
;
//
if (hasShort)
{
//
type = POSITION_TYPE_SELL;
sl = chhkHighMin;
}
}
}
//
// Check Signals based on:
// XCHSTR ...
if (allowCHSTRSignals)
{
}
//
// forceCloseLongs = isCHHKBullishBreaked;
// forceCloseShorts = isCHHKBearishBreaked;
//
// Check Exist Conditions ...
if (forceCloseLongs || forceCloseShorts)
{
//
string comment = "Exit Condition ...";
//
ENUM_X_POSITION_TYPES mType =
forceCloseLongs
? X_POSITION_TYPE_LONG
: X_POSITION_TYPE_SHORT;
//
int count = trader.Close(
comment,
mSymbol,
GetTag(),
mPeriod,
mType,
false // Filter By Magic ...
);
if (IsValidSize(count))
{
//
string msg = "Close (" + ToString(count) + ") " + (forceCloseLongs ? "Long" : "Short") + " Positions due Exit Conditions ...";
Alert(msg);
}
}
//
result = hasLong || hasShort;
if (!result)
{
//
CheckSupportValidation();
CheckResistanceValidation();
return result;
}
//
if (hasSupport)
{
//
supportTime = NULL;
isSupportTested = false;
RemoveSupport(support);
support.Clean();
}
//
if (hasResistance)
{
//
resistanceTime = NULL;
isResistanceTested = false;
RemoveResistance(resistance);
resistance.Clean();
}
//
// Retrieve Entry Price based on Position Type ...
entry = GetEntry(mSymbol, type);
//
// Calculate TP and SL ...
// based on Strategy ...
CalculateTPSLByPrice(
sl,
tp,
type,
entry,
r2r //
);
//
// Preparing Signal ...
result = signal.Prepare(
mSymbol,
GetTag(),
mPeriod,
type,
mode,
entry,
mVolume,
sl,
tp //
);
//
return result;
}
//
// Protected ...
protected:
//
// Props ...
//
XOHCL support;
XOHCL resistance;
//
// XPV ...
XPVInputs pvInputs;
XSCXPVHelper *pvHelper;
//
// XSTR ...
XCHSTRInputs chstrInputs;
XSCXCHSTRHelper *chstrHelper;
//
// XCHE ...
XCHEInputs cheInputs;
XSCXCHEHelper *cheHelper;
//
// XHK ...
XCHHKInputs chhkInputs;
XSCXCHHKHelper *chhkHelper;
//
// XCHMA ...
XCHMInputs chmInputs;
XSCXCHMHelper *chmHelper;
//
// Private ...
private:
//
// Props ...
//
void PrepareRequirements()
{
//
support.Clean();
supportTime = NULL;
isSupportTested = false;
//
resistance.Clean();
resistanceTime = NULL;
isResistanceTested = false;
//
// XPV ...
//
pvInputs.Default();
//
pvInputs.scMethod = X_PERIOD_MANUALLY;
pvInputs.scPeriod = PERIOD_M10;
pvInputs.mcMethod = X_PERIOD_MANUALLY;
pvInputs.mcPeriod = PERIOD_M15;
pvInputs.lcMethod = X_PERIOD_MANUALLY;
pvInputs.lcPeriod = PERIOD_M20;
pvInputs.hcMethod = X_PERIOD_MANUALLY;
pvInputs.hcPeriod = PERIOD_M30;
//
pvInputs.showPeaksAndVales = true;
pvInputs.showLevels = false;
pvInputs.showConsolidations = false;
pvInputs.showFibo1Levels = false;
pvInputs.showFibo2Levels = true;
pvInputs.showFibo3Levels = true;
pvInputs.showFibo4Levels = true;
pvInputs.showFibo5Levels = false;
//
pvHelper = new XSCXPVHelper();
pvHelper.Init(
mSymbol,
mPeriod,
pvInputs //
);
//
// XCHE ...
//
cheInputs.Default();
//
cheInputs.showLongExit1Line = false;
cheInputs.showShortExit1Line = false;
cheInputs.showLongExit2Line = false;
cheInputs.showShortExit2Line = false;
//
cheHelper = new XSCXCHEHelper();
cheHelper.Init(
mSymbol,
mPeriod,
cheInputs //
);
//
// XCHM ...
//
chmInputs.Default();
//
chmInputs.scMethod = X_PERIOD_MANUALLY;
chmInputs.scPeriod = PERIOD_M10;
chmInputs.mcMethod = X_PERIOD_MANUALLY;
chmInputs.mcPeriod = PERIOD_M15;
chmInputs.lcMethod = X_PERIOD_MANUALLY;
chmInputs.lcPeriod = PERIOD_M20;
chmInputs.hcMethod = X_PERIOD_MANUALLY;
chmInputs.hcPeriod = PERIOD_M30;
//
chmInputs.showFast = true;
chmInputs.showSlow = true;
chmInputs.showCCFast = false;
chmInputs.showCCSlow = false;
chmInputs.showSCFast = false;
chmInputs.showSCSlow = false;
chmInputs.showMCFast = false;
chmInputs.showMCSlow = false;
chmInputs.showLCFast = false;
chmInputs.showLCSlow = false;
chmInputs.showHCFast = false;
chmInputs.showHCSlow = false;
//
chmHelper = new XSCXCHMHelper();
chmHelper.Init(
mSymbol,
mPeriod,
chmInputs //
);
//
// XCHHK ...
//
chhkInputs.Default();
//
chhkInputs.scMethod = X_PERIOD_MANUALLY;
chhkInputs.scPeriod = PERIOD_M10;
chhkInputs.mcMethod = X_PERIOD_MANUALLY;
chhkInputs.mcPeriod = PERIOD_M15;
chhkInputs.lcMethod = X_PERIOD_MANUALLY;
chhkInputs.lcPeriod = PERIOD_M20;
chhkInputs.hcMethod = X_PERIOD_MANUALLY;
chhkInputs.hcPeriod = PERIOD_M30;
//
chhkInputs.showCurrent = false;
chhkInputs.showShort = false;
chhkInputs.showMedium = false;
chhkInputs.showLong = false;
chhkInputs.showHind = false;
//
chhkHelper = new XSCXCHHKHelper();
chhkHelper.Init(
mSymbol,
mPeriod,
chhkInputs //
);
//
// XCHSTR ...
//
chstrInputs.Default();
//
chstrInputs.scMethod = X_PERIOD_MANUALLY;
chstrInputs.scPeriod = PERIOD_M10;
chstrInputs.mcMethod = X_PERIOD_MANUALLY;
chstrInputs.mcPeriod = PERIOD_M15;
chstrInputs.lcMethod = X_PERIOD_MANUALLY;
chstrInputs.lcPeriod = PERIOD_M20;
chstrInputs.hcMethod = X_PERIOD_MANUALLY;
chstrInputs.hcPeriod = PERIOD_M30;
//
chstrInputs.showCurrent = true;
chstrInputs.showShort = true;
chstrInputs.showMedium = true;
chstrInputs.showLong = true;
chstrInputs.showHind = true;
//
chstrHelper = new XSCXCHSTRHelper();
chstrHelper.Init(
mSymbol,
mPeriod,
chstrInputs //
);
}
//
bool isSupportTested;
datetime supportTime;
void CheckSupportValidation()
{
//
if (!isSupportTested)
{
//
if (support.IsValid() && IsValid(supportTime))
{
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(supportTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
isSupportTested = false;
supportTime = NULL;
RemoveSupport(support);
support.Clean();
}
}
return;
}
//
XOHCL cBar;
bool isInited = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!isInited)
{
return;
}
//
double points = GetPoints(mSymbol);
//
// Find Price Distance ...
double highDiff = MathAbs(cBar.high - support.high);
double lowDiff = MathAbs(cBar.low - support.high);
//
bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points;
if (!isBreaked)
{
return;
}
//
isSupportTested = false;
RemoveSupport(support);
supportTime = NULL;
support.Clean();
}
//
bool isResistanceTested;
datetime resistanceTime;
void CheckResistanceValidation()
{
//
if (!isResistanceTested)
{
//
if (resistance.IsValid() && IsValid(resistanceTime))
{
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(resistanceTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
isResistanceTested = false;
resistanceTime = NULL;
RemoveResistance(resistance);
resistance.Clean();
}
}
return;
}
//
XOHCL cBar;
bool isInited = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!isInited)
{
return;
}
//
double points = GetPoints(mSymbol);
//
// Find Price Distance ...
double highDiff = MathAbs(cBar.high - resistance.low);
double lowDiff = MathAbs(cBar.low - resistance.low);
//
bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points;
if (!isBreaked)
{
return;
}
//
isResistanceTested = false;
RemoveResistance(resistance);
resistanceTime = NULL;
resistance.Clean();
}
};
//