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
@@ -41,7 +41,8 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
// Public ...
public:
//
XCAccount mAccount;
//
// Constructor(s) ...
XCX121SMCBaseStrategy(
@@ -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 ...
@@ -462,14 +639,18 @@ class XC121SMCCycleHelper : public XCBase
);
// //
// XCConsolidationZoneObject *czObj;
// bool isCreated = mPOIDrawer.CreateConsolidationZone(
// mActiveConsolidationZone,
// czObj //
// );
// if (isCreated)
// if (GetPeriod() == PERIOD_M5)
// {
// mConsolidationObjects.Add(czObj);
// //
// XCConsolidationZoneObject *czObj;
// bool isCreated = mPOIDrawer.CreateConsolidationZone(
// mActiveConsolidationZone,
// czObj //
// );
// if (isCreated)
// {
// mConsolidationObjects.Add(czObj);
// }
// }
//
@@ -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;
}