This commit is contained in:
2024-05-25 04:25:11 +03:30
parent 7a50508816
commit da63c4cb71
9 changed files with 3522 additions and 165 deletions
File diff suppressed because it is too large Load Diff
+346 -23
View File
@@ -289,7 +289,11 @@ public:
bool result = false; bool result = false;
// //
int requiredAgeForSLTrail = 10; // TODO:
// Make them Configurable ...
int numberOfPositionsForHege = 4;
int levelsOnClose = 6;
int requiredAgeForSLTrail = 3;
int requiredDistanceForSLTrail = 10; int requiredDistanceForSLTrail = 10;
// //
@@ -307,10 +311,18 @@ public:
// //
XPosition iPosition = positions[i]; XPosition iPosition = positions[i];
//
bool canManageState =
//
iPosition.provider == ToString(X786) ||
iPosition.provider == ToString(X121) ||
iPosition.provider == ToString(X92)
//
;
// //
// Position Management for X786 ... // Position Management for X786 ...
if (iPosition.provider == ToString(X786) || if (canManageState)
iPosition.provider == ToString(X121))
{ {
// //
// Check Position in Profit or not ... // Check Position in Profit or not ...
@@ -318,7 +330,7 @@ public:
{ {
// //
XTrail trail; XTrail trail;
bool isTrailedBefore = GetTrail( bool isTrailedBefore = GetSLTrail(
iPosition.ticket, iPosition.ticket,
trail // trail //
); );
@@ -355,6 +367,12 @@ public:
? iPosition.sl + slDiff ? iPosition.sl + slDiff
: iPosition.sl - slDiff; : iPosition.sl - slDiff;
// //
// double sl =
// IsLong(iPosition.type)
// ? iPosition.entry + (slDiff / 2)
// : iPosition.entry - (slDiff / 2);
// //
bool isInit = trail.Init( bool isInit = trail.Init(
iPosition.ticket, iPosition.ticket,
@@ -400,7 +418,7 @@ public:
{ {
// //
// int positionAge = iPosition.GetAge(iPosition.period); // int positionAge = iPosition.GetAge(iPosition.period);
if (trail.level >= 3) if (trail.level >= levelsOnClose)
{ {
// //
string comment = "EQM Close In Profit ..."; string comment = "EQM Close In Profit ...";
@@ -411,7 +429,7 @@ public:
if (isClosed) if (isClosed)
{ {
// //
RemoveTrail(iPosition.ticket); RemoveSLTrail(iPosition.ticket);
// //
string message = "EQM Close (" + ToString(iPosition.ticket) + ") In Profit ..."; string message = "EQM Close (" + ToString(iPosition.ticket) + ") In Profit ...";
@@ -424,11 +442,20 @@ public:
// //
double slDiff = PointToPrice(priceDistance, iPosition.symbol); double slDiff = PointToPrice(priceDistance, iPosition.symbol);
//
double selectedValue =
//
trail.level == 2
? iPosition.entry
: iPosition.sl
//
;
// //
double sl = double sl =
IsLong(iPosition.type) IsLong(iPosition.type)
? iPosition.sl + slDiff ? selectedValue + slDiff
: iPosition.sl - slDiff; : selectedValue - slDiff;
// //
// Update Trail Values ... // Update Trail Values ...
@@ -456,10 +483,10 @@ public:
if (isModified) if (isModified)
{ {
// //
RemoveTrail(trail.ticket); RemoveSLTrail(trail.ticket);
// //
AddTrail(trail); AddSLTrail(trail);
// //
string message = "Position (" + ToString(trail.ticket) + ") Trailed SL on Level: " + ToString(trail.level); string message = "Position (" + ToString(trail.ticket) + ") Trailed SL on Level: " + ToString(trail.level);
@@ -470,11 +497,193 @@ public:
} }
} }
//
// Hedge ...
if (positionsCount >= numberOfPositionsForHege)
{
//
double profit = CalculatePositionsProfit(positions);
double requiredProfit = CalculateRequiredProfitForHedge(positions);
//
bool isReadyForHedge = profit >= requiredProfit;
if (!isReadyForHedge)
{
return result;
}
//
string comment = "EQM Hedge ...";
int closed = mTrader.Close(
positions,
comment
//
);
if (closed > 0)
{
//
string message = "EQM Hedge Positions on Profit: " + ToString(profit);
//
mAlert.Alert(message);
//
for (int i = 0; i < positionsCount; i++)
{
RemoveSLTrail(positions[i].ticket);
}
}
}
// //
// Must false ... // Must false ...
return result; return result;
} }
//
// Here we Can Filter Signals before Sending them to Execution ...
// based on Providers and etc ...
// for Volumes and Benefits ...
int HandleSignalManagement(XSignal &signals[]) override
{
//
int result = 0;
//
if (ArraySize(signals) <= 0)
{
return result;
}
//
// Create temp Array for Filtering ...
XSignal tmps[];
Copy(
signals,
tmps //
);
int tmpsCount = ArraySize(tmps);
//
// Cleaning Source ...
Clean(signals);
//
// Loop through Signals for Management ...
for (int i = 0; i < tmpsCount; i++)
{
//
XSignal iSignal = tmps[i];
//
string provider = iSignal.provider;
if (!IsValid(provider))
{
//
AddRef(
iSignal,
signals //
);
//
continue;
}
//
XPosition positions[];
int positionsCount = mTrader.GetPositions(
positions,
iSignal.symbol,
iSignal.provider,
NULL, // All Periods ...
iSignal.type //
);
if (positionsCount <= 5)
{
//
// First Signal in a While of Specific Provider ...
AddRef(
iSignal,
signals //
);
//
continue;
}
else
{
//
// not First Signal ...
//
// Calculate Provider Specified Open Positions Profit ...
double profits = CalculatePositionsProfit(positions);
if (profits > 0)
{
//
AddRef(
iSignal,
signals //
);
//
continue;
}
else
{
//
// Find Max In Profit of Same Position ...
Clean(positions);
positionsCount = mTrader.GetInProfitPositions(
positions,
iSignal.symbol,
iSignal.provider,
NULL, // All Periods ...
iSignal.type,
X_POSITION_SELECT_MAX // Max In Profit ...
);
if (positionsCount <= 0)
{
continue;
}
//
string comment = "EQM Close Max Profit ...";
bool isClosed = mTrader.Close(
positions[0].ticket,
comment //
);
if (isClosed)
{
//
RemoveTrail(positions[0].ticket);
//
string message = "EQM Close Max In Profit (" + ToString(positions[0].ticket) + ") for new Signal ...";
//
mAlert.Alert(message);
//
AddRef(
iSignal,
signals //
);
//
continue;
}
}
}
}
//
result = ArraySize(signals);
//
return result;
}
// //
// Request for Support Signals using Guard ... // Request for Support Signals using Guard ...
bool RequestForSupport( bool RequestForSupport(
@@ -487,6 +696,12 @@ public:
{ {
// //
// TODO: Implement this ... // TODO: Implement this ...
//
// Support Senario ...
// Check Support Position Exists or not ...
// Check Positions for Support based on Types ...
// Update Untriggered Positions ...
return false; return false;
} }
@@ -544,22 +759,39 @@ private:
// Trails Holding ... // Trails Holding ...
// //
XTrail mTrails[]; XTrail mSLTrails[];
XTrail mTPTrails[];
// //
int CountTrails() int CountSLTrails()
{ {
return ArraySize(mTrails); return ArraySize(mSLTrails);
}
int CountTPTrails()
{
return ArraySize(mTPTrails);
} }
// //
bool RemoveTrail(ulong ticket) bool RemoveTrail(ulong ticket)
{
//
bool isSLRemoved = RemoveSLTrail(ticket);
bool isTPRemoved = RemoveTPTrail(ticket);
//
bool result = isSLRemoved || isTPRemoved;
//
return result;
}
bool RemoveSLTrail(ulong ticket)
{ {
// //
bool result = false; bool result = false;
// //
int idx = FindTrailIndex(ticket); int idx = FindSLTrailIndex(ticket);
result = idx >= 0; result = idx >= 0;
if (!result) if (!result)
{ {
@@ -568,7 +800,30 @@ private:
// //
result = ArrayRemove( result = ArrayRemove(
mTrails, mSLTrails,
idx,
1 //
);
//
return result;
}
bool RemoveTPTrail(ulong ticket)
{
//
bool result = false;
//
int idx = FindTPTrailIndex(ticket);
result = idx >= 0;
if (!result)
{
return result;
}
//
result = ArrayRemove(
mTPTrails,
idx, idx,
1 // 1 //
); );
@@ -578,13 +833,13 @@ private:
} }
// //
int FindTrailIndex(ulong ticket) int FindSLTrailIndex(ulong ticket)
{ {
// //
int result = -1; int result = -1;
// //
int trailsCount = CountTrails(); int trailsCount = CountSLTrails();
if (ticket <= 0 || trailsCount <= 0) if (ticket <= 0 || trailsCount <= 0)
{ {
return result; return result;
@@ -594,7 +849,37 @@ private:
for (int i = 0; i < trailsCount; i++) for (int i = 0; i < trailsCount; i++)
{ {
// //
XTrail iTrail = mTrails[i]; XTrail iTrail = mSLTrails[i];
//
if (iTrail.ticket == ticket)
{
//
result = i;
break;
}
}
//
return result;
}
int FindTPTrailIndex(ulong ticket)
{
//
int result = -1;
//
int trailsCount = CountTPTrails();
if (ticket <= 0 || trailsCount <= 0)
{
return result;
}
//
for (int i = 0; i < trailsCount; i++)
{
//
XTrail iTrail = mTPTrails[i];
// //
if (iTrail.ticket == ticket) if (iTrail.ticket == ticket)
@@ -610,7 +895,7 @@ private:
} }
// //
bool GetTrail( bool GetSLTrail(
ulong ticket, ulong ticket,
XTrail &trail // XTrail &trail //
) )
@@ -619,7 +904,7 @@ private:
bool result = false; bool result = false;
// //
int idx = FindTrailIndex(ticket); int idx = FindSLTrailIndex(ticket);
result = idx >= 0; result = idx >= 0;
if (!result) if (!result)
{ {
@@ -627,14 +912,36 @@ private:
} }
// //
trail = mTrails[idx]; trail = mSLTrails[idx];
//
return result;
}
bool GetTPTrail(
ulong ticket,
XTrail &trail //
)
{
//
bool result = false;
//
int idx = FindTPTrailIndex(ticket);
result = idx >= 0;
if (!result)
{
return result;
}
//
trail = mTPTrails[idx];
// //
return result; return result;
} }
// //
void AddTrail( void AddSLTrail(
XTrail &trail // XTrail &trail //
) )
{ {
@@ -647,7 +954,23 @@ private:
// //
AddRef( AddRef(
trail, trail,
mTrails // mSLTrails //
);
}
void AddTPTrail(
XTrail &trail //
)
{
//
if (!trail.IsValid())
{
return;
}
//
AddRef(
trail,
mTPTrails //
); );
} }
File diff suppressed because it is too large Load Diff
+28
View File
@@ -29,6 +29,14 @@
// Define On Signal Event Handler Type ... // Define On Signal Event Handler Type ...
typedef void (*TOnSignal)(XSignal &signals[]); typedef void (*TOnSignal)(XSignal &signals[]);
//
// Model Account Profits ...
struct XProfitTracker {
//
int count; // Number of Positions ...
};
// //
// Class Definition ... // Class Definition ...
@@ -566,6 +574,19 @@ public:
return false; return false;
} }
//
// Regulary Filtered Signals passed to this
// and here we can do Additional Signal Filtering
// for Signal Management such as (Providers and etc) ...
virtual int HandleSignalManagement(XSignal &signals[])
{
//
int result = ArraySize(signals);
//
return result;
}
// //
// Here we Have to Check Market based // Here we Have to Check Market based
// on our Strategy for Trading ... // on our Strategy for Trading ...
@@ -623,6 +644,13 @@ public:
return; return;
} }
//
int managedSignalsCount = HandleSignalManagement(filteredSignals);
if (managedSignalsCount <= 0)
{
return;
}
// //
// Try to Execute Signals ... // Try to Execute Signals ...
ENUM_X_SIGNAL_EXECUTION_RESULT reasons[]; ENUM_X_SIGNAL_EXECUTION_RESULT reasons[];
+5 -5
View File
@@ -37,11 +37,11 @@ string x121EASymbols = "EURUSDb"; // Symbols
bool x121EAAllowLong = true; // Allow Long Trades bool x121EAAllowLong = true; // Allow Long Trades
bool x121EAAllowShort = true; // Allow Short Trades bool x121EAAllowShort = true; // Allow Short Trades
int x121EAManageInterval = 5; // Manager Check Intervals Seconds int x121EAManageInterval = 5; // Manager Check Intervals Seconds
int x121EAMaxAllowedPositions = 0; // Max Allowed Positions int x121EAMaxAllowedPositions = 5; // Max Allowed Positions
double x121EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades double x121EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
double x121EAMinProfitPerTrade = 0; // Min Profit Per Trade based On Volume Factor (Hedge) double x121EAMinProfitPerTrade = 0.4; // Min Profit Per Trade based On Volume Factor (Hedge)
double x121EAMinProfitPerVolumeFactor = 0; // Min Volume Factor for Calculating Profit (Hedge) double x121EAMinProfitPerVolumeFactor = 0.01; // Min Volume Factor for Calculating Profit (Hedge)
double x121EAMaxAllowedDrawdownFactor = 0; // Max Allowed Drawdown Factor double x121EAMaxAllowedDrawdownFactor = 0.015; // Max Allowed Drawdown Factor
// //
double x121EAVolume = 0.01; double x121EAVolume = 0.01;
@@ -313,7 +313,7 @@ bool InitialEA()
string fontName = "Arial"; string fontName = "Arial";
ENUM_ANCHOR_POINT fontAnchor = ANCHOR_LEFT_UPPER; ENUM_ANCHOR_POINT fontAnchor = ANCHOR_LEFT_UPPER;
//false //
// Hind Market ... // Hind Market ...
iDescriptor.inputs.hMarketPeriod = NULL; iDescriptor.inputs.hMarketPeriod = NULL;
iDescriptor.inputs.hMarketMethod = X_PERIOD_AUTO; iDescriptor.inputs.hMarketMethod = X_PERIOD_AUTO;
+144
View File
@@ -314,6 +314,24 @@ public:
); );
} }
//
bool IsSameUpperO(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
upperOBuffer,
verifier,
barIndex //
);
}
// //
// Lower ... // Lower ...
@@ -367,6 +385,24 @@ public:
); );
} }
//
bool IsSameLowerO(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
lowerOBuffer,
verifier,
barIndex //
);
}
// //
// Close ... // Close ...
@@ -423,6 +459,24 @@ public:
); );
} }
//
bool IsSameUpperC(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
upperCBuffer,
verifier,
barIndex //
);
}
// //
// Lower ... // Lower ...
@@ -476,6 +530,24 @@ public:
); );
} }
//
bool IsSameLowerC(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
lowerCBuffer,
verifier,
barIndex //
);
}
// //
// High ... // High ...
@@ -532,6 +604,24 @@ public:
); );
} }
//
bool IsSameUpperH(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
upperHBuffer,
verifier,
barIndex //
);
}
// //
// Lower ... // Lower ...
@@ -585,6 +675,24 @@ public:
); );
} }
//
bool IsSameLowerH(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
lowerHBuffer,
verifier,
barIndex //
);
}
// //
// Low ... // Low ...
@@ -641,6 +749,24 @@ public:
); );
} }
//
bool IsSameUpperL(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
upperLBuffer,
verifier,
barIndex //
);
}
// //
// Lower ... // Lower ...
@@ -694,6 +820,24 @@ public:
); );
} }
//
bool IsSameLowerL(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
lowerLBuffer,
verifier,
barIndex //
);
}
// //
void GetUppers( void GetUppers(
double &result[], double &result[],
+72
View File
@@ -362,6 +362,24 @@ public:
); );
} }
//
bool IsSameTenkanSen(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
tenkanSenBuffer,
verifier,
barIndex //
);
}
// //
// KijunSen ... // KijunSen ...
@@ -408,6 +426,24 @@ public:
); );
} }
//
bool IsSameKijunSen(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
kijunSenBuffer,
verifier,
barIndex //
);
}
// //
// ChikouSpan ... // ChikouSpan ...
@@ -518,6 +554,24 @@ public:
); );
} }
//
bool IsSameSenkouSpanA(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
senkouSpanABuffer,
verifier,
barIndex //
);
}
// //
// SenkouSpanB ... // SenkouSpanB ...
@@ -573,6 +627,24 @@ public:
); );
} }
//
bool IsSameSenkouSpanB(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
senkouSpanBBuffer,
verifier,
barIndex //
);
}
// //
// Future SenkouSpanA ... // Future SenkouSpanA ...
+270
View File
@@ -477,6 +477,24 @@ public:
); );
} }
//
bool IsSamePeak(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
peaksBuffer,
verifier,
barIndex //
);
}
// //
// Vales ... // Vales ...
@@ -530,6 +548,24 @@ public:
); );
} }
//
bool IsSameVale(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
valesBuffer,
verifier,
barIndex //
);
}
// //
// Resistance ... // Resistance ...
@@ -692,6 +728,24 @@ public:
); );
} }
//
bool IsSameFib1(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
fib1Buffer,
verifier,
barIndex //
);
}
// //
// Level 2 ... // Level 2 ...
@@ -745,6 +799,24 @@ public:
); );
} }
//
bool IsSameFib2(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
fib2Buffer,
verifier,
barIndex //
);
}
// //
// Level 3 ... // Level 3 ...
@@ -798,6 +870,24 @@ public:
); );
} }
//
bool IsSameFib3(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
fib3Buffer,
verifier,
barIndex //
);
}
// //
// Level 4 ... // Level 4 ...
@@ -851,6 +941,24 @@ public:
); );
} }
//
bool IsSameFib4(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
fib4Buffer,
verifier,
barIndex //
);
}
// //
// Level 5 ... // Level 5 ...
@@ -904,6 +1012,24 @@ public:
); );
} }
//
bool IsSameFib5(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
fib5Buffer,
verifier,
barIndex //
);
}
// //
// Cycles ... // Cycles ...
@@ -963,6 +1089,24 @@ public:
); );
} }
//
bool IsSameSCHH(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
scHHBuffer,
verifier,
barIndex //
);
}
// //
// LL ... // LL ...
@@ -1016,6 +1160,24 @@ public:
); );
} }
//
bool IsSameSCLL(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
scLLBuffer,
verifier,
barIndex //
);
}
// //
// Medium ... // Medium ...
@@ -1072,6 +1234,24 @@ public:
); );
} }
//
bool IsSameMCHH(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
mcHHBuffer,
verifier,
barIndex //
);
}
// //
// LL ... // LL ...
@@ -1125,6 +1305,24 @@ public:
); );
} }
//
bool IsSameMCLL(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
mcLLBuffer,
verifier,
barIndex //
);
}
// //
// Long ... // Long ...
@@ -1181,6 +1379,24 @@ public:
); );
} }
//
bool IsSameLCHH(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
lcHHBuffer,
verifier,
barIndex //
);
}
// //
// LL ... // LL ...
@@ -1234,6 +1450,24 @@ public:
); );
} }
//
bool IsSameLCLL(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
lcLLBuffer,
verifier,
barIndex //
);
}
// //
// Hind ... // Hind ...
@@ -1290,6 +1524,24 @@ public:
); );
} }
//
bool IsSameHCHH(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
hcHHBuffer,
verifier,
barIndex //
);
}
// //
// LL ... // LL ...
@@ -1343,6 +1595,24 @@ public:
); );
} }
//
bool IsSameHCLL(
int barIndex, // Start Bar Index
int verifier = 71 // Number of Verifiers
)
{
//
// Update Calculations ...
Calculate();
//
return IsSame(
hcLLBuffer,
verifier,
barIndex //
);
}
// //
// Protected ... // Protected ...
protected: protected:
+5 -4
View File
@@ -3631,7 +3631,8 @@ MqlDateTime GetBarTimeStruct(
template <typename T> template <typename T>
bool IsSame( bool IsSame(
T &buffer[], // Search Buffer T &buffer[], // Search Buffer
int count = 5 // Number of Searchs int count = 5, // Number of Searchs
int start = 0 // Start ...
) )
{ {
// //
@@ -3647,15 +3648,15 @@ bool IsSame(
// //
// Validate Count ... // Validate Count ...
result = count < bufferSize; result = start + count < bufferSize;
if (!result) if (!result)
{ {
return result; return result;
} }
// //
T iTem = buffer[0]; T iTem = buffer[start];
for (int i = 0; i < count; i++) for (int i = start; i < start + count; i++)
{ {
// //
if (iTem != buffer[i]) if (iTem != buffer[i])