This commit is contained in:
2024-12-29 05:42:27 +03:30
parent 408422dcfc
commit ecdba76c3f
12 changed files with 2310 additions and 104 deletions
+371 -81
View File
@@ -49,16 +49,8 @@ struct X121SMCStrategyXTWPVSignalConditions
datetime triggerTime;
//
int peakRepeat;
double farPeak;
double middlePeak;
double nearPeak;
//
int valeRepeat;
double farVale;
double middleVale;
double nearVale;
double point;
XPVPivot pivot;
//
// Constructor ...
@@ -175,16 +167,13 @@ struct X121SMCStrategyXTWPVSignalConditions
void ExtensionClean()
{
//
peakRepeat = 0;
farPeak = 0;
middlePeak = 0;
nearPeak = 0;
point = 0;
pivot.Clean();
}
//
valeRepeat = 0;
farVale = 0;
middleVale = 0;
nearVale = 0;
bool HasPivot()
{
return pivot.IsValid();
}
//
@@ -409,7 +398,200 @@ bool DetectX121SMCXTWPVSiganlSetup(
// }
//
// Check Exists Valid Peaks or Vales ...
// Retrieve Active Pivots ...
//
// Select Source Cycle Helper ...
XC121SMCCycleHelper *helper = analyseCycleHelper;
X121SMCCycleConditions helperConditions = analyseConditions;
XPOIState helperState = analyseState;
XOHCL helperCBar;
result = helper.GetBar(
cBar,
helperCBar //
);
if (!result)
{
return result;
}
//
XPVPivot peakPivot;
bool hasPeakPivot = helper
.GetActivePeakPivot(peakPivot);
//
XPVPivot valePivot;
bool hasValePivot = helper
.GetActiveValePivot(valePivot);
//
// Check Pivot ...
bool hasPivot = conditions.HasPivot();
if (!hasPivot)
{
//
if (hasPeakPivot && !hasValePivot)
{
conditions.pivot = peakPivot;
}
else if (hasValePivot && !hasPeakPivot)
{
conditions.pivot = valePivot;
}
else if (hasPeakPivot && hasValePivot)
{
//
if (peakPivot.from > valePivot.from)
{
conditions.pivot = peakPivot;
}
else if (valePivot.from > peakPivot.from)
{
conditions.pivot = valePivot;
}
}
//
hasPivot = conditions.HasPivot();
result = hasPivot;
if (!result)
{
return result;
}
}
//
// Update Pivot States ...
if (hasPivot)
{
//
conditions.pivot.to = cTime;
helper.FillPivotState(conditions.pivot);
//
bool hasNewPivot =
//
(hasPeakPivot &&
peakPivot.from > conditions.pivot.from) ||
(hasValePivot &&
valePivot.from > conditions.pivot.from)
//
;
result = !hasNewPivot;
if (!result)
{
//
conditions.pivot.Clean();
return result;
}
}
//
// Waits for new Peaks or Vales ...
//
double peak = helperConditions.x121Conditions.peaksBuffer[1];
bool isNewPeak = helperConditions.x121Conditions.isNewPeak;
bool isNewPeakOverLast = helperConditions.x121Conditions.isNewPeakOverLast;
bool isNewPeakUnderLast = helperConditions.x121Conditions.isNewPeakUnderLast;
//
double vale = helperConditions.x121Conditions.valesBuffer[1];
bool isNewVale = helperConditions.x121Conditions.isNewVale;
bool isNewValeOverLast = helperConditions.x121Conditions.isNewValeOverLast;
bool isNewValeUnderLast = helperConditions.x121Conditions.isNewValeUnderLast;
//
result = isNewPeak ||
isNewVale;
if (!result)
{
return result;
}
//
// Calculate Conditions ...
//
// Bullish ...
//
// Bearish ...
//
double bullishFib = GetFibonacciLevel(
helperCBar.high,
helperCBar.low,
GetFiboLevelValue(X_FIBO_LEVEL_382),
-1 //
);
//
double bearishFib = GetFibonacciLevel(
helperCBar.high,
helperCBar.low,
GetFiboLevelValue(X_FIBO_LEVEL_382),
1 //
);
//
bool isBearishFiboPassed = bullishFib <= conditions.pivot.lower;
//
// Bearish Conditions 1 ...
bool bearishConditions1 =
//
isNewValeUnderLast &&
isBearishFiboPassed &&
helperCBar.IsBearish() &&
conditions.pivot.lower > vale &&
conditions.pivot.lower < helperCBar.GetUp() &&
conditions.pivot.lower > helperCBar.GetDown()
//
;
if (bearishConditions1)
{
conditions.point = conditions.pivot.lower;
}
//
double donCloseUpper = helperConditions.x121Conditions.donCloseUpperBuffer[1];
double donCloseLower = helperConditions.x121Conditions.donCloseLowerBuffer[1];
//
double donOpenUpper = helperConditions.x121Conditions.donOpenUpperBuffer[1];
double donOpenLower = helperConditions.x121Conditions.donOpenLowerBuffer[1];
//
bool bearishConditions2 =
//
isNewPeakUnderLast &&
donCloseUpper > peak
//
;
if (bearishConditions2)
{
conditions.point = peak;
}
//
// Summary Conditions ...
//
isBullish =
//
false
//
;
//
isBearish =
//
bearishConditions1 ||
bearishConditions2
//
;
//
result = isBullish ||
@@ -465,8 +647,8 @@ bool DetectX121SMCXTWPVSiganlTrigger(
ENUM_X_DIRECTION setupDir = conditions.dir;
//
bool isBullish = false;
bool isBearish = false;
bool isBullish = IsBullish(setupDir);
bool isBearish = IsBearish(setupDir);
//
int zIndex = 0;
@@ -639,56 +821,15 @@ bool DetectX121SMCXTWPVSiganlTrigger(
//
// Trigger Conditions ...
//
// Check VWap State ...
// //
// isBullish =
// isBullish &&
// false;
//
bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState;
bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState;
//
isBullish =
IsBullish(setupDir) &&
isVWapBullishState;
//
isBearish =
IsBearish(setupDir) &&
isVWapBearishState;
//
result = isBullish ||
isBearish;
if (!result)
{
return result;
}
//
// Waitings For Sar Switched to Direction ...
//
double sar = triggerConditions.x121Conditions.sarBuffer[1];
//
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
//
isBullish =
//
isBullish &&
isSarSwitchedToBullish
//
;
//
isBearish =
//
isBearish &&
isSarSwitchedToBearish
//
;
// //
// isBearish =
// isBearish &&
// false;
//
result = isBullish ||
@@ -710,32 +851,181 @@ bool DetectX121SMCXTWPVSiganlTrigger(
}
//
// Detect Nearest FVG or Supply Zone For Traget ...
// Detect Consolidation ...
XConsolidationZone consolidationZone;
bool hasConsolidationZone = triggerCycleHelper
.GetLastConsolidationZone(consolidationZone);
if (hasConsolidationZone)
{
//
hasConsolidationZone =
isBullish
? consolidationZone.upper <= conditions.point
: consolidationZone.lower >= conditions.point;
//
if (!hasConsolidationZone)
{
consolidationZone.Clean();
}
}
//
// Select Source State ...
XPOIState state = triggerState;
// Detect Nearest Pivot Point ...
XPVPivotPoint pivotPoints[];
XPVPivotPoint nearestPivotPoint;
bool hasNearestPivotPoint = false;
int pivotPointsCount = triggerCycleHelper
.FillPivotPoints(pivotPoints);
if (IsValidSize(pivotPointsCount))
{
//
for (int i = 0; i < pivotPointsCount; i++)
{
//
XPVPivotPoint iPoint = pivotPoints[i];
//
bool canSet =
(isBullish
? iPoint.value < conditions.point
: iPoint.value > conditions.point)
//
&&
//
(!nearestPivotPoint.IsValid()
? true
: isBullish
? nearestPivotPoint.value > iPoint.value
: nearestPivotPoint.value < iPoint.value);
if (canSet)
{
nearestPivotPoint = iPoint;
}
}
//
hasNearestPivotPoint = nearestPivotPoint.IsValid();
}
//
// Detect Target ...
double target = CalculateTarget(
cBar,
state,
analyseState,
setupDir //
);
if (target == 0)
{
//
target = CalculateTarget(
cBar,
verificationState,
setupDir //
);
}
//
double oppositTarget = CalculateTarget(
cBar,
analyseState,
Opposit(setupDir) //
);
//
double points = GetPoints(conditions.symbol);
//
double entry = GetEntry(
conditions.symbol,
setupDir //
);
//
result = target > 0;
if (!result)
// Filling SL Candidates ...
double sls[];
if (hasConsolidationZone)
{
return result;
//
if (isBullish)
{
Add(
consolidationZone.lower,
sls //
);
}
else
{
Add(
consolidationZone.upper,
sls //
);
}
}
if (hasNearestPivotPoint)
{
Add(
nearestPivotPoint.value,
sls //
);
}
if (ArraySize(sls) == 0)
{
//
double pointsDiff = (10 * points);
double pointsPlus = conditions.point + pointsDiff;
double pointsMinus = conditions.point - pointsDiff;
//
// Force SL ...
Add(
conditions.point,
sls //
);
//
Add(
pointsPlus,
sls //
);
//
Add(
pointsMinus,
sls //
);
//
Add(
oppositTarget,
sls //
);
}
//
double slsMin = GetMin(sls);
double slsMax = GetMax(sls);
//
double sl = isBullish
? slsMin
: slsMax;
double risk = MathAbs(entry - sl);
double targetDelta = 2 * (risk / 3);
if (target == 0)
{
//
// Force Target On Half Risk ...
target =
isBullish
? entry + targetDelta
: entry - targetDelta;
}
//
conditions.sl = sl;
conditions.target = target;
conditions.triggerTime = cTime;
conditions.sl = isBullish
? sar
: sar;
conditions.type = isBullish
? X_POSITION_TYPE_LONG
: X_POSITION_TYPE_SHORT;