last ...
This commit is contained in:
@@ -4866,3 +4866,209 @@ int pivotsCount = ArraySize(pivots);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void EQMHandleForceState()
|
||||
{
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(positions);
|
||||
if (!IsValidSize(positionsCount) || positionsCount <= 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double minRequiredProfitPerTrade = MinRequiredProfitPerTrade();
|
||||
double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor();
|
||||
|
||||
//
|
||||
double profit = SpecifiedCalculatePositionsProfit(positions);
|
||||
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
||||
positions,
|
||||
minRequiredProfitPerTrade,
|
||||
minRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
bool canClose =
|
||||
profit > 0 &&
|
||||
(profit == requiredProfit ||
|
||||
profit >= requiredProfit / 2);
|
||||
if (canClose)
|
||||
{
|
||||
DoEQMForceClose();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
// //
|
||||
// XPosition positions[];
|
||||
// int positionsCount = mTrader.GetPositions(positions);
|
||||
// if (!IsValidSize(positionsCount))
|
||||
// {
|
||||
// //
|
||||
// EQMClearAllForceStates();
|
||||
|
||||
// //
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Search For Force State Per Each Setup ...
|
||||
// //
|
||||
// int forceCount = 0;
|
||||
// int setupsCount = CountSetups();
|
||||
// if (IsValidSize(setupsCount))
|
||||
// {
|
||||
// //
|
||||
// int maxAllowed = MaxAllowedTrades();
|
||||
// bool perDirection = UseMaxAllowedPerDirection();
|
||||
|
||||
// //
|
||||
// for (int i = 0; i < setupsCount; i++)
|
||||
// {
|
||||
// //
|
||||
// string iSymbol = mSetups[i].GetSymbol();
|
||||
// ENUM_TIMEFRAMES iPeriod = mSetups[i].GetPeriod();
|
||||
|
||||
// //
|
||||
// XPosition iPositions[];
|
||||
// int iPositionsCount = mTrader.GetPositions(
|
||||
// iPositions,
|
||||
// iSymbol,
|
||||
// NULL, // All Providers ...
|
||||
// NULL, // All Periods ...
|
||||
// NULL, // All Types ...
|
||||
// true // Filter By Magic ...
|
||||
// );
|
||||
// if (!IsValidSize(iPositionsCount))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Counting Positions ...
|
||||
// int longs;
|
||||
// double longProfits;
|
||||
// double longVolumes;
|
||||
|
||||
// //
|
||||
// int shorts;
|
||||
// double shortProfits;
|
||||
// double shortVolumes;
|
||||
|
||||
// //
|
||||
// CountPositions(
|
||||
// iPositions,
|
||||
// //
|
||||
// longs,
|
||||
// longProfits,
|
||||
// longVolumes,
|
||||
// //
|
||||
// shorts,
|
||||
// shortProfits,
|
||||
// shortVolumes //
|
||||
// );
|
||||
|
||||
// //
|
||||
// bool isMaxReached =
|
||||
// maxAllowed <= 0
|
||||
// ? false
|
||||
// : !perDirection
|
||||
// ? longs + shorts >= maxAllowed
|
||||
// : longs >= maxAllowed && shorts >= maxAllowed;
|
||||
// double volumeSummary = longVolumes + shortVolumes;
|
||||
// double profitsSummary = longProfits + shortProfits;
|
||||
|
||||
// //
|
||||
// bool isIInForce =
|
||||
// //
|
||||
// maxAllowed <= 0
|
||||
// ? profitsSummary < 0 &&
|
||||
// longVolumes == shortVolumes
|
||||
// : isMaxReached &&
|
||||
// profitsSummary < 0 &&
|
||||
// longVolumes == shortVolumes
|
||||
// //
|
||||
// ;
|
||||
// if (isIInForce)
|
||||
// {
|
||||
// //
|
||||
// forceCount++;
|
||||
// mSetups[i].ForceState(true);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// bool isForce = forceCount >= 1;
|
||||
// if (!isForce)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
void EQMHandleForceSignals(
|
||||
XSignal &signals[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Signals Count ...
|
||||
int signalsCount = ArraySize(signals);
|
||||
if (!IsValidSize(signalsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Force Marigin ...
|
||||
double marigin = mTrader.mAccount.GetMargin();
|
||||
double forceMargin = 100; // TODO: Make It Configurable
|
||||
bool isInForceMarigin = marigin >= forceMargin;
|
||||
if (!isInForceMarigin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we are Sure we in Force State Margin amd we Have Signals ...
|
||||
|
||||
//
|
||||
// here we Must Symbol Categorized Positions ...
|
||||
int setupsCount = CountSetups();
|
||||
if (!IsValidSize(setupsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieving Positions ...
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XSymbolPositions symbolPositions[];
|
||||
int symbolPositionsCount = ExtractSymbolPositions(
|
||||
positions,
|
||||
symbolPositions //
|
||||
);
|
||||
if (!IsValidSize(symbolPositionsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Log("symbolPositionsCount: " + ToString(symbolPositionsCount));
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user