This commit is contained in:
2024-06-27 20:22:41 +03:30
parent 8dfe216d82
commit 46967136d3
5 changed files with 6099 additions and 315 deletions
+123 -311
View File
@@ -204,6 +204,53 @@ struct XTradeInfo
return result; return result;
} }
//
bool IsOwn(XSignal &signal)
{
//
return IsOwn(
signal.symbol,
signal.provider,
signal.time,
signal.period,
signal.type //
);
}
//
bool IsOwn(
string _symbol,
string _provider,
datetime _time,
ENUM_TIMEFRAMES _period,
ENUM_POSITION_TYPE _type //
)
{
//
bool result = false;
//
ENUM_X_POSITION_TYPES iType = ToPositionType(_type);
//
result =
//
IsValid(_symbol) &&
IsValid(_provider) &&
IsValid(_period) &&
//
symbol == _symbol &&
provider == _provider &&
period == _period &&
type == iType &&
time == _time
//
;
//
return result;
}
// //
// Data Collector ... // Data Collector ...
@@ -547,6 +594,7 @@ struct XTradeInfo
// //
result = IsValid() && result = IsValid() &&
allowGrid &&
distance > 0 && distance > 0 &&
volumeMultiplier > 0; volumeMultiplier > 0;
if (!result) if (!result)
@@ -765,6 +813,7 @@ struct XTradeInfo
entry > 0 && entry > 0 &&
volume > 0 && volume > 0 &&
distance > 0 && distance > 0 &&
allowRecover &&
volumeMultiplier > 0 volumeMultiplier > 0
// //
; ;
@@ -2026,6 +2075,77 @@ public:
Finish(infoIDX); Finish(infoIDX);
} }
//
bool AllowToGrid(
XSignal &signal //
)
{
//
bool result = false;
//
int count = Count();
result = IsValidSize(count);
if (!result)
{
return result;
}
//
int infoIDX = FindIndex(signal);
result = IsValidIndex(infoIDX);
if (!result)
{
return result;
}
//
data[infoIDX].allowGrid = true;
data[infoIDX].PrepareNextGrid(
GridDistance(),
GridVolumeMultiplier() //
);
//
return result;
}
//
bool AllowToRecovery(
XSignal &signal //
)
{
//
bool result = false;
//
int count = Count();
result = IsValidSize(count);
if (!result)
{
return result;
}
//
int infoIDX = FindIndex(signal);
result = IsValidIndex(infoIDX);
if (!result)
{
return result;
}
//
data[infoIDX].allowRecover = true;
data[infoIDX].PrepareNextRecovery(
GridDistance(),
GridVolumeMultiplier(),
signal.type //
);
//
return result;
}
// //
// Sync ... // Sync ...
void Sync() void Sync()
@@ -4600,10 +4720,6 @@ public:
eSignals // eSignals //
); );
} }
else
{
Alert("INNNValid Signal");
}
} }
// //
@@ -4640,7 +4756,7 @@ public:
// Youngest Age of Positions longest as enough // Youngest Age of Positions longest as enough
// Make State of Signalling to Force State for Recieving // Make State of Signalling to Force State for Recieving
// Signal and Clear their Tp and SL for allowing hedges ... // Signal and Clear their Tp and SL for allowing hedges ...
EQMHandleForceState(signals); // EQMHandleForceState(signals);
// if (mForce) // if (mForce)
// { // {
// result = true; // result = true;
@@ -4831,23 +4947,6 @@ protected:
// //
Alert(message); Alert(message);
//
EQMHandleForceState(signals);
//
return;
}
//
bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed();
if (!isNumberOfPositionsPassed)
{
//
string message = "Max Allowed Signals Reached ...";
//
Alert(message);
// //
return; return;
} }
@@ -4954,39 +5053,6 @@ protected:
return result; return result;
} }
//
bool IsNumberOfPositionsPassed()
{
//
bool result = false;
//
// int maxAllowed = MaxPositionsForce();
// result = maxAllowed <= 0;
// if (result)
// {
// return result;
// }
// //
// XPosition positions[];
// int positionsCount = mTrader.GetPositions(positions);
// result = !IsValidSize(positionsCount);
// if (result)
// {
// return result;
// }
// //
// result = positionsCount < maxAllowed;
//
result = true;
//
return result;
}
// //
// Private ... // Private ...
private: private:
@@ -5296,258 +5362,6 @@ private:
void EQMHandleForceState(XSignal &forceSignals[]) void EQMHandleForceState(XSignal &forceSignals[])
{ {
// //
// Validate Force Marigin ...
double marigin = mTrader.mAccount.GetMargin();
double minFreeMarigin = MinFreeMargingForOpenTrades();
double forceMargin = minFreeMarigin * 2; // TODO: Make It Configurable
bool isMarginForce = marigin >= forceMargin;
bool isMarginHotForce = marigin >= forceMargin * 3;
//
// Retrieving Positions ...
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
if (!IsValidSize(positionsCount))
{
//
mForce = false;
return;
}
bool isPositionsCountHotForce = positionsCount >= 10;
//
XPosition oldest;
int oldestAge = GetOldest(
oldest,
positions //
);
//
// Check Force State ...
bool isForce = isMarginForce; // && oldestAge >= 288;
if (!isForce)
{
//
if (mForce)
{
mForce = false;
}
return;
}
else
{
mForce = true;
}
//
// Prevent Moving Forward From Non Force State ...
if (!mForce)
{
return;
}
//
double minProfitPerTrade = MinProfitPerTrade();
double minProfitPerVolumeFactor = MinProfitPerVolumeFactor();
//
double profit = SpecifiedCalculatePositionsProfit(positions);
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
positions,
minProfitPerTrade,
minProfitPerVolumeFactor //
);
//
XSymbolPositions symbolPositions[];
int symbolPositionsCount = ExtractSymbolPositions(
positions,
symbolPositions,
minProfitPerTrade,
minProfitPerVolumeFactor //
);
if (!IsValidSize(symbolPositionsCount))
{
return;
}
//
XSignal signals[];
int forceSignalsCount = ArraySize(forceSignals);
if (IsValidSize(forceSignalsCount))
{
//
// Check if Symbol Contains or Not ...
for (int i = 0; i < forceSignalsCount; i++)
{
//
XSignal iForceSignal = forceSignals[i];
//
int symbolIDX = -1;
bool isSymbolContains = IsContainsSymbol(
iForceSignal.symbol,
symbolIDX,
symbolPositions //
);
if (!isSymbolContains)
{
//
AddRef(
iForceSignal,
signals //
);
//
continue;
}
else
{
//
ENUM_POSITION_TYPE iType = iForceSignal.type;
bool isLong = IsLong(iType);
//
XSymbolPositions iSymbolPositions = symbolPositions[symbolIDX];
if (isLong)
{
//
if (iSymbolPositions.longsProfit > 0)
{
//
if (!isMarginHotForce && !isPositionsCountHotForce)
{
//
AddRef(
iForceSignal,
signals //
);
}
else
{
}
}
else
{
//
// In Drawdown ...
if (isMarginHotForce && !isPositionsCountHotForce)
{
}
else
{
}
}
}
else
{
//
if (iSymbolPositions.shortsProfit > 0)
{
//
if (!isMarginHotForce && !isPositionsCountHotForce)
{
//
AddRef(
iForceSignal,
signals //
);
}
else
{
}
}
else
{
//
// In Drawdown ...
if (!isMarginHotForce && !isPositionsCountHotForce)
{
}
else
{
}
}
}
}
}
}
//
int signalsCount = ArraySize(signals);
if (IsValidSize(signalsCount))
{
EQMExecuteSignals(signals);
}
else
{
//
// Handle CLosing ...
if (!isMarginHotForce)
{
return;
}
//
for (int i = 0; i < symbolPositionsCount; i++)
{
//
XSymbolPositions iSymbolPositions = symbolPositions[i];
//
if (!iSymbolPositions.HasChild())
{
continue;
}
//
if (iSymbolPositions.profit > 0)
{
continue;
}
//
XPosition iOldest;
int oldestAge = GetOldest(
iOldest,
iSymbolPositions.positions //
);
if (oldestAge <= 140)
{
continue;
}
//
int maxInDPIDX = FindMaxDrawdownIndex(
iSymbolPositions.positions //
);
if (!IsValidIndex(maxInDPIDX))
{
continue;
}
//
XPosition maxInDP = iSymbolPositions.positions[maxInDPIDX];
//
string comment = XEQMSupportToken + " Close due Max In D ...";
bool isClosed = mTrader.Close(
maxInDP.ticket,
comment //
);
if (isClosed)
{
//
string message = XEQMSupportToken + " Close (" + ToString(maxInDP.ticket) + ") due Max In D ...";
//
Alert(message);
}
}
}
//
// Log("symbolPositionsCount: " + ToString(symbolPositionsCount));
} }
// //
@@ -5569,7 +5383,7 @@ private:
XSignal signals[]; XSignal signals[];
// //
if (isValid || pushers > 1) if (isValid)
{ {
// //
bool canSupport = bool canSupport =
@@ -5619,9 +5433,7 @@ private:
// //
if (ArraySize(signals) > 0) if (ArraySize(signals) > 0)
{ {
// EQMExecuteSignals(signals);
// EQMExecuteSignals(signals);
EQMHandleForceState(signals);
} }
} }
+2
View File
@@ -177,6 +177,8 @@ public:
// //
double GetDrawdownPercent() double GetDrawdownPercent()
{ {
//
CalculateMaxDrawdown();
return mDrawdownPercent; return mDrawdownPercent;
} }
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -94,11 +94,11 @@ input double x121EAMaxAllowedSupportVolume = 0; // Max Allowed Support Signals V
// //
input group "Grid"; input group "Grid";
input bool x121EAAllowGrid = false; // Allow Grid Signals input bool x121EAAllowGrid = true; // Allow Grid Signals
input bool x121EAGridOnlyForces = false; // Grid Only Force Signals input bool x121EAGridOnlyForces = true; // Grid Only Force Signals
input int x121EAMaxNumberOfGrids = 0; // Max Number of Grid Signals input int x121EAMaxNumberOfGrids = 0; // Max Number of Grid Signals
input double x121EAGridDistance = 0; // Grid Distance input double x121EAGridDistance = 200; // Grid Distance
input double x121EAGridVolumeMultiplier = 0; // Grid Volume Multiplier input double x121EAGridVolumeMultiplier = 2; // Grid Volume Multiplier
input double x121EAMaxAllowedGridVolume = 0; // Max Allowed Grid Signals Volume input double x121EAMaxAllowedGridVolume = 0; // Max Allowed Grid Signals Volume
// //
+92
View File
@@ -2929,6 +2929,98 @@ struct XSymbolPositions
return ArraySize(positions); return ArraySize(positions);
} }
//
int CountLongs()
{
return ArraySize(longs);
}
//
int CountShorts()
{
return ArraySize(shorts);
}
//
bool HasSupport()
{
//
bool result = false;
//
result = HasChild();
if (!result)
{
return result;
}
//
result = HasLongSupport() || HasShortSupport();
//
return result;
}
//
bool HasLongSupport()
{
//
bool result = false;
//
int count = CountLongs();
result = IsValidSize(count);
if (!result)
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
XPosition iPosition = longs[i];
result = IsSupport(iPosition.comment);
if (result)
{
break;
}
}
//
return result;
}
//
bool HasShortSupport()
{
//
bool result = false;
//
int count = CountShorts();
result = IsValidSize(count);
if (!result)
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
XPosition iPosition = shorts[i];
result = IsSupport(iPosition.comment);
if (result)
{
break;
}
}
//
return result;
}
// //
}; };