last ...
This commit is contained in:
@@ -204,6 +204,53 @@ struct XTradeInfo
|
||||
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 ...
|
||||
|
||||
@@ -547,6 +594,7 @@ struct XTradeInfo
|
||||
|
||||
//
|
||||
result = IsValid() &&
|
||||
allowGrid &&
|
||||
distance > 0 &&
|
||||
volumeMultiplier > 0;
|
||||
if (!result)
|
||||
@@ -765,6 +813,7 @@ struct XTradeInfo
|
||||
entry > 0 &&
|
||||
volume > 0 &&
|
||||
distance > 0 &&
|
||||
allowRecover &&
|
||||
volumeMultiplier > 0
|
||||
//
|
||||
;
|
||||
@@ -2026,6 +2075,77 @@ public:
|
||||
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 ...
|
||||
void Sync()
|
||||
@@ -4600,10 +4720,6 @@ public:
|
||||
eSignals //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert("INNNValid Signal");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -4640,7 +4756,7 @@ public:
|
||||
// Youngest Age of Positions longest as enough
|
||||
// Make State of Signalling to Force State for Recieving
|
||||
// Signal and Clear their Tp and SL for allowing hedges ...
|
||||
EQMHandleForceState(signals);
|
||||
// EQMHandleForceState(signals);
|
||||
// if (mForce)
|
||||
// {
|
||||
// result = true;
|
||||
@@ -4831,23 +4947,6 @@ protected:
|
||||
//
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
EQMHandleForceState(signals);
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed();
|
||||
if (!isNumberOfPositionsPassed)
|
||||
{
|
||||
//
|
||||
string message = "Max Allowed Signals Reached ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
@@ -4954,39 +5053,6 @@ protected:
|
||||
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:
|
||||
@@ -5296,258 +5362,6 @@ private:
|
||||
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[];
|
||||
|
||||
//
|
||||
if (isValid || pushers > 1)
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
bool canSupport =
|
||||
@@ -5619,9 +5433,7 @@ private:
|
||||
//
|
||||
if (ArraySize(signals) > 0)
|
||||
{
|
||||
//
|
||||
// EQMExecuteSignals(signals);
|
||||
EQMHandleForceState(signals);
|
||||
EQMExecuteSignals(signals);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user