cleanup and refocused workspace for using on XCATBEA Projects ...
This commit is contained in:
@@ -0,0 +1,955 @@
|
||||
|
||||
//
|
||||
// Detect Trigger Block ...
|
||||
bool DetectTriggerBlock(
|
||||
//
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period,
|
||||
//
|
||||
XTriggerBlock &tb,
|
||||
//
|
||||
XCBarAnalyser *barAnalyser,
|
||||
//
|
||||
// Required Buffers ...
|
||||
const double &_atrBuffer[],
|
||||
const double &_rsiBuffer[],
|
||||
const double &_adxBuffer[],
|
||||
const double &_adxpBuffer[],
|
||||
const double &_adxnBuffer[],
|
||||
const double &_peakBuffer[],
|
||||
const double &_valeBuffer[],
|
||||
const double &_deltaBuffer[],
|
||||
const double &_sarBuffer[],
|
||||
const double &_sarStateBuffer[],
|
||||
const double &_trendBuffer[],
|
||||
const double &_trendStateBuffer[],
|
||||
const double &_atrUpperBuffer[],
|
||||
const double &_atrLowerBuffer[],
|
||||
const double &_sBarOpenSBuffer[],
|
||||
const double &_sBarCloseBuffer[],
|
||||
const double &_hkSBarOpenBuffer[],
|
||||
const double &_hkSBarCloseBuffer[],
|
||||
const double &_peakGoldenBuffer[],
|
||||
const double &_valeGoldenBuffer[],
|
||||
const double &_deltaSignalBuffer[],
|
||||
const double &_bullishVolumeSignalBuffer[],
|
||||
const double &_bearishVolumeSignalBuffer[],
|
||||
//
|
||||
int barIndex,
|
||||
//
|
||||
int _r2r,
|
||||
double _slAtrMultiplier,
|
||||
//
|
||||
// Configs ...
|
||||
double _rsiOBLevel,
|
||||
double _rsiOSLevel,
|
||||
double _adxThreshold,
|
||||
//
|
||||
// Validators ...
|
||||
//
|
||||
bool _forceOBBarType = false,
|
||||
bool _forceFVGBarType = false,
|
||||
bool _forceHasSwing = false,
|
||||
bool _forceHasFLiquidity = false,
|
||||
bool _forceHasRLiquidity = false,
|
||||
bool _validateGapSequence = false,
|
||||
bool _validateBlockEdgeBreakout = false,
|
||||
//
|
||||
// Filters ...
|
||||
bool _filterBasedOnPV = false,
|
||||
bool _filterBasedOnSar = false,
|
||||
bool _filterBasedOnRSI = false,
|
||||
bool _filterBasedOnADX = false,
|
||||
bool _filterBasedOnATR = false,
|
||||
bool _filterBasedOnTrend = false,
|
||||
bool _filterBasedOnDelta = false,
|
||||
bool _filterBasedOnVolume = false,
|
||||
bool _filterBasedOnSignalBar = false,
|
||||
bool _filterBasedOnHKSignalBar = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Custom Configs ...
|
||||
|
||||
// //
|
||||
// _r2r = 2;
|
||||
// _slAtrMultiplier = 1;
|
||||
|
||||
// //
|
||||
// // Validators ...
|
||||
// _forceHasSwing = true;
|
||||
// _forceOBBarType = true;
|
||||
// _forceFVGBarType = true;
|
||||
// _validateGapSequence = true;
|
||||
|
||||
// //
|
||||
// _forceHasFLiquidity = false;
|
||||
// _forceHasRLiquidity = false;
|
||||
// _validateBlockEdgeBreakout = true;
|
||||
|
||||
// //
|
||||
// // Filters ...
|
||||
// _filterBasedOnPV = true;
|
||||
// _filterBasedOnATR = true;
|
||||
// _filterBasedOnDelta = true;
|
||||
// _filterBasedOnVolume = true;
|
||||
|
||||
// //
|
||||
// _filterBasedOnSar = true;
|
||||
// _filterBasedOnRSI = false;
|
||||
// _filterBasedOnADX = false;
|
||||
// _filterBasedOnTrend = false;
|
||||
// _filterBasedOnSignalBar = true;
|
||||
// _filterBasedOnHKSignalBar = true;
|
||||
|
||||
//
|
||||
tb.Clean();
|
||||
|
||||
//
|
||||
result = barAnalyser != NULL;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int zIDX = 0;
|
||||
bool has = false;
|
||||
bool isDone = false;
|
||||
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Retrieve Required Bars ...
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
XOHCL zBar; // Current Start Checking Bar (Usually Used for Triggering) ...
|
||||
has = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
// Detect Based Order Block ...
|
||||
has =
|
||||
has &&
|
||||
barAnalyser.IsOB(
|
||||
zBar,
|
||||
tb.ob,
|
||||
_forceFVGBarType, // Force FVG Bar Type ...
|
||||
_forceOBBarType // Force Block Two Bar Checking ...
|
||||
);
|
||||
|
||||
//
|
||||
// Detect Based Fair Value Gap ...
|
||||
has =
|
||||
has &&
|
||||
barAnalyser.IsFVG(
|
||||
zBar,
|
||||
tb.fvg,
|
||||
_forceFVGBarType // Force FVG Bar Type ...
|
||||
);
|
||||
|
||||
//
|
||||
// Clone Trigger Block ...
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
tb.trigger = tb.ob;
|
||||
tb.trigger.type = "XTRGB";
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish =
|
||||
has &&
|
||||
tb.IsBullish();
|
||||
|
||||
//
|
||||
bool isBearish =
|
||||
has &&
|
||||
tb.IsBearish();
|
||||
|
||||
//
|
||||
int toIDX = tb.ToIndex();
|
||||
int fromIDX = tb.FromIndex();
|
||||
|
||||
//
|
||||
// Verifications and Filters ...
|
||||
|
||||
//
|
||||
int loopback = 144;
|
||||
|
||||
//
|
||||
// Forces ...
|
||||
|
||||
//
|
||||
// Force Has Proper Swing ...
|
||||
if (has &&
|
||||
_forceHasSwing)
|
||||
{
|
||||
//
|
||||
XOHCL iPBar;
|
||||
XOHCL iP2Bar;
|
||||
toIDX = tb.ToIndex();
|
||||
fromIDX = tb.FromIndex();
|
||||
for (int i = toIDX; i <= fromIDX; i++)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ...
|
||||
isDone = iBar.Init(
|
||||
zBar.symbol,
|
||||
zBar.period,
|
||||
i //
|
||||
);
|
||||
isDone =
|
||||
isDone &&
|
||||
iBar.GetPreviousBar(iPBar);
|
||||
isDone =
|
||||
isDone &&
|
||||
iPBar.GetPreviousBar(iP2Bar);
|
||||
isDone =
|
||||
isDone &&
|
||||
barAnalyser.IsSimpleSwing(
|
||||
iBar,
|
||||
iDir //
|
||||
) &&
|
||||
iDir == tb.GetDirection();
|
||||
if (isDone)
|
||||
{
|
||||
//
|
||||
bool canSet =
|
||||
!tb.swingBar.IsValid()
|
||||
? true
|
||||
: (isBullish
|
||||
? tb.swingBar.low > iP2Bar.low
|
||||
: tb.swingBar.high < iP2Bar.high);
|
||||
if (canSet)
|
||||
{
|
||||
tb.swingBar = iP2Bar;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
iPBar.Clean();
|
||||
iP2Bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
has = tb.swingBar.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
// Force Has Liquidity ...
|
||||
// TODO: Add Validation based on Liquidities
|
||||
// if necessary ...
|
||||
if (has &&
|
||||
(_forceHasFLiquidity ||
|
||||
_forceHasRLiquidity))
|
||||
{
|
||||
//
|
||||
toIDX = tb.ToIndex();
|
||||
fromIDX = tb.FromIndex();
|
||||
for (int i = toIDX; i < fromIDX + loopback; i++)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ...
|
||||
isDone = iBar.Init(
|
||||
zBar.symbol,
|
||||
zBar.period,
|
||||
i //
|
||||
);
|
||||
|
||||
//
|
||||
bool isRejected =
|
||||
isDone &&
|
||||
barAnalyser.IsRejected(
|
||||
iBar,
|
||||
iDir,
|
||||
false, // Force Bar Type ...
|
||||
true // Force Fibo Pressure ...
|
||||
);
|
||||
|
||||
//
|
||||
// Following Liquidity ...
|
||||
bool isFLiq =
|
||||
isDone &&
|
||||
isRejected &&
|
||||
iDir == tb.GetDirection() &&
|
||||
(isBullish
|
||||
? iBar.low < tb.trigger.lower
|
||||
: iBar.high > tb.trigger.upper);
|
||||
if (isFLiq &&
|
||||
_forceHasFLiquidity &&
|
||||
!tb.fLiquidity.IsValid())
|
||||
{
|
||||
//
|
||||
FillLiquidity(
|
||||
iBar,
|
||||
iDir,
|
||||
tb.fLiquidity,
|
||||
tb.trigger.to //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Reversal Liquidity ...
|
||||
bool isRLiq =
|
||||
isDone &&
|
||||
isRejected &&
|
||||
Opposit(iDir) == tb.GetDirection() &&
|
||||
(isBullish
|
||||
? iBar.low > tb.trigger.upper
|
||||
: iBar.high < tb.trigger.lower);
|
||||
if (isRLiq &&
|
||||
_forceHasRLiquidity &&
|
||||
!tb.rLiquidity.IsValid())
|
||||
{
|
||||
//
|
||||
FillLiquidity(
|
||||
iBar,
|
||||
iDir,
|
||||
tb.rLiquidity,
|
||||
tb.trigger.to //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
isDone =
|
||||
(!_forceHasFLiquidity
|
||||
? true
|
||||
: tb.fLiquidity.IsValid()) &&
|
||||
(!_forceHasRLiquidity
|
||||
? true
|
||||
: tb.rLiquidity.IsValid());
|
||||
if (isDone)
|
||||
{
|
||||
//
|
||||
iBar.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
has =
|
||||
(!_forceHasFLiquidity
|
||||
? true
|
||||
: tb.fLiquidity.IsValid()) &&
|
||||
(!_forceHasRLiquidity
|
||||
? true
|
||||
: tb.rLiquidity.IsValid());
|
||||
}
|
||||
|
||||
//
|
||||
// Validations ...
|
||||
|
||||
//
|
||||
// Validating Gap Sequence means
|
||||
// Gap Bars must Follow each Other ...
|
||||
if (has &&
|
||||
_validateGapSequence)
|
||||
{
|
||||
//
|
||||
XOHCL iPBar;
|
||||
toIDX = tb.fvg.ToIndex();
|
||||
fromIDX = tb.fvg.FromIndex();
|
||||
|
||||
//
|
||||
for (int i = toIDX; i < fromIDX - 1; i++)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ...
|
||||
has = iBar.Init(
|
||||
zBar.symbol,
|
||||
zBar.period,
|
||||
i //
|
||||
);
|
||||
has =
|
||||
has &&
|
||||
iBar.GetPreviousBar(iPBar);
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? iBar.low > iPBar.low
|
||||
: iBar.high < iPBar.high);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
iPBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Block Edge Breakout ...
|
||||
if (has &&
|
||||
_validateBlockEdgeBreakout)
|
||||
{
|
||||
//
|
||||
has = tb.fvg.ToBar(iBar);
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? (iBar.GetDown() < tb.ob.upper &&
|
||||
iBar.GetUp() > tb.ob.upper)
|
||||
: (iBar.GetDown() < tb.ob.lower &&
|
||||
iBar.GetUp() > tb.ob.lower));
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Filters ...
|
||||
|
||||
//
|
||||
// PV ...
|
||||
if (has &&
|
||||
_filterBasedOnPV)
|
||||
{
|
||||
//
|
||||
double iPeak = _peakBuffer[barIndex];
|
||||
double iPPeak = _peakBuffer[barIndex + 1];
|
||||
double iP2Peak = _peakBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
double iPeakGolden = _peakGoldenBuffer[barIndex];
|
||||
double iPPeakGolden = _peakGoldenBuffer[barIndex + 1];
|
||||
double iP2PeakGolden = _peakGoldenBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
double iVale = _valeBuffer[barIndex];
|
||||
double iPVale = _valeBuffer[barIndex + 1];
|
||||
double iP2Vale = _valeBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
double iValeGolden = _valeGoldenBuffer[barIndex];
|
||||
double iPValeGolden = _valeGoldenBuffer[barIndex + 1];
|
||||
double iP2ValeGolden = _valeGoldenBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
// TODO: Fix this ...
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? (tb.trigger.lower <= iVale &&
|
||||
tb.trigger.upper < iPeak
|
||||
// || tb.trigger.lower <= iValeGolden
|
||||
)
|
||||
: (tb.trigger.upper >= iPeak &&
|
||||
tb.trigger.lower > iVale
|
||||
// || tb.trigger.upper >= iPeakGolden
|
||||
));
|
||||
}
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
if (has &&
|
||||
_filterBasedOnSar)
|
||||
{
|
||||
//
|
||||
double iSarState = _sarStateBuffer[barIndex];
|
||||
double iPSarState = _sarStateBuffer[barIndex + 1];
|
||||
double iP2SarState = _sarStateBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
bool isSarBullish = iSarState > 0;
|
||||
bool isPSarBullish = iPSarState > 0;
|
||||
bool isP2SarBullish = iP2SarState > 0;
|
||||
|
||||
//
|
||||
bool isSarBearish = iSarState < 0;
|
||||
bool isPSarBearish = iPSarState < 0;
|
||||
bool isP2SarBearish = iP2SarState < 0;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish =
|
||||
isSarBullish &&
|
||||
!isPSarBullish;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBearish =
|
||||
isSarBearish &&
|
||||
!isPSarBearish;
|
||||
|
||||
//
|
||||
bool isSarPSwitchedToBullish =
|
||||
isPSarBullish &&
|
||||
!isP2SarBullish;
|
||||
|
||||
//
|
||||
bool isSarPSwitchedToBearish =
|
||||
isPSarBearish &&
|
||||
!isP2SarBearish;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? (isSarSwitchedToBullish ||
|
||||
isSarPSwitchedToBullish)
|
||||
: (isSarSwitchedToBearish ||
|
||||
isSarPSwitchedToBearish));
|
||||
}
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
if (has &&
|
||||
_filterBasedOnRSI)
|
||||
{
|
||||
//
|
||||
double rsiTrend = (_rsiOBLevel + _rsiOSLevel) / 2;
|
||||
|
||||
//
|
||||
double iRSI = _rsiBuffer[barIndex];
|
||||
double iPRSI = _rsiBuffer[barIndex + 1];
|
||||
double iP2RSI = _rsiBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
bool isRSICrossedOverOS =
|
||||
iRSI > _rsiOSLevel &&
|
||||
iPRSI <= _rsiOSLevel;
|
||||
|
||||
//
|
||||
bool isRSICrossedUnderOB =
|
||||
iRSI < _rsiOBLevel &&
|
||||
iPRSI >= _rsiOBLevel;
|
||||
|
||||
//
|
||||
bool isPRSICrossedOverOS =
|
||||
iPRSI > _rsiOSLevel &&
|
||||
iP2RSI <= _rsiOSLevel;
|
||||
|
||||
//
|
||||
bool isPRSICrossedUnderOB =
|
||||
iPRSI < _rsiOBLevel &&
|
||||
iP2RSI >= _rsiOBLevel;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? (isRSICrossedOverOS ||
|
||||
isPRSICrossedOverOS)
|
||||
: (isRSICrossedUnderOB ||
|
||||
isPRSICrossedUnderOB));
|
||||
}
|
||||
|
||||
//
|
||||
// ADX ...
|
||||
if (has &&
|
||||
_filterBasedOnADX)
|
||||
{
|
||||
//
|
||||
// ADX ...
|
||||
double iADX = _adxBuffer[barIndex];
|
||||
double iPADX = _adxBuffer[barIndex + 1];
|
||||
double iP2ADX = _adxBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
// ADX +DI ...
|
||||
double iADXP = _adxpBuffer[barIndex];
|
||||
double iPADXP = _adxpBuffer[barIndex + 1];
|
||||
double iP2ADXP = _adxpBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
// ADX -DI ...
|
||||
double iADXN = _adxnBuffer[barIndex];
|
||||
double iPADXN = _adxnBuffer[barIndex + 1];
|
||||
double iP2ADXN = _adxnBuffer[barIndex + 2];
|
||||
|
||||
//
|
||||
// Preparing Conditions ...
|
||||
|
||||
//
|
||||
bool isADXBullish = iADX > _adxThreshold;
|
||||
bool isADXBearish = iADX < _adxThreshold;
|
||||
|
||||
//
|
||||
bool isPADXBullish = iPADX > _adxThreshold;
|
||||
bool isPADXBearish = iPADX < _adxThreshold;
|
||||
|
||||
//
|
||||
bool isP2ADXBullish = iP2ADX > _adxThreshold;
|
||||
bool isP2ADXBearish = iP2ADX < _adxThreshold;
|
||||
|
||||
//
|
||||
bool isADXSwitchedToBullish =
|
||||
isADXBullish &&
|
||||
!isPADXBullish;
|
||||
|
||||
//
|
||||
bool isADXSwitchedToBearish =
|
||||
isADXBearish &&
|
||||
!isPADXBearish;
|
||||
|
||||
//
|
||||
bool isPADXSwitchedToBullish =
|
||||
isPADXBullish &&
|
||||
!isP2ADXBullish;
|
||||
|
||||
//
|
||||
bool isPADXSwitchedToBearish =
|
||||
isPADXBearish &&
|
||||
!isP2ADXBearish;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? (isADXSwitchedToBullish ||
|
||||
isPADXSwitchedToBullish)
|
||||
: (isADXSwitchedToBearish ||
|
||||
isPADXSwitchedToBearish));
|
||||
}
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
if (has &&
|
||||
_filterBasedOnATR)
|
||||
{
|
||||
//
|
||||
fromIDX = tb.FromIndex();
|
||||
double iATRUpper = _atrUpperBuffer[fromIDX];
|
||||
double iATRLower = _atrLowerBuffer[fromIDX];
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? tb.trigger.lower < iATRLower
|
||||
: tb.trigger.upper > iATRUpper);
|
||||
}
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
if (has &&
|
||||
_filterBasedOnTrend)
|
||||
{
|
||||
//
|
||||
double iTrendState = _trendStateBuffer[barIndex];
|
||||
double iPTrendState = _trendStateBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isTrendBullish = iTrendState > 0;
|
||||
bool isPTrendBullish = iPTrendState > 0;
|
||||
|
||||
//
|
||||
bool isTrendBearish = iTrendState < 0;
|
||||
bool isPTrendBearish = iPTrendState < 0;
|
||||
|
||||
//
|
||||
double trends[];
|
||||
int toIDX = tb.ToIndex();
|
||||
int fromIDX = tb.FromIndex();
|
||||
double iTrend = _trendBuffer[toIDX];
|
||||
for (int i = toIDX; i <= fromIDX; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
_trendBuffer[i],
|
||||
trends //
|
||||
);
|
||||
}
|
||||
double trendsMin = GetMin(trends);
|
||||
double trendsMax = GetMax(trends);
|
||||
double trendsAVG = GetAverage(trends);
|
||||
|
||||
//
|
||||
bool isTrendUp =
|
||||
iTrend > trendsMin &&
|
||||
iTrend >= trendsAVG;
|
||||
|
||||
//
|
||||
bool isTrendDown =
|
||||
iTrend < trendsMax &&
|
||||
iTrend <= trendsAVG;
|
||||
|
||||
//
|
||||
bool isTrendSwitchedToBullish =
|
||||
isTrendUp &&
|
||||
isTrendBullish &&
|
||||
!isPTrendBullish;
|
||||
|
||||
//
|
||||
bool isTrendSwitchedToBearish =
|
||||
isTrendDown &&
|
||||
isTrendBearish &&
|
||||
!isPTrendBearish;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? isTrendSwitchedToBullish
|
||||
: isTrendSwitchedToBearish);
|
||||
}
|
||||
|
||||
//
|
||||
// DELTA ...
|
||||
if (has &&
|
||||
_filterBasedOnDelta)
|
||||
{
|
||||
//
|
||||
double iDelta = _deltaBuffer[barIndex];
|
||||
double iPDelta = _deltaBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isDeltaUp = iDelta > iPDelta;
|
||||
bool isDeltaDown = iDelta < iPDelta;
|
||||
|
||||
//
|
||||
double iDeltaSignal = _deltaSignalBuffer[barIndex];
|
||||
double iPDeltaSignal = _deltaSignalBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isDeltaSignalUp = iDeltaSignal > iPDeltaSignal;
|
||||
bool isDeltaSignalDown = iDeltaSignal < iPDeltaSignal;
|
||||
|
||||
//
|
||||
bool isDeltaSwitchedToBullish =
|
||||
isDeltaUp &&
|
||||
isDeltaSignalUp &&
|
||||
iDelta > iDeltaSignal &&
|
||||
iPDelta < iPDeltaSignal;
|
||||
|
||||
//
|
||||
bool isDeltaSwitchedToBearish =
|
||||
isDeltaDown &&
|
||||
isDeltaSignalDown &&
|
||||
iDelta < iDeltaSignal &&
|
||||
iPDelta > iPDeltaSignal;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? isDeltaSwitchedToBullish
|
||||
: isDeltaSwitchedToBearish);
|
||||
}
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
if (has &&
|
||||
_filterBasedOnVolume)
|
||||
{
|
||||
//
|
||||
double iBullishVolumeSignal = _bullishVolumeSignalBuffer[barIndex];
|
||||
double iPBullishVolumeSignal = _bullishVolumeSignalBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isBullishVolumeSignalUp = iBullishVolumeSignal > iPBullishVolumeSignal;
|
||||
bool isBullishVolumeSignalDown = iBullishVolumeSignal < iPBullishVolumeSignal;
|
||||
|
||||
//
|
||||
double iBearishVolumeSignal = _bearishVolumeSignalBuffer[barIndex];
|
||||
double iPBearishVolumeSignal = _bearishVolumeSignalBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isBearishVolumeSignalUp = iBearishVolumeSignal > iPBearishVolumeSignal;
|
||||
bool isBearishVolumeSignalDown = iBearishVolumeSignal < iPBearishVolumeSignal;
|
||||
|
||||
//
|
||||
bool isVolumeSwitchdToBullish =
|
||||
isBullishVolumeSignalUp &&
|
||||
!isBearishVolumeSignalUp &&
|
||||
iBullishVolumeSignal > iBearishVolumeSignal &&
|
||||
iPBullishVolumeSignal < iPBearishVolumeSignal;
|
||||
|
||||
//
|
||||
bool isVolumeSwitchdToBearish =
|
||||
isBearishVolumeSignalUp &&
|
||||
!isBullishVolumeSignalUp &&
|
||||
iBearishVolumeSignal > iBullishVolumeSignal &&
|
||||
iPBearishVolumeSignal < iPBullishVolumeSignal;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? isVolumeSwitchdToBullish
|
||||
: isVolumeSwitchdToBearish);
|
||||
}
|
||||
|
||||
//
|
||||
// SIGNAL Bar ...
|
||||
if (has &&
|
||||
_filterBasedOnSignalBar)
|
||||
{
|
||||
//
|
||||
double iSignalOpen = _sBarOpenSBuffer[barIndex];
|
||||
double iPSignalOpen = _sBarOpenSBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
double iSignalClose = _sBarCloseBuffer[barIndex];
|
||||
double iPSignalClose = _sBarCloseBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isSignalBarBullish = iSignalOpen < iSignalClose;
|
||||
bool isPSignalBarBullish = iPSignalOpen < iPSignalClose;
|
||||
|
||||
//
|
||||
bool isSignalBarBearish = iSignalOpen > iSignalClose;
|
||||
bool isPSignalBarBearish = iPSignalOpen > iPSignalClose;
|
||||
|
||||
//
|
||||
bool isSignalBarSwitchedToBullish =
|
||||
isSignalBarBullish &&
|
||||
!isPSignalBarBullish;
|
||||
|
||||
//
|
||||
bool isSignalBarSwitchedToBearish =
|
||||
isSignalBarBearish &&
|
||||
!isPSignalBarBearish;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? isSignalBarSwitchedToBullish
|
||||
: isSignalBarSwitchedToBearish);
|
||||
}
|
||||
|
||||
//
|
||||
// HK SIGNAL Bar ...
|
||||
if (has &&
|
||||
_filterBasedOnHKSignalBar)
|
||||
{
|
||||
//
|
||||
double iHKSignalOpen = _hkSBarOpenBuffer[barIndex];
|
||||
double iPHKSignalOpen = _hkSBarOpenBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
double iHKSignalClose = _hkSBarCloseBuffer[barIndex];
|
||||
double iPHKSignalClose = _hkSBarCloseBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isHKSignalBarBullish = iHKSignalOpen < iHKSignalClose;
|
||||
bool isPHKSignalBarBullish = iPHKSignalOpen < iPHKSignalClose;
|
||||
|
||||
//
|
||||
bool isHKSignalBarBearish = iHKSignalOpen > iHKSignalClose;
|
||||
bool isPHKSignalBarBearish = iPHKSignalOpen > iPHKSignalClose;
|
||||
|
||||
//
|
||||
bool isHKSignalBarSwitchedToBullish =
|
||||
isHKSignalBarBullish &&
|
||||
!isPHKSignalBarBullish;
|
||||
|
||||
//
|
||||
bool isHKSignalBarSwitchedToBearish =
|
||||
isHKSignalBarBearish &&
|
||||
!isPHKSignalBarBearish;
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? isHKSignalBarSwitchedToBullish
|
||||
: isHKSignalBarSwitchedToBearish);
|
||||
}
|
||||
|
||||
//
|
||||
// Valdating Directional Trending ...
|
||||
bool _filterBasedOnDirection = false;
|
||||
if (has &&
|
||||
_filterBasedOnDirection)
|
||||
{
|
||||
//
|
||||
iBar.Clean();
|
||||
fromIDX = tb.FromIndex();
|
||||
int loopbackForValidating = 30;
|
||||
for (int i = fromIDX; i < fromIDX + loopbackForValidating; i++)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ...
|
||||
iBar.Clean();
|
||||
has = iBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
i //
|
||||
);
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? iBar.high < tb.trigger.upper
|
||||
: iBar.low > tb.trigger.lower);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Update Trigger Block ...
|
||||
if (has)
|
||||
{
|
||||
tb.trigger.from = iBar.time;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Preparing Signal ...
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// CArrayObj *tbObjects = new CArrayObj();
|
||||
// DrawTriggerBlock(
|
||||
// tb,
|
||||
// drawer,
|
||||
// tbObjects,
|
||||
// NULL //
|
||||
// );
|
||||
|
||||
//
|
||||
double targets[];
|
||||
for (int i = 1; i <= _r2r; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(double)i,
|
||||
targets //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double iATR = 0;
|
||||
if (barIndex > 0 &&
|
||||
barIndex < ArraySize(_atrBuffer))
|
||||
{
|
||||
iATR = _atrBuffer[barIndex];
|
||||
}
|
||||
double slAdditional = _slAtrMultiplier * iATR;
|
||||
|
||||
//
|
||||
has = ToSignal(
|
||||
tb.trigger,
|
||||
tb.signal,
|
||||
targets,
|
||||
slAdditional //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
result = has;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
+602
-8
@@ -145,10 +145,13 @@ struct XTriggerBlockValidationRules
|
||||
// Props ...
|
||||
bool forceHasSwing; // Force Block to Has Propper Swing ...
|
||||
bool forceOBBarType; // Force Order Block to Has InDirectional Bars ...
|
||||
int minRequiredOBBar; // Min Required OB Bar ...
|
||||
bool forceFVGBarType; // Force Fair Value Gaps Bars Type ...
|
||||
double maxAllowedRange; // Max Allowed Order Block Range ...
|
||||
double minAllowedRange; // Min Allowed Order Block Range ...
|
||||
bool forceHasFLiquidity; // Force Order Block To Has Reversal Liquidity ...
|
||||
bool forceHasRLiquidity; // Force Order Block to Has Following Liquidity ...
|
||||
int liquidityLoopback; // Liquidity Detection Loopback ...
|
||||
bool validateGapSequence; // Validate Fair Value Gaps Bar Sequences ...
|
||||
bool validateBlockEdgeBreakout; // Validate Order Block Edge Breakeout ...
|
||||
|
||||
@@ -168,6 +171,9 @@ struct XTriggerBlockValidationRules
|
||||
{
|
||||
//
|
||||
maxAllowedRange = 0;
|
||||
minAllowedRange = 0;
|
||||
minRequiredOBBar = 0;
|
||||
liquidityLoopback = 0;
|
||||
forceHasSwing = false;
|
||||
forceOBBarType = false;
|
||||
forceFVGBarType = false;
|
||||
@@ -198,6 +204,9 @@ struct XTriggerBlockFilters
|
||||
bool filterBasedOnSignalBar; // Filter Based on Signal Bar ...
|
||||
bool filterBasedOnHKSignalBar; // Filter Based On HK Signal Bar ...
|
||||
|
||||
//
|
||||
int bosLoopback; // PV Based Filtering BOS Lookup ...
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XTriggerBlockFilters()
|
||||
@@ -224,6 +233,9 @@ struct XTriggerBlockFilters
|
||||
filterBasedOnSignalBar = false;
|
||||
filterBasedOnHKSignalBar = false;
|
||||
|
||||
//
|
||||
bosLoopback = 0;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
@@ -232,7 +244,20 @@ struct XTriggerBlockFilters
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
//
|
||||
/**
|
||||
* Detect Trigger Block ...
|
||||
*
|
||||
* @param helper: XCX121XCatbHelper instance pointer ...
|
||||
* @param barAnalyser: XCBarAnalyser instance pointer ...
|
||||
* @param triggerBlock: XTriggerBlock Refrence, holds Detected Trigger Block ...
|
||||
* @param conditions: X121XCatbConditions Refrence, holds Trigger Block Conditions ...
|
||||
* @param validations: XTriggerBlockValidationRules Refrence, Provides Trigger Block Validation Rules ...
|
||||
* @param filters: XTriggerBlockFilters Refrence, Provides Trigger Block Filters ...
|
||||
* @param barIndex: int, Bar Index ...
|
||||
* @param loopback: int, Loopback for Conditions reading ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectTriggerBlock1(
|
||||
XCX121XCatbHelper *helper,
|
||||
XCBarAnalyser *barAnalyser,
|
||||
@@ -346,8 +371,47 @@ bool DetectTriggerBlock1(
|
||||
//
|
||||
triggerBlock.trigger = triggerBlock.ob;
|
||||
triggerBlock.trigger.type = XTriggerBlockToken;
|
||||
|
||||
//
|
||||
// Update Upper and Lower ...
|
||||
int toIDX = triggerBlock.ob.ToIndex();
|
||||
int fromIDX = triggerBlock.ob.FromIndex();
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
result = iBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
toIDX //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
double iLL = iBar.FindLowest(fromIDX - toIDX, MODE_LOW);
|
||||
double iHH = iBar.FindHighest(fromIDX - toIDX, MODE_HIGH);
|
||||
|
||||
//
|
||||
triggerBlock.trigger.upper = MathMax(iHH, triggerBlock.trigger.upper);
|
||||
triggerBlock.trigger.lower = MathMin(iLL, triggerBlock.trigger.lower);
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Remove this ...
|
||||
// Temparory Testing Configs ...
|
||||
// validations.maxAllowedRange = 200;
|
||||
// validations.forceHasSwing = true;
|
||||
// validations.forceFVGBarType = true;
|
||||
// validations.forceOBBarType = true;
|
||||
// validations.validateGapSequence = true;
|
||||
// validations.validateBlockEdgeBreakout = true;
|
||||
// validations.liquidityLoopback = 144;
|
||||
// validations.forceHasFLiquidity = true;
|
||||
// validations.forceHasRLiquidity = true;
|
||||
|
||||
//
|
||||
// Apply Validations ...
|
||||
if (result)
|
||||
@@ -370,6 +434,11 @@ bool DetectTriggerBlock1(
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Remove this ...
|
||||
filters.bosLoopback = 30;
|
||||
filters.filterBasedOnPV = true;
|
||||
|
||||
//
|
||||
// Apply Filtering ...
|
||||
if (result)
|
||||
@@ -398,17 +467,18 @@ bool DetectTriggerBlock1(
|
||||
result &&
|
||||
triggerBlock.IsValid();
|
||||
|
||||
//
|
||||
// Preparing Signal ...
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Preparing Signal ...
|
||||
if (result) {
|
||||
//
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
|
||||
@@ -422,7 +492,19 @@ bool DetectTriggerBlock1(
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
/**
|
||||
* Validate a Trigger Block ...
|
||||
*
|
||||
* @param helper: XCX121XCatbHelper instance pointer ...
|
||||
* @param barAnalyser: XCBarAnalyser instance pointer ...
|
||||
* @param triggerBlock: XTriggerBlock Refrence, Trigger Block ...
|
||||
* @param conditions: X121XCatbConditions Refrence, Trigger Block Conditions ...
|
||||
* @param validations: XTriggerBlockValidationRules Refrence, Provides Trigger Block Validation Rules ...
|
||||
* @param barIndex: int, Bar Index ...
|
||||
* @param loopback: int, Loopback for Conditions reading ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateTriggerBlock(
|
||||
XCX121XCatbHelper *helper,
|
||||
XCBarAnalyser *barAnalyser,
|
||||
@@ -480,9 +562,389 @@ bool ValidateTriggerBlock(
|
||||
int p3IDX = p2IDX + 1;
|
||||
int p4IDX = p3IDX + 1;
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
int count = 0;
|
||||
int toIDX = -1;
|
||||
int fromIDX = -1;
|
||||
bool has = false;
|
||||
bool isBullish = triggerBlock.IsBullish();
|
||||
bool isBearish = triggerBlock.IsBearish();
|
||||
double points = GetPoints(triggerBlock.ob.symbol);
|
||||
ENUM_X_DIRECTION iDir = triggerBlock.GetDirection();
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Range Validation ...
|
||||
|
||||
//
|
||||
// Max Allowed OB Range ...
|
||||
if (result &&
|
||||
validations.maxAllowedRange > 0)
|
||||
{
|
||||
//
|
||||
double iRange = triggerBlock.ob.GetRange();
|
||||
result = iRange <= (validations.maxAllowedRange * points);
|
||||
}
|
||||
|
||||
//
|
||||
// Min Allowed OB Range ...
|
||||
if (result &&
|
||||
validations.minAllowedRange > 0)
|
||||
{
|
||||
//
|
||||
double iRange = triggerBlock.ob.GetRange();
|
||||
result = iRange >= (validations.maxAllowedRange * points);
|
||||
}
|
||||
|
||||
//
|
||||
// Has Swing ...
|
||||
if (result &&
|
||||
validations.forceHasSwing)
|
||||
{
|
||||
//
|
||||
bool isSwing = false;
|
||||
toIDX = triggerBlock.ToIndex();
|
||||
fromIDX = triggerBlock.FromIndex();
|
||||
ENUM_X_DIRECTION swingDir = X_DIRECTION_NONE;
|
||||
for (int i = toIDX; i <= fromIDX; i++)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ...
|
||||
has = iBar.Init(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
i //
|
||||
);
|
||||
isSwing =
|
||||
has &&
|
||||
barAnalyser
|
||||
.IsSimpleSwing(
|
||||
iBar,
|
||||
swingDir //
|
||||
);
|
||||
if (isSwing &&
|
||||
swingDir == iDir)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
isSwing &&
|
||||
iBar.IsValid() &&
|
||||
swingDir == iDir;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Initialize Swing Bar ...
|
||||
result = triggerBlock
|
||||
.swingBar
|
||||
.Init(
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
iBar.Index() + 2 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Force FVG Bar Types ...
|
||||
if (result &&
|
||||
validations.forceFVGBarType)
|
||||
{
|
||||
//
|
||||
toIDX = triggerBlock.fvg.ToIndex();
|
||||
fromIDX = triggerBlock.fvg.FromIndex();
|
||||
for (int i = toIDX; i < fromIDX; i++)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ...
|
||||
result = iBar.Init(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
i //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
iDir == iBar.GetDirection();
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Force OB Start By InDirectional Bars ...
|
||||
if (result &&
|
||||
validations.forceOBBarType)
|
||||
{
|
||||
//
|
||||
count = 0;
|
||||
fromIDX = triggerBlock.fvg.FromIndex() + 1;
|
||||
int sIDX = fromIDX;
|
||||
has = true;
|
||||
while (has)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ..
|
||||
has = iBar.Init(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
fromIDX //
|
||||
);
|
||||
has = has &&
|
||||
iDir == Opposit(iBar.GetDirection());
|
||||
if (has)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
//
|
||||
fromIDX++;
|
||||
}
|
||||
|
||||
//
|
||||
int required =
|
||||
validations.minRequiredOBBar > 0
|
||||
? validations.minRequiredOBBar
|
||||
: 1;
|
||||
|
||||
//
|
||||
result = count >= required;
|
||||
|
||||
//
|
||||
// Update Trigger Block Box based on OB Bar Types ...
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
result = iBar.Init(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
sIDX //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
datetime iFrom = GetBarTime(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
sIDX + count //
|
||||
);
|
||||
double iLL = iBar.FindLowest(count, MODE_LOW);
|
||||
double iHH = iBar.FindHighest(count, MODE_HIGH);
|
||||
|
||||
//
|
||||
triggerBlock.trigger.from = iFrom;
|
||||
triggerBlock.trigger.upper = MathMax(iHH, triggerBlock.trigger.upper);
|
||||
triggerBlock.trigger.lower = MathMin(iLL, triggerBlock.trigger.lower);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Force Fair Value Gap to Following Sequence ...
|
||||
if (result &&
|
||||
validations.validateGapSequence)
|
||||
{
|
||||
//
|
||||
XOHCL iPBar;
|
||||
toIDX = triggerBlock.fvg.ToIndex();
|
||||
fromIDX = triggerBlock.fvg.FromIndex() - 1;
|
||||
for (int i = toIDX; i < fromIDX; i++)
|
||||
{
|
||||
//
|
||||
result = iBar.Init(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
i //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
iBar.GetPreviousBar(iPBar);
|
||||
result =
|
||||
result &&
|
||||
(isBullish
|
||||
? iBar.low > iPBar.low
|
||||
: iBar.high < iPBar.high);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
iPBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
iPBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate OB Edge Breakeout Using Gaps End Bar ...
|
||||
if (result &&
|
||||
validations.validateBlockEdgeBreakout)
|
||||
{
|
||||
//
|
||||
// Initialize Gap End Bar ...
|
||||
toIDX = triggerBlock.fvg.ToIndex();
|
||||
result = iBar.Init(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
toIDX //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
result &&
|
||||
(isBullish
|
||||
? iBar.open < triggerBlock.ob.upper &&
|
||||
iBar.close > triggerBlock.ob.upper
|
||||
: iBar.open > triggerBlock.ob.lower &&
|
||||
iBar.close < triggerBlock.ob.lower);
|
||||
|
||||
//
|
||||
// Here we Can Apply Edge Breakout Using Fibo ...
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Force Block to Has Liquidity ...
|
||||
if (result &&
|
||||
validations.liquidityLoopback > 0 &&
|
||||
(validations.forceHasFLiquidity ||
|
||||
validations.forceHasRLiquidity))
|
||||
{
|
||||
//
|
||||
toIDX = triggerBlock.ToIndex();
|
||||
fromIDX = triggerBlock.FromIndex();
|
||||
ENUM_X_DIRECTION iLiqDir = X_DIRECTION_NONE;
|
||||
for (int i = toIDX; i < fromIDX + validations.liquidityLoopback; i++)
|
||||
{
|
||||
//
|
||||
// Initialize iBar ...
|
||||
has = iBar.Init(
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
i //
|
||||
);
|
||||
has =
|
||||
has &&
|
||||
barAnalyser
|
||||
.IsRejected(
|
||||
iBar,
|
||||
iLiqDir,
|
||||
false, // Force Bar Type ...
|
||||
true // Force Fibo Pressure ...
|
||||
);
|
||||
|
||||
//
|
||||
bool isFLiq =
|
||||
has &&
|
||||
iLiqDir == iDir;
|
||||
if (isFLiq &&
|
||||
validations.forceHasFLiquidity &&
|
||||
!triggerBlock.fLiquidity.IsValid())
|
||||
{
|
||||
//
|
||||
FillLiquidity(
|
||||
iBar,
|
||||
iLiqDir,
|
||||
triggerBlock.fLiquidity,
|
||||
triggerBlock.trigger.to //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool isRLiq =
|
||||
has &&
|
||||
iLiqDir == Opposit(iDir);
|
||||
if (isRLiq &&
|
||||
validations.forceHasRLiquidity &&
|
||||
!triggerBlock.rLiquidity.IsValid())
|
||||
{
|
||||
//
|
||||
FillLiquidity(
|
||||
iBar,
|
||||
iLiqDir,
|
||||
triggerBlock.rLiquidity,
|
||||
triggerBlock.trigger.to //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Here We Can Apply Liquidity Validations ...
|
||||
ValidateTriggerBlockLiquidities(
|
||||
helper,
|
||||
barAnalyser,
|
||||
triggerBlock,
|
||||
conditions,
|
||||
validations //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Liquidities ...
|
||||
has = (!validations.forceHasFLiquidity
|
||||
? true
|
||||
: triggerBlock.fLiquidity.IsValid()) &&
|
||||
(!validations.forceHasRLiquidity
|
||||
? true
|
||||
: triggerBlock.rLiquidity.IsValid());
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
if (has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Result ...
|
||||
result = (!validations.forceHasFLiquidity
|
||||
? true
|
||||
: triggerBlock.fLiquidity.IsValid()) &&
|
||||
(!validations.forceHasRLiquidity
|
||||
? true
|
||||
: triggerBlock.rLiquidity.IsValid());
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
triggerBlock.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Summarize result ...
|
||||
result = triggerBlock.IsValid();
|
||||
@@ -490,17 +952,34 @@ bool ValidateTriggerBlock(
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
conditions.Clean();
|
||||
triggerBlock.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
/**
|
||||
* Filter a Trigger Block ...
|
||||
*
|
||||
* @param helper: XCX121XCatbHelper instance pointer ...
|
||||
* @param barAnalyser: XCBarAnalyser instance pointer ...
|
||||
* @param triggerBlock: XTriggerBlock Refrence, Trigger Block ...
|
||||
* @param conditions: X121XCatbConditions Refrence, Trigger Block Conditions ...
|
||||
* @param filters: XTriggerBlockFilters Refrence, Provides Trigger Block Filters ...
|
||||
* @param barIndex: int, Bar Index ...
|
||||
* @param loopback: int, Loopback for Conditions reading ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool FilterTriggerBlock(
|
||||
XCX121XCatbHelper *helper,
|
||||
XCBarAnalyser *barAnalyser,
|
||||
@@ -558,9 +1037,87 @@ bool FilterTriggerBlock(
|
||||
int p3IDX = p2IDX + 1;
|
||||
int p4IDX = p3IDX + 1;
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
int toIDX = -1;
|
||||
int fromIDX = -1;
|
||||
bool has = false;
|
||||
bool isBullish = triggerBlock.IsBullish();
|
||||
bool isBearish = triggerBlock.IsBearish();
|
||||
double points = GetPoints(triggerBlock.ob.symbol);
|
||||
ENUM_X_DIRECTION iDir = triggerBlock.GetDirection();
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Filter Based On PV ...
|
||||
if (result &&
|
||||
filters.filterBasedOnPV)
|
||||
{
|
||||
//
|
||||
// For PV Filtering ...
|
||||
|
||||
//
|
||||
// Detect Bos ...
|
||||
if (filters.bosLoopback > 0)
|
||||
{
|
||||
//
|
||||
has = true;
|
||||
bool isBOS = false;
|
||||
bool isPeakOverLast = false;
|
||||
bool isValeUnderLast = false;
|
||||
toIDX = triggerBlock.ob.ToIndex();
|
||||
fromIDX = triggerBlock.ob.FromIndex();
|
||||
int sIDX = fromIDX;
|
||||
while (has)
|
||||
{
|
||||
//
|
||||
double iPeak = helper.GetPeak(sIDX);
|
||||
double iPPeak = helper.GetPeak(sIDX + 1);
|
||||
|
||||
//
|
||||
double iVale = helper.GetVale(sIDX);
|
||||
double iPVale = helper.GetVale(sIDX + 1);
|
||||
|
||||
//
|
||||
isPeakOverLast =
|
||||
iPeak > 0 &&
|
||||
iPeak > iPPeak;
|
||||
|
||||
//
|
||||
isValeUnderLast =
|
||||
iVale > 0 &&
|
||||
iVale < iPVale;
|
||||
|
||||
//
|
||||
isBOS =
|
||||
(isBullish &&
|
||||
isPeakOverLast) ||
|
||||
(isBearish &&
|
||||
isValeUnderLast);
|
||||
if (isBOS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
sIDX++;
|
||||
has = !isBOS &&
|
||||
sIDX < fromIDX + filters.bosLoopback;
|
||||
}
|
||||
|
||||
//
|
||||
result = isBOS;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
triggerBlock.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Summarize result ...
|
||||
result = triggerBlock.IsValid();
|
||||
@@ -568,16 +1125,53 @@ bool FilterTriggerBlock(
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
conditions.Clean();
|
||||
triggerBlock.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void ValidateTriggerBlockLiquidities(
|
||||
XCX121XCatbHelper *helper,
|
||||
XCBarAnalyser *barAnalyser,
|
||||
XTriggerBlock &triggerBlock,
|
||||
X121XCatbConditions &conditions,
|
||||
XTriggerBlockValidationRules &validations //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
has =
|
||||
helper != NULL &&
|
||||
barAnalyser != NULL &&
|
||||
triggerBlock.IsValid() &&
|
||||
(triggerBlock.fLiquidity.IsValid() ||
|
||||
triggerBlock.rLiquidity.IsValid());
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasFLiq = triggerBlock.fLiquidity.IsValid();
|
||||
bool hasRLiq = triggerBlock.rLiquidity.IsValid();
|
||||
|
||||
//
|
||||
// TODO: Implement Liquidity Validation ...
|
||||
}
|
||||
|
||||
//
|
||||
bool DetectSignalZone(
|
||||
XCPOIDrawer *&drawer,
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,259 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCCHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// 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-saherelm.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X121XCCInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Chart Style ...
|
||||
ENUM_CHART_MODE mode; // Mode
|
||||
color upColor; // Up Color
|
||||
color downColor; // Down Color
|
||||
color lineColor; // Line mode and Doji candlestick Color
|
||||
color bearishColor; // Bullish Color
|
||||
color bullishColor; // Bearish Color
|
||||
color volumesColor; // Volumes Color
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandles; // Show Candles
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X121XCCInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = CLR_NONE;
|
||||
downColor = CLR_NONE;
|
||||
lineColor = CLR_NONE;
|
||||
bearishColor = CLR_NONE;
|
||||
bullishColor = CLR_NONE;
|
||||
volumesColor = CLR_NONE;
|
||||
|
||||
//
|
||||
showCandles = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = clrLime;
|
||||
downColor = clrRed;
|
||||
lineColor = clrLime;
|
||||
bearishColor = clrRed;
|
||||
bullishColor = clrLime;
|
||||
volumesColor = clrGreen;
|
||||
//
|
||||
showCandles = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Hide all Visible Buffers ...
|
||||
void Hide()
|
||||
{
|
||||
showCandles = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XCX121XCCHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCCHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCCHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCCInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xcc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Chart Style ...
|
||||
"",
|
||||
mInputs.mode, // Mode
|
||||
mInputs.upColor, // Up Color
|
||||
mInputs.downColor, // Down Color
|
||||
mInputs.lineColor, // Line mode and Doji candlestick Color
|
||||
mInputs.bullishColor, // Bearish Color
|
||||
mInputs.bearishColor, // Bullish Color
|
||||
mInputs.volumesColor, // Volumes Color
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandles // Show Candles
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XCCInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCCInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCCInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,241 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCTHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// 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-saherelm.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X121XCTInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string font; // Font
|
||||
int fontSize; // Font Size;
|
||||
color clr; // Text Color
|
||||
ENUM_BASE_CORNER corner; // Text Position
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandleTime; // Show Candle Time
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X121XCTInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
font = NULL;
|
||||
fontSize = 15;
|
||||
clr = CLR_NONE;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
font = "Arial";
|
||||
fontSize = 15;
|
||||
clr = clrYellow;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Hide all Visible Buffers ...
|
||||
void Hide()
|
||||
{
|
||||
showCandleTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XCX121XCTHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCTHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCTHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xct",
|
||||
//
|
||||
// Inputs ...
|
||||
mInputs.fontSize, // Font Size ...
|
||||
mInputs.font, // Font ...
|
||||
mInputs.clr, // Text Color ...
|
||||
mInputs.corner, // Text Position ...
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandleTime // Show Candle Time
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XCTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCTInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,9 +26,8 @@
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-volume.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.x121.xcatb.lib.mq5"
|
||||
#include "../XCAEA/Classes/xcaea.x-trade.manager.class.mq5"
|
||||
#include "../XCATBEA/Classes/xcatbea.x-trade.manager.class.mq5"
|
||||
#include "../XCATBEA/Libraries/xcatbea.signaller.lib.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XCATBEA"
|
||||
@@ -97,7 +96,7 @@ input bool eaAllowTrade = true;
|
||||
input bool eaAllowLongs = true; // Allow Long Trades
|
||||
input bool eaAllowShorts = true; // Allow Short Trades
|
||||
input string eaSessions = ""; // Active Sessions
|
||||
input ENUM_XCAEA_TRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XCAEA_TRADE_RESTRICATION_NONE; // Restrictions Period
|
||||
input ENUM_XCATBEA_TRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XCATBEA_TRADE_RESTRICATION_NONE; // Restrictions Period
|
||||
input int eaMaxAllowedTPs = 0; // Max Allowed TP(s) in Restrictions Period
|
||||
input int eaMaxAllowedSLs = 0; // Max Allowed SL(s) in Restrictions Period
|
||||
input int eaMaxAllowedTrades = 0; // Max Allowed Trades in Restrictions Period
|
||||
@@ -145,8 +144,8 @@ X121XCatbInputs eaInputs;
|
||||
XTimeTracker eaTimeTracker;
|
||||
XCX121XCatbHelper *eaHelper;
|
||||
XCBarAnalyser *eaBarAnalyser;
|
||||
XCXCAEATradeManager *eaTradeManager;
|
||||
XCAEAStrategyConditions eaConditions;
|
||||
XCXCATBEATradeManager *eaTradeManager;
|
||||
XCATBEAStrategyConditions eaConditions;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
@@ -299,77 +298,6 @@ void OnTick()
|
||||
// Check Trigger Block Detected or Not ...
|
||||
if (tradeUsingTriggerBlock)
|
||||
{
|
||||
//
|
||||
// XTriggerBlock iTB;
|
||||
// X121XCatbConditions iConditions;
|
||||
// has = DetectTriggerBlock(
|
||||
// //
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// //
|
||||
// iTB,
|
||||
// //
|
||||
// eaDrawer,
|
||||
// eaBarAnalyser,
|
||||
// //
|
||||
// // Required Buffers ...
|
||||
// eaHelper.atrBuffer,
|
||||
// eaHelper.rsiBuffer,
|
||||
// eaHelper.adxBuffer,
|
||||
// eaHelper.adxpBuffer,
|
||||
// eaHelper.adxnBuffer,
|
||||
// eaHelper.peakBuffer,
|
||||
// eaHelper.valeBuffer,
|
||||
// eaHelper.deltaBuffer,
|
||||
// eaHelper.sarBuffer,
|
||||
// eaHelper.sarStateBuffer,
|
||||
// eaHelper.trendBuffer,
|
||||
// eaHelper.trendStateBuffer,
|
||||
// eaHelper.atrUpperBuffer,
|
||||
// eaHelper.atrLowerBuffer,
|
||||
// eaHelper.sBarOpenBuffer,
|
||||
// eaHelper.sBarCloseBuffer,
|
||||
// eaHelper.hkSBarOpenBuffer,
|
||||
// eaHelper.hkSBarCloseBuffer,
|
||||
// eaHelper.peakGoldenBuffer,
|
||||
// eaHelper.valeGoldenBuffer,
|
||||
// eaHelper.deltaSignalBuffer,
|
||||
// eaHelper.bullishVolumeSignalBuffer,
|
||||
// eaHelper.bearishVolumeSignalBuffer,
|
||||
// //
|
||||
// cBarIndex,
|
||||
// //
|
||||
// // Signalling ...
|
||||
// eaInputs.signalR2R,
|
||||
// eaInputs.slAtrMultiplier,
|
||||
// //
|
||||
// // Configs ...
|
||||
// eaInputs.rsiOBLevel,
|
||||
// eaInputs.rsiOSLevel,
|
||||
// eaInputs.adxThreshold,
|
||||
// //
|
||||
// // Validators ...
|
||||
// eaInputs.forceObBarType,
|
||||
// eaInputs.forceOBFVGBarType,
|
||||
// eaInputs.forceHasSwing,
|
||||
// eaInputs.forceHasFLiquidity,
|
||||
// eaInputs.forceHasRLiquidity,
|
||||
// eaInputs.validateGapSequence,
|
||||
// eaInputs.validateBlockEdgeBreakout,
|
||||
// //
|
||||
// // Filters ...
|
||||
// eaInputs.filterBasedOnPV,
|
||||
// eaInputs.filterBasedOnSar,
|
||||
// eaInputs.filterBasedOnRSI,
|
||||
// eaInputs.filterBasedOnADX,
|
||||
// eaInputs.filterBasedOnATR,
|
||||
// eaInputs.filterBasedOnTrend,
|
||||
// eaInputs.filterBasedOnDelta,
|
||||
// eaInputs.filterBasedOnVolume,
|
||||
// eaInputs.filterBasedOnSignalBar,
|
||||
// eaInputs.filterBasedOnHKSignalBar //
|
||||
// );
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
XTriggerBlock iTB;
|
||||
@@ -869,7 +797,7 @@ void InitRequirements()
|
||||
|
||||
//
|
||||
// EA Trae Manager ...
|
||||
eaTradeManager = new XCXCAEATradeManager(
|
||||
eaTradeManager = new XCXCATBEATradeManager(
|
||||
eaTrade //
|
||||
);
|
||||
eaTradeManager.SaveTrades(true);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-helper.class.mq5"
|
||||
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
@@ -1,788 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 X3MA
|
||||
// Description: X3MA ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 X3MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 X3MA"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
input group "Fast";
|
||||
input int fastLength = 6; // Length
|
||||
input ENUM_MA_METHOD fastMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE fastAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
input group "Medium";
|
||||
input int mediumLength = 21; // Length
|
||||
input ENUM_MA_METHOD mediumMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE mediumAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
input group "Slow";
|
||||
input int slowLength = 34; // Length
|
||||
input ENUM_MA_METHOD slowMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE slowAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool applyColor = false;
|
||||
|
||||
//
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showMedium = true; // Show Medium
|
||||
input bool showSlow = true; // Show Slow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define bullishState 1
|
||||
#define neuturalState 0
|
||||
#define bearishState -1
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
#define fastBufferIndex 0
|
||||
double fastBuffer[];
|
||||
|
||||
//
|
||||
#define fastColorBufferIndex 1
|
||||
double fastColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121 X3MA Fast"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrYellow, clrChocolate, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
#define mediumBufferIndex 2
|
||||
double mediumBuffer[];
|
||||
|
||||
//
|
||||
#define mediumColorBufferIndex 3
|
||||
double mediumColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121 X3MA Medium"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_style2 STYLE_DASHDOTDOT
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
#define slowBufferIndex 4
|
||||
double slowBuffer[];
|
||||
|
||||
//
|
||||
#define slowColorBufferIndex 5
|
||||
double slowColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121 X3MA Slow"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 5
|
||||
|
||||
//
|
||||
#define fastStateBufferIndex mLastBufferIndex + 1
|
||||
double fastStateBuffer[];
|
||||
|
||||
//
|
||||
#define mediumStateBufferIndex mLastBufferIndex + 2
|
||||
double mediumStateBuffer[];
|
||||
|
||||
//
|
||||
#define slowStateBufferIndex mLastBufferIndex + 3
|
||||
double slowStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int fastHandler = INVALID_HANDLE;
|
||||
int mediumHandler = INVALID_HANDLE;
|
||||
int slowHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
fastHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastLength,
|
||||
0,
|
||||
fastMethod,
|
||||
fastAppliedTo //
|
||||
);
|
||||
bool isInited = fastHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
mediumHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumLength,
|
||||
0,
|
||||
mediumMethod,
|
||||
mediumAppliedTo //
|
||||
);
|
||||
isInited = mediumHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
slowHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowLength,
|
||||
0,
|
||||
slowMethod,
|
||||
slowAppliedTo //
|
||||
);
|
||||
isInited = slowHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(fastHandler);
|
||||
IndicatorRelease(mediumHandler);
|
||||
IndicatorRelease(slowHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
int fastCalculatedBars = BarsCalculated(fastHandler);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
int mediumCalculatedBars = BarsCalculated(mediumHandler);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
int slowCalculatedBars = BarsCalculated(slowHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// FAST ...
|
||||
fastCalculatedBars >= maxLength &&
|
||||
//
|
||||
// MEDIUM ...
|
||||
mediumCalculatedBars >= maxLength &&
|
||||
//
|
||||
// SLOW ...
|
||||
slowCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
int copiedFasts = CopyBuffer(fastHandler, 0, 0, limit, fastBuffer);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
int copiedMediumss = CopyBuffer(mediumHandler, 0, 0, limit, mediumBuffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
int copiedSlows = CopyBuffer(slowHandler, 0, 0, limit, slowBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// FAST ...
|
||||
copiedFasts >= limit &&
|
||||
//
|
||||
// MEDIUM ...
|
||||
copiedMediumss >= limit &&
|
||||
//
|
||||
// SLOW ...
|
||||
copiedSlows >= limit
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
fastLength > 2 &&
|
||||
mediumLength > 2 &&
|
||||
slowLength > 2 &&
|
||||
mediumLength > fastLength &&
|
||||
mediumLength < slowLength
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(fastLength, mediumLength);
|
||||
result = MathMax(result, slowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, showFast);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(fastBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fastColorBuffer, true);
|
||||
SetIndexBuffer(fastColorBufferIndex, fastColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mediumBuffer, true);
|
||||
SetIndexBuffer(mediumBufferIndex, mediumBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mediumBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(mediumBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mediumColorBuffer, true);
|
||||
SetIndexBuffer(mediumColorBufferIndex, mediumColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, showSlow);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(slowBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slowColorBuffer, true);
|
||||
SetIndexBuffer(slowColorBufferIndex, slowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// FAST State ...
|
||||
ArraySetAsSeries(fastStateBuffer, true);
|
||||
SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MEDIUM State ...
|
||||
ArraySetAsSeries(mediumStateBuffer, true);
|
||||
SetIndexBuffer(mediumStateBufferIndex, mediumStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// SLOW State ...
|
||||
ArraySetAsSeries(slowStateBuffer, true);
|
||||
SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
// Calculate Values ...
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// FAST ...
|
||||
fastBuffer[barIndex] = emptyValue;
|
||||
fastColorBuffer[barIndex] = hideColorIDX;
|
||||
fastStateBuffer[barIndex] = neuturalState;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
mediumBuffer[barIndex] = emptyValue;
|
||||
mediumColorBuffer[barIndex] = hideColorIDX;
|
||||
mediumStateBuffer[barIndex] = neuturalState;
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
slowBuffer[barIndex] = emptyValue;
|
||||
slowColorBuffer[barIndex] = hideColorIDX;
|
||||
slowStateBuffer[barIndex] = neuturalState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Values ...
|
||||
*
|
||||
* @param bar_index: int, Specified Bar Index ...
|
||||
* @param prevCalculated: int, Provides Previous Calculated Bars ...
|
||||
* @param ratesTotal: int, Provides All Availabled Bars ...
|
||||
* @param open: double Collection, Provides Open Prices Time Series ...
|
||||
* @param high: double Collection, Provides High Prices Time Series ...
|
||||
* @param close: double Collection, Provides Close Prices Time Series ...
|
||||
* @param low: double Collection, Provides Low Prices Time Series ...
|
||||
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Prev Bar ...
|
||||
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == ratesTotal;
|
||||
|
||||
//
|
||||
double iLow = low[bar_index];
|
||||
double iHigh = high[bar_index];
|
||||
double iClose = close[bar_index];
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
double iFast = fastBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iFastState =
|
||||
iLow > iFast
|
||||
? bullishState
|
||||
: iHigh < iFast
|
||||
? bearishState
|
||||
: neuturalState;
|
||||
double iFastColor = hideColorIDX;
|
||||
if (showFast)
|
||||
{
|
||||
//
|
||||
if (applyColor)
|
||||
{
|
||||
//
|
||||
iFastColor =
|
||||
iFastState == bullishState
|
||||
? bullishColorIDX
|
||||
: iFastState == bearishState
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
iFastColor = bullishColorIDX;
|
||||
}
|
||||
}
|
||||
fastColorBuffer[bar_index] = iFastColor;
|
||||
fastStateBuffer[bar_index] = iFastState;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
double iMedium = mediumBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iMediumState =
|
||||
iLow > iMedium
|
||||
? bullishState
|
||||
: iHigh < iMedium
|
||||
? bearishState
|
||||
: neuturalState;
|
||||
double iMediumColor = hideColorIDX;
|
||||
if (showMedium)
|
||||
{
|
||||
//
|
||||
if (applyColor)
|
||||
{
|
||||
//
|
||||
iMediumColor =
|
||||
iMediumState == bullishState
|
||||
? bullishColorIDX
|
||||
: iMediumState == bearishState
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
iMediumColor = bullishColorIDX;
|
||||
}
|
||||
}
|
||||
mediumColorBuffer[bar_index] = iMediumColor;
|
||||
mediumStateBuffer[bar_index] = iMediumState;
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
double iSlow = slowBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iSlowState =
|
||||
iLow > iSlow
|
||||
? bullishState
|
||||
: iHigh < iSlow
|
||||
? bearishState
|
||||
: neuturalState;
|
||||
double iSlowColor = hideColorIDX;
|
||||
if (showSlow)
|
||||
{
|
||||
//
|
||||
if (applyColor)
|
||||
{
|
||||
//
|
||||
iSlowColor =
|
||||
iSlowState == bullishState
|
||||
? bullishColorIDX
|
||||
: iSlowState == bearishState
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
iSlowColor = bullishColorIDX;
|
||||
}
|
||||
}
|
||||
slowColorBuffer[bar_index] = iSlowColor;
|
||||
slowStateBuffer[bar_index] = iSlowState;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1,882 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XATR
|
||||
// Description: XATR ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XATR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XATR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
|
||||
//
|
||||
input group "RSI Detection";
|
||||
input int rsiLength = 14; // Length
|
||||
input ENUM_X_PRICE rsiPriceType = X_PRICE_CLOSE; // Applied To
|
||||
input ENUM_X_MA_METHOD rsiSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method;
|
||||
|
||||
//
|
||||
input group "ATR Detection";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 1; // Multiplier
|
||||
input ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // Upper Zone Applied To
|
||||
input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // Lower Zone Applied To
|
||||
input ENUM_X_MA_METHOD atrSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method
|
||||
|
||||
//
|
||||
input group "Price Change";
|
||||
input int priceChangeSmoothingLength = 14; // Length
|
||||
input ENUM_X_PRICE priceChangeType = X_PRICE_CLOSE; // Price Type
|
||||
input ENUM_X_MA_METHOD priceChangeSmoothingMethod = X_MA_MODE_SMA; // Moving Average Moethod
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool showAtrUpper = true; // Show Upper Zone
|
||||
input bool showAtrLower = true; // Show Lower Zone
|
||||
input bool showSmoothedAtrUpper = true; // Show Smoothed Upper Zone
|
||||
input bool showSmoothedAtrLower = true; // Show Smoothed Lower Zone
|
||||
input bool showRSIChange = true; // Show RSI Change
|
||||
input bool showSmoothedRSIChange = true; // ShowSmoothed RSI Change
|
||||
input bool showPriceChange = true; // Show Price Change
|
||||
input bool showSmoothedPriceChange = true; // ShowSmoothed Price Change
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
#define atrUpperBufferIndex 0
|
||||
double atrUpperBuffer[];
|
||||
|
||||
#property indicator_label1 "X121 ATRU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
#define atrLowerBufferIndex 1
|
||||
double atrLowerBuffer[];
|
||||
|
||||
#property indicator_label2 "X121 ATRL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrYellow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// ATR Smoothed ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
#define atrSmoothedUpperBufferIndex 2
|
||||
double atrSmoothedUpperBuffer[];
|
||||
|
||||
#property indicator_label3 "X121 ATRUSM"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
#define atrSmoothedLowerBufferIndex 3
|
||||
double atrSmoothedLowerBuffer[];
|
||||
|
||||
#property indicator_label4 "X121 ATRLSM"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrYellow
|
||||
#property indicator_style4 STYLE_DASH
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Price Change ...
|
||||
|
||||
//
|
||||
#define priceChangeBufferIndex 4
|
||||
double priceChangeBuffer[];
|
||||
|
||||
#property indicator_label5 "X121 PCH"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrOrchid
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// Price Change Smoothed ...
|
||||
|
||||
//
|
||||
#define priceChangeSmoothedBufferIndex 5
|
||||
double priceChangeSmoothedBuffer[];
|
||||
|
||||
#property indicator_label6 "X121 PCHSM"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrOrchid
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// RSI Change ...
|
||||
|
||||
//
|
||||
#define rsiChangeBufferIndex 6
|
||||
double rsiChangeBuffer[];
|
||||
|
||||
#property indicator_label7 "X121 RSICH"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrCornflowerBlue
|
||||
#property indicator_style7 STYLE_SOLID
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// RSI Change Smoothed ...
|
||||
|
||||
//
|
||||
#define rsiChangeSmoothedBufferIndex 7
|
||||
double rsiChangeSmoothedBuffer[];
|
||||
|
||||
#property indicator_label8 "X121 RSICHSM"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrCornflowerBlue
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex mLastBufferIndex + 2
|
||||
double rsiBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// RSI Handler ...
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
ENUM_APPLIED_PRICE rsiAppliedTo = ToAppliedPrice(rsiPriceType);
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rsiLength,
|
||||
rsiAppliedTo //
|
||||
);
|
||||
bool isInited = rsiHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength //
|
||||
);
|
||||
isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(rsiHandler);
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Fill All Buffers by Zero ...
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// RSI ...
|
||||
rsiCalculatedBars >= maxLength &&
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
//
|
||||
// RSI ...
|
||||
copiedRsis > 0 &&
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// RSI ...
|
||||
rsiLength > 0 &&
|
||||
//
|
||||
// ATR ...
|
||||
atrLength > 0 &&
|
||||
atrMultiplier > 0 &&
|
||||
//
|
||||
priceChangeSmoothingLength > 0 &&
|
||||
//
|
||||
IsValid(rsiPriceType) &&
|
||||
IsValid(priceChangeType) &&
|
||||
IsValid(atrUpperPriceType) &&
|
||||
IsValid(atrLowerPriceType)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(rsiLength, atrLength);
|
||||
result = MathMax(result, priceChangeSmoothingLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
ENUM_DRAW_TYPE atrUpperDrawType = showAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrUpperBuffer, true);
|
||||
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, showAtrUpper);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
ENUM_DRAW_TYPE atrLowerDrawType = showAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrLowerBuffer, true);
|
||||
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, showAtrLower);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
|
||||
|
||||
//
|
||||
// ATR Smoothed ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
ENUM_DRAW_TYPE atrSmoothedUpperDrawType = showSmoothedAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrSmoothedUpperBuffer, true);
|
||||
SetIndexBuffer(atrSmoothedUpperBufferIndex, atrSmoothedUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrSmoothedUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrUpper);
|
||||
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_DRAW_TYPE, atrSmoothedUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
ENUM_DRAW_TYPE atrSmoothedLowerDrawType = showSmoothedAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrSmoothedLowerBuffer, true);
|
||||
SetIndexBuffer(atrSmoothedLowerBufferIndex, atrSmoothedLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrSmoothedLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrLower);
|
||||
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_DRAW_TYPE, atrSmoothedLowerDrawType);
|
||||
|
||||
//
|
||||
// PriceChange ...
|
||||
ENUM_DRAW_TYPE priceChangeDrawType = showPriceChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(priceChangeBuffer, true);
|
||||
SetIndexBuffer(priceChangeBufferIndex, priceChangeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(priceChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_SHOW_DATA, showPriceChange);
|
||||
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_DRAW_TYPE, priceChangeDrawType);
|
||||
|
||||
//
|
||||
// PriceChange Smoothed ...
|
||||
ENUM_DRAW_TYPE priceChangeSmoothedaDrawType = showSmoothedPriceChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(priceChangeSmoothedBuffer, true);
|
||||
SetIndexBuffer(priceChangeSmoothedBufferIndex, priceChangeSmoothedBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(priceChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedPriceChange);
|
||||
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, priceChangeSmoothedaDrawType);
|
||||
|
||||
//
|
||||
// RSIChange ...
|
||||
ENUM_DRAW_TYPE rsiChangeDrawType = showRSIChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(rsiChangeBuffer, true);
|
||||
SetIndexBuffer(rsiChangeBufferIndex, rsiChangeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(rsiChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_SHOW_DATA, showRSIChange);
|
||||
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_DRAW_TYPE, rsiChangeDrawType);
|
||||
|
||||
//
|
||||
// RSIChangeMa ...
|
||||
ENUM_DRAW_TYPE rsiChangeMaDrawType = showSmoothedRSIChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(rsiChangeSmoothedBuffer, true);
|
||||
SetIndexBuffer(rsiChangeSmoothedBufferIndex, rsiChangeSmoothedBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(rsiChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedRSIChange);
|
||||
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, rsiChangeMaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateAtrZones(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
rsiBuffer[barIndex] = 0;
|
||||
atrBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrLowerBuffer[barIndex] = 0;
|
||||
rsiChangeBuffer[barIndex] = 0;
|
||||
priceChangeBuffer[barIndex] = 0;
|
||||
atrSmoothedUpperBuffer[barIndex] = 0;
|
||||
atrSmoothedLowerBuffer[barIndex] = 0;
|
||||
rsiChangeSmoothedBuffer[barIndex] = 0;
|
||||
priceChangeSmoothedBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate ATR Zones ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateAtrZones(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double points = GetPoints(_Symbol);
|
||||
|
||||
//
|
||||
// ATR Calculations ...
|
||||
double iAtr = atrBuffer[bar_index];
|
||||
double iMultiPliedAtr = iAtr * atrMultiplier;
|
||||
|
||||
//
|
||||
// Select Upper Price ...
|
||||
double iUpperPrice = GetAppliedPrice(
|
||||
atrUpperPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Select Lower Price ...
|
||||
double iLowerPrice = GetAppliedPrice(
|
||||
atrLowerPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Atrs ...
|
||||
|
||||
//
|
||||
double iAtrUpper = iUpperPrice + iMultiPliedAtr;
|
||||
double iAtrLower = iLowerPrice - iMultiPliedAtr;
|
||||
|
||||
//
|
||||
atrUpperBuffer[bar_index] = iAtrUpper;
|
||||
atrLowerBuffer[bar_index] = iAtrLower;
|
||||
|
||||
//
|
||||
bool canSmoothAtr = atrSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothAtr)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrUpperBuffer,
|
||||
atrSmoothedUpperBuffer,
|
||||
atrSmoothingMethod //
|
||||
);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrLowerBuffer,
|
||||
atrSmoothedLowerBuffer,
|
||||
atrSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
atrSmoothedUpperBuffer[bar_index] = iAtrUpper;
|
||||
atrSmoothedLowerBuffer[bar_index] = iAtrLower;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Change Calculations ...
|
||||
|
||||
//
|
||||
double iRsi = rsiBuffer[bar_index];
|
||||
double iRsiP = rsiBuffer[bar_index + 1];
|
||||
double iRsiPrice = GetAppliedPrice(
|
||||
rsiPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
double iRsiChanged = iRsi - iRsiP;
|
||||
double iRsiPointsChanged = iRsiChanged / points;
|
||||
|
||||
//
|
||||
double iRChange = iRsiPrice + (iRsiChanged * points);
|
||||
rsiChangeBuffer[bar_index] = iRChange;
|
||||
|
||||
//
|
||||
bool canSmoothRsi = rsiSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothRsi)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
rsiChangeBuffer,
|
||||
rsiChangeSmoothedBuffer,
|
||||
rsiSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
rsiChangeSmoothedBuffer[bar_index] = iRChange;
|
||||
}
|
||||
|
||||
//
|
||||
// PRICE Change Calculation ...
|
||||
|
||||
//
|
||||
double iPChangePrice = GetAppliedPrice(
|
||||
priceChangeType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
double iPPChangePrice = GetAppliedPrice(
|
||||
priceChangeType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index + 1 //
|
||||
);
|
||||
|
||||
//
|
||||
double iPriceChange = iPChangePrice - iPPChangePrice;
|
||||
double iPricePointsChanged = iPriceChange / points;
|
||||
double iVolatilityChange = iPriceChange / iAtr;
|
||||
|
||||
//
|
||||
double iPChange = iPChangePrice + (iPricePointsChanged * points);
|
||||
priceChangeBuffer[bar_index] = iPChange;
|
||||
|
||||
//
|
||||
bool canSmoothPriceChange = priceChangeSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothPriceChange)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
priceChangeBuffer,
|
||||
priceChangeSmoothedBuffer,
|
||||
priceChangeSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
priceChangeSmoothedBuffer[bar_index] = iPChange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,7 +47,6 @@
|
||||
#include "../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.x121.xcatb.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
@@ -1938,131 +1937,6 @@ void CalculateValues(
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
|
||||
//
|
||||
// Try To Detect Trigger Block ...
|
||||
|
||||
//
|
||||
// Prevent Calculation ...
|
||||
if (maxBarIndex - barIndex < maxLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XTriggerBlock tb;
|
||||
bool has = DetectTriggerBlock(
|
||||
//
|
||||
_Symbol,
|
||||
_Period,
|
||||
//
|
||||
tb,
|
||||
//
|
||||
mBarAnalyser,
|
||||
//
|
||||
// Required Buffers ...
|
||||
atrBuffer,
|
||||
rsiBuffer,
|
||||
adxBuffer,
|
||||
adxpBuffer,
|
||||
adxnBuffer,
|
||||
peakBuffer,
|
||||
valeBuffer,
|
||||
deltaBuffer,
|
||||
sarBuffer,
|
||||
sarStateBuffer,
|
||||
trendBuffer,
|
||||
trendStateBuffer,
|
||||
atrUpperBuffer,
|
||||
atrLowerBuffer,
|
||||
sBarOpenBuffer,
|
||||
sBarCloseBuffer,
|
||||
hkSBarOpenBuffer,
|
||||
hkSBarCloseBuffer,
|
||||
peakGoldenBuffer,
|
||||
valeGoldenBuffer,
|
||||
deltaSignalBuffer,
|
||||
bullishVolumeSignalBuffer,
|
||||
bearishVolumeSignalBuffer,
|
||||
//
|
||||
barIndex,
|
||||
//
|
||||
// Signalling ...
|
||||
signalR2R,
|
||||
slAtrMultiplier,
|
||||
//
|
||||
// Configs ...
|
||||
rsiOBLevel,
|
||||
rsiOSLevel,
|
||||
adxThreshold,
|
||||
//
|
||||
// Validators ...
|
||||
forceObBarType,
|
||||
forceOBFVGBarType,
|
||||
forceHasSwing,
|
||||
forceHasFLiquidity,
|
||||
forceHasRLiquidity,
|
||||
validateGapSequence,
|
||||
validateBlockEdgeBreakout,
|
||||
//
|
||||
// Filters ...
|
||||
filterBasedOnPV,
|
||||
filterBasedOnSar,
|
||||
filterBasedOnRSI,
|
||||
filterBasedOnADX,
|
||||
filterBasedOnATR,
|
||||
filterBasedOnTrend,
|
||||
filterBasedOnDelta,
|
||||
filterBasedOnVolume,
|
||||
filterBasedOnSignalBar,
|
||||
filterBasedOnHKSignalBar //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Draw ...
|
||||
if (drawTriggerBlock)
|
||||
{
|
||||
//
|
||||
has = DrawTriggerBlock(
|
||||
tb,
|
||||
mDrawer,
|
||||
mObjects,
|
||||
NULL,
|
||||
drawSignals //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
bool canAlert =
|
||||
mEnableAlerts &&
|
||||
prevCalculated > 0;
|
||||
bool canLogOnly =
|
||||
mEnableAlerts &&
|
||||
prevCalculated == 0;
|
||||
if (has &&
|
||||
(canAlert ||
|
||||
canLogOnly))
|
||||
{
|
||||
//
|
||||
string message =
|
||||
tb.trigger.symbol + "," +
|
||||
ToString(tb.trigger.period) + "> " +
|
||||
ToString(tb.trigger.dir) +
|
||||
" Zone Detected at: " + ToString(tb.trigger.to);
|
||||
|
||||
//
|
||||
if (canLogOnly)
|
||||
{
|
||||
mAlert.LogAlert(message);
|
||||
}
|
||||
else if (canAlert)
|
||||
{
|
||||
mAlert.SendAlert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -1,550 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Ocillator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XDelta
|
||||
// Description: Detect Comulative Volumes Delta ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XDelta Ocillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XDELTA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Makret ...
|
||||
input group "Market";
|
||||
input int maLength = 14; // Moving Averge Length
|
||||
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showDeltaLine = true; // Show Delta Line
|
||||
input bool showDeltaHistogram = true; // Show Delta Histogram
|
||||
input bool showDeltaMa = true; // Show Delta Moving Average
|
||||
|
||||
//
|
||||
// Buffers Props ...
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define deltaLineBufferIndex 0
|
||||
double deltaLineBuffer[];
|
||||
|
||||
#property indicator_label1 "Delta Line"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define deltaHistogramBufferIndex 1
|
||||
double deltaHistogramBuffer[];
|
||||
|
||||
//
|
||||
#define deltaHistogramColorBufferIndex 2
|
||||
double deltaHistogramColorBuffer[];
|
||||
|
||||
#property indicator_label2 "Delta Histogram"
|
||||
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define deltaMaBufferIndex 3
|
||||
double deltaMaBuffer[];
|
||||
|
||||
#property indicator_label3 "Delta MA"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrOrchid
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 3
|
||||
|
||||
//
|
||||
#define rawDeltaBufferIndex mLastBufferIndex + 1
|
||||
double rawDeltaBuffer[];
|
||||
|
||||
//
|
||||
#define deltaStateBufferIndex mLastBufferIndex + 2
|
||||
double deltaStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int firstBarIndex;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = maLength > 0 &&
|
||||
IsValid(maMethod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, maLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Delta Line ...
|
||||
ENUM_DRAW_TYPE deltaLineDrawType = showDeltaLine ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaLineBuffer, true);
|
||||
SetIndexBuffer(deltaLineBufferIndex, deltaLineBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaLineBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_SHOW_DATA, showDeltaLine);
|
||||
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_DRAW_TYPE, deltaLineDrawType);
|
||||
|
||||
//
|
||||
// Delta Histogram ...
|
||||
ENUM_DRAW_TYPE deltaHistogramDrawType = showDeltaHistogram ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaHistogramBuffer, true);
|
||||
SetIndexBuffer(deltaHistogramBufferIndex, deltaHistogramBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaHistogramBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_SHOW_DATA, showDeltaHistogram);
|
||||
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_DRAW_TYPE, deltaHistogramDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaHistogramColorBuffer, true);
|
||||
SetIndexBuffer(deltaHistogramColorBufferIndex, deltaHistogramColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Delta Ma ...
|
||||
ENUM_DRAW_TYPE deltaMaDrawType = showDeltaMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaMaBuffer, true);
|
||||
SetIndexBuffer(deltaMaBufferIndex, deltaMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaMaBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_SHOW_DATA, showDeltaMa);
|
||||
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_DRAW_TYPE, deltaMaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rawDeltaBuffer, true);
|
||||
SetIndexBuffer(rawDeltaBufferIndex, rawDeltaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaStateBuffer, true);
|
||||
SetIndexBuffer(deltaStateBufferIndex, deltaStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
if (barsLimit == 0)
|
||||
{
|
||||
//
|
||||
barsLimit = ratesTotal;
|
||||
firstBarIndex = barsLimit - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
firstBarIndex = startCalculationForLastBars;
|
||||
}
|
||||
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
rawDeltaBuffer[barIndex] = 0.0;
|
||||
deltaLineBuffer[barIndex] = 0.0;
|
||||
deltaStateBuffer[barIndex] = 0.0;
|
||||
deltaHistogramBuffer[barIndex] = 0.0;
|
||||
deltaMaBuffer[barIndex] = 0.0;
|
||||
deltaHistogramColorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Prev Bar ...
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == firstBarIndex;
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double iDelta = 0.0;
|
||||
|
||||
//
|
||||
// Detecting Delta Volume ...
|
||||
if (bar.IsBullish())
|
||||
{
|
||||
iDelta = (double)bar.volume;
|
||||
}
|
||||
else if (bar.IsBearish())
|
||||
{
|
||||
iDelta = -(double)bar.volume;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting iDelta Value ...
|
||||
if (isFirstBar)
|
||||
{
|
||||
//
|
||||
rawDeltaBuffer[bar_index] = iDelta;
|
||||
deltaLineBuffer[bar_index] = iDelta;
|
||||
deltaHistogramBuffer[bar_index] = iDelta;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
iDelta += deltaLineBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
rawDeltaBuffer[bar_index] = iDelta;
|
||||
deltaLineBuffer[bar_index] = iDelta;
|
||||
deltaHistogramBuffer[bar_index] = iDelta;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting iDelta State ...
|
||||
double iState = iDelta > 0
|
||||
? bullishColorIDX
|
||||
: iDelta < 0
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
//
|
||||
// Setting iDelta Color ...
|
||||
double iDeltaColor = iDelta > 0
|
||||
? bullishColorIDX
|
||||
: iDelta < 0
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
|
||||
//
|
||||
deltaStateBuffer[bar_index] = iState;
|
||||
deltaHistogramColorBuffer[bar_index] = iDeltaColor;
|
||||
|
||||
//
|
||||
// Calculate Moving Averages ...
|
||||
int deltaMAsCount = iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
maLength,
|
||||
rawDeltaBuffer,
|
||||
deltaMaBuffer,
|
||||
maMethod //
|
||||
);
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,167 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: XCXCATBEADataCollector ...
|
||||
// Description: Class for XCATBEA Data Collector ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm Class for XCATBEA Data Collector"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.base.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
class XCXCATBEADataCollector : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructors ...
|
||||
XCXCATBEADataCollector()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCXCATBEADataCollector()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Properties ...
|
||||
|
||||
//
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
void Path(string value)
|
||||
{
|
||||
//
|
||||
// Normalizing Collector Path ...
|
||||
if (IsValid(value))
|
||||
{
|
||||
mPath = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
mPath = "XCXCATBEADataCollector";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
mPath + "\\" + fileName + ".x121.log"
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int GetFileHandlerForWrite(string filePath)
|
||||
{
|
||||
//
|
||||
int result = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
if (!IsValid(filePath))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = FileOpen(
|
||||
filePath,
|
||||
FILE_READ | FILE_WRITE | FILE_TXT //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Specified Content into Specified File Name ...
|
||||
*
|
||||
* @param fileName: string, file name ...
|
||||
* @param content: string, content ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Save(
|
||||
string fileName,
|
||||
string content //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(content);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
int mHandler = GetFileHandlerForWrite(fileName);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
FileWrite(mHandler, content);
|
||||
FileFlush(mHandler);
|
||||
FileClose(mHandler);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string mPath; // Base Collector Path ...
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,293 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: XCATBEA Lib
|
||||
// Description: Library for XCATBEA ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm Library for XCATBEA Signaller"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-trade.lib.mq5"
|
||||
#include "../../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
|
||||
//
|
||||
// Enumeration ...
|
||||
|
||||
//
|
||||
// Guard Actions ...
|
||||
enum ENUM_XCATBEA_GUARD_ACTIONS
|
||||
{
|
||||
XCATBEA_GUARD_ACTION_NONE, // Nothing to Do
|
||||
XCATBEA_GUARD_ACTION_CLOSE, // Close Specified Position
|
||||
XCATBEA_GUARD_ACTION_CLOSE_ALL, // Close All Positions
|
||||
XCATBEA_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions
|
||||
XCATBEA_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position
|
||||
XCATBEA_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position
|
||||
XCATBEA_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position
|
||||
XCATBEA_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position
|
||||
XCATBEA_GUARD_ACTION_HEDGE, // Hedge Specified Positions
|
||||
};
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Conditions Struct ...
|
||||
struct XCATBEAStrategyConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
double sl;
|
||||
double tp;
|
||||
double pivot;
|
||||
double point;
|
||||
double entry;
|
||||
double reward;
|
||||
string provider;
|
||||
|
||||
//
|
||||
XTarget targets[];
|
||||
|
||||
//
|
||||
datetime time;
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION dir;
|
||||
XBoxZone decisionZone;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
X121XCatbConditions conditions;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCATBEAStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
pivot = 0;
|
||||
point = 0;
|
||||
entry = 0;
|
||||
reward = 0;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
provider = NULL;
|
||||
|
||||
//
|
||||
time = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
Clean(targets);
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
decisionZone.Clean();
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period) &&
|
||||
IsSpecifiedValid(time);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bullish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBullishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBullish(dir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bearish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBearishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBearish(dir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Up and Triggering Up ...
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Setup Age ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetSetupAge()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsSetuped())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
+1
-2
@@ -17,8 +17,7 @@ async function handleCleanup() {
|
||||
"Libraries", // Required Libraries
|
||||
"Parsers", // Strategies Filters based on Conditions
|
||||
"Strategies", // Strategies Classes which Provides Signals
|
||||
"X121SMCEA", // X121SMC EA Projects ...
|
||||
"XCAEA", // XCAEA Projects ...
|
||||
"XCATBEA", // XCATBEA Projects ...
|
||||
];
|
||||
|
||||
//
|
||||
|
||||
@@ -17,6 +17,7 @@ async function handleCompile() {
|
||||
"Parsers", // Strategies Filters based on Conditions
|
||||
"Strategies", // Strategies Classes which Provides Signals
|
||||
"Experts", // Expert Advisers
|
||||
"XCATBEA", // XCATBEA Projects ...
|
||||
];
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user