This commit is contained in:
2024-06-24 17:08:46 +03:30
parent 1e424c4c71
commit ba23e2d9e9
4 changed files with 672 additions and 433 deletions
+299
View File
@@ -4567,3 +4567,302 @@ int pivotsCount = ArraySize(pivots);
//
return result;
}
///////////////////////////////////////////////////////////////////////////
// input double x121EAForceCloseProfit = 5; // Close All Positions Regardless of Policies when Profit Reached
// input double x121EAMaxDrawdownForce = 5; // Max Drawdown Force State for Handling Guards
// input int x121EAMaxPositionsForce = 10; // Max Number of Positions Force State for Handling Guards
// input double x121EAMinFreeMargingForHandleForce = 800; // Min Free Margin for Force States
// input bool x121EAAllowSymbolHedgeOnForce = false; // Allow Symbol Hedging on Force States
// x121EA.ForceCloseProfit(x121EAForceCloseProfit);
// x121EA.MaxDrawdownForce(x121EAMaxDrawdownForce);
// x121EA.MaxPositionsForce(x121EAMaxPositionsForce);
// x121EA.AllowSymbolHedgeOnForce(x121EAAllowSymbolHedgeOnForce);
// x121EA.MinFreeMargingForHandleForce(x121EAMinFreeMargingForHandleForce);
double mForceCloseProfit; // Close All Positions Regardless of Policies when Profit Reached
//
double ForceCloseProfit()
{
return mForceCloseProfit;
}
//
void ForceCloseProfit(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mForceCloseProfit = value;
}
//
double MaxDrawdownForce()
{
return mMaxDrawdownForce;
}
//
void MaxDrawdownForce(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mMaxDrawdownForce = value;
}
//
int MaxPositionsForce()
{
return mMaxPositionsForce;
}
//
void MaxPositionsForce(int value)
{
//
if (value < 0)
{
value = 0;
}
//
mMaxPositionsForce = value;
}
//
bool AllowSymbolHedgeOnForce()
{
return mAllowSymbolHedgeOnForce;
}
//
void AllowSymbolHedgeOnForce(bool value)
{
mAllowSymbolHedgeOnForce = value;
}
return;
//
if (!IsValidSize(setupsCount))
{
return;
}
//
// Here i Can Check what to do In Force State ...
//
// Handle Hedging Based On Positions ...
double drawdown = GetDrawdownPercent();
double forceDrawdown = MaxDrawdownForce();
int positionsForce = MaxPositionsForce();
double forceCloseProfit = ForceCloseProfit();
double minRequiredProfitPerTrade = MinRequiredProfitPerTrade();
double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor();
//
// Try To Force Hedging ...
bool canForceHedge =
(positionsForce <= 0
? true
: positionsCount > positionsForce)
//
||
//
(forceDrawdown > 0 &&
drawdown >= forceDrawdown);
if (canForceHedge)
{
//
// Check Required Profit ...
//
double profit = SpecifiedCalculatePositionsProfit(positions);
//
// Check Force Close Profit ...
if (forceCloseProfit > 0)
{
//
canForceHedge = profit >= forceCloseProfit;
if (canForceHedge)
{
//
bool isHedged = DoEQMForceClose();
if (isHedged)
{
return;
}
}
}
//
// Calculate Required Profit ...
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
positions,
minRequiredProfitPerTrade,
minRequiredProfitPerVolumeFactor //
);
//
canForceHedge =
requiredProfit <= 0
? profit > 0
: profit >= (requiredProfit / 2);
if (canForceHedge)
{
//
bool isHedged = DoEQMForceClose();
if (isHedged)
{
return;
}
}
//
// At Least Hedgeing ...
// Minimal Hedge ...
//
// Check Symbol Hedging ...
bool allowSymbolHedge = AllowSymbolHedgeOnForce();
if (allowSymbolHedge)
{
for (int i = 0; i < setupsCount; i++)
{
//
string iSymbol = mSetups[i].GetSymbol();
//
XPosition iSymbolPositions[];
int iSymbolPositionsCount = mTrader.GetPositions(
iSymbolPositions,
//
iSymbol,
NULL, // All Providers ...
NULL, // All Periods ...
NULL, // All Types ...
true // Filter By Magic ...
);
if (!IsValidSize(iSymbolPositionsCount))
{
continue;
}
//
double profit = SpecifiedCalculatePositionsProfit(iSymbolPositions);
//
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
iSymbolPositions,
minRequiredProfitPerTrade,
minRequiredProfitPerVolumeFactor //
);
//
bool canHedge =
requiredProfit <= 0
? profit > 0
: profit >= requiredProfit;
if (canHedge)
{
//
string comment = XEQMSupportToken + " Hedge Symbol ...";
//
int closed = mTrader.Close(
iSymbolPositions,
comment //
);
//
if (closed == iSymbolPositionsCount)
{
//
mSetups[i].ForceState(false);
//
string message = XEQMSupportToken + " Hedge Symbol (" + iSymbol + "): " + ToString(profit);
Alert(message);
}
}
}
}
return;
}
//
// Implement Other Senarios ...
//
bool isMarginPassed = IsMarginPassed();
bool isMaxNumberPassed = IsNumberOfPositionsPassed();
bool canProtect = !isMarginPassed || !isMaxNumberPassed;
if (canProtect)
{
//
int maxInDIDX = FindMaxDrawdownIndex(
positions //
);
int setupIDX = FindSetupIndex(positions[maxInDIDX].symbol);
if (IsValidIndex(maxInDIDX) && IsValidIndex(setupIDX))
{
//
string iSymbol = positions[maxInDIDX].symbol;
ENUM_TIMEFRAMES iPeriod = mSetups[setupIDX].GetPeriod();
//
// Check Position Age ...
int age = GetAge(
positions[maxInDIDX],
iPeriod //
);
if (age >= 700)
{
//
// Calculate Trend ...
XSCTrend *trend = new XSCTrend(
iSymbol,
iPeriod //
);
//
XSCTrendInput tInputs;
tInputs.Default();
bool canUseTrend = trend.Init(tInputs);
if (canUseTrend)
{
//
trend.Draw();
Print("UseTrend");
trend.Remove();
}
// string comment = XEQMSupportToken + " Close Max In D ...";
// bool isClosed = mTrader.Close(
// positions[maxInDIDX].ticket,
// comment //
// );
// if (isClosed)
// {
// //
// string message = XEQMSupportToken + " Close Position (" + ToString(positions[maxInDIDX].ticket) + ") Due Max In Drawdown ...";
// Alert(message);
// }
}
}
}