Files
MQL5Data/Documents/BKP/1/4.mq5
T
2025-01-21 05:46:01 +03:30

531 lines
15 KiB
Plaintext

//////////////////////////////////////////////////////////////////////////////////
////// Detect Price Zones :
/////////////////////////////////////////////////////////////////////////////////
//
XPriceZones priceZone;
bool isPriceZoneValidForPeak;
bool isPriceZoneValidForVale;
//
priceZone.Clean();
isPriceZoneValidForPeak = false;
isPriceZoneValidForVale = false;
//
// Detect Price Zone ...
//
double pzPeak = decisionXConditions.peaksBuffer[1];
double pzVale = decisionXConditions.valesBuffer[1];
//
// Detecting Decision Price ones ...
XPriceZones decisionPriceZone;
bool hasDecisionPriceZone = CalculatePriceInsideZones(
decisionPriceZone,
decisionState,
cBar //
);
double decisionPriceZoneUpper = 0;
double decisionPriceZoneLower = 0;
bool isDecisionPriceZoneValidForPeak = false;
bool isDecisionPriceZoneValidForVale = false;
if (hasDecisionPriceZone)
{
//
bool hasBoundary = decisionPriceZone.GetBoundary(
X_DIRECTION_ALL,
decisionPriceZoneUpper,
decisionPriceZoneLower //
);
//
isDecisionPriceZoneValidForPeak =
hasBoundary &&
pzPeak <= decisionPriceZoneUpper &&
pzPeak >= decisionPriceZoneLower;
//
isDecisionPriceZoneValidForVale =
hasBoundary &&
pzVale <= decisionPriceZoneUpper &&
pzVale >= decisionPriceZoneLower;
}
//
// Detecting Analyse Price ones ...
XPriceZones analysePriceZone;
bool hasAnalysePriceZone = CalculatePriceInsideZones(
analysePriceZone,
analyseState,
cBar //
);
double analysePriceZoneUpper = 0;
double analysePriceZoneLower = 0;
bool isAnalysePriceZoneValidForPeak = false;
bool isAnalysePriceZoneValidForVale = false;
if (hasAnalysePriceZone)
{
//
bool hasBoundary = analysePriceZone.GetBoundary(
X_DIRECTION_ALL,
analysePriceZoneUpper,
analysePriceZoneLower //
);
//
isAnalysePriceZoneValidForPeak =
hasBoundary &&
pzPeak <= analysePriceZoneUpper &&
pzPeak >= analysePriceZoneLower;
//
isAnalysePriceZoneValidForVale =
hasBoundary &&
pzVale <= analysePriceZoneUpper &&
pzVale >= analysePriceZoneLower;
}
//
// Detecting Verification Price ones ...
XPriceZones verificationPriceZone;
bool hasVerificationPriceZone = CalculatePriceInsideZones(
verificationPriceZone,
verificationState,
cBar //
);
double verificationPriceZoneUpper = 0;
double verificationPriceZoneLower = 0;
bool isVerificationPriceZoneValidForPeak = false;
bool isVerificationPriceZoneValidForVale = false;
if (hasVerificationPriceZone)
{
//
bool hasBoundary = verificationPriceZone.GetBoundary(
X_DIRECTION_ALL,
verificationPriceZoneUpper,
verificationPriceZoneLower //
);
//
isVerificationPriceZoneValidForPeak =
hasBoundary &&
pzPeak <= verificationPriceZoneUpper &&
pzPeak >= verificationPriceZoneLower;
//
isVerificationPriceZoneValidForVale =
hasBoundary &&
pzVale <= verificationPriceZoneUpper &&
pzVale >= verificationPriceZoneLower;
}
//////////////////////////////////////////////////////////////////////////////////
////// Detect Pivot Zones :
/////////////////////////////////////////////////////////////////////////////////
//
double X121SMCXPivotPeak;
double X121SMCXPivotVale;
datetime X121SMCXPivotEnd;
datetime X121SMCXPivotStart;
ENUM_XPV_PIVOTS X121SMCXPivotType = XPV_NONE;
//
// Detect PV Pivot ...
//
bool isPivotPeakZoneRejected = false;
bool isPivotPeakZoneBreakedUp = false;
bool isPivotPeakZoneBreakedDown = false;
bool isPivotValeZoneRejected = false;
bool isPivotValeZoneBreakedUp = false;
bool isPivotValeZoneBreakedDown = false;
bool hasPivot = conditions.pivotZone.IsValid();
if (!hasPivot)
{
//
hasPivot = IsValid(X121SMCXPivotStart);
if (!hasPivot)
{
//
bool isNewVale = decisionXConditions.isNewVale;
bool isNewValeOverLast = decisionXConditions.isNewValeOverLast;
bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast;
bool isSameVales = decisionXConditions.valesBuffer[1] ==
decisionXConditions.valesBuffer[2] &&
decisionXConditions.valesBuffer[2] ==
decisionXConditions.valesBuffer[3];
bool isSameCycleVales = decisionXConditions.valesBuffer[1] ==
analyseXConditions.valesBuffer[1] &&
analyseXConditions.valesBuffer[1] ==
verificationXConditions.valesBuffer[1];
//
bool isNewPeak = decisionXConditions.isNewPeak;
bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast;
bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast;
bool isSamePeaks = decisionXConditions.peaksBuffer[1] ==
decisionXConditions.peaksBuffer[2] &&
decisionXConditions.peaksBuffer[2] ==
decisionXConditions.peaksBuffer[3];
bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] ==
analyseXConditions.peaksBuffer[1] &&
analyseXConditions.peaksBuffer[1] ==
verificationXConditions.peaksBuffer[1];
//
bool isValeStart =
isSameVales &&
isSameCycleVales;
bool isPeakStart =
isSamePeaks &&
isSameCyclePeaks;
//
bool isStart = isPeakStart ||
isValeStart;
if (isStart)
{
//
X121SMCXPivotStart = cTime;
X121SMCXPivotType =
isPeakStart
? XPV_PEAK
: XPV_VALE;
//
X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1];
X121SMCXPivotVale = decisionXConditions.valesBuffer[1];
}
//
hasPivot = IsValid(X121SMCXPivotStart);
//
// Create XPVPivot instance ...
if (hasPivot)
{
//
conditions.pivotZone.symbol = symbol;
conditions.pivotZone.period = period;
//
conditions.pivotZone.to = cTime;
conditions.pivotZone.repetition = 3;
//
conditions.pivotZone.upper = X121SMCXPivotPeak;
conditions.pivotZone.lower = X121SMCXPivotVale;
//
conditions.pivotZone.type = X121SMCXPivotType;
conditions.pivotZone.from = X121SMCXPivotStart;
}
}
}
//
if (hasPivot)
{
//
bool isBreaked = X121SMCXPivotType == XPV_PEAK
? decisionXConditions.isBreakedUpPrevPeak
: decisionXConditions.isBreakedDownPrevVale;
//
if (!isBreaked)
{
//
X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1];
X121SMCXPivotVale = decisionXConditions.valesBuffer[1];
//
conditions.pivotZone.to = cTime;
conditions.pivotZone.repetition++;
conditions.pivotZone.upper = X121SMCXPivotPeak;
conditions.pivotZone.lower = X121SMCXPivotVale;
}
else
{
//
X121SMCXPivotEnd = cTime;
conditions.pivotZone.to = cTime;
}
//
// Fill Pivot State ...
//
XPOIState analysePivotState;
DetectPivotPOIs(
conditions.pivotZone,
analyseState,
analysePivotState //
);
//
XPOIState decisionPivotState;
DetectPivotPOIs(
conditions.pivotZone,
decisionState,
decisionPivotState //
);
//
// Combine two State ...
XPOIState combinedPivotState;
XPOIState iStates[];
AddRef(
analysePivotState,
iStates //
);
AddRef(
decisionPivotState,
iStates //
);
CombineStates(
combinedPivotState,
iStates //
);
combinedPivotState = decisionPivotState;
//
ArrayFree(iStates);
//
combinedPivotState.time = decisionPivotState.time;
combinedPivotState.symbol = decisionPivotState.symbol;
combinedPivotState.period = decisionPivotState.period;
//
// Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ...
FilterPivotState(
conditions.pivotZone,
combinedPivotState //
);
//
conditions.pivotZone.state = combinedPivotState;
//
double peakUpper = 0;
double peakLower = 0;
double valeUpper = 0;
double valeLower = 0;
//
datetime peakTo = NULL;
datetime valeTo = NULL;
datetime peakFrom = NULL;
datetime valeFrom = NULL;
//
bool hasBoxData = DetectPivotStateBoxData(
conditions.pivotZone,
peakUpper,
peakLower,
peakFrom,
peakTo,
valeUpper,
valeLower,
valeFrom,
valeTo //
);
//
// Calculate Pivot Tick Zones ...
//
int ticksLevels = decisionCycleHelper
.mPOIDetector
.TicksRangeZoneLevel();
int ticksRange = decisionCycleHelper
.mPOIDetector
.TicksRangeZoneRange();
//
CalculatePivotTickZone(
conditions.pivotZone,
ticksLevels,
ticksRange //
);
//
isPivotPeakZoneRejected =
hasBoxData &&
(
//
IsBarReject(
peakLower,
X_DIRECTION_BEARISH,
cBar //
)
//
||
//
IsBarReject(
peakUpper,
X_DIRECTION_BEARISH,
cBar //
)
//
);
isPivotPeakZoneBreakedUp =
hasBoxData &&
IsBarBreak(
peakUpper,
X_DIRECTION_BULLISH,
cBar //
);
isPivotPeakZoneBreakedDown =
hasBoxData &&
IsBarBreak(
peakLower,
X_DIRECTION_BEARISH,
cBar //
);
//
isPivotValeZoneRejected =
hasBoxData &&
(
//
IsBarReject(
valeLower,
X_DIRECTION_BULLISH,
cBar //
)
//
||
//
IsBarReject(
valeUpper,
X_DIRECTION_BULLISH,
cBar //
)
//
);
isPivotValeZoneBreakedUp =
hasBoxData &&
IsBarBreak(
valeUpper,
X_DIRECTION_BULLISH,
cBar //
);
isPivotValeZoneBreakedDown =
hasBoxData &&
IsBarBreak(
valeLower,
X_DIRECTION_BEARISH,
cBar //
);
}
//
bool isPivotEnded = IsValid(X121SMCXPivotEnd);
if (isPivotEnded)
{
//
X121SMCXPivotPeak = 0;
X121SMCXPivotVale = 0;
X121SMCXPivotEnd = NULL;
X121SMCXPivotStart = NULL;
X121SMCXPivotType = XPV_NONE;
//
conditions.pivotZone.Clean();
}
//////////////////////////////////////////////////////////////////////////////////
////// Detect Pivot Zones :
/////////////////////////////////////////////////////////////////////////////////
//
bool isCondition1Bullish =
//
hasPivot &&
//
isCBarBullishFormed &&
isCBarBullishPullbacked &&
//
hasAnalyseBullishTrend &&
hasDecisionBullishTrend &&
hasVerificationBullishTrend &&
//
decisionXConditions.isSarBullish &&
analyseXConditions.isSarBullish &&
verificationXConditions.isSarBullish &&
//
false
//
;
//
bool isCondition1Bearish =
//
hasPivot &&
//
isCBarBearishFormed &&
isCBarBearishPullbacked &&
//
hasAnalyseBearishTrend &&
hasDecisionBearishTrend &&
hasVerificationBearishTrend &&
//
decisionXConditions.isSarBearish &&
analyseXConditions.isSarBearish &&
verificationXConditions.isSarBearish &&
//
false
//
;
//
bool hasCondition1 = isCondition1Bullish ||
isCondition1Bearish;
if (hasCondition1)
{
//
ENUM_X_DIRECTION pzDir =
isCondition1Bullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
conditions.priceZone = analysePriceZone;
conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak;
conditions.isPriceZoneValidForVale = isAnalysePriceZoneValidForVale;
//
pzPeak = analysePriceZoneUpper;
pzVale = analysePriceZoneLower;
//
double point = GetEntry(
conditions.symbol,
pzDir //
);
//
// Manipulate Conditions Point ...
//
// point =
// isCondition1Bullish ? pzPeak
// : pzVale;
conditions.point = point;
//
// Manipulate Conditions Pivot ...
//
conditions.pivot =
isCondition1Bullish
? pzVale
: pzPeak;
}