add MQL5Test Workspace Content as BKP Solution ...

This commit is contained in:
2024-04-22 07:42:50 +03:30
parent ec0a03203e
commit f7fd579a9d
197 changed files with 80113 additions and 0 deletions
@@ -0,0 +1,227 @@
//
// Close All Open Positions when Profit Summary is Reached ...
void HandleGridHedge()
{
//
int openPositionsCount = xEATrade.PositionsCount();
if (openPositionsCount <= 1 ||
xEAMinProfitPerOpenPositionForHedging <= 0)
{
return;
}
//
double requiredProfitForHedging = xEAMinProfitPerOpenPositionForHedging * openPositionsCount;
double accountProfit = xEATrade.GetPositionsProfit();
if (accountProfit > 0 || MathAbs(accountProfit) < requiredProfitForHedging)
{
return;
}
//
string comment = "Close since Grid Hedging ...";
xEATrade.CloseAllPositions(comment);
//
string msg = "Grid Hedging in Loss: " + (string)accountProfit;
LogMessage(msg);
}
//
// Close All Open Positions when Profit Summary is Reached ...
void HandlePyramidHedge()
{
//
int openPositionsCount = xEATrade.PositionsCount();
if (openPositionsCount <= 1 ||
xEAMinProfitPerOpenPositionForHedging <= 0)
{
return;
}
//
double requiredProfitForHedging = xEAMinProfitPerOpenPositionForHedging * openPositionsCount;
double accountProfit = xEATrade.GetPositionsProfit();
if (accountProfit < requiredProfitForHedging)
{
return;
}
//
string comment = "Close since Pyramid Hedging ...";
xEATrade.CloseAllPositions(comment);
//
string msg = "Pyramid Hedging in Profit: " + (string)accountProfit;
LogMessage(msg);
}
//
// Force Close Signals ...
void HandleForceClosing()
{
//
int positionsCount = xEATrade.PositionsCount();
int ordersCount = xEATrade.OrdersCount();
if (positionsCount <= 0 || ordersCount <= 0)
{
return;
}
//
X121ForceClose results[];
xEAProvider.CanForceCloseShortSignals(results);
int resultsCount = ArraySize(results);
if (resultsCount <= 0)
{
return;
}
//
for (int i = 0; i < resultsCount; i++)
{
//
X121ForceClose iForceClose = results[i];
if (!iForceClose.force)
{
continue;
}
//
XPosition iPositions[];
xEATrade.GetPositions(
iPositions,
iForceClose.symbol,
iForceClose.period);
int iPositionsCount = ArraySize(iPositions);
if (iPositionsCount > 0)
{
//
for (int j = 0; j < iPositionsCount; j++)
{
//
XPosition jPosition = iPositions[j];
bool isLong = IsLong(jPosition.type);
if (isLong)
{
continue;
}
//
ENUM_X121_SIGNAL_PROVIDERS jProvider = ExtractProvider(jPosition);
string jProviderStr = ToString(jProvider);
if (jProviderStr != iForceClose.provider)
{
continue;
}
//
string comment = "Force Close Signals ...";
bool isClosed = xEATrade.Close(jPosition.ticket, comment);
if (isClosed)
{
//
string msg = "Position (" + (string)jPosition.ticket + ") Closed Due Force Event ...";
LogMessage(msg);
}
}
}
//
XOrder iOrders[];
xEATrade.GetOrders(
iOrders,
iForceClose.symbol,
iForceClose.period,
ORDER_STATE_PLACED);
int iOrdersCount = ArraySize(iOrders);
if (iOrdersCount > 0)
{
//
bool isCanceled = xEATrade.CancelOrders(iOrders);
if (isCanceled)
{
//
string msg = "(" + (string)ordersCount + ") Canceled due Cycle Change ...";
//
LogMessage(msg);
}
}
}
}
//
// Close a Position and it's Support Due to Profit ...
void HandleHedgeSupports()
{
//
int positionsCount = xEATrade.PositionsCount();
if (positionsCount <= 0)
{
return;
}
//
XPosition positions[];
xEATrade.GetPositions(
positions);
positionsCount = ArraySize(positions);
if (positionsCount <= 0)
{
return;
}
//
for (int i = 0; i < positionsCount; i++)
{
//
XPosition iPosition = positions[i];
//
bool hasSupport = xEATrade.HasSupport(iPosition.ticket);
if (!hasSupport)
{
continue;
}
//
bool isClosed = xEATrade.ClosePositionAndSupports(
iPosition.ticket);
if (isClosed)
{
//
string msg = "Position and Supports Closed ...";
LogMessage(msg);
}
}
}
//
// Delete Specific Order of Support if Exists ...
ulong positionId = deal.positionId;
//
XOrder supports[];
bool hasSupport = xEATrade.GetSupportOrders(
positionId,
supports,
NULL,
NULL,
ORDER_STATE_PLACED);
if (hasSupport)
{
//
bool isCanceled = xEATrade.CancelOrders(supports);
//
if (isCanceled)
{
//
string msg = "Close all Supports of (" + (string)positionId + ") Due to it's TakeProfit Event ...";
LogMessage(msg);
}
}
@@ -0,0 +1,124 @@
//
void DrawSupportResistance(
int bar_index,
XOHCLSupRes &data,
string prefix = "",
color supportColor = clrLime,
color lowSupportColor = clrGreen,
color resistanceColor = clrRed,
color highResistanceColor = clrBrown)
{
//
datetime barTime = GetCandleTime(
_Symbol,
_Period,
bar_index);
//
datetime prevBarTime = GetCandleTime(
_Symbol,
_Period,
bar_index + 5);
//
long chID = ChartID();
int subWindiw = 0;
//
string mPrefix = prefix + "_" + (string)barTime + "_";
//
// SUPPORT ...
//
if (data.sup > 0)
{
//
string supTlName = mPrefix + "SUP_(" + (string)data.sup + ")";
//
// Draw Support ...
DrawTrendLine(
chID,
supTlName,
subWindiw,
prevBarTime,
data.sup,
barTime,
data.sup,
supportColor,
STYLE_DOT,
1,
true);
}
//
if (data.lowSup > 0)
{
//
string lowSupTlName = mPrefix + "LOW-SUP_(" + (string)data.lowSup + ")";
//
// Draw Low Support ...
DrawTrendLine(
chID,
lowSupTlName,
subWindiw,
prevBarTime,
data.lowSup,
barTime,
data.lowSup,
lowSupportColor,
STYLE_DOT,
1,
true);
}
//
// RESISTANCE ...
//
if (data.res > 0)
{
//
string resTlName = mPrefix + "RES_(" + (string)data.res + ")";
//
// Draw Support ...
DrawTrendLine(
chID,
resTlName,
subWindiw,
prevBarTime,
data.res,
barTime,
data.res,
resistanceColor,
STYLE_DOT,
1,
true);
}
//
if (data.highRes > 0)
{
//
string highResTlName = mPrefix + "HIGH-RES_(" + (string)data.highRes + ")";
//
// Draw Low Support ...
DrawTrendLine(
chID,
highResTlName,
subWindiw,
prevBarTime,
data.highRes,
barTime,
data.highRes,
highResistanceColor,
STYLE_DOT,
1,
true);
}
}
@@ -0,0 +1,30 @@
//
bool isTrendSwitchedBullish = mTRNDHelper.IsTrendSwitchedBullish(1);
if (isTrendSwitchedBullish)
{
LogMessage("isTrendSwitchedBullish");
}
//
bool isTrendSwitchedBearish = mTRNDHelper.IsTrendSwitchedBearish(1);
if (isTrendSwitchedBearish)
{
LogMessage("isTrendSwitchedBearish");
}
//
bool isTrendSwitchedConsolidation = mTRNDHelper.IsTrendSwitchedConsolidation(1);
if (isTrendSwitchedConsolidation)
{
LogMessage("isTrendSwitchedConsolidation");
}
//
if (
isTrendSwitchedBullish ||
isTrendSwitchedBearish ||
isTrendSwitchedConsolidation)
{
LogMessage(" ");
}
@@ -0,0 +1,100 @@
//
if (mIsNewCandle)
{
//
datetime barTime = iTime(
mSymbol,
mPeriod,
0);
//
datetime time = iTime(
mSymbol,
mPeriod,
1);
//
long chartID = ChartID();
//
int barIndex = 0;
// //
// // Check Kumo Is Bullish On State ...
// bool isKumoBullish =
// //
// mIchiHelper.IsKumoBullish(barIndex + 1, true)
// //
// ;
// //
// if (isKumoBullish)
// {
// //
// LogMessage("isKumoBullish");
// LogMessage("TenkanSen: " + (string)mIchiHelper.tenkanSenBuffer[barIndex]);
// LogMessage("KijunSen: " + (string)mIchiHelper.kijunSenBuffer[barIndex]);
// LogMessage("SenkouSpan A: " + (string)mIchiHelper.senkouSpanABuffer[barIndex + 26]);
// LogMessage("SenkouSpan B: " + (string)mIchiHelper.senkouSpanBBuffer[barIndex + 26]);
// LogMessage(" ");
// }
// //
// // Check Kumo Is Bearish On State ...
// bool isKumoBearish =
// //
// mIchiHelper.IsKumoBearish(barIndex + 1, true)
// //
// ;
// //
// if (isKumoBearish)
// {
// //
// LogMessage("isKumoBearish");
// LogMessage("TenkanSen: " + (string)mIchiHelper.tenkanSenBuffer[barIndex]);
// LogMessage("KijunSen: " + (string)mIchiHelper.kijunSenBuffer[barIndex]);
// LogMessage("SenkouSpan A: " + (string)mIchiHelper.senkouSpanABuffer[barIndex + 26]);
// LogMessage("SenkouSpan B: " + (string)mIchiHelper.senkouSpanBBuffer[barIndex + 26]);
// LogMessage(" ");
// }
// //
// // Check Kumo Switched To Bullish On State ...
// bool isKumoSwitchedToBullish =
// //
// mIchiHelper.IsKumoSwitchedToBullish(barIndex + 1, true)
// //
// ;
// //
// if (isKumoSwitchedToBullish)
// {
// //
// LogMessage("isKumoSwitchedToBullish");
// LogMessage("TenkanSen: " + (string)mIchiHelper.tenkanSenBuffer[barIndex]);
// LogMessage("KijunSen: " + (string)mIchiHelper.kijunSenBuffer[barIndex]);
// LogMessage("SenkouSpan A: " + (string)mIchiHelper.senkouSpanABuffer[barIndex + 26]);
// LogMessage("SenkouSpan B: " + (string)mIchiHelper.senkouSpanBBuffer[barIndex + 26]);
// LogMessage(" ");
// }
// //
// // Check Kumo Switched To Bearish On State ...
// bool isKumoSwitchedToBearish =
// //
// mIchiHelper.IsKumoSwitchedToBearish(barIndex + 1, true)
// //
// ;
// if (isKumoSwitchedToBearish)
// {
// //
// LogMessage("isKumoSwitchedToBearish");
// LogMessage("TenkanSen: " + (string)mIchiHelper.tenkanSenBuffer[barIndex]);
// LogMessage("KijunSen: " + (string)mIchiHelper.kijunSenBuffer[barIndex]);
// LogMessage("SenkouSpan A: " + (string)mIchiHelper.senkouSpanABuffer[barIndex + 26]);
// LogMessage("SenkouSpan B: " + (string)mIchiHelper.senkouSpanBBuffer[barIndex + 26]);
// LogMessage(" ");
// }
}
@@ -0,0 +1,251 @@
bool XTestPRVDHasShortCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
XOHCL c2 = GetCandle(
_Symbol,
_Period,
2);
//
XIchiInfo ichiInfo = XICHIHLPGetInfo(2);
//
bool isCandleClosedUnderPsar =
//
c1.high < atrslSarBuffer[1]
//
;
//
bool isTrendSwitched =
//
XTRNDHLPIsTrendStronglyBearish(1)
//
;
//
bool isNewValeHappends =
//
XPVHLPIsVale(1) &&
!XPVHLPIsVale(2)
//
;
//
bool isKumoBearish =
//
XICHIHLPIsKumoBearish(1)
//
;
//
bool isTenkanSenUnderKijunSen =
//
XICHIHLPIsTenkanSenUnderKijunSen(1)
//
;
//
bool isTenkanSenCrossedUnderKijunSen =
//
XICHIHLPIsTenkanSenCrossedUnderKijunSen(1)
//
;
//
bool isBullishKumoBreakout =
//
XICHIHLPIsKumoBullish(1) &&
XICHIHLPIsKumoBullish(2) &&
(c2.high > MathMax(ichiInfo.senkouSpanA, ichiInfo.senkouSpanB) &&
c2.low < MathMin(ichiInfo.senkouSpanA, ichiInfo.senkouSpanB)) &&
c1.high < MathMin(ichiInfo.senkouSpanA, ichiInfo.senkouSpanB)
//
;
//
bool isCandloClosedUnderTenkanSen =
//
c1.high < ichiInfo.tenkanSen
//
;
//
bool isKijunbSenUnderKumo =
//
ichiInfo.kijunSen < MathMin(ichiInfo.senkouSpanA, ichiInfo.senkouSpanB)
//
;
//
bool isChikouSpanFree =
//
c1.close < GetLowestLow(
_Symbol,
_Period,
1,
26)
//
;
//
bool isKumoSoFat =
//
MathAbs(ichiInfo.senkouSpanA - ichiInfo.senkouSpanB) > MathAbs(GetHighestHigh(
_Symbol,
_Period,
1,
17) -
GetLowestLow(
_Symbol,
_Period,
1,
17))
//
;
//
bool isKijunSenInsideFutureKumo =
//
ichiInfo.kijunSen < MathMax(ichiInfo.senkouSpanAFuture, ichiInfo.senkouSpanBFuture) &&
ichiInfo.kijunSen > MathMin(ichiInfo.senkouSpanAFuture, ichiInfo.senkouSpanBFuture)
//
;
//
bool isFutureKumoBearish =
//
XICHIHLPIsKumoBearish(1, true)
// &&
//
// TODO: Remove this ...
// MathMax(ichiInfo.senkouSpanA, ichiInfo.senkouSpanB) < MathMax(ichiInfo.senkouSpanAFuture, ichiInfo.senkouSpanBFuture)
//
;
//
bool signal1 =
//
isKumoBearish &&
isTrendSwitched &&
isNewValeHappends &&
isCandleClosedUnderPsar &&
isTenkanSenUnderKijunSen
//
;
//
bool signal2 =
//
isKijunbSenUnderKumo &&
isBullishKumoBreakout &&
isTenkanSenUnderKijunSen &&
isCandloClosedUnderTenkanSen
//
;
//
bool signal3 =
//
!isKumoSoFat &&
isChikouSpanFree &&
isFutureKumoBearish &&
isKijunbSenUnderKumo &&
!isKijunSenInsideFutureKumo &&
isCandloClosedUnderTenkanSen &&
isTenkanSenCrossedUnderKijunSen
//
;
//
result =
//
// signal1
// //
// ||
//
// signal2
// //
// ||
//
signal3
//
;
//
return result;
}
///
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
XOHCL c2 = GetCandle(
_Symbol,
_Period,
2);
//
XIchiInfo ichiInfo = XICHIHLPGetInfo(1);
//
bool isKumoSwitchedToBeraish =
//
XICHIHLPIsKumoSwitchedToBearish(1)
//
;
//
double ll9Value = GetLowestLow(
_Symbol,
_Period,
9,
1);
double hh9Value = GetHighestHigh(
_Symbol,
_Period,
9,
1);
bool isChikouSpanUnderPrice =
//
ichiInfo.chikouSpan < ll9Value &&
ichiInfo.chikouSpan < hh9Value
//
;
//
bool isTenkanSenOverKijunSen =
//
XICHIHLPIsTenkanSenOverKijunSen(1)
//
;
//
bool isPriceUnderTenkanSen =
c1.high < ichiInfo.tenkanSen;
//
bool signal1 =
//
isChikouSpanUnderPrice &&
isKumoSwitchedToBeraish &&
(isTenkanSenOverKijunSen
? isPriceUnderTenkanSen
: true)
//
;
@@ -0,0 +1,79 @@
//
bool result = false;
//
double entry = GetEntry(
mSymbol,
POSITION_TYPE_BUY);
//
XOHCL c0 = GetCandle(
mSymbol,
mPeriod,
0);
double c0AppliedPrice = MathMin(c0.low, c0.open);
//
XOHCL c1 = GetCandle(
mSymbol,
mPeriod,
1);
//
X121MarketConditions mConditions = GetMarketConditions(1);
//
bool signal1 =
//
mConditions.xtrndInfo.l1ll == mConditions.xtrndInfo.l2ll &&
mConditions.xtrndInfo.l1ll == mConditions.xtrndInfo.l3ll &&
mConditions.xtrndInfo.l1ll == mConditions.xpvInfo.vale &&
//
c0AppliedPrice == mConditions.xtrndInfo.l1ll
// &&
//
// mConditions.xmrbInfo.isFastUnderSlow
//
;
//
if (signal1)
{
//
Add(
ToString(XPVF),
mConditions.signal.providers);
//
mConditions.signal.r2r = 1.5;
mConditions.signal.riskAmount = 0.0001;
mConditions.signal.mode = X_ORDER_MODE_STOP;
mConditions.signal.entry = mConditions.xpvInfo.fl3;
mConditions.signal.sl = mConditions.xtrndInfo.l1ll;
mConditions.signal.tp = mConditions.xpvInfo.fl1;
}
//
result =
//
false
// signal1
//
;
//
if (result)
{
//
conditions = mConditions;
//
conditions.signal.symbol = mSymbol;
conditions.signal.period = mPeriod;
conditions.signal.type = POSITION_TYPE_BUY;
//
conditions.hasSignal = true;
}
//
return result;
@@ -0,0 +1,130 @@
//
// When Price going Down of Fibo 3 Level from Up ...
// Chandelier Exit Must Verify Short trade by providing Short Exit 1 and 2 ...
bool signal1 =
//
c1.close < mConditions.xpvInfo.fl3 &&
//
mConditions.xcheInfo.shortExit1 > c1.open &&
mConditions.xcheInfo.shortExit1 != EMPTY_VALUE &&
//
mConditions.xcheInfo.shortExit2 > c1.open &&
mConditions.xcheInfo.shortExit2 != EMPTY_VALUE &&
//
!(mConditions.xtrndInfo.isTrendBullish ||
mConditions.xtrndInfo.isL1TrendBullish ||
mConditions.xtrndInfo.isL2TrendBullish ||
mConditions.xtrndInfo.isL3TrendBullish)
//
;
X121MarketConditions m0Conditions = GetMarketConditions(0);
//
bool signal1 =
//
mConditions.xtrndInfo.l1hh == mConditions.xtrndInfo.l2hh &&
mConditions.xtrndInfo.l1hh == mConditions.xtrndInfo.l3hh &&
mConditions.xtrndInfo.l1hh == mConditions.xpvInfo.peak &&
//
c0AppliedPrice == mConditions.xtrndInfo.l1hh
// &&
//
// mConditions.xmrbInfo.isFastUnderSlow
//
;
//
if (signal1)
{
//
Add(
ToString(XPVF),
mConditions.signal.providers);
//
mConditions.signal.r2r = 1.5;
mConditions.signal.riskAmount = 0.0001;
mConditions.signal.mode = X_ORDER_MODE_STOP;
mConditions.signal.entry = mConditions.xpvInfo.fl1;
mConditions.signal.sl = mConditions.xtrndInfo.l1hh;
mConditions.signal.tp = mConditions.xpvInfo.fl3;
}
//
double minVerifier = MathMin(m0Conditions.xhullInfo.up, m0Conditions.xhullInfo.down);
minVerifier = MathMin(minVerifier, m0Conditions.xmrbInfo.fast);
minVerifier = MathMin(minVerifier, m0Conditions.xmrbInfo.slow);
minVerifier = MathMin(minVerifier, m0Conditions.xsslcInfo.up);
minVerifier = MathMin(minVerifier, m0Conditions.xsslcInfo.down);
//
bool signal2 =
//
(mConditions.xsslcInfo.isBearish &&
mConditions.xmrbInfo.isFastUnderSlow &&
mConditions.xhullInfo.isUpBearish &&
mConditions.xhullInfo.isDownBearish)
//
&&
//
!(m0Conditions.xsslcInfo.isBearish &&
m0Conditions.xmrbInfo.isFastUnderSlow &&
m0Conditions.xhullInfo.isUpBearish &&
m0Conditions.xhullInfo.isDownBearish)
//
&&
//
(mConditions.xtrndInfo.isTrendBearish &&
(mConditions.xtrndInfo.isL1TrendBearish ||
mConditions.xtrndInfo.isL2TrendBearish))
//
&&
//
c1.high < minVerifier
//
;
//
if (signal2)
{
//
Add(
ToString(XCHNL),
mConditions.signal.providers);
//
mConditions.signal.r2r = 1.5;
mConditions.signal.riskAmount = 0.0001;
mConditions.signal.mode = X_ORDER_MODE_MARKET;
mConditions.signal.entry = entry;
mConditions.signal.sl = mConditions.xpvInfo.peak;
mConditions.signal.tp = mConditions.xpvInfo.vale;
}
//
bool signal3 =
//
mConditions.xtrndInfo.isL3TrendSwitchedToBearish
//
;
//
if (signal3)
{
//
Add(
ToString(XTRND),
mConditions.signal.providers);
//
mConditions.signal.r2r = 1.5;
mConditions.signal.riskAmount = 0.0001;
mConditions.signal.mode = X_ORDER_MODE_MARKET;
mConditions.signal.entry = entry;
mConditions.signal.sl = mConditions.xtrndInfo.l3hh;
mConditions.signal.tp = mConditions.xtrndInfo.l3ll;
}
@@ -0,0 +1,181 @@
//
// Find Reversal Position Type ...
ENUM_POSITION_TYPE GetSupportPositionType(ENUM_POSITION_TYPE type)
{
//
ENUM_POSITION_TYPE result = POSITION_TYPE_BUY;
//
if (type == POSITION_TYPE_BUY)
{
result = POSITION_TYPE_SELL;
}
else
{
result = POSITION_TYPE_BUY;
}
//
return result;
}
//
// Check a Position Has Supportable or not ...
bool IsSupportablePosition(XPosition &position)
{
//
bool result = false;
//
if (StringLen(position.comment) <= 0)
{
return result;
}
//
int supStrPos = StringFind(
position.comment,
mSupportPrefix + "(");
//
result = supStrPos < 0;
//
return result;
}
//
// Check a Position has Support Position or not ...
bool HasSupportPosition(XPosition &position)
{
//
bool result = false;
//
int positionsCount = xEATrade.PositionsCount();
//
if (positionsCount <= 0 ||
position.ticket == 0 ||
StringLen(position.comment) <= 0)
{
return result;
}
//
string supCommentStr = mSupportPrefix + "(" + (string)position.ticket + ")";
//
XPosition positions[];
xEATrade.GetPositions(positions);
//
for (int i = 0; i < positionsCount; i++)
{
//
XPosition iPosition = positions[i];
//
int supCommentPos = StringFind(
iPosition.comment,
supCommentStr);
//
result = supCommentPos >= 0;
if (result)
{
break;
}
}
//
return result;
}
//
// Open a Support Position based on Exists ...
void OpenSupportPosition(XPosition &position)
{
//
bool isSupportable = IsSupportablePosition(position);
if (!isSupportable)
{
return;
}
//
bool hasSupport = HasSupportPosition(position);
if (hasSupport)
{
return;
}
//
ENUM_POSITION_TYPE type = GetSupportPositionType(position.type);
double entry = GetEntry(
position.symbol,
type);
//
bool isLong = IsLong(type);
//
double tpPrice = PipsToPrice(
position.symbol,
10);
double slPrice = PipsToPrice(
position.symbol,
5);
//
double tp = 0;
// isLong
// ? entry + tpPrice
// : entry - tpPrice;
//
double sl = 0;
// isLong
// ? entry - slPrice
// : entry + slPrice;
//
string comment = mSupportPrefix + "(" + (string)position.ticket + ")";
//
bool isPositionOpen = false;
//
// Open Signal Position ...
if (isLong)
{
//
isPositionOpen = xEATrade.Buy(
position.symbol,
position.period,
position.volume,
entry,
sl,
tp,
comment);
}
else
{
//
isPositionOpen = xEATrade.Sell(
position.symbol,
position.period,
position.volume,
entry,
sl,
tp,
comment);
}
//
if (isPositionOpen)
{
//
LogMessage("Open Support Psition for: " + position.comment);
}
}
@@ -0,0 +1,62 @@
// //
// int prevBearish =
// XTRNDHLPFindNextTrendSwitchedBearish(1);
// XOHCL cPrevBearish = GetCandle(
// _Symbol,
// _Period,
// prevBearish);
// //
// int prevBullish =
// XTRNDHLPFindNextTrendSwitchedBearish(1);
// XOHCL cPrevBullish = GetCandle(
// _Symbol,
// _Period,
// prevBullish);
// //
// double changeRate = XATRSLHLPGetChangeRate(1);
// double rangeChangeRate = XATRSLHLPGetRangeChangeRate(2);
// double atrValue = atrslUpBuffer[1];
// if (changeRate > rangeChangeRate)
// {
// atrValue = atrslUpBuffer[2];
// }
//
// double hhValue = GetHighestHigh(
// _Symbol,
// _Period,
// 3,
// 1);
//
// double mrbValue = MathMax(mrbFastBuffer[1], mrbSlowBuffer[1]);
//
// atrslUpBuffer[1];
// ichiKijunSenBuffer[1];
// MathMin(cPrevBullish.high, cPrevBearish.high);
// double hh9Value =
// GetHighestHigh(
// _Symbol,
// _Period,
// 1,
// 9);
//
// int prevSwingHigh = FindSwing(
// _Symbol,
// _Period,
// MODE_HIGH,
// 5,
// 1);
// //
// double s1 = XPVHLPGetLastStrongSupport(1);
// double s2 = XPVHLPGetLastStrongSupport(2);
// //
// double r1 = XPVHLPGetLastStrongResistance(1);
// double r2 = XPVHLPGetLastStrongResistance(2);
@@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XHLP Indicator Helper for Signal Providers
// --------------------------------------------------------------------------
//
// 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
//
// START Includes ...
//
//
// Includes ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
#include "../../Libraries/x-saherelm.models.lib.mq5"
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes ...
//
//
// START Constants/Enums ...
//
//
// END Constants/Enums ...
//
//
// START Definitions ...
//
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
bool XHLPOnInit() {
//
bool result = false;
//
return result;
}
//
void XHLPOnDeInit() {
//
// Release Indicators ...
}
//
void XHLPReadBuffers() {
//
}
//
// END Handler Functions ...
//
//
// START Helper Functions ...
//
//
// END Helper Functions ...
//
@@ -0,0 +1,129 @@
//
// Support Signals ...
void GenerateSupportSignals(
XSignal &result[], // Hold Result ...
const XSignal &source // Source Signal to Use for Generation ...
)
{
//
// Here we must Prepare all Signals ...
//
Clean(result);
//
if (source.entry <= 0 ||
(ArraySize(source.supportAndResistance.sup) == 0 &&
ArraySize(source.supportAndResistance.res) == 0))
{
return;
}
//
double priceOf10Points = PointToPrice(
source.symbol,
10);
//
double tmpSupRes[];
int supResCount = ArraySize(source.supportAndResistance.sup) +
ArraySize(source.supportAndResistance.res);
ArrayResize(
tmpSupRes,
supResCount);
ArrayCopy(
tmpSupRes,
source.supportAndResistance.sup);
ArrayCopy(
tmpSupRes,
source.supportAndResistance.res,
0,
ArraySize(source.supportAndResistance.sup) - 1);
//
bool isLong = IsLong(source.type);
//
ENUM_POSITION_TYPE signalReverseType = isLong
? POSITION_TYPE_SELL
: POSITION_TYPE_BUY;
//
// Template Variables ...
double sl;
double tp;
double entry;
ENUM_POSITION_TYPE type;
ENUM_X_ORDER_MODES mode;
double r2r = 1.5;
double volume = NormalizeVolume(
source.volume, // * 1.5,
source.symbol);
string symbol = source.symbol;
ENUM_TIMEFRAMES period = source.period;
double riskAmount = source.riskAmount; // * 1.5;
//
XSignal tmpSignal;
Clean(tmpSignal);
//
// since SL is Lower Sup or Higher Res ...
// we have to add a Reversal Support for SL ...
if (source.sl > 0)
{
//
// Sl Type Signals are Reversal ...
type = signalReverseType;
//
// Finding Entry Price ...
entry = source.sl - priceOf10Points;
sl = !isLong
? FindLesserThanValue(entry, tmpSupRes)
: FindBiggerThanValue(entry, tmpSupRes);
double riskPrice = sl > 0
? MathAbs(entry - sl)
: MathAbs(entry - priceOf10Points);
double riskPoint = PriceToPoint(
symbol,
riskPrice);
double rewardPoint = r2r * riskPoint;
double rewardPrice = PointToPrice(
symbol,
rewardPoint);
tp = !isLong
? entry + rewardPrice
: entry - rewardPrice;
//
mode = X_ORDER_MODE_STOP;
//
// Fill ...
tmpSignal.sl = sl;
tmpSignal.tp = tp;
tmpSignal.r2r = r2r;
tmpSignal.type = type;
tmpSignal.mode = mode;
tmpSignal.entry = entry;
tmpSignal.symbol = symbol;
tmpSignal.volume = volume;
tmpSignal.period = period;
tmpSignal.riskAmount = riskAmount;
//
Add(
tmpSignal,
result);
Clean(tmpSignal);
}
//
// add MidTerm Support Signal ...
// TODO:
//
// TODO: Implement another Support Scenarios ...
}
@@ -0,0 +1,253 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XHULL Indicator
// ---------------------------------------------
// Name: XHULL
// Description: Hull Trend Indicator ...
//
//
// 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 XHull Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XHull"
//
// END Constants ...
//
//
// START Inputs ...
//
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// 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;
}
//
// DeInitialization ...
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
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
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);
//
// this counts Available Bars ...
int limit;
//
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);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
}
//
// END Functions ...
//
@@ -0,0 +1,164 @@
//////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_ICH Ichimoku Time Teory
// ------------------------------------------------------
// Name: X121_ICH_
// Description:
// Market Analysor ...
//
//
// 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_ICH Timing"
//
#property strict
#property indicator_chart_window
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_ICH_T"
//
// Ichimoku Golden Numbers ...
enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS
{
X_ICH_BASE = 9,
X_ICH_GOLDEN = 17,
X_ICH_CYCLE = 26,
X_ICH_PERIOD = 35,
X_ICH_STAR = 45,
X_ICH_MED = 52,
X_ICH_LONG = 63,
X_ICH_FULL = 72
};
//
// END Constants ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// Indicator Chart ID ...
string mIndicatorId;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Assign a hopefully-unique ID to the indicator so that it can later remove itself
mIndicatorId = ShortName + "." + IntegerToString(GetMicrosecondCount());
IndicatorSetString(INDICATOR_SHORTNAME, mIndicatorId);
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
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
}
//
// Calculations ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
return rates_total;
}
//
// Handle Chart Events ...
void OnChartEvent(
const int id, // event ID
const long &lparam, // long type event parameter
const double &dparam, // double type event parameter
const string &sparam // string type event parameter
)
{
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Remove Indicator From Chart ...
void RemoveIndicator()
{
ChartIndicatorDelete(0, 0, mIndicatorId);
}
//
// END Functions ...
//
@@ -0,0 +1,151 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCBaseHelper
// 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
//
// START Definitions ...
//
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Constructor ...
void XSCHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
) : XSCBaseHelper(symbol, period)
{
//
}
//
// Deconstructor ...
void ~XSCHelper()
{
}
//
// START Properties ...
//
//
// Symbol ...
string GetSymbol()
{
return mSymbol;
}
//
// Period ...
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
// Tag ...
string GetTag()
{
return mTag;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Initial Indicator Handler ...
virtual bool Init();
//
// Reading Buffers based on Given Bar Index ...
virtual void ReadBuffers(
int barIndex // Given Bar Index
);
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Indicator Handler ...
int mHandler;
//
// Tag Identifier ...
string mTag;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,435 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXPVHelper
// 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
//
// START Definitions ...
//
//
// Index of Lines ...
enum ENUM_XPV_BUFFERS
{
//
// Main Requirements ...
XPV_PEAKS_LINE = 0,
XPV_VALES_LINE = 1,
};
//
// Retrieve Info Model ...
struct XPVInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Peak Value ...
double peak;
//
// Vales Value ...
double vale;
//
// Conditions ...
//
// Determines New Peaks Happens ...
bool isNewPeak;
//
// Determines New Vales Happens ...
bool isNewVale;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXPVHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double peaksBuffer[];
double valesBuffer[];
//
// Constructor ...
void XSCXPVHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Short Length ...
int shortLength = 9,
//
// Medium Length
int mediumLength = 17,
//
// Long Length ...
int longLength = 26,
//
// Hind Length ...
int hindLength = 35,
//
// Detection Mode ...
//
// Highest High Calculation Method ...
ENUM_SERIESMODE hhMode = MODE_HIGH,
//
// Lowest Low Calculation Method ...
ENUM_SERIESMODE llMode = MODE_LOW,
//
// Presentations ...
//
// Show Peaks and Vales ...
bool showPeaksAndVales = false,
//
// Show Levels ...
bool showLevels = false
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mHHMode = hhMode;
mLLMode = llMode;
mLongLength = longLength;
mHindLength = hindLength;
mShowLevels = showLevels;
mShortLength = shortLength;
mMediumLength = mediumLength;
mShowPeaksAndVales = showPeaksAndVales;
//
Init();
}
//
// Deconstructor ...
void ~XSCXPVHelper()
{
}
//
// START Properties ...
//
//
// Show Levels ...
bool ShowLevels(
bool show // Show or Hide Levels
)
{
//
bool result = false;
//
if (mShowLevels == show)
{
return true;
}
//
mShowLevels = show;
result = Init();
//
return result;
}
//
// Show Peaks and Vales ...
bool ShowPeaksAnVales(
bool show // Show or Hide Levels
)
{
//
bool result = false;
//
if (mShowPeaksAndVales == show)
{
return true;
}
//
mShowPeaksAndVales = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
void PrepareTag()
{
mTag = "" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mShortLength > 2 &&
mMediumLength > mShortLength &&
mLongLength > mMediumLength &&
mHindLength > mLongLength)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xpv",
//
// Inputs ...
//
// Market ...
"",
//
// Short Length ...
mShortLength,
//
// Medium Length
mMediumLength,
//
// Long Length ...
mLongLength,
//
// Hind Length ...
mHindLength,
//
// Detection Mode ...
"",
//
// Highest High Calculation Method ...
mHHMode,
//
// Lowest Low Calculation Method ...
mLLMode,
//
// Presentations ...
"",
//
// Show Peaks and Vales ...
mShowPeaksAndVales,
//
// Show Levels ...
mShowLevels
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// PEAKS ...
CopyBuffer(
mHandler,
XPV_PEAKS_LINE,
barIndex,
mLoopbackBars,
peaksBuffer);
//
// VALES ...
CopyBuffer(
mHandler,
XPV_VALES_LINE,
barIndex,
mLoopbackBars,
valesBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XPVInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XPVInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex
);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;;
result.barIndex = barIndex;
//
result.peak = peaksBuffer[barIndex];
result.vale = valesBuffer[barIndex];
//
result.isNewPeak =
peaksBuffer[barIndex] != peaksBuffer[barIndex + 1];
result.isNewVale =
valesBuffer[barIndex] != valesBuffer[barIndex + 1];
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Short Length ...
int mShortLength;
//
// Medium Length
int mMediumLength;
//
// Long Length ...
int mLongLength;
//
// Hind Length ...
int mHindLength;
//
// Detection Mode ...
//
// Highest High Calculation Method ...
ENUM_SERIESMODE mHHMode;
//
// Lowest Low Calculation Method ...
ENUM_SERIESMODE mLLMode;
//
// Presentations ...
//
// Show Peaks and Vales ...
bool mShowPeaksAndVales;
//
// Show Levels ...
bool mShowLevels;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,310 @@
//
XOHCLSupRes XPVHLPFindCandleSupprtAndResistance(
int bar_index, // Bar Index ...
int verifications = 4 // Number of Verifications ...
)
{
//
XOHCLSupRes result = {};
result.res = 0;
result.highRes = 0;
result.sup = 0;
result.lowSup = 0;
//
XOHCL cBar = GetCandle(
_Symbol,
_Period,
bar_index);
//
int tries = 0;
int lastBar = bar_index;
while (
result.res == 0 ||
result.highRes == 0 ||
result.sup == 0 ||
result.lowSup == 0)
{
//
int bar = XPVHLPFindSupportBar(lastBar);
double val = XPVHLPFindSupportValue(lastBar);
//
int bar1 = XPVHLPFindResistanceBar(lastBar);
double val1 = XPVHLPFindResistanceValue(lastBar);
//
if (result.res == 0 && result.highRes == 0 && val > cBar.high && val1 > cBar.high)
{
//
result.res = MathMin(val, val1);
result.highRes = MathMax(val, val1);
}
else if (result.sup == 0 && result.lowSup == 0 && val < cBar.low && val1 < cBar.low)
{
//
result.sup = MathMax(val, val1);
result.lowSup = MathMin(val, val1);
}
else if (val > cBar.high)
{
//
if (result.res == 0 || result.highRes == 0)
{
//
if (result.res == 0)
{
result.res = val;
}
else if (val > result.res)
{
result.highRes = val;
}
else if (val < result.res)
{
//
result.highRes = result.res;
result.res = val;
}
}
}
else if (val < cBar.low)
{
//
if (result.sup == 0 || result.lowSup == 0)
{
//
if (result.sup == 0)
{
result.sup = val;
}
else if (val < result.sup)
{
result.lowSup = val;
}
else if (val > result.sup)
{
//
result.lowSup = result.sup;
result.sup = val;
}
}
}
else if (val1 > cBar.high)
{
//
if (result.res == 0 || result.highRes == 0)
{
//
if (result.res == 0)
{
result.res = val1;
}
else if (val1 > result.res)
{
result.highRes = val1;
}
else if (val1 < result.res)
{
//
result.highRes = result.res;
result.res = val1;
}
}
}
else if (val1 < cBar.low)
{
//
if (result.sup == 0 || result.lowSup == 0)
{
//
if (result.sup == 0)
{
result.sup = val1;
}
else if (val1 < result.sup)
{
result.lowSup = val1;
}
else if (val1 > result.sup)
{
//
result.lowSup = result.sup;
result.sup = val1;
}
}
}
//
if (tries >= verifications)
{
break;
}
//
lastBar = MathMin(bar, bar1);
tries++;
}
//
return result;
}
//
int XPVHLPFindSupportBar(
int bar_index, // Bar Index ...
int verifications = 4 // Number of Verifications ...
)
{
//
int result = -1;
//
int mVerified = 0;
int idx = bar_index;
bool founded = false;
double lastValue = 0;
while (!founded)
{
//
XPVHLPReadBuffers(idx);
bool isSupport = XPVHLPIsStrongSupport(idx);
if (isSupport)
{
//
if (lastValue != pvLLLBuffer[idx])
{
//
lastValue = pvLLLBuffer[idx];
mVerified = 0;
}
else if (lastValue == pvLLLBuffer[idx])
{
mVerified++;
}
}
else
{
mVerified = 0;
}
//
idx++;
//
founded = mVerified >= verifications;
if (founded)
{
result = idx;
break;
}
}
//
return result;
}
//
double XPVHLPFindSupportValue(
int bar_index, // Bar Index ...
int verifications = 4 // Number of Verifications ...
)
{
//
double result = 0;
//
int supportBar = XPVHLPFindSupportBar(bar_index, verifications);
if (supportBar < -1)
{
return result;
}
//
return pvSLLBuffer[bar_index];
//
return result;
}
//
int XPVHLPFindResistanceBar(
int bar_index, // Bar Index ...
int verifications = 4 // Number of Verifications ...
)
{
//
int result = -1;
//
int mVerified = 0;
int idx = bar_index;
bool founded = false;
double lastValue = 0;
while (!founded)
{
//
XPVHLPReadBuffers(idx);
bool isSupport = XPVHLPIsStrongResistance(idx);
if (isSupport)
{
//
if (lastValue != pvLHHBuffer[idx])
{
//
lastValue = pvLHHBuffer[idx];
mVerified = 0;
}
else if (lastValue == pvLHHBuffer[idx])
{
mVerified++;
}
}
else
{
mVerified = 0;
}
//
idx++;
//
founded = mVerified >= verifications;
if (founded)
{
result = idx;
break;
}
}
//
return result;
}
//
double XPVHLPFindResistanceValue(
int bar_index, // Bar Index ...
int verifications = 4 // Number of Verifications ...
)
{
//
double result = 0;
//
int supportBar = XPVHLPFindResistanceBar(bar_index, verifications);
if (supportBar < -1)
{
return result;
}
//
return pvSHHBuffer[bar_index];
//
return result;
}
@@ -0,0 +1,164 @@
//
// Find Last Strong Support ...
double XPVHLPGetLastStrongSupport(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
double result = 0;
//
bool isBarIndexSupport = XPVHLPIsStrongSupport(bar_index);
if (isBarIndexSupport)
{
length += bar_index;
}
//
if (!XPVHLPIsValidArraySize(bar_index + length + 1))
{
return result;
}
//
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (XPVHLPIsStrongSupport(i))
{
//
result = mpvSLLBuffer[i];
break;
}
}
//
return result;
}
//
// Find Last Strong Resistance ...
double XPVHLPGetLastStrongResistance(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
double result = 0;
//
bool isBarIndexResistance = XPVHLPIsStrongResistance(bar_index);
if (isBarIndexResistance)
{
length += bar_index;
}
//
if (!XPVHLPIsValidArraySize(bar_index + length + 1))
{
return result;
}
//
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (XPVHLPIsStrongResistance(i))
{
//
result = mpvSHHBuffer[i];
break;
}
}
//
return result;
}
//
// Find Strong Support Break Stop ...
bool XPVHLPIsSupportBreakedStop(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
bool result = false;
//
bool isBaIndexSupport = XPVHLPIsStrongSupport(bar_index);
if (isBaIndexSupport)
{
return result;
}
//
if (!XPVHLPIsValidArraySize(bar_index + length + 1))
{
return result;
}
//
bool isAllStrongSupport = true;
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (!XPVHLPIsStrongSupport(i) && isAllStrongSupport)
{
//
isAllStrongSupport = false;
break;
}
}
//
result = !isBaIndexSupport && isAllStrongSupport;
//
return result;
}
//
// Find Strong Resistance Break Stop ...
bool XPVHLPIsResistanceBreakedStop(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
bool result = false;
//
bool isBaIndexResistance = XPVHLPIsStrongResistance(bar_index);
if (isBaIndexResistance)
{
return result;
}
//
if (!XPVHLPIsValidArraySize(bar_index + length + 1))
{
return result;
}
//
bool isAllStrongResistance = true;
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (!XPVHLPIsStrongResistance(i) && isAllStrongResistance)
{
//
isAllStrongResistance = false;
break;
}
}
//
result = !isBaIndexResistance && isAllStrongResistance;
//
return result;
}