last ...
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user