This commit is contained in:
2024-06-27 19:03:17 +03:30
parent 3fca0fb9c5
commit 8dfe216d82
3 changed files with 504 additions and 91 deletions
+217 -91
View File
@@ -4231,7 +4231,7 @@ public:
; ;
// //
bool forceState = mSetups[i].ForceState(); bool forceState = mForce; // mSetups[i].ForceState();
// //
if (!forceState) if (!forceState)
@@ -4600,6 +4600,10 @@ public:
eSignals // eSignals //
); );
} }
else
{
Alert("INNNValid Signal");
}
} }
// //
@@ -4625,7 +4629,7 @@ public:
bool HandleStateManagement(XSignal &signals[]) override bool HandleStateManagement(XSignal &signals[]) override
{ {
// //
bool result = false; const bool result = false;
// //
// Do all State Management here ... // Do all State Management here ...
@@ -4637,10 +4641,10 @@ public:
// 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;
} // }
// //
DoHedge(); DoHedge();
@@ -5215,8 +5219,8 @@ private:
if (result) if (result)
{ {
// //
mForce = false;
mTradeHandler.Sync(); mTradeHandler.Sync();
EQMClearAllForceStates();
} }
// //
@@ -5295,7 +5299,9 @@ private:
// Validate Force Marigin ... // Validate Force Marigin ...
double marigin = mTrader.mAccount.GetMargin(); double marigin = mTrader.mAccount.GetMargin();
double minFreeMarigin = MinFreeMargingForOpenTrades(); double minFreeMarigin = MinFreeMargingForOpenTrades();
double forceMargin = 3 * minFreeMarigin; // TODO: Make It Configurable double forceMargin = minFreeMarigin * 2; // TODO: Make It Configurable
bool isMarginForce = marigin >= forceMargin;
bool isMarginHotForce = marigin >= forceMargin * 3;
// //
// Retrieving Positions ... // Retrieving Positions ...
@@ -5305,15 +5311,9 @@ private:
{ {
// //
mForce = false; mForce = false;
//
datetime cTime = TimeCurrent();
string message = "Exit From Force State: " + ToString(cTime);
//
// Log(message);
return; return;
} }
bool isPositionsCountHotForce = positionsCount >= 10;
// //
XPosition oldest; XPosition oldest;
@@ -5324,21 +5324,13 @@ private:
// //
// Check Force State ... // Check Force State ...
bool isForce = marigin >= forceMargin && oldestAge >= 288; bool isForce = isMarginForce; // && oldestAge >= 288;
if (!isForce) if (!isForce)
{ {
// //
if (mForce) if (mForce)
{ {
//
mForce = false; mForce = false;
//
datetime cTime = TimeCurrent();
string message = "Exit From Force State: " + ToString(cTime);
//
// Log(message);
} }
return; return;
} }
@@ -5379,6 +5371,181 @@ private:
return; 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)); // Log("symbolPositionsCount: " + ToString(symbolPositionsCount));
} }
@@ -5393,92 +5560,68 @@ private:
) )
{ {
// //
// Check Force State ... if (!mForce)
// if (!ForceState())
// {
// return;
// }
//
int setupIDX = FindSetupIndex(signal.symbol);
if (!IsValidIndex(setupIDX))
{ {
return; return;
} }
//
bool isForce = mSetups[setupIDX].ForceState();
if (!isForce)
{
return;
}
//
// Check Delay Between Two Signals ...
bool isMarginPassed = IsMarginPassed();
bool isDelayPassed = IsSignalDelayPassed(signal);
bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed();
bool canUseSignal =
isMarginPassed &&
isDelayPassed &&
isNumberOfPositionsPassed;
// //
XSignal signals[]; XSignal signals[];
// //
if (isValid) if (isValid || pushers > 1)
{ {
// //
bool canSupport = bool canSupport =
// //
mForce &&
EnableSupport() && EnableSupport() &&
SupportOnlyForces() SupportOnlyForces()
// //
; ;
bool canGrid = bool canGrid =
// //
mForce &&
EnableGrid() && EnableGrid() &&
GridOnlyForces() GridOnlyForces()
// //
; ;
bool canRecover = bool canRecover =
// //
mForce &&
EnableRecovery() && EnableRecovery() &&
RecoverOnlyForces() RecoverOnlyForces()
// //
; ;
// //
if (canUseSignal) AddRef(
{ signal,
// signals //
AddRef( );
signal,
signals //
);
// //
// Add new Signal Info ... // Add new Signal Info ...
mTradeHandler.Add( mTradeHandler.Add(
signal, signal,
pushers, pushers,
canGrid, canGrid,
canRecover, canRecover,
canSupport, canSupport,
conditions[0], conditions[0],
conditions[1], conditions[1],
conditions[2], conditions[2],
conditions[3], conditions[3],
conditions[4] // conditions[4] //
); );
}
} }
// //
if (ArraySize(signals) > 0) if (ArraySize(signals) > 0)
{ {
EQMExecuteSignals(signals); //
// EQMExecuteSignals(signals);
EQMHandleForceState(signals);
} }
} }
@@ -5575,23 +5718,6 @@ private:
} }
} }
//
void EQMClearAllForceStates()
{
//
int setupsCount = CountSetups();
if (!IsValidSize(setupsCount))
{
return;
}
//
for (int i = 0; i < setupsCount; i++)
{
mSetups[i].ForceState(false);
}
}
// //
}; };
+238
View File
@@ -5072,3 +5072,241 @@ int pivotsCount = ArraySize(pivots);
// //
} }
/////////////////////////////////////////////////////////////
//
// Handle Force State Management ...
bool mForce;
void EQMHandleForceState(XSignal &forceSignals[])
{
//
// Validate Force Marigin ...
double marigin = mTrader.mAccount.GetMargin();
double minFreeMarigin = MinFreeMargingForOpenTrades();
double forceMargin = 2 * minFreeMarigin; // TODO: Make It Configurable
bool isMarginForce = marigin >= forceMargin;
//
// Retrieving Positions ...
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
if (!IsValidSize(positionsCount))
{
//
mForce = false;
//
datetime cTime = TimeCurrent();
string message = "Exit From Force State: " + ToString(cTime);
//
// Log(message);
return;
}
//
XPosition oldest;
int oldestAge = GetOldest(
oldest,
positions //
);
//
// Check Force State ...
bool isForce = isMarginForce; // && oldestAge >= 288;
if (!isForce)
{
//
if (mForce)
{
//
mForce = false;
//
datetime cTime = TimeCurrent();
string message = "Exit From Force State: " + ToString(cTime);
//
// Log(message);
}
return;
}
else
{
mForce = true;
}
//
// Prevent Moving Forward From Non Force State ...
if (!mForce)
{
return;
}
//
int forceSignalsCount = ArraySize(forceSignals);
if (IsValidSize(forceSignalsCount))
{
//
Log("Force Signals Count: " + ToString(forceSignalsCount));
}
// //
// 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;
// }
//
// Log("symbolPositionsCount: " + ToString(symbolPositionsCount));
}
/////////////////////////////////////////////////////////////////
//
// Handle any Invalid Signals ...
void EQMHandleInvalidSignal(
XSignal &signal, // Invalid Signal
int pushers, // Pushers
bool isValid, // IsValid Signal ...
X121SetupConditions &conditions[] // All Time Frames Conditions
)
{
//
// Check Force State ...
// if (!ForceState())
// {
// return;
// }
//
int setupIDX = FindSetupIndex(signal.symbol);
if (!IsValidIndex(setupIDX))
{
return;
}
//
bool isForce = mForce; // mSetups[setupIDX].ForceState();
if (!isForce)
{
return;
}
//
// Check Delay Between Two Signals ...
// bool isMarginPassed = IsMarginPassed();
// bool isDelayPassed = IsSignalDelayPassed(signal);
// bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed();
// bool canUseSignal =
// isMarginPassed &&
// isDelayPassed &&
// isNumberOfPositionsPassed;
//
XSignal signals[];
//
if (isValid)
{
//
Log("IsValid Invalid Signal ...");
//
bool canSupport =
//
EnableSupport() &&
SupportOnlyForces()
//
;
bool canGrid =
//
EnableGrid() &&
GridOnlyForces()
//
;
bool canRecover =
//
EnableRecovery() &&
RecoverOnlyForces()
//
;
//
if (canUseSignal)
{
//
AddRef(
signal,
signals //
);
//
// Add new Signal Info ...
mTradeHandler.Add(
signal,
pushers,
canGrid,
canRecover,
canSupport,
conditions[0],
conditions[1],
conditions[2],
conditions[3],
conditions[4] //
);
}
}
else
{
Log("IsValid Invalid Signal INN ...");
}
//
// if (ArraySize(signals) > 0)
// {
// EQMExecuteSignals(signals);
// }
}
/////////////////////////////////////////////////////////
//
void EQMClearAllForceStates()
{
//
int setupsCount = CountSetups();
if (!IsValidSize(setupsCount))
{
return;
}
//
for (int i = 0; i < setupsCount; i++)
{
mSetups[i].ForceState(false);
}
}
+49
View File
@@ -2797,6 +2797,9 @@ struct XSymbolPositions
XPosition shorts[]; XPosition shorts[];
XPosition positions[]; XPosition positions[];
//
bool forceHedge;
// //
XSymbolPositions() XSymbolPositions()
{ {
@@ -2862,6 +2865,7 @@ struct XSymbolPositions
{ {
// //
symbol = NULL; symbol = NULL;
forceHedge = false;
// //
profit = 0; profit = 0;
@@ -2928,6 +2932,51 @@ struct XSymbolPositions
// //
}; };
//
bool IsContainsSymbol(
string symbol,
int &_index,
XSymbolPositions &_items[] //
)
{
//
bool result = false;
//
_index = -1;
//
result = IsValid(symbol);
if (!result)
{
return result;
}
//
int itemsCount = ArraySize(_items);
result = IsValidSize(itemsCount);
if (!result)
{
return result;
}
//
for (int i = 0; i < itemsCount; i++)
{
//
result = _items[i].symbol == symbol;
if (result)
{
//
_index = i;
break;
}
}
//
return result;
}
// //
// TypeDefs ... // TypeDefs ...