Apply Last Fixes on TWPV Strategy Method 1 ...

This commit is contained in:
2024-12-31 18:45:16 +03:30
parent 8d90d3bcc2
commit 1c1e1c8365
5 changed files with 194 additions and 86 deletions
+52
View File
@@ -265,6 +265,14 @@ class XCZone : public XCBasePOI
return mUpper;
}
/**
* Set Zone Upper Boundary ...
*/
void Upper(double value)
{
mUpper = value;
}
/**
* Get Zone Lower Boundary ...
*
@@ -275,6 +283,14 @@ class XCZone : public XCBasePOI
return mLower;
}
/**
* Set Zone Lower Boundary ...
*/
void Lower(double value)
{
mLower = value;
}
/**
* Retrieve Zone Range ...
*
@@ -4763,6 +4779,42 @@ struct XConsolidationZone
//
};
/**
* Converts a Consolidation Zone ...
*
* @param zone: XConsolidationZone instance Reference ...
* @param dest: XCZone pointer Reference ...
*
* @return ( bool )
*/
bool ToZone(
XConsolidationZone &zone,
XCZone *&dest //
)
{
//
bool result = false;
//
dest = NULL;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
dest = new XCZone();
dest.Upper(zone.upper);
dest.Lower(zone.lower);
result = dest.IsValidBoundary();
//
return result;
}
//
// Model Value Changed ...
struct XValueChange
+16 -10
View File
@@ -129,15 +129,16 @@ enum ENUM_X_POSITION_SELECT_METHODS
enum ENUM_X_SIGNAL_EXECUTION_RESULT
{
//
X_SIGNAL_EXECUTION_UNKNOWN, // Unknown
X_SIGNAL_EXECUTION_SUCCEED, // Succed
X_SIGNAL_EXECUTION_FAILED_SPREAD, // Spread more than Max Allowed
X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED, // Not Allowed Trade Type
X_SIGNAL_EXECUTION_FAILED_NO_EQUITY, // No Equity for Trade
X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR, // Price Error
X_SIGNAL_EXECUTION_FAILED_MAX_REACHED, // Max Allowed Positions Reached
X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED, // Same Positions Delay Not Passed
X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS, // Invalid Params
X_SIGNAL_EXECUTION_UNKNOWN, // Unknown
X_SIGNAL_EXECUTION_SUCCEED, // Succed
X_SIGNAL_EXECUTION_FAILED_SPREAD, // Spread more than Max Allowed
X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED, // Not Allowed Trade Type
X_SIGNAL_EXECUTION_FAILED_NO_EQUITY, // No Equity for Trade
X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR, // Price Error
X_SIGNAL_EXECUTION_FAILED_PREV_PROFIT_ERROR, // Prev Profit Error
X_SIGNAL_EXECUTION_FAILED_MAX_REACHED, // Max Allowed Positions Reached
X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED, // Same Positions Delay Not Passed
X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS, // Invalid Params
};
//
@@ -5328,6 +5329,11 @@ string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value)
result = "Price Error";
break;
//
case X_SIGNAL_EXECUTION_FAILED_PREV_PROFIT_ERROR:
result = "Previous Position Profit not Passed for Accept Next";
break;
//
case X_SIGNAL_EXECUTION_FAILED_MAX_REACHED:
result = "Max Allowed Positions Reached";
@@ -5337,7 +5343,7 @@ string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value)
case X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED:
result = "Min Delay Between to Signal not Passed";
break;
//
case X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS:
result = "Invalid Params";
@@ -2637,11 +2637,11 @@ class XC121SMCCycleHelper : public XCBase
//
if (hasConsolidation &&
!mActioveConsolidationZone.IsValid())
!mActiveConsolidationZone.IsValid())
{
//
// Initialize Consolidation Zone ...
bool isInited = mActioveConsolidationZone.Init(
bool isInited = mActiveConsolidationZone.Init(
changeBar.symbol,
changeBar.period,
upper,
@@ -2652,23 +2652,23 @@ class XC121SMCCycleHelper : public XCBase
//
if (!hasConsolidation &&
mActioveConsolidationZone.IsValid())
mActiveConsolidationZone.IsValid())
{
//
mActioveConsolidationZone.Update();
bool isBreaked = mActioveConsolidationZone.IsBreaked();
mActiveConsolidationZone.Update();
bool isBreaked = mActiveConsolidationZone.IsBreaked();
//
if (isBreaked)
{
//
// Add Active to List ...
bool isInited = AddConsolidationZone(mActioveConsolidationZone);
bool isInited = AddConsolidationZone(mActiveConsolidationZone);
if (isInited)
{
//
// Clean Active Zone ...
mActioveConsolidationZone.Clean();
mActiveConsolidationZone.Clean();
//
Add(
@@ -2678,6 +2678,23 @@ class XC121SMCCycleHelper : public XCBase
}
}
}
//
// Draw ...
// if (mActiveConsolidationZone.IsValid())
// {
// //
// if (mActiveConsolidationZoneObj != NULL)
// {
// mActiveConsolidationZoneObj.Delete();
// }
// //
// bool isCreated = mPOIDetector.mDrawer.CreateConsolidationZone(
// mActiveConsolidationZone,
// mActiveConsolidationZoneObj //
// );
// }
}
//
@@ -3128,7 +3145,8 @@ class XC121SMCCycleHelper : public XCBase
//
int mConsolidationLoopback; // Consolidation Loopback Length ...
XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ...
XConsolidationZone mActioveConsolidationZone; // Holds Actiove Consolidation Zone ...
XConsolidationZone mActiveConsolidationZone; // Holds Actiove Consolidation Zone ...
// XCConsolidationZoneObject *mActiveConsolidationZoneObj;
//
int mValidPivotRepetition; // Valid Pivot Point's Repetition ...
@@ -2914,7 +2914,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (!result)
{
//
state = X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR;
state = X_SIGNAL_EXECUTION_FAILED_PREV_PROFIT_ERROR;
return result;
}
@@ -646,12 +646,6 @@ bool DetectX121SMCXTWPVSiganlSetup(
//
// Setup Conditions ...
// //
// // Select Sources ...
// XC121SMCCycleHelper *helper = analyseCycleHelper;
// X121SMCCycleConditions helperConditions = analyseConditions;
// XPOIState helperState = analyseState;
//
XOHCL analyseCBar;
result = analyseCycleHelper.GetBar(
@@ -895,6 +889,62 @@ bool DetectX121SMCXTWPVSiganlSetup(
priceInsideZonesCount = conditions.CountPriceInsideZones();
}
//
// Check Price Inside Consolidation Zone ...
XConsolidationZone cZone;
bool hasConsolidationZone = conditions
.HasConsolidationZone();
if (!hasConsolidationZone)
{
//
hasConsolidationZone = triggerCycleHelper
.GetLastConsolidationZone(cZone);
//
if (!hasConsolidationZone)
{
//
XConsolidationZone cZones[];
int count = triggerCycleHelper
.FillConsolidationZones(cZones);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XConsolidationZone iZone = cZones[i];
//
XCZone *iCZone;
bool isInited = ToZone(iZone, iCZone);
if (!isInited)
{
continue;
}
//
bool isValid = IsPriceInsideZone(
cBar,
iCZone //
);
if (isValid)
{
cZone = iZone;
}
}
}
//
conditions.consolidationZone = cZone;
hasConsolidationZone = conditions
.HasConsolidationZone();
}
}
if (hasConsolidationZone)
{
conditions.consolidationZone = cZone;
}
//
// PV Conditions ...
@@ -1221,18 +1271,6 @@ bool DetectX121SMCXTWPVSiganlSetup(
return result;
}
//
if (isBullish)
{
Print("Bullish ...");
}
//
if (isBearish)
{
Print("Bearish ...");
}
//
conditions.setupTime = cTime;
conditions.dir =
@@ -1461,16 +1499,6 @@ bool DetectX121SMCXTWPVSiganlTrigger(
//
// Trigger Conditions ...
// //
// isBullish =
// isBullish &&
// false;
// //
// isBearish =
// isBearish &&
// false;
//
result = isBullish ||
isBearish;
@@ -1490,34 +1518,34 @@ bool DetectX121SMCXTWPVSiganlTrigger(
return result;
}
//
// Detect Consolidation ...
bool hasConsolidationZone = conditions.HasConsolidationZone();
if (hasConsolidationZone)
{
//
hasConsolidationZone = triggerCycleHelper
.GetLastConsolidationZone(conditions.consolidationZone);
// //
// // Detect Consolidation ...
// bool hasConsolidationZone = conditions.HasConsolidationZone();
// if (hasConsolidationZone)
// {
// //
// hasConsolidationZone = triggerCycleHelper
// .GetLastConsolidationZone(conditions.consolidationZone);
//
if (hasConsolidationZone)
{
//
hasConsolidationZone =
isBullish
? conditions.consolidationZone.upper <= conditions.point
: conditions.consolidationZone.lower >= conditions.point;
// //
// if (hasConsolidationZone)
// {
// //
// hasConsolidationZone =
// isBullish
// ? conditions.consolidationZone.upper <= conditions.point
// : conditions.consolidationZone.lower >= conditions.point;
//
if (!hasConsolidationZone)
{
//
conditions
.consolidationZone
.Clean();
}
}
}
// //
// if (!hasConsolidationZone)
// {
// //
// conditions
// .consolidationZone
// .Clean();
// }
// }
// }
//
// Detect Nearest Pivot Point ...
@@ -1589,7 +1617,13 @@ bool DetectX121SMCXTWPVSiganlTrigger(
//
// Filling SL Candidates ...
double atr = triggerConditions.x121Conditions.atrBuffer[1];
//
double sls[];
//
bool hasConsolidationZone = conditions.HasConsolidationZone();
if (hasConsolidationZone)
{
//
@@ -1773,30 +1807,28 @@ bool DetectX121SMCXTWPVSiganlTrigger(
//
double sl = isBullish
? slsMin
: slsMax;
? slsMin - atr
: slsMax + atr;
double risk = MathAbs(entry - sl);
double targetDelta = 2 * (risk / 3);
if (target == 0)
{
//
int minTargetPint = 50;
double minTargetPointValue = minTargetPint * points;
if (targetDelta < minTargetPointValue)
{
targetDelta = minTargetPointValue;
}
//
// Force Target On Half Risk ...
target =
isBullish
? entry + targetDelta
: entry - targetDelta;
}
//
if (isBullish)
{
Print("Bullish ...");
}
//
if (isBearish)
{
Print("Bearish ...");
//
}
//