last ...
This commit is contained in:
@@ -3361,6 +3361,56 @@ public:
|
||||
mMaxPositionsForce = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool AllowSymbolHedgeOnForce()
|
||||
{
|
||||
return mAllowSymbolHedgeOnForce;
|
||||
}
|
||||
|
||||
//
|
||||
void AllowSymbolHedgeOnForce(bool value)
|
||||
{
|
||||
mAllowSymbolHedgeOnForce = value;
|
||||
}
|
||||
|
||||
//
|
||||
double ForceCloseOnEuityDiff()
|
||||
{
|
||||
return mForceCloseOnEuityDiff;
|
||||
}
|
||||
|
||||
//
|
||||
void ForceCloseOnEuityDiff(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mForceCloseOnEuityDiff = value;
|
||||
}
|
||||
|
||||
//
|
||||
double MinFreeMargingForHandleForce()
|
||||
{
|
||||
return mMinFreeMargingForHandleForce;
|
||||
}
|
||||
|
||||
//
|
||||
void MinFreeMargingForHandleForce(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mMinFreeMargingForHandleForce = value;
|
||||
}
|
||||
|
||||
// //
|
||||
// bool ForceState()
|
||||
// {
|
||||
@@ -4245,6 +4295,34 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isMarginPassed = IsMarginPassed();
|
||||
if (!isMarginPassed)
|
||||
{
|
||||
//
|
||||
string message = "No Margin For Execute Signals ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed();
|
||||
if (!isNumberOfPositionsPassed)
|
||||
{
|
||||
//
|
||||
string message = "Max Allowed Signals Reached ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
|
||||
int executedSignalsCount = ExecuteSignals(
|
||||
@@ -4310,6 +4388,52 @@ protected:
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsMarginPassed()
|
||||
{
|
||||
//
|
||||
double freeMargin = mTrader.mAccount.GetFreeMargin();
|
||||
double minFreeMargingForHandleForce = MinFreeMargingForHandleForce();
|
||||
|
||||
//
|
||||
bool result = minFreeMargingForHandleForce <= 0
|
||||
? true
|
||||
: freeMargin >= minFreeMargingForHandleForce;
|
||||
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
@@ -4349,9 +4473,12 @@ private:
|
||||
// - Increase Volume Size of in Profit Positions;
|
||||
// - etc ...
|
||||
// bool mForceState; // Determine in Force State or not
|
||||
int mDelayBetweenTwoSignal; // Delay between two same signal
|
||||
int mMaxPositionsForce; // Max Number of Positions For Guard Handling
|
||||
double mMaxDrawdownForce; // Force Handling State on Drawdown for Guard
|
||||
int mDelayBetweenTwoSignal; // Delay between two same signal
|
||||
int mMaxPositionsForce; // Max Number of Positions For Guard Handling
|
||||
double mMaxDrawdownForce; // Force Handling State on Drawdown for Guard
|
||||
bool mAllowSymbolHedgeOnForce; // Allow Symbol Hedging on Force States
|
||||
double mMinFreeMargingForHandleForce; // Min Free Margin for Force States
|
||||
double mForceCloseOnEuityDiff; // Force Close On Equity Differential
|
||||
|
||||
//
|
||||
XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions
|
||||
@@ -4802,62 +4929,66 @@ private:
|
||||
|
||||
//
|
||||
// Check Symbol Hedging ...
|
||||
for (int i = 0; i < setupsCount; i++)
|
||||
bool allowSymbolHedge = AllowSymbolHedgeOnForce();
|
||||
if (allowSymbolHedge)
|
||||
{
|
||||
//
|
||||
string iSymbol = mSetups[i].GetSymbol();
|
||||
|
||||
//
|
||||
XPosition iSymbolPositions[];
|
||||
int iSymbolPositionsCount = mTrader.GetPositions(
|
||||
iSymbolPositions,
|
||||
//
|
||||
iSymbol,
|
||||
NULL, // All Providers ...
|
||||
NULL, // All Periods ...
|
||||
NULL, // All Types ...
|
||||
true // Filter By Magic ...
|
||||
);
|
||||
if (!IsValidSize(iSymbolPositionsCount))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
double profit = SpecifiedCalculatePositionsProfit(iSymbolPositions);
|
||||
|
||||
//
|
||||
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
||||
iSymbolPositions,
|
||||
minRequiredProfitPerTrade,
|
||||
minRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
bool canHedge =
|
||||
requiredProfit <= 0
|
||||
? profit > 0
|
||||
: profit >= requiredProfit;
|
||||
if (canHedge)
|
||||
for (int i = 0; i < setupsCount; i++)
|
||||
{
|
||||
//
|
||||
string comment = XEQMSupportToken + " Hedge Symbol ...";
|
||||
string iSymbol = mSetups[i].GetSymbol();
|
||||
|
||||
//
|
||||
int closed = mTrader.Close(
|
||||
XPosition iSymbolPositions[];
|
||||
int iSymbolPositionsCount = mTrader.GetPositions(
|
||||
iSymbolPositions,
|
||||
comment //
|
||||
//
|
||||
iSymbol,
|
||||
NULL, // All Providers ...
|
||||
NULL, // All Periods ...
|
||||
NULL, // All Types ...
|
||||
true // Filter By Magic ...
|
||||
);
|
||||
if (!IsValidSize(iSymbolPositionsCount))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
double profit = SpecifiedCalculatePositionsProfit(iSymbolPositions);
|
||||
|
||||
//
|
||||
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
||||
iSymbolPositions,
|
||||
minRequiredProfitPerTrade,
|
||||
minRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
if (closed == iSymbolPositionsCount)
|
||||
bool canHedge =
|
||||
requiredProfit <= 0
|
||||
? profit > 0
|
||||
: profit >= requiredProfit;
|
||||
if (canHedge)
|
||||
{
|
||||
//
|
||||
mSetups[i].ForceState(false);
|
||||
string comment = XEQMSupportToken + " Hedge Symbol ...";
|
||||
|
||||
//
|
||||
string message = XEQMSupportToken + " Hedge Symbol (" + iSymbol + "): " + ToString(profit);
|
||||
Alert(message);
|
||||
int closed = mTrader.Close(
|
||||
iSymbolPositions,
|
||||
comment //
|
||||
);
|
||||
|
||||
//
|
||||
if (closed == iSymbolPositionsCount)
|
||||
{
|
||||
//
|
||||
mSetups[i].ForceState(false);
|
||||
|
||||
//
|
||||
string message = XEQMSupportToken + " Hedge Symbol (" + iSymbol + "): " + ToString(profit);
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4868,6 +4999,17 @@ private:
|
||||
//
|
||||
// Implement Other Senarios ...
|
||||
|
||||
// //
|
||||
// double equity = mTrader.mAccount.GetEquity();
|
||||
// double balance = mTrader.mAccount.GetBalance();
|
||||
// double forceCloseOnEuityDiff = ForceCloseOnEuityDiff();
|
||||
|
||||
// //
|
||||
// bool canForceClose =
|
||||
// forceCloseOnEuityDiff <= 0
|
||||
// ? false
|
||||
// : balance >
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user