complete grid mechanism ...

This commit is contained in:
2024-06-14 18:33:38 +03:30
parent a78cf432ac
commit 001c5f687e
3 changed files with 279 additions and 29 deletions
+4 -4
View File
@@ -2062,8 +2062,8 @@ struct X121SignalGenerator
// //
bool IsConditionsValidForLong( bool IsConditionsValidForLong(
X121SetupConditions &conditions, X121SetupConditions &conditions, // Conditions
int verification = 4 // int verification = 4 // Number of Verifications
) )
{ {
// //
@@ -2304,8 +2304,8 @@ struct X121SignalGenerator
// //
bool IsConditionsValidForShort( bool IsConditionsValidForShort(
X121SetupConditions &conditions, X121SetupConditions &conditions, // Conditions
int verification = 4 // int verification = 4 // Number of Verifications
) )
{ {
// //
+254 -12
View File
@@ -817,12 +817,63 @@ public:
mUseSupport = value; mUseSupport = value;
} }
//
bool UseGrid()
{
return mUseGrid;
}
//
void UseGrid(bool value)
{
mUseGrid = value;
}
//
double GridDistance()
{
return mGridDistance;
}
//
void GridDistance(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mGridDistance = value;
}
//
double GridVolumeMultiplier()
{
return mGridVolumeMultiplier;
}
//
void GridVolumeMultiplier(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mGridVolumeMultiplier = value;
}
// //
// Overrides ... // Overrides ...
// //
// Customize Token ... // Customize Token ...
string GetToken() override string
GetToken() override
{ {
return GetSpecificToken(this); return GetSpecificToken(this);
} }
@@ -1003,7 +1054,7 @@ public:
// //
// Parse Conditions for Signal ... // Parse Conditions for Signal ...
bool cHasSignal = signalGenerator.HasSignal( cHasSignal = signalGenerator.HasSignal(
cConditions, cConditions,
cSignal, cSignal,
cPusher, cPusher,
@@ -1066,7 +1117,7 @@ public:
// //
// Parse Conditions for Signal ... // Parse Conditions for Signal ...
bool sHasSignal = signalGenerator.HasSignal( sHasSignal = signalGenerator.HasSignal(
sConditions, sConditions,
sSignal, sSignal,
sPusher, sPusher,
@@ -1128,7 +1179,7 @@ public:
// //
// Parse Conditions for Signal ... // Parse Conditions for Signal ...
bool mHasSignal = signalGenerator.HasSignal( mHasSignal = signalGenerator.HasSignal(
mConditions, mConditions,
mSignal, mSignal,
mPusher, mPusher,
@@ -1191,7 +1242,7 @@ public:
// //
// Parse Conditions for Signal ... // Parse Conditions for Signal ...
bool lHasSignal = signalGenerator.HasSignal( lHasSignal = signalGenerator.HasSignal(
lConditions, lConditions,
lSignal, lSignal,
lPusher, lPusher,
@@ -1254,7 +1305,7 @@ public:
// //
// Parse Conditions for Signal ... // Parse Conditions for Signal ...
bool hHasSignal = signalGenerator.HasSignal( hHasSignal = signalGenerator.HasSignal(
hConditions, hConditions,
hSignal, hSignal,
hPusher, hPusher,
@@ -1750,6 +1801,13 @@ public:
} }
} }
} }
//
bool hasSignal = cHasSignal || sHasSignal || mHasSignal || lHasSignal || hHasSignal;
if (hasSignal)
{
Print("Signal Recieved ...");
}
} }
// //
@@ -1891,6 +1949,10 @@ public:
// Handle Close All Positions on Specific Time ... // Handle Close All Positions on Specific Time ...
DoEQMCloseOnSpecificTime(); DoEQMCloseOnSpecificTime();
//
// Do EQM Grid if Provided ...
DoEQMGrid();
// //
// if Returns true, Signal Execution failed ... // if Returns true, Signal Execution failed ...
return result; return result;
@@ -1986,7 +2048,6 @@ private:
double mVolume; // Volume double mVolume; // Volume
double mTPPoint; // TP Point double mTPPoint; // TP Point
double mSLPoint; // SL Point double mSLPoint; // SL Point
bool mUseSupport; // Use Support Signals
bool mIgnoreTP; // Ignore Calculated TP bool mIgnoreTP; // Ignore Calculated TP
bool mIgnoreSL; // Ignore Calculated SL bool mIgnoreSL; // Ignore Calculated SL
int mMaxAllowedTrades; // Max Alloed Positions int mMaxAllowedTrades; // Max Alloed Positions
@@ -1995,6 +2056,12 @@ private:
int mReuiredSignalVerifications; // Required Verifications for Validate Signals int mReuiredSignalVerifications; // Required Verifications for Validate Signals
bool mGetVerificationFromOtherTimeFrames; // Get Verifications from Other Time Frames bool mGetVerificationFromOtherTimeFrames; // Get Verifications from Other Time Frames
//
bool mUseSupport; // Use Support Signals
bool mUseGrid; // Use Grid Signals
double mGridDistance; // Grid Distance
double mGridVolumeMultiplier; // Grid Volume Multiplier
// //
XSignalInfo mSignalInfos[]; XSignalInfo mSignalInfos[];
XSignalInfoCollector *mSignalCollector; XSignalInfoCollector *mSignalCollector;
@@ -2098,11 +2165,20 @@ private:
// //
if (IsValid(deal.provider)) if (IsValid(deal.provider))
{ {
result = FindSignalInfoIndex( //
deal.symbol, ulong supTicket = ExtractSupportedTicket(deal.comment);
deal.provider, ulong supTicket1 = ExtractEQMSupportedTicket(deal.comment);
deal.period //
); //
if (supTicket <= 0 && supTicket1 <= 0)
{
//
result = FindSignalInfoIndex(
deal.symbol,
deal.provider,
deal.period //
);
}
} }
else else
{ {
@@ -2167,6 +2243,30 @@ private:
mSignalInfos[infoIDX].ticket = deal.positionId; mSignalInfos[infoIDX].ticket = deal.positionId;
mSignalInfos[infoIDX].commission = deal.commission; mSignalInfos[infoIDX].commission = deal.commission;
mSignalInfos[infoIDX].signal.positionId = deal.positionId; mSignalInfos[infoIDX].signal.positionId = deal.positionId;
//
bool isLong = IsLong(mSignalInfos[infoIDX].signal.type);
double sEntry = mSignalInfos[infoIDX].signal.entry;
//
// Setting Grid Data ...
if (mUseGrid)
{
//
mSignalInfos[infoIDX].ResetGrid();
//
double gDistancePrice = PointToPrice(
mGridDistance,
mSignalInfos[infoIDX].signal.symbol //
);
//
mSignalInfos[infoIDX].gVolume = mSignalInfos[infoIDX].volume * mGridVolumeMultiplier;
mSignalInfos[infoIDX].gEntry = isLong
? sEntry - gDistancePrice
: sEntry + gDistancePrice;
}
} }
else if (deal.entry == DEAL_ENTRY_OUT) else if (deal.entry == DEAL_ENTRY_OUT)
{ {
@@ -2527,6 +2627,148 @@ private:
} }
} }
//
// Do Gridding Mechanism ...
void DoEQMGrid()
{
//
if (!mUseGrid)
{
return;
}
//
int infosCount = CountSignalInfos();
if (!IsValidSize(infosCount))
{
return;
}
//
for (int i = 0; i < infosCount; i++)
{
//
// Check Signal Executed or not ...
if (mSignalInfos[i].ticket <= 0)
{
continue;
}
//
// Check Specific Position not a Support Position ...
XPosition position;
bool hasPosition = mTrader.GetPosition(
mSignalInfos[i].ticket,
position //
);
if (!hasPosition)
{
continue;
}
//
// Check Position not a Support or EQM Support ...
ulong supParent = 0;
supParent = ExtractSupportedTicket(position.comment);
if (supParent > 0)
{
continue;
}
supParent = ExtractEQMSupportedTicket(position.comment);
if (supParent > 0)
{
continue;
}
//
// Check Grid Data ...
if (mSignalInfos[i].gEntry <= 0 || mSignalInfos[i].gVolume <= 0)
{
continue;
}
//
// Retrieve Type of Position ...
bool isLong = IsLong(mSignalInfos[i].signal.type);
//
// Retrieve Cureent Entry Price based on Signal ...
double cEntry = GetEntry(
mSignalInfos[i].symbol,
mSignalInfos[i].signal.type //
);
//
// Check Price Distance passed or not ...
bool isPriceDistancePassedForGrid =
isLong
? cEntry <= mSignalInfos[i].gEntry
: cEntry >= mSignalInfos[i].gEntry;
if (!isPriceDistancePassedForGrid)
{
continue;
}
//
// Prepare Grid Signal ...
XSignal gSignal;
bool isPrepared = gSignal.Prepare(
mSignalInfos[i].signal.symbol,
mSignalInfos[i].signal.provider,
mSignalInfos[i].signal.period,
mSignalInfos[i].signal.type,
X_ORDER_MODE_MARKET,
mSignalInfos[i].gEntry,
mSignalInfos[i].gVolume,
0, // SL ...
0 // TP ...
);
if (!isPrepared)
{
continue;
}
//
// Add Support Tag ...
string comment = GenerateSupportTag(mSignalInfos[i].ticket);
gSignal.comment = comment;
//
// Try to Execute Grid Signal ...
ENUM_X_SIGNAL_EXECUTION_RESULT gState;
int isExecuted = mTrader.ExecuteSignal(
gSignal,
gState,
ORDER_TIME_GTC,
NULL,
false // Ignore Policies ...
);
if (isExecuted)
{
//
// Update Grid State of Signal Info ...
//
double gDistancePrice = PointToPrice(
mGridDistance,
mSignalInfos[i].signal.symbol //
);
//
mSignalInfos[i].gVolume *= mGridVolumeMultiplier;
mSignalInfos[i].gEntry = isLong
? mSignalInfos[i].gEntry - gDistancePrice
: mSignalInfos[i].gEntry + gDistancePrice;
//
string message = XEQMSupportToken + " Execute Grid ...";
//
Alert(message);
}
}
}
// //
// Handle Close Trades on Specific Time ... // Handle Close Trades on Specific Time ...
void DoEQMCloseOnSpecificTime() void DoEQMCloseOnSpecificTime()
+21 -13
View File
@@ -48,18 +48,21 @@ input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications
// //
// Risk Management ... // Risk Management ...
input group "Risk Management"; input group "Risk Management";
input double x121EAVolume = 0.01; // Static Volume input double x121EAVolume = 0.01; // Static Volume
input double x121EATPPoint = 60; // TP Point input double x121EATPPoint = 60; // TP Point
input double x121EASLPoint = 300; // SL Point input double x121EASLPoint = 300; // SL Point
input int x121EAMaxAllowedTrades = 1; // Max Allowed Positions input int x121EAMaxAllowedTrades = 1; // Max Allowed Positions
input bool x121EAIgnoreSL = true; // Ignore Calculated SL input bool x121EAIgnoreSL = true; // Ignore Calculated SL
input bool x121EAIgnoreTP = false; // Ignore Calculated TP input bool x121EAIgnoreTP = false; // Ignore Calculated TP
input bool x121EAUseSupport = false; // Use Support Signals input bool x121EAUseSupport = false; // Use Support Signals
input double x121EAMinRequiredProfitPerTrade = 0; // Minimum Required Profit for Hedging input bool x121EAUseGrid = true; // Use Grid Signals
input double x121EAMinRequiredProfitPerVolumeFactor = 0; // Minimum Required Profit for Hedging Per Velume input double x121EAGridDistance = 50; // Grid Distance
input int x121EARestingAfterHedge = 0; // Resting Seconds After Hedge input double x121EAGridVolumeMultiplier = 2; // Grid Volume Multiplier
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time input double x121EAMinRequiredProfitPerTrade = 1; // Minimum Required Profit for Hedging
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit input double x121EAMinRequiredProfitPerVolumeFactor = 0.1; // Minimum Required Profit for Hedging Per Velume
input int x121EARestingAfterHedge = 0; // Resting Seconds After Hedge
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
// //
// Alert ... // Alert ...
@@ -174,7 +177,6 @@ bool InitialEA()
x121EA.IgnoreTP(x121EAIgnoreTP); x121EA.IgnoreTP(x121EAIgnoreTP);
x121EA.AllowLong(x121EAAllowLong); x121EA.AllowLong(x121EAAllowLong);
x121EA.AllowShort(x121EAAllowShort); x121EA.AllowShort(x121EAAllowShort);
x121EA.UseSupport(x121EAUseSupport);
x121EA.CloseOnOpposit(x121EACloseOnOpposit); x121EA.CloseOnOpposit(x121EACloseOnOpposit);
x121EA.MaxAllowedTrades(x121EAMaxAllowedTrades); x121EA.MaxAllowedTrades(x121EAMaxAllowedTrades);
x121EA.RestingAfterHedge(x121EARestingAfterHedge); x121EA.RestingAfterHedge(x121EARestingAfterHedge);
@@ -184,6 +186,12 @@ bool InitialEA()
x121EA.MinRequiredProfitPerVolumeFactor(x121EAMinRequiredProfitPerVolumeFactor); x121EA.MinRequiredProfitPerVolumeFactor(x121EAMinRequiredProfitPerVolumeFactor);
x121EA.GetVerificationFromOtherTimeFrames(x121EAGetVerificationFromOtherTimeFrames); x121EA.GetVerificationFromOtherTimeFrames(x121EAGetVerificationFromOtherTimeFrames);
//
x121EA.UseGrid(x121EAUseGrid);
x121EA.UseSupport(x121EAUseSupport);
x121EA.GridDistance(x121EAGridDistance);
x121EA.GridVolumeMultiplier(x121EAGridVolumeMultiplier);
// //
// Configure Alert ... // Configure Alert ...
x121EA.SetAlertPrefix(ShortName); x121EA.SetAlertPrefix(ShortName);