apply trail stop and break even ...

This commit is contained in:
2025-02-11 23:28:28 +03:30
parent fe129c3288
commit 4a70a3ef4f
11 changed files with 2682 additions and 1063 deletions
+3 -2
View File
@@ -362,7 +362,8 @@ class XCBarAnalyser : public XCBase
* Detect Price Consolidation ...
*
* @param bar: XOHCL instance Reference, Start Bar ...
* @param loopback: Integer, Consolidation Range Finder ...
* @param loopback: Integer, Consolidation Length Finder ...
* @param consolidationRange: Integer, Consolidation Range Finder ...
* @param upper: Double Reference ...
* @param lower: Double Reference ...
* @param upperAppliedTo: ENUM_APPLIED_PRICE member, Upper Price ...
@@ -375,6 +376,7 @@ class XCBarAnalyser : public XCBase
double &upper,
double &lower,
int loopback = 30,
int consolidationRange = 70,
ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH,
ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW //
)
@@ -400,7 +402,6 @@ class XCBarAnalyser : public XCBase
}
//
int consolidationRange = 30;
double points = GetPoints(bar.symbol);
int index = bar.Index();
@@ -4582,4 +4582,893 @@ else if (isPriceInsideDemandZone)
/////////////////////////////////////////////////////////////////////
// //
// bool isPriceAboveUpper =
// //
// decisionZBar.high < conditions.workingZone.zoneUpper &&
// decisionCBar.high < conditions.workingZone.zoneUpper &&
// //
// decisionZBar.low > conditions.workingZone.upper &&
// decisionCBar.low > conditions.workingZone.upper
// //
// ;
// if (isPriceAboveUpper)
// {
// //
// bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
// bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_HIGH;
// }
// //
// bool isPriceInQuarterOne =
// //
// decisionZBar.high < conditions.workingZone.upper &&
// decisionCBar.high < conditions.workingZone.upper &&
// //
// decisionZBar.low > conditions.workingZone.quarter1 &&
// decisionCBar.low > conditions.workingZone.quarter1
// //
// ;
// if (isPriceInQuarterOne)
// {
// //
// bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
// bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_REGULAR;
// }
// //
// bool isPriceInQuarterTwo =
// //
// decisionZBar.high < conditions.workingZone.quarter1 &&
// decisionCBar.high < conditions.workingZone.quarter1 &&
// //
// decisionZBar.low > conditions.workingZone.quarter2 &&
// decisionCBar.low > conditions.workingZone.quarter2
// //
// ;
// if (isPriceInQuarterTwo)
// {
// //
// bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
// bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_LOW;
// }
// //
// bool isPriceInQuarterThree =
// //
// decisionZBar.high < conditions.workingZone.quarter2 &&
// decisionCBar.high < conditions.workingZone.quarter2 &&
// //
// decisionZBar.low > conditions.workingZone.quarter3 &&
// decisionCBar.low > conditions.workingZone.quarter3
// //
// ;
// if (isPriceInQuarterThree)
// {
// //
// bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_LOW;
// bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
// }
// //
// bool isPriceInQuarterFour =
// //
// decisionZBar.high < conditions.workingZone.quarter3 &&
// decisionCBar.high < conditions.workingZone.quarter3 &&
// //
// decisionZBar.low > conditions.workingZone.lower &&
// decisionCBar.low > conditions.workingZone.lower
// //
// ;
// if (isPriceInQuarterFour)
// {
// //
// bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_REGULAR;
// bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
// }
// //
// bool isPriceBelowLower =
// //
// decisionZBar.high < conditions.workingZone.lower &&
// decisionCBar.high < conditions.workingZone.lower &&
// //
// decisionZBar.low > conditions.workingZone.zoneLower &&
// decisionCBar.low > conditions.workingZone.zoneLower
// //
// ;
// if (isPriceBelowLower)
// {
// //
// bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_HIGH;
// bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
// }
/////////////////////////////////////////////////////////////////////
//
//
//
//
// Close ...
if (!ignoreCloseOnTPNearGuard)
{
//
double tpCloseDiff = (15 * points);
for (int i = 0; i < count; i++)
{
//
XPosition iPosition = ownPositions[i];
//
// Position Must be In Profit ...
if (iPosition.profit <= 0)
{
continue;
}
//
bool isPricePassed = MathAbs(iPosition.tp - iPosition.price) <= tpCloseDiff;
if (!isPricePassed)
{
continue;
}
//
bool isLong = IsLong(iPosition.type);
//
bool iHasGuard =
//
isLong
? //
false
//
: //
false
//
;
if (iHasGuard)
{
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE;
//
iGuard.ticket = iPosition.ticket;
//
AddGuard(
iGuard,
guards //
);
}
}
}
//
if (hasLongs)
{
//
if (!ignoreCloseLongsOnBearishTrendGuard)
{
//
bool hasGuard = false; // hasDecisionBearishTrend;
//
if (hasGuard)
{
//
for (int i = 0; i < longsCount; i++)
{
//
XPosition iPosition = ownLongPositions[i];
//
// Position must be in Draw Down ...
if (iPosition.profit > 0)
{
continue;
}
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE;
//
iGuard.ticket = iPosition.ticket;
//
AddGuard(
iGuard,
guards //
);
}
}
}
}
//
if (hasShorts)
{
//
if (!ignoreCloseShortsOnBullishTrendGuard)
{
//
bool hasGuard = false; // hasDecisionBullishTrend;
//
if (hasGuard)
{
//
for (int i = 0; i < shortsCount; i++)
{
//
XPosition iPosition = ownShortPositions[i];
//
// Position must be in Draw Down ...
if (iPosition.profit > 0)
{
continue;
}
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE;
//
iGuard.ticket = iPosition.ticket;
//
AddGuard(
iGuard,
guards //
);
}
}
}
}
//
// Close All ...
//
// Close All Weekend ...
if (!ignoreCloseAllWeekendGuard)
{
//
MqlDateTime mDate;
bool hasDate = TimeCurrent(mDate);
if (hasDate)
{
//
ENUM_X_WEEK_DAYS dayOfWeek = GetDayOfWeek();
//
bool isWeekend = dayOfWeek == X_WEEK_DAY_FRIDAY;
if (isWeekend && mDate.hour == 23 && mDate.min == 30)
{
//
X121SMCGuard guard;
//
guard.time = cTime;
guard.symbol = symbol;
guard.provider = provider;
guard.action = X_121_SMC_GUARD_ACTION_CLOSE_ALL;
//
AddGuard(
guard,
guards //
);
}
}
}
//
// Close Longs ...
if (hasLongs)
{
//
bool hasGuard =
//
false
//
// hasAnalyseBearishTrend &&
// hasDecisionBearishTrend
//
;
//
if (hasGuard)
{
//
X121SMCGuard guard;
//
guard.time = cTime;
guard.symbol = symbol;
guard.provider = provider;
guard.action = X_121_SMC_GUARD_ACTION_CLOSE_LONGS;
//
AddGuard(
guard,
guards //
);
}
}
//
// Close Shorts ...
if (hasShorts)
{
//
bool hasGuard =
//
false
//
// hasAnalyseBullishTrend &&
// hasDecisionBullishTrend
//
;
//
if (hasGuard)
{
//
X121SMCGuard guard;
//
guard.time = cTime;
guard.symbol = symbol;
guard.provider = provider;
guard.action = X_121_SMC_GUARD_ACTION_CLOSE_SHORTS;
//
AddGuard(
guard,
guards //
);
}
}
//
// Partial Close ...
//
if (!ignorePartialCloseOnTrendChangeGuard)
{
//
if (hasLongs)
{
//
bool hasGuard =
//
false
//
// hasTriggerBearishTrend ||
// !hasDecisionBullishTrend
//
;
//
if (hasGuard)
{
//
for (int i = 0; i < longsCount; i++)
{
//
XPosition iPosition = ownLongPositions[i];
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE;
//
iGuard.ticket = iPosition.ticket;
iGuard.volumeMultiplier = 0.5;
//
AddGuard(
iGuard,
guards //
);
}
}
}
//
if (hasShorts)
{
//
bool hasGuard =
//
false
//
// hasTriggerBullishTrend ||
// !hasDecisionBearishTrend
//
;
//
if (hasGuard)
{
//
for (int i = 0; i < shortsCount; i++)
{
//
XPosition iPosition = ownShortPositions[i];
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE;
//
iGuard.ticket = iPosition.ticket;
iGuard.volumeMultiplier = 0.5;
//
AddGuard(
iGuard,
guards //
);
}
}
}
}
//
// Trail Stop ...
if (!ignoreTrailStopGuard)
{
//
if (hasLongs)
{
//
bool hasTrendGuard = false; // hasDecisionBearishTrend;
//
bool hasConsolidationGuard =
(hasConsolidationZone &&
isConsolidationZoneBreaked &&
isConsolidationZoneBreakedUp);
//
bool hasDecisionPriceZoneGuard =
false;
// (hasDecisionPriceZone &&
// isDecisionPriceZoneBullish &&
// isDecisionPriceZoneValidForVale &&
// isDecisionPriceZoneUpperBreakedUp);
//
bool hasAnalysePriceZoneGuard =
false;
// (hasAnalysePriceZone &&
// isAnalysePriceZoneBullish &&
// isAnalysePriceZoneValidForVale &&
// isAnalysePriceZoneUpperBreakedUp);
//
bool hasVerificationPriceZoneGuard =
false;
// (hasVerificationPriceZone &&
// isVerificationPriceZoneBullish &&
// isVerificationPriceZoneValidForVale &&
// isVerificationPriceZoneUpperBreakedUp);
//
bool hasGuard =
//
hasTrendGuard ||
hasConsolidationGuard ||
hasDecisionPriceZoneGuard ||
hasAnalysePriceZoneGuard ||
hasVerificationPriceZoneGuard
//
;
//
double guardStop =
hasConsolidationGuard
? consolidationZoneLower
: hasDecisionPriceZoneGuard
? 0 // decisionPriceZoneLower
: hasAnalysePriceZoneGuard
? 0 // analysePriceZoneLower
: hasVerificationPriceZoneGuard
? 0 // verificationPriceZoneLower
: 0;
//
if (hasGuard)
{
//
for (int i = 0; i < longsCount; i++)
{
//
XPosition iPosition = ownLongPositions[i];
//
// Position Must Be In Profit ...
if (iPosition.profit <= 0)
{
continue;
}
//
if (hasTrendGuard)
{
// guardStop = decisionXConditions.strBuffer[1] - decisionXConditions.atrBuffer[1];
}
//
// Price Must Greater than Zone Lower ...
if (iPosition.price < guardStop)
{
continue;
}
//
// Position Entry Must Lesser than Zone Lower ...
if (iPosition.entry > guardStop)
{
continue;
}
//
// Position SL must be Zero or Lesser than Zone Lower ...
if (iPosition.sl != 0 &&
iPosition.sl > guardStop)
{
continue;
}
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP;
//
iGuard.sl = guardStop;
iGuard.ticket = iPosition.ticket;
//
AddGuard(
iGuard,
guards //
);
}
}
}
//
if (hasShorts)
{
//
bool hasTrendGuard = false; // hasDecisionBullishTrend;
//
bool hasConsolidationGuard =
(hasConsolidationZone &&
isConsolidationZoneBreaked &&
isConsolidationZoneBreakedDown);
//
bool hasDecisionPriceZoneGuard =
false;
// (hasDecisionPriceZone &&
// isDecisionPriceZoneBearish &&
// isDecisionPriceZoneValidForPeak &&
// isDecisionPriceZoneLowerBreakedDown);
//
bool hasAnalysePriceZoneGuard =
false;
// (hasAnalysePriceZone &&
// isAnalysePriceZoneBearish &&
// isAnalysePriceZoneValidForPeak &&
// isAnalysePriceZoneLowerBreakedDown);
//
bool hasVerificationPriceZoneGuard =
false;
// (hasVerificationPriceZone &&
// isVerificationPriceZoneBearish &&
// isVerificationPriceZoneValidForPeak &&
// isVerificationPriceZoneLowerBreakedDown);
//
bool hasGuard =
//
hasTrendGuard ||
hasConsolidationGuard ||
hasDecisionPriceZoneGuard ||
hasAnalysePriceZoneGuard ||
hasVerificationPriceZoneGuard
//
;
//
double guardStop =
hasConsolidationGuard
? consolidationZoneUpper
: hasDecisionPriceZoneGuard
? 0 // decisionPriceZoneUpper
: hasAnalysePriceZoneGuard
? 0 // analysePriceZoneUpper
: hasVerificationPriceZoneGuard
? 0 // verificationPriceZoneUpper
: 0;
//
if (hasGuard)
{
//
for (int i = 0; i < shortsCount; i++)
{
//
XPosition iPosition = ownShortPositions[i];
//
// Position Must Be In Profit ...
if (iPosition.profit <= 0)
{
continue;
}
//
if (hasTrendGuard)
{
// guardStop = decisionXConditions.strBuffer[1] + decisionXConditions.atrBuffer[1];
}
//
// Price Must Lesser than Zone Upper ...
if (iPosition.price > guardStop)
{
continue;
}
//
// Position Entry Must Greater than Zone Upper ...
if (iPosition.entry < guardStop)
{
continue;
}
//
// Position SL must be Zero or Greater than Zone Upper ...
if (iPosition.sl != 0 &&
iPosition.sl < guardStop)
{
continue;
}
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP;
//
iGuard.sl = guardStop;
iGuard.ticket = iPosition.ticket;
//
AddGuard(
iGuard,
guards //
);
}
}
}
}
//
// Trail Target ...
if (!ignoreTrailTargetGuard)
{
//
if (hasLongs)
{
//
bool hasAnalyseGuard =
//
false
//
// (hasAnalysePriceZone &&
// isAnalysePriceZoneValidForPeak &&
// isAnalysePriceZoneUpperRejected)
//
;
//
bool hasVerificationGuard =
//
false
//
// (hasVerificationPriceZone &&
// isVerificationPriceZoneValidForPeak &&
// isVerificationPriceZoneUpperRejected)
//
;
//
bool hasGuard =
//
hasAnalyseGuard ||
hasVerificationGuard
//
;
//
double guardTP =
hasAnalyseGuard
? 0 // analysePriceZoneUpper
: hasVerificationGuard
? 0 // verificationPriceZoneUpper
: 0;
//
if (hasGuard)
{
//
for (int i = 0; i < longsCount; i++)
{
//
XPosition iPosition = ownLongPositions[i];
//
// Position Must Be In Profit ...
if (iPosition.profit <= 0)
{
continue;
}
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET;
//
iGuard.tp = guardTP;
iGuard.ticket = iPosition.ticket;
//
AddGuard(
iGuard,
guards //
);
}
}
}
//
if (hasShorts)
{
//
bool hasAnalyseGuard =
//
false
//
// (hasAnalysePriceZone &&
// isAnalysePriceZoneValidForVale &&
// isAnalysePriceZoneLowerRejected)
//
;
//
bool hasVerificationGuard =
//
false
//
// (hasVerificationPriceZone &&
// isVerificationPriceZoneValidForVale &&
// isVerificationPriceZoneLowerRejected)
//
;
//
bool hasGuard =
//
hasAnalyseGuard ||
hasVerificationGuard
//
;
//
double guardTP =
hasAnalyseGuard
? 0 // analysePriceZoneLower
: hasVerificationGuard
? 0 // verificationPriceZoneLower
: 0;
//
if (hasGuard)
{
//
for (int i = 0; i < shortsCount; i++)
{
//
XPosition iPosition = ownShortPositions[i];
//
// Position Must Be In Profit ...
if (iPosition.profit <= 0)
{
continue;
}
//
X121SMCGuard iGuard;
//
iGuard.time = cTime;
iGuard.symbol = symbol;
iGuard.provider = provider;
iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET;
//
iGuard.tp = guardTP;
iGuard.ticket = iPosition.ticket;
//
AddGuard(
iGuard,
guards //
);
}
}
}
}
//
// Hedge ...
if (!ignoreHedgeGuard)
{
}
/////////////////////////////////////////////////////////
+41 -1
View File
@@ -70,7 +70,6 @@ enum ENUM_XPOIS
// Fair Value Gaps ...
X_POI_BULLISH_FVG, // Bullish Order Block ...
X_POI_BEARISH_FVG, // Bearish Order Block ...
X_POI_CONSOLIDATION_ZONE, // Consolidation Zone ...
};
//
@@ -5959,6 +5958,7 @@ struct XConsolidationZone
//
};
//
struct XBoxZone
{
//
@@ -8293,6 +8293,46 @@ bool ToBox(
return result;
}
/**
* Converts to XBoxZone ...
*
* @return ( bool )
*/
bool ToBox(
XBoxZone &box,
XConsolidationZone &item //
)
{
//
bool result = false;
//
box.Clean();
//
result = item.IsValid();
if (!result)
{
return result;
}
//
box.upper = item.upper;
box.lower = item.lower;
box.dir = item.breakDir;
box.from = item.initTime;
box.symbol = item.symbol;
box.period = item.period;
box.to = item.breakerBar.time;
box.type = "X_CONSOLIDATION_ZONE";
//
result = box.IsValid();
//
return result;
}
/**
* Get Oldest Zone ...
*
+2
View File
@@ -1119,6 +1119,7 @@ struct XSignal
//
// Traget ...
double target; // Force Risk Free On Target ...
bool ignoreEAVolume; // Ignore EA Volume ...
//
// SL Trail ...
@@ -1679,6 +1680,7 @@ struct XSignal
//
target = 0;
ignoreEAVolume = false;
//
trailSL = false;
@@ -41,6 +41,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
// Public ...
public:
//
XCAccount mAccount;
//
// Constructor(s) ...
@@ -106,6 +106,183 @@ class XC121SMCCycleHelper : public XCBase
//
// Getter/Setter(s) ...
//
int CountConsolidationZones()
{
return ArraySize(mConsolidationZones);
}
//
bool HasConsolidationZones()
{
return HasChild(mConsolidationZones);
}
//
bool GetConsolidationZone(
int idx,
XConsolidationZone &zone //
)
{
//
bool result = false;
//
zone.Clean();
//
result = HasConsolidationZones();
if (!result)
{
return result;
}
//
int count = CountConsolidationZones();
result = idx >= 0 &&
idx < count;
if (!result)
{
return result;
}
//
zone = mConsolidationZones[idx];
result = zone.IsValid();
//
return result;
}
//
bool GetLastDirectionalConsolidationZone(
ENUM_X_DIRECTION forDir,
XConsolidationZone &zone //
)
{
//
bool result = false;
//
zone.Clean();
//
result = HasDirection(forDir);
if (!result)
{
return result;
}
//
bool hasZones = HasConsolidationZones();
int zonesCount = CountConsolidationZones();
result = hasZones;
if (!result)
{
return result;
}
//
for (int i = zonesCount - 1; i >= 0; i--)
{
//
XConsolidationZone iZone = mConsolidationZones[i];
//
if (!iZone.IsBreaked())
{
continue;
}
//
if (!HasDirection(iZone.breakDir))
{
continue;
}
//
if (iZone.breakDir != forDir)
{
continue;
}
//
zone = iZone;
break;
}
//
result = zone.IsValid();
//
return result;
}
//
bool GetActiveConsolidationZone(
XConsolidationZone &zone //
)
{
//
bool result = false;
//
zone = mActiveConsolidationZone;
result = zone.IsValid();
//
return result;
}
//
int FillConsolidationZones(
ENUM_X_DIRECTION forDir,
XConsolidationZone &zones[] //
)
{
//
int result = 0;
//
Clean(zones);
//
bool hasZones = HasConsolidationZones();
if (!hasZones)
{
return result;
}
//
int count = CountConsolidationZones();
for (int i = 0; i < count; i++)
{
//
XConsolidationZone iZone = mConsolidationZones[i];
//
bool isDirPassed =
(forDir == X_DIRECTION_ALL ||
forDir == X_DIRECTION_NONE)
? true
: forDir == iZone.breakDir;
if (isDirPassed)
{
//
AddRef(
iZone,
zones //
);
}
}
//
result = ArraySize(zones);
//
return result;
}
//
// Actions ...
@@ -461,6 +638,9 @@ class XC121SMCCycleHelper : public XCBase
maxAllowed //
);
// //
// if (GetPeriod() == PERIOD_M5)
// {
// //
// XCConsolidationZoneObject *czObj;
// bool isCreated = mPOIDrawer.CreateConsolidationZone(
@@ -471,6 +651,7 @@ class XC121SMCCycleHelper : public XCBase
// {
// mConsolidationObjects.Add(czObj);
// }
// }
//
mActiveConsolidationZone.Clean();
@@ -551,7 +732,7 @@ class XC121SMCCycleHelper : public XCBase
ENUM_TIMEFRAMES mPeriod;
//
CArrayObj mConsolidationObjects;
// CArrayObj mConsolidationObjects;
XConsolidationZone mActiveConsolidationZone;
XConsolidationZone mConsolidationZones[];
+7 -1
View File
@@ -22,8 +22,8 @@
//
// Imports ...
#include "../../Classes/x-saherelm.x-expert.class.mq5"
#include "../../Helpers/x-saherelm.x121.xct.helper.mq5"
#include "../../Helpers/x-saherelm.x121.xcc.helper.mq5"
#include "../../Helpers/x-saherelm.x121.xct.helper.mq5"
#include "../Classes/x-121.smc.x-tradehandler.class.mq5"
#include "../Libraries/x-121.smc.lib.mq5"
#include "../Strategy/x-121.smc.strategy.class.mq5"
@@ -1609,6 +1609,12 @@ class XC121SMCExpert : public XCBaseExpert
*/
void ApplyVolumeOnSignal(XSignal &signal)
{
//
if (signal.ignoreEAVolume)
{
return;
}
//
double staticVolume = Volume();
double fVolume = staticVolume > 0
File diff suppressed because it is too large Load Diff
+2 -16
View File
@@ -71,11 +71,9 @@ struct X121SMCCycleConditions
ENUM_TIMEFRAMES period;
datetime time;
//
X121Conditions x121Conditions;
//
XPOIState state;
X121Conditions x121Conditions;
//
void X121SMCStrategyConditions()
@@ -98,7 +96,7 @@ struct X121SMCCycleConditions
//
state.Clean();
// x121Conditions.Clean();
x121Conditions.Clean();
//
ZeroMemory(this);
@@ -272,12 +270,6 @@ struct X121SMCStrategyConditions
string provider;
ENUM_X_DIRECTION signalDir;
//
// X121Conditions conditions;
// XPriceZones priceZones;
// XPriceZones decisionZones;
// XMarketStructure marketStructure;
//
void X121SMCStrategyConditions()
{
@@ -303,12 +295,6 @@ struct X121SMCStrategyConditions
provider = NULL;
signalDir = X_DIRECTION_NONE;
//
// conditions.Clean();
// priceZones.Clean();
// decisionZones.Clean();
// marketStructure.Clean();
//
ZeroMemory(this);
}
File diff suppressed because it is too large Load Diff
+110 -40
View File
@@ -102,27 +102,23 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
void Destroy() override
{
//
// XSupDemOBS ...
RemoveX121SMCXSupDemOBSDraws();
mX121SMCXSupDemOBSConditions.Clean();
Clean(mX121SMCXSupDemOBSConditionsCollection);
RemoveX121SMCXSupDemOBSWorkingZoneDraws();
//
// ZeroMemory(mTriggerCycleHelper);
ZeroMemory(mDecisionCycleHelper);
ZeroMemory(mAnalyseCycleHelper);
// ZeroMemory(mVerificationCycleHelper);
ZeroMemory(mConsolidationCycleHelper);
ZeroMemory(mVisionCycleHelper);
//
// delete mTriggerCycleHelper;
delete mDecisionCycleHelper;
delete mAnalyseCycleHelper;
// delete mVerificationCycleHelper;
delete mConsolidationCycleHelper;
delete mVisionCycleHelper;
//
RemoveX121SMCXSupDemOBSDraws();
RemoveX121SMCXSupDemOBSWorkingZoneDraws();
}
/**
@@ -205,10 +201,14 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
//
// XSupDemOBS Signal ...
X121SMCStrategyXSupDemOBSSignalConditions mXSupDemOBSConditions;
if (useXSupDemOBSSignal && !hasSignal)
{
//
hasXSupDemOBSSignal = DetectXSupDemOBSSignal(conditions);
hasXSupDemOBSSignal = DetectXSupDemOBSSignal(
conditions,
mXSupDemOBSConditions //
);
hasSignal = hasXSupDemOBSSignal;
}
@@ -317,46 +317,107 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
//
if (result)
{
//
// Configure Signal Protector ...
// if (useXSTRPVSignal)
// {
// //
// signal.trailSL = false;
// signal.fullTPLevel = r2r;
// signal.partialCloseOnTPLevel = 2;
// signal.partialCloseMultiplier = 0.5;
// signal.trailSLStartOnReachTPLevel = 2;
// }
//
// TODO: Remove this ...
// XCSignalObject *iObj;
// mPOIDrawer.DrawSignal(signal, iObj);
// Print("");
//
if (useXSupDemOBSSignal &&
hasXSupDemOBSSignal)
{
//
// double sR2R = signal.GetRiskRewardRatio();
// double risk = signal.GetRisk();
//
// double tp = signal.tp;
// double target = signal.tp + (risk * sR2R);
// Re Draw Working Zone ...
RemoveX121SMCXSupDemOBSWorkingZoneDraws();
DrawX121SMCXSupDemOBSWorkingZone(
mXSupDemOBSConditions,
mVisionCycleHelper.mPOIDrawer //
);
//
// signal.tp = target;
// signal.target = tp;
// Re Draw Working Zone ...
RemoveX121SMCXSupDemOBSDraws();
DrawX121SMCXSupDemOBSConditions(
mXSupDemOBSConditions,
mVisionCycleHelper.mPOIDrawer //
);
//
// Configuring Amount Percent and ETC ...
bool ignoreEAVolume = mXSupDemOBSConditions.reward > 0 &&
mXSupDemOBSConditions.amountPercent > 0;
if (ignoreEAVolume)
{
//
double cReward = mXSupDemOBSConditions.reward;
double cAmountPercent = mXSupDemOBSConditions.amountPercent;
//
double cRiskReward = risk * cReward;
double cTP = hasLong
? entry + cRiskReward
: entry - cRiskReward;
//
double balance = mAccount.GetBalance();
double cRiskAmount = balance * cAmountPercent / 100;
double cRiskInPoints = risk / points;
double cVolume = mAccount.CalculateVolume(
signal.symbol,
cRiskAmount,
cRiskInPoints //
);
cVolume = NormalizeVolume(cVolume, signal.symbol);
//
if (cVolume > 0)
{
//
signal.ignoreEAVolume = ignoreEAVolume;
signal.volume = cVolume;
}
}
//
// Fix Signal TP Based On Working Zone ...
double maxAllowedTP =
hasLong
? mXSupDemOBSConditions.workingZone.upper
: mXSupDemOBSConditions.workingZone.lower;
bool canApplyMaxAlowedTP = (hasLong &&
signal.tp > maxAllowedTP) ||
(!hasLong && signal.tp < maxAllowedTP);
if (canApplyMaxAlowedTP)
{
signal.tp = maxAllowedTP;
}
//
// Configuring Global Protector ...
signal.trailSL = true;
signal.fullTPLevel = r2r;
signal.partialCloseOnTPLevel = 0;
signal.partialCloseMultiplier = 0;
signal.trailSLStartOnReachTPLevel = 3;
signal.fullTPLevel = signal.GetRiskRewardRatio();
}
//
// Draw Signal Oject ...
XCSignalObject *iSignalObj;
bool isCreated = mVisionCycleHelper
.mPOIDrawer
.DrawSignal(signal, iSignalObj);
if (isCreated)
{
//
mSignalDrawnObjects.Add(iSignalObj);
//
int maxAllowedDrawnSignals = 15;
int count = mSignalDrawnObjects.Total();
if (count > maxAllowedDrawnSignals)
{
//
int to = count - maxAllowedDrawnSignals;
mSignalDrawnObjects.DeleteRange(
0,
to //
);
}
}
}
@@ -365,6 +426,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
hasShort = false;
}
//
mXSupDemOBSConditions.Clean();
//
return result;
}
@@ -431,6 +495,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
//
// Props ...
CArrayObj mSignalDrawnObjects;
//
// XC121SMCCycleHelper *mTriggerCycleHelper;
@@ -449,7 +514,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
//
// XSupDemOBS Signal ...
bool DetectXSupDemOBSSignal(
X121SMCStrategyConditions &conditions //
X121SMCStrategyConditions &conditions,
X121SMCStrategyXSupDemOBSSignalConditions &xSupDemOBSConditions //
)
{
//
@@ -599,10 +665,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
mTmpConditions[i],
symbol,
period,
// mTriggerCycleHelper,
mDecisionCycleHelper,
mAnalyseCycleHelper,
// mVerificationCycleHelper,
mConsolidationCycleHelper,
mVisionCycleHelper //
);
@@ -673,6 +737,12 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
conditions.signalDir = mConditions.dir;
conditions.target = mConditions.target;
//
xSupDemOBSConditions = mConditions;
//
mConditions.Clean();
//
return result;
}