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:
|
||||
@@ -4352,6 +4476,9 @@ private:
|
||||
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,6 +4929,9 @@ private:
|
||||
|
||||
//
|
||||
// Check Symbol Hedging ...
|
||||
bool allowSymbolHedge = AllowSymbolHedgeOnForce();
|
||||
if (allowSymbolHedge)
|
||||
{
|
||||
for (int i = 0; i < setupsCount; i++)
|
||||
{
|
||||
//
|
||||
@@ -4861,6 +4991,7 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -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 >
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,9 @@ input int x121EARestingAfterHedge = 0; // Resting Seconds A
|
||||
input double x121EAForceCloseProfit = 15; // Close All Positions Regardless of Policies when Profit Reached
|
||||
input double x121EAMaxDrawdownForce = 5; // Max Drawdown Force State for Handling Guards
|
||||
input int x121EAMaxPositionsForce = 10; // Max Number of Positions Force State for Handling Guards
|
||||
input double x121EAMinFreeMargingForHandleForce = 800; // Min Free Margin for Force States
|
||||
input double x121EAForceCloseOnEuityDiff = 15; // Force Close On Equity Differential
|
||||
input bool x121EAAllowSymbolHedgeOnForce = false; // Allow Symbol Hedging on Force States
|
||||
input double x121EAMinRequiredProfitPerTrade = 0.5; // Minimum Required Profit for Hedging
|
||||
input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume
|
||||
|
||||
@@ -379,6 +382,9 @@ bool InitialEA()
|
||||
x121EA.RestingAfterHedge(x121EARestingAfterHedge);
|
||||
x121EA.MaxDrawdownForce(x121EAMaxDrawdownForce);
|
||||
x121EA.MaxPositionsForce(x121EAMaxPositionsForce);
|
||||
x121EA.AllowSymbolHedgeOnForce(x121EAAllowSymbolHedgeOnForce);
|
||||
x121EA.ForceCloseOnEuityDiff(x121EAMinFreeMargingForHandleForce);
|
||||
x121EA.MinFreeMargingForHandleForce(x121EAForceCloseOnEuityDiff);
|
||||
x121EA.MinRequiredProfitPerTrade(x121EAMinRequiredProfitPerTrade);
|
||||
x121EA.MinRequiredProfitPerVolumeFactor(x121EAMinRequiredProfitPerVolumeFactor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user