This commit is contained in:
2024-06-22 08:33:18 +03:30
parent 532be35f74
commit 6063d3be61
5 changed files with 597 additions and 57 deletions
+49
View File
@@ -69,6 +69,7 @@ enum ENUM_X121_SIGNAL_PROVIDER
PROVIDER_XASCT = 16,
PROVIDER_XVLM = 17,
PROVIDER_XPVF = 18,
PROVIDER_XPVSAR = 19,
};
//
@@ -197,6 +198,10 @@ ENUM_X121_SIGNAL_PROVIDER FromString(string value)
{
result = PROVIDER_XPVF;
}
else if (Contains(value, (EnumToString(PROVIDER_XPVSAR))))
{
result = PROVIDER_XPVSAR;
}
//
return result;
@@ -1422,6 +1427,24 @@ struct X121SignalGenerator
provider = ToString(PROVIDER_XPVF);
}
//
// XPVSAR ...
bool long19 =
//
// Starting Conditions ...
conditions.mcConditions.isSARSwitchedToBullish &&
conditions.pvConditions.vales[zIndex] == conditions.mcConditions.psar[zIndex] &&
conditions.strConditions.isTrendBullish &&
conditions.cheConditions.isStrongBullish
//
;
if (long19)
{
//
pusher += 2;
provider = ToString(PROVIDER_XPVSAR);
}
//
result =
//
@@ -1500,6 +1523,10 @@ struct X121SignalGenerator
//
long18
//
||
//
long19
//
)
//
;
@@ -2068,6 +2095,24 @@ struct X121SignalGenerator
provider = ToString(PROVIDER_XPVF);
}
//
// XPVSAR ...
bool short19 =
//
// Starting Conditions ...
conditions.mcConditions.isSARSwitchedToBearish &&
conditions.pvConditions.peaks[zIndex] == conditions.mcConditions.psar[zIndex] &&
conditions.strConditions.isTrendBearish &&
conditions.cheConditions.isStrongBearish
//
;
if (short19)
{
//
pusher += 2;
provider = ToString(PROVIDER_XPVSAR);
}
//
result =
//
@@ -2146,6 +2191,10 @@ struct X121SignalGenerator
//
short18
//
||
//
short19
//
)
//
;
+299 -29
View File
@@ -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 //
);
}
}
//
+4 -4
View File
@@ -39,6 +39,10 @@ public:
//
// Props ...
//
// Trade Class Instance ...
XSCTrade *mTrader;
//
// Constructor ...
XSCBaseEA(
@@ -580,10 +584,6 @@ protected:
//
// Props ...
//
// Trade Class Instance ...
XSCTrade *mTrader;
//
// Check in Test Mode or not ...
bool mIsInTestMode;