2013 lines
46 KiB
Plaintext
2013 lines
46 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.xchm.helper.mq5"
|
|
#include "../Helpers/x-saherelm.xchhk.helper.mq5"
|
|
#include "../Helpers/x-saherelm.xchche.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
|
|
ENUM_TIMEFRAMES _analizePeriod, // Important Area Detect Time Frame
|
|
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 //
|
|
)
|
|
{
|
|
//
|
|
mAnalizePeriod = _analizePeriod;
|
|
|
|
//
|
|
SetAlertPrefix(GetTag());
|
|
|
|
//
|
|
PrepareRequirements();
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
void ~XSCXCHKMStrategy()
|
|
{
|
|
//
|
|
delete pvHelper;
|
|
|
|
//
|
|
delete chmHelper;
|
|
delete chhkHelper;
|
|
delete chstrHelper;
|
|
delete chcheHelper;
|
|
}
|
|
|
|
//
|
|
// Getter / Setter (s) ...
|
|
|
|
//
|
|
ENUM_TIMEFRAMES AnalizePeriod()
|
|
{
|
|
return mAnalizePeriod;
|
|
}
|
|
|
|
//
|
|
void AnalizePeriod(ENUM_TIMEFRAMES value)
|
|
{
|
|
mAnalizePeriod = value;
|
|
}
|
|
|
|
//
|
|
bool DrawImportantAreas()
|
|
{
|
|
return mDrawImportantAreas;
|
|
}
|
|
|
|
//
|
|
void DrawImportantAreas(bool value)
|
|
{
|
|
mDrawImportantAreas = value;
|
|
}
|
|
|
|
//
|
|
bool EnableXCHE()
|
|
{
|
|
return mEnableXCHE;
|
|
}
|
|
|
|
//
|
|
void EnableXCHE(bool value)
|
|
{
|
|
mEnableXCHE = value;
|
|
}
|
|
|
|
//
|
|
bool EnableXCHM()
|
|
{
|
|
return mEnableXCHM;
|
|
}
|
|
|
|
//
|
|
void EnableXCHM(bool value)
|
|
{
|
|
mEnableXCHM = value;
|
|
}
|
|
|
|
//
|
|
bool EnableXCHHK()
|
|
{
|
|
return mEnableXCHHK;
|
|
}
|
|
|
|
//
|
|
void EnableXCHHK(bool value)
|
|
{
|
|
mEnableXCHHK = value;
|
|
}
|
|
|
|
//
|
|
bool EnableXCHSTR()
|
|
{
|
|
return mEnableXCHSTR;
|
|
}
|
|
|
|
//
|
|
void EnableXCHSTR(bool value)
|
|
{
|
|
mEnableXCHSTR = value;
|
|
}
|
|
|
|
//
|
|
// Important Areas Getters ...
|
|
|
|
//
|
|
bool GetSupport(
|
|
XOHCL &bar //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
result = support.IsValid();
|
|
if (result)
|
|
{
|
|
bar = support;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetResistance(
|
|
XOHCL &bar //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
result = resistance.IsValid();
|
|
if (result)
|
|
{
|
|
bar = resistance;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetBullishOB(
|
|
XOHCL &bar //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
result = bullishOB.IsValid();
|
|
if (result)
|
|
{
|
|
bar = bullishOB;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetBearishOB(
|
|
XOHCL &bar //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
result = bearishOB.IsValid();
|
|
if (result)
|
|
{
|
|
bar = bearishOB;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetBullishFVG(
|
|
XOHCL &bar,
|
|
double upper,
|
|
double lower //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
upper = 0;
|
|
lower = 0;
|
|
bar.Clean();
|
|
|
|
//
|
|
result = bullishFVG.IsValid();
|
|
if (result)
|
|
{
|
|
//
|
|
bar = bullishFVG;
|
|
upper = bullishFVGUpper;
|
|
lower = bullishFVGLower;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetBearishFVG(
|
|
XOHCL &bar,
|
|
double upper,
|
|
double lower //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
upper = 0;
|
|
lower = 0;
|
|
bar.Clean();
|
|
|
|
//
|
|
result = bearishFVG.IsValid();
|
|
if (result)
|
|
{
|
|
//
|
|
bar = bearishFVG;
|
|
upper = bearishFVGUpper;
|
|
lower = bearishFVGLower;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetBullishTrend(
|
|
XOHCL &bar,
|
|
XOHCL &swingHighs[],
|
|
XOHCL &swingLows[] //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
Clean(swingHighs);
|
|
Clean(swingLows);
|
|
|
|
//
|
|
result = bullishTrend.IsValid();
|
|
if (result)
|
|
{
|
|
//
|
|
bar = bullishTrend;
|
|
|
|
//
|
|
Copy(
|
|
bullishTrendSwingHighs,
|
|
swingHighs //
|
|
);
|
|
Copy(
|
|
bullishTrendSwingLows,
|
|
swingLows //
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetBearishTrend(
|
|
XOHCL &bar,
|
|
XOHCL &swingHighs[],
|
|
XOHCL &swingLows[] //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
Clean(swingHighs);
|
|
Clean(swingLows);
|
|
|
|
//
|
|
result = bearishTrend.IsValid();
|
|
if (result)
|
|
{
|
|
//
|
|
bar = bearishTrend;
|
|
|
|
//
|
|
Copy(
|
|
bearishTrendSwingHighs,
|
|
swingHighs //
|
|
);
|
|
Copy(
|
|
bearishTrendSwingLows,
|
|
swingLows //
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
// Retrieve Conditions ...
|
|
|
|
//
|
|
// XPV ...
|
|
XPVConditions pvConditions;
|
|
result = pvHelper.GetConditions(pvConditions);
|
|
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;
|
|
}
|
|
|
|
//
|
|
// XCHCHE ...
|
|
XCHCHEConditions chcheConditions;
|
|
result = chcheHelper.GetConditions(chcheConditions);
|
|
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;
|
|
}
|
|
|
|
//
|
|
// Analyzing Bar ...
|
|
XOHCL aBar;
|
|
if (IsValid(mAnalizePeriod))
|
|
{
|
|
//
|
|
result = aBar.Init(
|
|
mSymbol,
|
|
mAnalizePeriod,
|
|
cIndex //
|
|
);
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
aBar = cBar;
|
|
}
|
|
|
|
//
|
|
// 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 //
|
|
);
|
|
|
|
//
|
|
// Support nad Resistance ...
|
|
|
|
//
|
|
// Check Support Exists or Find ...
|
|
bool hasSupport = support.IsValid();
|
|
if (!hasSupport)
|
|
{
|
|
//
|
|
hasSupport =
|
|
//
|
|
aBar.HasSupport(support)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (hasSupport)
|
|
{
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawSupport(
|
|
support,
|
|
ChartID() //
|
|
);
|
|
}
|
|
|
|
//
|
|
supportTime = aBar.time;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check Resistance Exists or Find ...
|
|
bool hasResistance = resistance.IsValid();
|
|
if (!hasResistance)
|
|
{
|
|
//
|
|
hasResistance =
|
|
//
|
|
aBar.HasResistance(resistance)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (hasResistance)
|
|
{
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawResistance(
|
|
resistance,
|
|
ChartID() //
|
|
);
|
|
}
|
|
|
|
//
|
|
resistanceTime = aBar.time;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Order Blocks ...
|
|
|
|
//
|
|
bool hasBullishOB = bullishOB.IsValid();
|
|
if (!hasBullishOB)
|
|
{
|
|
//
|
|
hasBullishOB =
|
|
//
|
|
aBar.HasBullishOrderBlock(bullishOB)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (hasBullishOB)
|
|
{
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawBullishOrderBlock(
|
|
bullishOB,
|
|
ChartID() //
|
|
);
|
|
}
|
|
|
|
//
|
|
bullishOBTime = aBar.time;
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasBearishOB = bearishOB.IsValid();
|
|
if (!hasBearishOB)
|
|
{
|
|
//
|
|
hasBearishOB =
|
|
//
|
|
aBar.HasBearishOrderBlock(bearishOB)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (hasBearishOB)
|
|
{
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawBearishOrderBlock(
|
|
bearishOB,
|
|
ChartID() //
|
|
);
|
|
}
|
|
|
|
//
|
|
bearishOBTime = aBar.time;
|
|
}
|
|
}
|
|
|
|
//
|
|
// FVG ...
|
|
|
|
//
|
|
bool hasBullishFVG = bullishFVG.IsValid();
|
|
if (!hasBullishFVG)
|
|
{
|
|
//
|
|
hasBullishFVG =
|
|
//
|
|
aBar.HasBullishFVG(
|
|
bullishFVGUpper,
|
|
bullishFVGLower //
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (hasBullishFVG)
|
|
{
|
|
//
|
|
bullishFVG = aBar;
|
|
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawBullishFVG(
|
|
bullishFVG,
|
|
bullishFVGUpper,
|
|
bullishFVGLower,
|
|
ChartID() //
|
|
);
|
|
}
|
|
|
|
//
|
|
bullishFVGTime = aBar.time;
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasBearishFVG = bearishFVG.IsValid();
|
|
if (!hasBearishFVG)
|
|
{
|
|
//
|
|
hasBearishFVG =
|
|
//
|
|
aBar.HasBearishFVG(
|
|
bearishFVGUpper,
|
|
bearishFVGLower //
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (hasBearishFVG)
|
|
{
|
|
//
|
|
bearishFVG = aBar;
|
|
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawBearishFVG(
|
|
bearishFVG,
|
|
bearishFVGUpper,
|
|
bearishFVGLower,
|
|
ChartID() //
|
|
);
|
|
}
|
|
|
|
//
|
|
bearishFVGTime = aBar.time;
|
|
}
|
|
}
|
|
|
|
//
|
|
// TREND ...
|
|
|
|
//
|
|
bool hasBullishTrend = bullishTrend.IsValid();
|
|
if (!hasBullishTrend)
|
|
{
|
|
//
|
|
hasBullishTrend = aBar.HasBullishTrend(
|
|
bullishTrendSwingHighs,
|
|
bullishTrendSwingLows,
|
|
false //
|
|
);
|
|
|
|
//
|
|
if (hasBullishTrend)
|
|
{
|
|
//
|
|
bullishTrend = aBar;
|
|
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawBullishTrend(
|
|
bullishTrend,
|
|
bullishTrendSwingHighs,
|
|
bullishTrendSwingLows,
|
|
ChartID() //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasBearishTrend = bearishTrend.IsValid();
|
|
if (!hasBearishTrend)
|
|
{
|
|
//
|
|
hasBearishTrend = aBar.HasBearishTrend(
|
|
bearishTrendSwingHighs,
|
|
bearishTrendSwingLows,
|
|
false //
|
|
);
|
|
|
|
//
|
|
if (hasBearishTrend)
|
|
{
|
|
//
|
|
bearishTrend = aBar;
|
|
|
|
//
|
|
if (mDrawImportantAreas)
|
|
{
|
|
//
|
|
DrawBearishTrend(
|
|
bearishTrend,
|
|
bearishTrendSwingHighs,
|
|
bearishTrendSwingLows,
|
|
ChartID() //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// For Trend ...
|
|
XOHCL tmpHSW[];
|
|
XOHCL tmpLSW[];
|
|
|
|
//
|
|
// Detect Bullish/Bearish Patterns and Trends ...
|
|
|
|
//
|
|
// Bullish ...
|
|
bool hasBullishPower = cBar.HasBullishPower();
|
|
bool hasBullishPattern = HasBullishPattern(cBar);
|
|
bool hasBullishPressure = cBar.HasBullishPressure();
|
|
bool isBullishTrend = cBar.HasBullishTrend(
|
|
tmpHSW,
|
|
tmpLSW,
|
|
true //
|
|
);
|
|
|
|
//
|
|
// Bearish ...
|
|
bool hasBearishPower = cBar.HasBearishPower();
|
|
bool hasBearishPattern = HasBearishPattern(cBar);
|
|
bool hasBearishPressure = cBar.HasBearishPressure();
|
|
bool isBearishTrend = cBar.HasBearishTrend(
|
|
tmpHSW,
|
|
tmpLSW,
|
|
false //
|
|
);
|
|
|
|
//
|
|
// XCHE ...
|
|
|
|
//
|
|
if (cheConditions.long1[pIndex] > 0 &&
|
|
cheConditions.long2[pIndex] > 0 &&
|
|
cheConditions.long1[pIndex] != EMPTY_VALUE &&
|
|
cheConditions.long2[pIndex] != EMPTY_VALUE &&
|
|
!cheConditions.isStrongBullish)
|
|
{
|
|
//
|
|
cheLastLongExitTime = pBar.time;
|
|
cheLastLongExit1 = cheConditions.long1[pIndex];
|
|
cheLastLongExit2 = cheConditions.long2[pIndex];
|
|
}
|
|
|
|
//
|
|
if (cheConditions.short1[pIndex] > 0 &&
|
|
cheConditions.short2[pIndex] > 0 &&
|
|
cheConditions.short1[pIndex] != EMPTY_VALUE &&
|
|
cheConditions.short2[pIndex] != EMPTY_VALUE &&
|
|
!cheConditions.isStrongBearish)
|
|
{
|
|
//
|
|
cheLastShortExitTime = pBar.time;
|
|
cheLastShortExit1 = cheConditions.short1[pIndex];
|
|
cheLastShortExit2 = cheConditions.short2[pIndex];
|
|
}
|
|
|
|
//
|
|
double chhkBullishPower = chhkHelper.GetBullishPower(cIndex);
|
|
double chhkBearishPower = chhkHelper.GetBearishPower(cIndex);
|
|
|
|
//
|
|
double chhkMinBearishHigh = chhkHelper.GetMinBearishHigh(cIndex);
|
|
double chhkMaxBearishHigh = chhkHelper.GetMaxBearishHigh(cIndex);
|
|
double chhkMinBearishLow = chhkHelper.GetMinBearishLow(cIndex);
|
|
double chhkMaxBearishLow = chhkHelper.GetMaxBearishLow(cIndex);
|
|
double chhkMaxBullishHigh = chhkHelper.GetMaxBullishHigh(cIndex);
|
|
double chhkMinBullishHigh = chhkHelper.GetMinBullishHigh(cIndex);
|
|
double chhkMaxBullishLow = chhkHelper.GetMaxBullishLow(cIndex);
|
|
double chhkMinBullishLow = chhkHelper.GetMinBullishLow(cIndex);
|
|
|
|
//
|
|
double chmBullishPower = chmHelper.GetBullishPower(cIndex);
|
|
double chmBearishPower = chmHelper.GetBearishPower(cIndex);
|
|
|
|
//
|
|
double chmMaxBullishFast = chmHelper.GetMaxBullishFast(cIndex);
|
|
double chmMinBullishFast = chmHelper.GetMinBullishFast(cIndex);
|
|
double chmMaxBullishSlow = chmHelper.GetMaxBullishSlow(cIndex);
|
|
double chmMinBullishSlow = chmHelper.GetMinBullishSlow(cIndex);
|
|
double chmMaxBearishFast = chmHelper.GetMaxBearishFast(cIndex);
|
|
double chmMinBearishFast = chmHelper.GetMinBearishFast(cIndex);
|
|
double chmMaxBearishSlow = chmHelper.GetMaxBearishSlow(cIndex);
|
|
double chmMinBearishSlow = chmHelper.GetMinBearishSlow(cIndex);
|
|
|
|
//
|
|
double chstrBullishPower = chstrHelper.GetBullishPower(cIndex);
|
|
double chstrBearishPower = chstrHelper.GetBearishPower(cIndex);
|
|
|
|
//
|
|
double chstrMinBullish = chstrHelper.GetMinBullish(cIndex);
|
|
double chstrMaxBullish = chstrHelper.GetMaxBullish(cIndex);
|
|
double chstrMinBearish = chstrHelper.GetMinBearish(cIndex);
|
|
double chstrMaxBearish = chstrHelper.GetMaxBearish(cIndex);
|
|
|
|
//
|
|
double cheMaxLE = cheHelper.GetMaxLongExit(cIndex);
|
|
double cheMinLE = cheHelper.GetMinLongExit(cIndex);
|
|
double cheMaxSE = cheHelper.GetMaxShortExit(cIndex);
|
|
double cheMinSE = cheHelper.GetMinShortExit(cIndex);
|
|
|
|
//
|
|
int pushers = 0;
|
|
string signallers[];
|
|
|
|
//
|
|
// XCHHK ...
|
|
if (mEnableXCHHK)
|
|
{
|
|
//
|
|
if (chhkConditions.isBullishPowerUp)
|
|
{
|
|
//
|
|
bool chhkHasLong =
|
|
//
|
|
hasBullishPower &&
|
|
cBar.IsBullish() &&
|
|
hasBullishPattern &&
|
|
hasBullishPressure &&
|
|
cheConditions.isStrongBullish &&
|
|
cBar.low > chhkMinBullishHigh &&
|
|
chhkConditions.isBullishPowerUp
|
|
//
|
|
;
|
|
|
|
//
|
|
if (chhkHasLong)
|
|
{
|
|
//
|
|
hasLong = chhkHasLong;
|
|
if (hasLong)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHHK",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = chhkMaxBullishLow;
|
|
type = POSITION_TYPE_BUY;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (chhkConditions.isBearishPowerUp)
|
|
{
|
|
//
|
|
bool chhkHasShort =
|
|
//
|
|
hasBearishPower &&
|
|
cBar.IsBearish() &&
|
|
hasBearishPattern &&
|
|
hasBearishPressure &&
|
|
cheConditions.isStrongBearish &&
|
|
cBar.high < chhkMaxBearishLow &&
|
|
chhkConditions.isBearishPowerUp
|
|
//
|
|
;
|
|
|
|
//
|
|
if (chhkHasShort)
|
|
{
|
|
//
|
|
hasShort = chhkHasShort;
|
|
if (hasShort)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHHK",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = chhkMinBearishHigh;
|
|
type = POSITION_TYPE_SELL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// XCHM ...
|
|
if (mEnableXCHM)
|
|
{
|
|
//
|
|
if (chmConditions.isBullishPowerUp)
|
|
{
|
|
//
|
|
bool chmHasLong =
|
|
//
|
|
hasBullishPower &&
|
|
cBar.IsBullish() &&
|
|
hasBullishPattern &&
|
|
hasBullishPressure &&
|
|
cBar.low > chmMinBullishFast &&
|
|
cheConditions.isStrongBullish &&
|
|
chmConditions.isBullishPowerUp
|
|
//
|
|
;
|
|
|
|
//
|
|
if (chmHasLong)
|
|
{
|
|
//
|
|
hasLong = chmHasLong;
|
|
if (hasLong)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHM",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = chmMaxBullishFast;
|
|
type = POSITION_TYPE_BUY;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (chmConditions.isBearishPowerUp)
|
|
{
|
|
//
|
|
bool chmHasShort =
|
|
//
|
|
hasBearishPower &&
|
|
cBar.IsBearish() &&
|
|
hasBearishPattern &&
|
|
hasBearishPressure &&
|
|
cBar.high < chmMaxBearishFast &&
|
|
cheConditions.isStrongBearish &&
|
|
chmConditions.isBearishPowerUp
|
|
//
|
|
;
|
|
|
|
//
|
|
if (chmHasShort)
|
|
{
|
|
//
|
|
hasShort = chmHasShort;
|
|
if (hasShort)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHM",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = chmMinBearishFast;
|
|
type = POSITION_TYPE_SELL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// XCHSTR ...
|
|
if (mEnableXCHSTR)
|
|
{
|
|
//
|
|
if (chstrConditions.isBullishPowerUp)
|
|
{
|
|
//
|
|
bool chstrHasLong =
|
|
//
|
|
hasBullishPower &&
|
|
cBar.IsBullish() &&
|
|
hasBullishPattern &&
|
|
hasBullishPressure &&
|
|
cBar.low > chstrMinBullish &&
|
|
cheConditions.isStrongBullish &&
|
|
chstrConditions.isBullishPowerUp
|
|
//
|
|
;
|
|
|
|
//
|
|
if (chstrHasLong)
|
|
{
|
|
//
|
|
hasLong = chstrHasLong;
|
|
if (hasLong)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHSTR",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = chstrMinBullish;
|
|
type = POSITION_TYPE_BUY;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (chstrConditions.isBearishPowerUp)
|
|
{
|
|
//
|
|
bool chstrHasShort =
|
|
//
|
|
hasBearishPower &&
|
|
cBar.IsBearish() &&
|
|
hasBearishPattern &&
|
|
hasBearishPressure &&
|
|
cBar.high < chstrMaxBearish &&
|
|
cheConditions.isStrongBearish &&
|
|
chstrConditions.isBearishPowerUp
|
|
//
|
|
;
|
|
|
|
//
|
|
if (chstrHasShort)
|
|
{
|
|
//
|
|
hasShort = chstrHasShort;
|
|
if (hasShort)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHSTR",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = chstrMaxBearish;
|
|
type = POSITION_TYPE_SELL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// XCHE ...
|
|
if (mEnableXCHE)
|
|
{
|
|
//
|
|
if (cheConditions.isStrongBullish)
|
|
{
|
|
//
|
|
bool cheHasLong =
|
|
//
|
|
HasCheLast() &&
|
|
cheMinLE > 0 &&
|
|
hasBullishPower &&
|
|
cBar.IsBullish() &&
|
|
hasBullishPattern &&
|
|
hasBullishPressure &&
|
|
cheMinLE > GetMaxCHELast() &&
|
|
cheConditions.isStrongBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (cheHasLong)
|
|
{
|
|
//
|
|
hasLong = cheHasLong;
|
|
if (hasLong)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHE",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = cheMinLE;
|
|
type = POSITION_TYPE_BUY;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (cheConditions.isStrongBearish)
|
|
{
|
|
//
|
|
bool cheHasShort =
|
|
//
|
|
HasCheLast() &&
|
|
cheMaxSE > 0 &&
|
|
hasBearishPower &&
|
|
cBar.IsBearish() &&
|
|
hasBearishPattern &&
|
|
hasBearishPressure &&
|
|
cheMaxSE < GetMinCHELast() &&
|
|
cheConditions.isStrongBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (cheHasShort)
|
|
{
|
|
//
|
|
hasShort = cheHasShort;
|
|
if (hasShort)
|
|
{
|
|
//
|
|
pushers++;
|
|
Add(
|
|
"XCHE",
|
|
signallers //
|
|
);
|
|
|
|
//
|
|
sl = cheMaxSE;
|
|
type = POSITION_TYPE_SELL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
result = hasLong || hasShort;
|
|
if (!result)
|
|
{
|
|
//
|
|
CheckSupportValidation();
|
|
CheckResistanceValidation();
|
|
|
|
//
|
|
CheckBullishOBValidation();
|
|
CheckBearishOBValidation();
|
|
|
|
//
|
|
CheckBullishFVGValidation();
|
|
CheckBearishFVgValidation();
|
|
|
|
//
|
|
CheckBullishTrendValidation();
|
|
CheckBearishTrendValidation();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (hasSupport)
|
|
{
|
|
//
|
|
supportTime = NULL;
|
|
isSupportTested = false;
|
|
RemoveSupport(support);
|
|
support.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasResistance)
|
|
{
|
|
//
|
|
resistanceTime = NULL;
|
|
isResistanceTested = false;
|
|
RemoveResistance(resistance);
|
|
resistance.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasBullishOB)
|
|
{
|
|
//
|
|
bullishOBTime = NULL;
|
|
RemoveBullishOrderBlock(bullishOB);
|
|
bullishOB.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasBearishOB)
|
|
{
|
|
//
|
|
bearishOBTime = NULL;
|
|
RemoveBearishOrderBlock(bearishOB);
|
|
bearishOB.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasBullishFVG)
|
|
{
|
|
//
|
|
bullishFVGUpper = 0;
|
|
bullishFVGLower = 0;
|
|
bullishFVGTime = NULL;
|
|
RemoveBullishFVG(bullishFVG);
|
|
bullishFVG.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasBearishFVG)
|
|
{
|
|
//
|
|
bearishFVGUpper = 0;
|
|
bearishFVGLower = 0;
|
|
bearishFVGTime = NULL;
|
|
RemoveBullishFVG(bearishFVG);
|
|
bearishFVG.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasBullishTrend)
|
|
{
|
|
//
|
|
RemoveBullishTrend(bullishTrend);
|
|
bullishTrend.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasBearishTrend)
|
|
{
|
|
//
|
|
RemoveBearishTrend(bearishTrend);
|
|
bearishTrend.Clean();
|
|
}
|
|
|
|
//
|
|
// Retrieve Entry Price based on Position Type ...
|
|
entry = GetEntry(mSymbol, type);
|
|
|
|
//
|
|
// Calculate TP and SL ...
|
|
// based on Strategy ...
|
|
// only when on of TP or SL Provides, using provided R2R ...
|
|
if ((tp <= 0 && sl > 0) || (tp > 0 && sl <= 0))
|
|
{
|
|
CalculateTPSLByPrice(
|
|
sl,
|
|
tp,
|
|
type,
|
|
entry,
|
|
r2r //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Prepare Signal ...
|
|
result = signal.Prepare(
|
|
mSymbol,
|
|
signallers[0],
|
|
mPeriod,
|
|
type,
|
|
mode,
|
|
entry,
|
|
mVolume,
|
|
sl,
|
|
tp //
|
|
);
|
|
if (result)
|
|
{
|
|
signal.pushers = pushers;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
ENUM_TIMEFRAMES mAnalizePeriod; // Important Area Detect Time Frame
|
|
|
|
//
|
|
bool mDrawImportantAreas; // Draw Important Areas where Founded in Analyzing Time Frame
|
|
|
|
//
|
|
bool mEnableXCHE; // Enable XCHE Signaller
|
|
bool mEnableXCHM; // Enable XCHM Signaller
|
|
bool mEnableXCHHK; // Enable XCHHK Signaller
|
|
bool mEnableXCHSTR; // Enable XCHSTR Signaller
|
|
|
|
//
|
|
XOHCL support;
|
|
XOHCL resistance;
|
|
XOHCL bullishOB;
|
|
XOHCL bearishOB;
|
|
|
|
//
|
|
double bullishFVGUpper;
|
|
double bullishFVGLower;
|
|
XOHCL bullishFVG;
|
|
|
|
//
|
|
double bearishFVGUpper;
|
|
double bearishFVGLower;
|
|
XOHCL bearishFVG;
|
|
|
|
//
|
|
XOHCL bullishTrendSwingHighs[];
|
|
XOHCL bullishTrendSwingLows[];
|
|
XOHCL bullishTrend;
|
|
|
|
//
|
|
XOHCL bearishTrendSwingHighs[];
|
|
XOHCL bearishTrendSwingLows[];
|
|
XOHCL bearishTrend;
|
|
|
|
//
|
|
// XPV ...
|
|
XPVInputs pvInputs;
|
|
XSCXPVHelper *pvHelper;
|
|
|
|
//
|
|
// XHK ...
|
|
XCHHKInputs chhkInputs;
|
|
XSCXCHHKHelper *chhkHelper;
|
|
|
|
//
|
|
// XCHMA ...
|
|
XCHMInputs chmInputs;
|
|
XSCXCHMHelper *chmHelper;
|
|
|
|
//
|
|
// XSTR ...
|
|
XCHSTRInputs chstrInputs;
|
|
XSCXCHSTRHelper *chstrHelper;
|
|
|
|
//
|
|
// XCHCHE ...
|
|
XCHCHEInputs chcheInputs;
|
|
XSCXCHCHEHelper *chcheHelper;
|
|
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Install all Helpers and Prepare all
|
|
// Configurations for required Indicators ...
|
|
void PrepareRequirements()
|
|
{
|
|
//
|
|
mDrawImportantAreas = false;
|
|
|
|
//
|
|
mEnableXCHE = false;
|
|
mEnableXCHM = true;
|
|
mEnableXCHHK = true;
|
|
mEnableXCHSTR = true;
|
|
|
|
//
|
|
support.Clean();
|
|
supportTime = NULL;
|
|
isSupportTested = false;
|
|
|
|
//
|
|
resistance.Clean();
|
|
resistanceTime = NULL;
|
|
isResistanceTested = false;
|
|
|
|
//
|
|
// Short ...
|
|
ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
|
|
ENUM_TIMEFRAMES scPeriod = NULL; // PERIOD_M20; // Time Period
|
|
|
|
//
|
|
// Medium ...
|
|
ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
|
|
ENUM_TIMEFRAMES mcPeriod = NULL; // PERIOD_M30; // Time Period
|
|
|
|
//
|
|
// Long ...
|
|
ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
|
|
ENUM_TIMEFRAMES lcPeriod = NULL; // PERIOD_H1; // Time Period
|
|
|
|
//
|
|
// Hind ...
|
|
ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // X_PERIOD_MANUALLY; // How to Find Period
|
|
ENUM_TIMEFRAMES hcPeriod = NULL; // PERIOD_H2; // Time Period
|
|
|
|
//
|
|
// XPV ...
|
|
|
|
//
|
|
pvInputs.Default();
|
|
|
|
//
|
|
pvInputs.scMethod = scMethod;
|
|
pvInputs.scPeriod = scPeriod;
|
|
pvInputs.mcMethod = mcMethod;
|
|
pvInputs.mcPeriod = mcPeriod;
|
|
pvInputs.lcMethod = lcMethod;
|
|
pvInputs.lcPeriod = lcPeriod;
|
|
pvInputs.hcMethod = hcMethod;
|
|
pvInputs.hcPeriod = hcPeriod;
|
|
|
|
//
|
|
pvInputs.showPeaksAndVales = true;
|
|
pvInputs.showLevels = false;
|
|
pvInputs.showConsolidations = false;
|
|
pvInputs.showFibo1Levels = false;
|
|
pvInputs.showFibo2Levels = false;
|
|
pvInputs.showFibo3Levels = false;
|
|
pvInputs.showFibo4Levels = false;
|
|
pvInputs.showFibo5Levels = false;
|
|
|
|
//
|
|
pvHelper = new XSCXPVHelper();
|
|
pvHelper.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
pvInputs //
|
|
);
|
|
|
|
//
|
|
// XCHM ...
|
|
|
|
//
|
|
chmInputs.Default();
|
|
|
|
//
|
|
chmInputs.scMethod = scMethod;
|
|
chmInputs.scPeriod = scPeriod;
|
|
chmInputs.mcMethod = mcMethod;
|
|
chmInputs.mcPeriod = mcPeriod;
|
|
chmInputs.lcMethod = lcMethod;
|
|
chmInputs.lcPeriod = lcPeriod;
|
|
chmInputs.hcMethod = hcMethod;
|
|
chmInputs.hcPeriod = hcPeriod;
|
|
|
|
//
|
|
chmInputs.showFast = false;
|
|
chmInputs.showSlow = false;
|
|
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 = scMethod;
|
|
chhkInputs.scPeriod = scPeriod;
|
|
chhkInputs.mcMethod = mcMethod;
|
|
chhkInputs.mcPeriod = mcPeriod;
|
|
chhkInputs.lcMethod = lcMethod;
|
|
chhkInputs.lcPeriod = lcPeriod;
|
|
chhkInputs.hcMethod = hcMethod;
|
|
chhkInputs.hcPeriod = hcPeriod;
|
|
|
|
//
|
|
chhkInputs.ignoreShadows = true;
|
|
|
|
//
|
|
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 = scMethod;
|
|
chstrInputs.scPeriod = scPeriod;
|
|
chstrInputs.mcMethod = mcMethod;
|
|
chstrInputs.mcPeriod = mcPeriod;
|
|
chstrInputs.lcMethod = lcMethod;
|
|
chstrInputs.lcPeriod = lcPeriod;
|
|
chstrInputs.hcMethod = hcMethod;
|
|
chstrInputs.hcPeriod = hcPeriod;
|
|
|
|
//
|
|
chstrInputs.showCurrent = false;
|
|
chstrInputs.showShort = false;
|
|
chstrInputs.showMedium = false;
|
|
chstrInputs.showLong = false;
|
|
chstrInputs.showHind = false;
|
|
|
|
//
|
|
chstrHelper = new XSCXCHSTRHelper();
|
|
chstrHelper.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
chstrInputs //
|
|
);
|
|
|
|
//
|
|
// XCHCHE ...
|
|
|
|
//
|
|
chcheInputs.Default();
|
|
|
|
//
|
|
chcheInputs.showCurrentLE1 = true;
|
|
chcheInputs.showCurrentLE2 = true;
|
|
chcheInputs.showCurrentSE1 = true;
|
|
chcheInputs.showCurrentSE2 = true;
|
|
chcheInputs.showShortLE1 = true;
|
|
chcheInputs.showShortLE2 = true;
|
|
chcheInputs.showShortSE1 = true;
|
|
chcheInputs.showShortSE2 = true;
|
|
chcheInputs.showMediumLE1 = true;
|
|
chcheInputs.showMediumLE2 = true;
|
|
chcheInputs.showMediumSE1 = true;
|
|
chcheInputs.showMediumSE2 = true;
|
|
chcheInputs.showLongLE1 = true;
|
|
chcheInputs.showLongLE2 = true;
|
|
chcheInputs.showLongSE1 = true;
|
|
chcheInputs.showLongSE2 = true;
|
|
chcheInputs.showHindLE1 = true;
|
|
chcheInputs.showHindLE2 = true;
|
|
chcheInputs.showHindSE1 = true;
|
|
chcheInputs.showHindSE2 = true;
|
|
|
|
//
|
|
chcheHelper = new XSCXCHEHelper();
|
|
chcheHelper.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
chcheInputs //
|
|
);
|
|
}
|
|
|
|
//
|
|
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();
|
|
}
|
|
|
|
//
|
|
datetime bullishOBTime;
|
|
void CheckBullishOBValidation()
|
|
{
|
|
//
|
|
if (!IsValid(bullishOBTime))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishOBTime))) / PeriodSeconds(mPeriod));
|
|
if (age >= 50)
|
|
{
|
|
//
|
|
bullishOBTime = NULL;
|
|
RemoveBullishOrderBlock(bullishOB);
|
|
bullishOB.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
datetime bearishOBTime;
|
|
void CheckBearishOBValidation()
|
|
{
|
|
//
|
|
if (!IsValid(bearishOBTime))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishOBTime))) / PeriodSeconds(mPeriod));
|
|
if (age >= 50)
|
|
{
|
|
//
|
|
bearishOBTime = NULL;
|
|
RemoveBearishOrderBlock(bearishOB);
|
|
bearishOB.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
datetime bullishFVGTime;
|
|
void CheckBullishFVGValidation()
|
|
{
|
|
//
|
|
if (!IsValid(bullishFVGTime))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishFVGTime))) / PeriodSeconds(mPeriod));
|
|
if (age >= 50)
|
|
{
|
|
//
|
|
bullishFVGTime = NULL;
|
|
RemoveBullishFVG(bullishFVG);
|
|
bullishFVG.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
datetime bearishFVGTime;
|
|
void CheckBearishFVgValidation()
|
|
{
|
|
//
|
|
if (!IsValid(bearishFVGTime))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishFVGTime))) / PeriodSeconds(mPeriod));
|
|
if (age >= 50)
|
|
{
|
|
//
|
|
bearishFVGTime = NULL;
|
|
RemoveBearishFVG(bearishFVG);
|
|
bearishFVG.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
void CheckBullishTrendValidation()
|
|
{
|
|
//
|
|
// TODO: Complete this ...
|
|
}
|
|
|
|
//
|
|
void CheckBearishTrendValidation()
|
|
{
|
|
//
|
|
// TODO: Complete this ...
|
|
}
|
|
|
|
//
|
|
// XCHE Custom Data ...
|
|
|
|
//
|
|
double cheLastLongExit1;
|
|
double cheLastLongExit2;
|
|
datetime cheLastLongExitTime;
|
|
double GetMaxCHELastLong()
|
|
{
|
|
//
|
|
return MathMax(
|
|
cheLastLongExit1,
|
|
cheLastLongExit2 //
|
|
);
|
|
}
|
|
double GetMinCHELastLong()
|
|
{
|
|
//
|
|
return MathMin(
|
|
cheLastLongExit1,
|
|
cheLastLongExit2 //
|
|
);
|
|
}
|
|
|
|
//
|
|
double cheLastShortExit1;
|
|
double cheLastShortExit2;
|
|
datetime cheLastShortExitTime;
|
|
double GetMaxCHELastShort()
|
|
{
|
|
//
|
|
return MathMax(
|
|
cheLastShortExit1,
|
|
cheLastShortExit2 //
|
|
);
|
|
}
|
|
double GetMinCHELastShort()
|
|
{
|
|
//
|
|
return MathMin(
|
|
cheLastShortExit1,
|
|
cheLastShortExit2 //
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetMaxCHELast()
|
|
{
|
|
//
|
|
return MathMax(
|
|
GetMaxCHELastLong(),
|
|
GetMaxCHELastShort() //
|
|
);
|
|
}
|
|
double GetMinCHELast()
|
|
{
|
|
//
|
|
return MathMin(
|
|
GetMinCHELastLong(),
|
|
GetMinCHELastShort() //
|
|
);
|
|
}
|
|
|
|
//
|
|
bool HasCheLast()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
IsValid(cheLastLongExitTime) ||
|
|
IsValid(cheLastShortExitTime);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |