last works ...

This commit is contained in:
2024-11-24 13:48:12 +03:30
parent 0e2e474d46
commit 042fa88d3a
6 changed files with 701 additions and 203 deletions
+138 -5
View File
@@ -53,6 +53,34 @@ class XC121SMCExpert : public XCBaseExpert
//
// Getter(s) / Setter(s) ...
/**
* Get Risk to Reward Ratio ...
*
* @return ( double )
*/
double R2R()
{
return mR2R;
}
/**
* Set Risk to Reward Ratio ...
*
* @param value: Double ...
*/
void R2R(double value)
{
//
if (value < 1)
{
value = 1;
}
//
mR2R = value;
ReConfigureAllStrategies();
}
/**
* Get Use Dynamic Volume State ...
*
@@ -154,6 +182,26 @@ class XC121SMCExpert : public XCBaseExpert
mRiskPercentPerBalance = value;
}
/**
* Get Dynamic Risk Management State ...
*
* @return ( bool )
*/
bool DynamicRiskManagement()
{
return mDynamicRiskManagement;
}
/**
* Set Dynamic Risk Management State ...
*
* @param value: Boolean ...
*/
void DynamicRiskManagement(bool value)
{
mDynamicRiskManagement = value;
}
/**
* Get Static Volume ...
*
@@ -265,12 +313,27 @@ class XC121SMCExpert : public XCBaseExpert
//
datetime currentTime = TimeCurrent();
//
// Check Signal Protections ...
bool canTrail = false;
ENUM_X_121_SMC_PROVIDERS signalProvider = ParseProvider(signal.provider);
if (IsValid(signalProvider))
{
//
// Complete this in Force States ...
// canTrail = true;
}
//
// Execute Signal Using Trade Handler ...
ENUM_X_SIGNAL_EXECUTION_RESULT state;
bool isExecuted = mTradeHandler.ExecuteSignal(
signal,
state //
state,
false, // ignore Policies ...
//
// Force Protections ...
canTrail //
);
//
@@ -326,12 +389,19 @@ class XC121SMCExpert : public XCBaseExpert
ReportNewHours(false);
ReportNewMonths(false);
//
R2R(1);
//
// Volume Default Configurations ...
Volume(0.01);
UseDynamicVolume(false);
DynamicVolumeStep(0.01);
DynamicVolumeBalanceFactor(200);
//
RiskPercentPerBalance(0);
DynamicRiskManagement(false);
}
/**
@@ -495,8 +565,8 @@ class XC121SMCExpert : public XCBaseExpert
// TODO: Make This Configurable Later ...
//
mTradeHandler.DelayBarBetweenTwoSignal(3);
mTradeHandler.MaxAllowedSLToPause(0);
mTradeHandler.DelayBarBetweenTwoSignal(3);
mTradeHandler.MaxAllowedSLReachedPauseDelay(HoursToSeconds(24));
//
@@ -532,7 +602,7 @@ class XC121SMCExpert : public XCBaseExpert
mTradeHandler.TrailStep(15);
mTradeHandler.TrailStartDistance(30);
mTradeHandler.OnlyTrailUnprotected(true);
mTradeHandler.RemoveTPAfterTrailedLevel(4);
mTradeHandler.RemoveTPAfterTrailedLevel(3);
//
// Partial Close (In Profit) ...
@@ -676,6 +746,10 @@ class XC121SMCExpert : public XCBaseExpert
*/
void HandleStrategiesOnTick() override
{
//
// Calling Protection Handler of TradeHandler ...
mTradeHandler.HandleProtection();
//
int count = ArraySize(mStrategies);
if (!IsValidSize(count))
@@ -721,6 +795,13 @@ class XC121SMCExpert : public XCBaseExpert
// Finish ...
mTradeHandler.Finish(deal);
//
bool useDynamicRiskManagement = DynamicRiskManagement();
if (useDynamicRiskManagement)
{
mTradeHandler.ResetSymbolInfo(deal.symbol);
}
//
HandleReportBalance();
}
@@ -781,7 +862,7 @@ class XC121SMCExpert : public XCBaseExpert
//
result =
XCBaseExpertToken + result;
XC121SMCExpertToken + result;
//
return result;
@@ -856,6 +937,23 @@ class XC121SMCExpert : public XCBaseExpert
riskInPoints //
);
//
// Check Dynamic Risk Management ...
bool allowDynamicRiskManagement = DynamicRiskManagement();
if (allowDynamicRiskManagement)
{
//
// Calculate Dynamic Additional Risk Management Volume Multiplier ...
double mAdditionalRiskMultiplier = CalculateAdditionalVolumeMultiplier(signal);
if (mAdditionalRiskMultiplier < 1)
{
mAdditionalRiskMultiplier = 1;
}
//
volume *= mAdditionalRiskMultiplier;
}
//
if (volume > 0)
{
@@ -898,7 +996,7 @@ class XC121SMCExpert : public XCBaseExpert
// Confiugre Signalling ...
//
strategy.R2R(2);
strategy.R2R(R2R());
strategy.AllowLong(AllowLong());
strategy.AllowShort(AllowShort());
strategy.MaxAllowedSpread(20);
@@ -968,12 +1066,47 @@ class XC121SMCExpert : public XCBaseExpert
//
// Volume Management ...
double mR2R; // Signallers Risk to Reward Ratio ...
bool mUseDynamicVolume; // Use Dynamic Volume ...
double mDynamicVolumeStep; // Increase Volume Step ...
double mDynamicVolumeBalanceFactor; // Balance Factor for Generate Dynamic Volume ...
double mVolume; // Static Volume ...
bool mDynamicRiskManagement; // Dynamic Risk Management ...
double mRiskPercentPerBalance; // Risk Percent Per Balance in Each Trade ...
//
double CalculateAdditionalVolumeMultiplier(XSignal &signal)
{
//
double result = 0;
//
if (!signal.IsValid())
{
return result;
}
//
X121SMCSymbolPositionInfo info;
bool hasInfo = mTradeHandler.GetSymbolInfo(
signal.symbol,
info //
);
if (!hasInfo)
{
return result;
}
//
if (info.countedSLs >= 2)
{
result = (info.countedSLs / 2) + 1;
}
//
return result;
}
//
};