last ...
This commit is contained in:
@@ -204,53 +204,6 @@ 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 ...
|
||||||
|
|
||||||
@@ -594,7 +547,6 @@ struct XTradeInfo
|
|||||||
|
|
||||||
//
|
//
|
||||||
result = IsValid() &&
|
result = IsValid() &&
|
||||||
allowGrid &&
|
|
||||||
distance > 0 &&
|
distance > 0 &&
|
||||||
volumeMultiplier > 0;
|
volumeMultiplier > 0;
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -813,7 +765,6 @@ struct XTradeInfo
|
|||||||
entry > 0 &&
|
entry > 0 &&
|
||||||
volume > 0 &&
|
volume > 0 &&
|
||||||
distance > 0 &&
|
distance > 0 &&
|
||||||
allowRecover &&
|
|
||||||
volumeMultiplier > 0
|
volumeMultiplier > 0
|
||||||
//
|
//
|
||||||
;
|
;
|
||||||
@@ -2075,77 +2026,6 @@ 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()
|
||||||
@@ -4351,7 +4231,7 @@ public:
|
|||||||
;
|
;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool forceState = mForce; // mSetups[i].ForceState();
|
bool forceState = mSetups[i].ForceState();
|
||||||
|
|
||||||
//
|
//
|
||||||
if (!forceState)
|
if (!forceState)
|
||||||
@@ -4745,7 +4625,7 @@ public:
|
|||||||
bool HandleStateManagement(XSignal &signals[]) override
|
bool HandleStateManagement(XSignal &signals[]) override
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
const bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Do all State Management here ...
|
// Do all State Management here ...
|
||||||
@@ -4756,11 +4636,11 @@ 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;
|
||||||
// }
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
DoHedge();
|
DoHedge();
|
||||||
@@ -4947,6 +4827,23 @@ protected:
|
|||||||
//
|
//
|
||||||
Alert(message);
|
Alert(message);
|
||||||
|
|
||||||
|
//
|
||||||
|
EQMHandleForceState(signals);
|
||||||
|
|
||||||
|
//
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed();
|
||||||
|
if (!isNumberOfPositionsPassed)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string message = "Max Allowed Signals Reached ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
Alert(message);
|
||||||
|
|
||||||
//
|
//
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5053,6 +4950,39 @@ 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:
|
||||||
@@ -5285,8 +5215,8 @@ private:
|
|||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
mForce = false;
|
|
||||||
mTradeHandler.Sync();
|
mTradeHandler.Sync();
|
||||||
|
EQMClearAllForceStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -5362,6 +5292,95 @@ private:
|
|||||||
void EQMHandleForceState(XSignal &forceSignals[])
|
void EQMHandleForceState(XSignal &forceSignals[])
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
// Validate Force Marigin ...
|
||||||
|
double marigin = mTrader.mAccount.GetMargin();
|
||||||
|
double minFreeMarigin = MinFreeMargingForOpenTrades();
|
||||||
|
double forceMargin = 3 * minFreeMarigin; // TODO: Make It Configurable
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 = marigin >= forceMargin && 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -5374,11 +5393,36 @@ private:
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (!mForce)
|
// Check Force State ...
|
||||||
|
// 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[];
|
||||||
|
|
||||||
@@ -5388,46 +5432,47 @@ private:
|
|||||||
//
|
//
|
||||||
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()
|
||||||
//
|
//
|
||||||
;
|
;
|
||||||
|
|
||||||
//
|
//
|
||||||
AddRef(
|
if (canUseSignal)
|
||||||
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] //
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -5530,6 +5575,23 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void EQMClearAllForceStates()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int setupsCount = CountSetups();
|
||||||
|
if (!IsValidSize(setupsCount))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < setupsCount; i++)
|
||||||
|
{
|
||||||
|
mSetups[i].ForceState(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user