last ...
This commit is contained in:
@@ -2825,6 +2825,25 @@ public:
|
||||
mAllowShort = value;
|
||||
}
|
||||
|
||||
//
|
||||
int DelayBetweenTwoSignal()
|
||||
{
|
||||
return mDelayBetweenTwoSignal;
|
||||
}
|
||||
|
||||
//
|
||||
void DelayBetweenTwoSignal(int value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mDelayBetweenTwoSignal = value;
|
||||
}
|
||||
|
||||
//
|
||||
int ReuiredSignalVerifications()
|
||||
{
|
||||
@@ -3318,6 +3337,44 @@ public:
|
||||
mForceCloseProfit = value;
|
||||
}
|
||||
|
||||
//
|
||||
double MaxDrawdownForce()
|
||||
{
|
||||
return mMaxDrawdownForce;
|
||||
}
|
||||
|
||||
//
|
||||
void MaxDrawdownForce(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mMaxDrawdownForce = value;
|
||||
}
|
||||
|
||||
//
|
||||
int MaxPositionsForce()
|
||||
{
|
||||
return mMaxPositionsForce;
|
||||
}
|
||||
|
||||
//
|
||||
void MaxPositionsForce(int value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mMaxPositionsForce = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool ForceState()
|
||||
{
|
||||
@@ -3349,6 +3406,18 @@ public:
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
double GetBullishScore()
|
||||
{
|
||||
return mBullishScore;
|
||||
}
|
||||
|
||||
//
|
||||
double GetBearishScore()
|
||||
{
|
||||
return mBearishScore;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Provider for any Guards ...
|
||||
bool CheckForGuard(XGuard &guards[]) override
|
||||
@@ -4187,10 +4256,18 @@ public:
|
||||
if (isSignalValid)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iSignal,
|
||||
eSignals //
|
||||
);
|
||||
// Check Delay Between Two Signals ...
|
||||
bool isDelayPassed = IsSignalDelayPassed(iSignal);
|
||||
|
||||
//
|
||||
if (isDelayPassed)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iSignal,
|
||||
eSignals //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4409,6 +4486,62 @@ protected:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Check Delay Between Two Signals ...
|
||||
bool IsSignalDelayPassed(
|
||||
XSignal &signal //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Check Signal Validation ...
|
||||
result = signal.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Delay Signals Allowed ...
|
||||
int delay = DelayBetweenTwoSignal();
|
||||
result = delay <= 0;
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Positions ...
|
||||
// Based On Provider and Symbol and TimeFrame ...
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(
|
||||
positions,
|
||||
signal.symbol,
|
||||
signal.provider,
|
||||
signal.period,
|
||||
ToPositionType(signal.type),
|
||||
true // Filter By Magic ...
|
||||
);
|
||||
result = !IsValidSize(positionsCount);
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition youngest;
|
||||
int youngestAge = GetYoungest(
|
||||
youngest,
|
||||
positions //
|
||||
);
|
||||
result = youngestAge >= delay;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
@@ -4446,7 +4579,10 @@ private:
|
||||
// - Receive Signals with minimal Verifications;
|
||||
// - Increase Volume Size of in Profit Positions;
|
||||
// - etc ...
|
||||
bool mForceState; // Determine in Force State or not
|
||||
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
|
||||
|
||||
//
|
||||
XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions
|
||||
@@ -4641,10 +4777,8 @@ private:
|
||||
}
|
||||
|
||||
//
|
||||
double profit = SpecifiedIsPositionsReadyForHedge(
|
||||
positions,
|
||||
0.15,
|
||||
0.01 //
|
||||
double profit = SpecifiedCalculatePositionsProfit(
|
||||
positions //
|
||||
);
|
||||
result =
|
||||
profit > hedgingProfit;
|
||||
@@ -4761,30 +4895,158 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double profits = SpecifiedCalculatePositionsProfit(positionsCount);
|
||||
|
||||
//
|
||||
// Checking Force Sate Conditions ...
|
||||
if (ForceState())
|
||||
{
|
||||
//
|
||||
// Check Force State Hedging ...
|
||||
// bool isHedged = DoEQMForceClose();
|
||||
// if (isHedged)
|
||||
// {
|
||||
// //
|
||||
// ForceState(false);
|
||||
// return;
|
||||
// }
|
||||
bool isHedged = DoEQMForceClose();
|
||||
if (isHedged)
|
||||
{
|
||||
//
|
||||
ForceState(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// //
|
||||
// isHedged = DoEQMForceClose(5);
|
||||
// if (isHedged)
|
||||
// {
|
||||
// //
|
||||
// ForceState(false);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Handle Act Based On Drawdow ...
|
||||
if (mMaxDrawdownForce > 0)
|
||||
{
|
||||
//
|
||||
double drawdown = GetDrawdownPercent();
|
||||
if (drawdown > 5)
|
||||
{
|
||||
//
|
||||
// Try to Hedge ...
|
||||
if (profits > 0)
|
||||
{
|
||||
//
|
||||
bool isHedged = DoEQMForceClose(profits);
|
||||
if (isHedged)
|
||||
{
|
||||
//
|
||||
ForceState(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// //
|
||||
//
|
||||
// Close Max In Drawdown Position ...
|
||||
int maxInDIDX = FindMaxDrawdownIndex(positions);
|
||||
if (isValidIndex(maxInDIDX))
|
||||
{
|
||||
//
|
||||
string comment = XEQMSupportToken + " Max In D ...";
|
||||
|
||||
//
|
||||
bool isClosed = mTrader.Close(
|
||||
positions[maxInDIDX].ticket,
|
||||
comment //
|
||||
);
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
string message = XEQMSupportToken + "Close " + ToString(positions[maxInDIDX].ticket) + " Due Max In Drawdown ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Act Based on Positions Count ...
|
||||
if (mMaxPositionsForce > 0 && positionsCount > mMaxPositionsForce)
|
||||
{
|
||||
//
|
||||
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
||||
positions,
|
||||
mMinRequiredProfitPerTrade,
|
||||
mMinRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
double halfProfit = requiredProfit / 2;
|
||||
if (halfProfit > 0 && profit > halfProfit)
|
||||
{
|
||||
//
|
||||
bool isHedged = DoEQMForceClose(halfProfit);
|
||||
if (isHedged)
|
||||
{
|
||||
//
|
||||
ForceState(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Close Min In Profit Position ...
|
||||
int minInPIDX = FindMinProfitIndex(positions);
|
||||
if (IsValidIndex(minInPIDX))
|
||||
{
|
||||
//
|
||||
string comment = XEQMSupportToken + " Min In P ...";
|
||||
|
||||
//
|
||||
bool isClosed = mTrader.Close(
|
||||
positions[minInPIDX].ticket,
|
||||
comment //
|
||||
);
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
string message = XEQMSupportToken + "Close " + ToString(positions[maxInDIDX].ticket) + " Due Min In Profit ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Close Max In Drawdown Position ...
|
||||
int maxInDIDX = FindMaxDrawdownIndex(positions);
|
||||
if (isValidIndex(maxInDIDX))
|
||||
{
|
||||
//
|
||||
string comment = XEQMSupportToken + " Max In D ...";
|
||||
|
||||
//
|
||||
bool isClosed = mTrader.Close(
|
||||
positions[maxInDIDX].ticket,
|
||||
comment //
|
||||
);
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
string message = XEQMSupportToken + "Close " + ToString(positions[maxInDIDX].ticket) + " Due Max In Drawdown ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4905,10 +5167,18 @@ private:
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
signal,
|
||||
signals //
|
||||
);
|
||||
// Check Delay Between Two Signals ...
|
||||
bool isDelayPassed = IsSignalDelayPassed(signal);
|
||||
|
||||
//
|
||||
if (isDelayPassed)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
signal,
|
||||
signals //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user