last ...
This commit is contained in:
@@ -5040,115 +5040,143 @@ private:
|
||||
// Handle Force State Management ...
|
||||
void EQMHandleForceState()
|
||||
{
|
||||
//
|
||||
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)
|
||||
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;
|
||||
// }
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user