This commit is contained in:
2024-06-21 09:18:04 +03:30
parent a5cb716d0b
commit e54a991b6d
4 changed files with 554 additions and 335 deletions
+393 -173
View File
@@ -116,6 +116,7 @@ struct XTradeInfo
//
ResetGrid();
ResetSupport();
ResetRecovery();
}
@@ -181,6 +182,15 @@ struct XTradeInfo
bullishScore = _bullishScore;
bearishScore = _bearishScore;
//
X121SignalGenerator generator;
XSignal tSignal = _signal;
generator.GenerateSupportPivots(
tSignal,
pivots //
);
tSignal.Clean();
//
return result;
}
@@ -427,6 +437,183 @@ struct XTradeInfo
// These are Some Helpers for Trading Controls and do not relate to Main
// purpose of Trade Handler ...
//
// Supporting ...
//
double pivots[];
//
void ResetSupport()
{
Clean(pivots);
}
//
// Retrieve Support Signal ...
bool HasSupport(
XSignal &support //
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
int pivotsCount = ArraySize(pivots);
result = IsValidSize(pivotsCount);
if (!result)
{
return result;
}
//
support.Clean();
//
ENUM_POSITION_TYPE sType =
type == X_POSITION_TYPE_LONG
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
//
bool isLong = IsLong(type);
//
ENUM_POSITION_TYPE cType = GetOpposit(sType);
double cEntry = GetEntry(
symbol,
cType //
);
//
double pivot = 0;
int pivotIndex = -1;
for (int i = 0; i < pivotsCount; i++)
{
//
double iPivot = pivots[i];
if (iPivot <= 0)
{
continue;
}
//
result =
isLong
? cEntry < entry && cEntry <= iPivot
: cEntry > entry && cEntry >= iPivot;
if (result)
{
//
pivot = iPivot;
pivotIndex = i;
break;
}
}
//
if (result)
{
//
result = support.Prepare(
symbol,
XEQMSupportToken + XINDirectionalToken,
period,
cType,
X_ORDER_MODE_MARKET,
cEntry,
volume * 2,
0,
0 //
);
if (result)
{
//
string comment = GenerateSupportTag(ticket);
support.comment = comment;
//
// Prepare Directional Support ...
XSignal mSup;
result = mSup.Prepare(
symbol,
XEQMSupportToken + XDirectionalToken,
period,
sType,
X_ORDER_MODE_STOP,
entry,
volume,
0,
0 //
);
if (result)
{
//
string comment = GenerateSupportTag(ticket);
mSup.comment = comment;
//
AddRef(
mSup,
support.supports //
);
//
result = ArrayRemove(
pivots,
pivotIndex,
1 //
);
}
}
}
//
if (!result)
{
support.Clean();
}
//
return result;
}
//
bool RemovePivot(
double pivot,
int index //
)
{
//
bool result = false;
//
result = IsValid() &&
IsValidIndex(index) &&
ArraySize(pivots) > index;
if (!result)
{
return result;
}
//
result = ArrayRemove(
pivots,
index,
1 //
);
//
return result;
}
//
// Grid System Calculations ...
@@ -1860,8 +2047,7 @@ public:
}
//
// Supporting ...
if (EnableSupport())
if (AllowSupport())
{
//
XSignal supports[];
@@ -2148,10 +2334,6 @@ protected:
//
int result = 0;
//
// TODO: Complete this Later ...
return result;
//
Clean(signals);
@@ -2165,104 +2347,137 @@ protected:
Sync();
//
// Validate Setups Count ...
int setupsCount = ArraySize(setups);
if (!IsValidSize(setupsCount))
int count = Count();
if (!IsValidSize(count))
{
return result;
}
//
// Implement Supporting Mechanism ...
//
// Extracting In Drawdown Positions ...
XPosition positions[];
int positionsCount = mTrader.GetInDrawdownPositions(
positions //
);
if (!IsValidSize(positionsCount))
{
return result;
}
//
double supportDistance = SupportDistance();
int maxNUmberOfSupports = MaxNumberOfSupports();
double maxAllowedVolume = MaxAllowedSupportVolume();
double volumeMultiplier = SupportVolumeMultiplier();
//
X121SignalGenerator signalGenerator;
//
for (int i = 0; i < positionsCount; i++)
for (int i = 0; i < count; i++)
{
//
XPosition iPosition = positions[i];
//
// Check Position is not Support Position ...
bool isSupport = IsSupport(iPosition.comment);
if (isSupport)
{
continue;
}
//
// Find Related Setp ...
int idx = FindSetupIndex(
iPosition.symbol,
setups //
XSignal iSupport;
double iPivot = -1;
int iPivotIDX = -1;
bool hasSupport = data[i].HasSupport(
iSupport //
);
if (!IsValidIndex(idx))
if (hasSupport)
{
continue;
//
AddRef(
iSupport,
signals //
);
}
//
int index = FindIndex(iPosition.ticket);
if (!IsValidIndex(index))
{
continue;
}
//
// Check Position must atleast 20 Point in drawdown ...
//
double onePointPrice = PointToPrice(
1,
iPosition.symbol //
);
//
double iExitPrice = GetExit(
iPosition.symbol,
iPosition.type //
);
//
double priceDiff = MathAbs(iPosition.entry - iExitPrice);
double priceDiffPoints = priceDiff / onePointPrice;
//
bool isFarEnough = priceDiffPoints >= (supportDistance / 2);
if (!isFarEnough)
{
continue;
}
//
// Check Support COunts and etc ...
// implementing supporting mechanis ...
//
}
//
result = ArraySize(signals);
//
// TODO: Complete this Later ...
return result;
//
// Validate Setups Count ...
// int setupsCount = ArraySize(setups);
// if (!IsValidSize(setupsCount))
// {
// return result;
// }
// //
// // Implement Supporting Mechanism ...
// //
// // Extracting In Drawdown Positions ...
// XPosition positions[];
// int positionsCount = mTrader.GetInDrawdownPositions(
// positions //
// );
// if (!IsValidSize(positionsCount))
// {
// return result;
// }
// //
// double supportDistance = SupportDistance();
// int maxNUmberOfSupports = MaxNumberOfSupports();
// double maxAllowedVolume = MaxAllowedSupportVolume();
// double volumeMultiplier = SupportVolumeMultiplier();
// //
// X121SignalGenerator signalGenerator;
// //
// for (int i = 0; i < positionsCount; i++)
// {
// //
// XPosition iPosition = positions[i];
// //
// // Check Position is not Support Position ...
// bool isSupport = IsSupport(iPosition.comment);
// if (isSupport)
// {
// continue;
// }
// //
// // Find Related Setp ...
// int idx = FindSetupIndex(
// iPosition.symbol,
// setups //
// );
// if (!IsValidIndex(idx))
// {
// continue;
// }
// //
// int index = FindIndex(iPosition.ticket);
// if (!IsValidIndex(index))
// {
// continue;
// }
// //
// // Check Position must atleast 20 Point in drawdown ...
// //
// double onePointPrice = PointToPrice(
// 1,
// iPosition.symbol //
// );
// //
// double iExitPrice = GetExit(
// iPosition.symbol,
// iPosition.type //
// );
// //
// double priceDiff = MathAbs(iPosition.entry - iExitPrice);
// double priceDiffPoints = priceDiff / onePointPrice;
// //
// bool isFarEnough = priceDiffPoints >= (supportDistance / 2);
// if (!isFarEnough)
// {
// continue;
// }
// //
// // Check Support COunts and etc ...
// // implementing supporting mechanis ...
// //
// }
// //
// result = ArraySize(signals);
//
return result;
}
@@ -4029,10 +4244,10 @@ public:
}
//
// Handle Support of Supports here ...
void OnPositionsChangedHandler(int count) override
// Orders Changed ...
void OnOrdersChangedHandler(int count) override
{
// EQMHandleSupportProtection(count);
EQMHandleSupportProtection(count);
}
//
@@ -4756,98 +4971,103 @@ private:
}
//
void EQMHandleSupportProtection(int positionsCount)
void EQMHandleSupportProtection(int count)
{
//
if (!IsValidSize(positionsCount))
{
return;
}
// //
// if (IsValidSize(count))
// {
// return;
// }
//
ulong ticket = mTrader.GetLastOpenPositionTicket();
XPosition position;
bool hasPosition = mTrader.GetPosition(
ticket,
position //
);
if (!hasPosition)
{
return;
}
// //
// // This means on order Executed ...
// ulong ticket = mTrader.GetLastOpenPositionTicket();
//
bool isSupport = IsSupport(position.comment);
if (!isSupport)
{
return;
}
// //
// XPosition position;
// bool hasPosition = mTrader.GetPosition(
// ticket,
// position //
// );
// if (!hasPosition)
// {
// return;
// }
//
bool isINDIRSupport = position.provider == XEQMSupportToken + XINDirectionalToken;
if (!isINDIRSupport)
{
return;
}
// //
// bool isSupport = IsSupport(position.comment);
// if (!isSupport)
// {
// return;
// }
//
ulong parentTicket = ExtractParentTicket(position.comment);
XPosition parent;
bool hasParent = mTrader.GetPosition(
parentTicket,
parent //
);
if (!hasParent)
{
return;
}
// //
// bool isInDirectional = position.provider == XEQMSupportToken + XINDirectionalToken;
// if (!isInDirectional)
// {
// return;
// }
//
// Remove Parent TP SL ...
if (parent.tp > 0 || parent.sl > 0)
{
//
string comment = XEQMSupportToken + "Remoove TPSL due Protect ...";
bool isModeified = mTrader.Modify(
parentTicket,
0,
0,
comment //
);
if (isModeified)
{
//
string message = XEQMSupportToken + " Removes Position (" + ToString(parentTicket) + ")' TP/SL Due Start Supporting ...";
// //
// XPosition parent;
// ulong parentTicket = ExtractParentTicket(position.comment);
// bool hasParent = mTrader.GetPosition(
// parentTicket,
// parent //
// );
//
Alert(message);
}
}
// //
// if (!hasParent)
// {
// return;
// }
//
XSignal signal;
X121SignalGenerator signalGenerator;
bool hasSupport = signalGenerator.PrepareDirectionalSupportSignals(
position,
parent,
signal //
);
if (!hasSupport)
{
return;
}
// //
// // Remove Parent TP SL ...
// if (parent.tp > 0 || parent.sl > 0)
// {
// //
// string comment = XEQMSupportToken + " Remoove TP/SL due Protect ...";
// bool isModeified = mTrader.Modify(
// parentTicket,
// 0,
// 0,
// comment //
// );
// if (isModeified)
// {
// //
// string message = XEQMSupportToken + " Removes Position (" + ToString(parentTicket) + ")' TP/SL Due Start Supporting ...";
//
XSignal signals[];
// //
// Alert(message);
// }
// }
//
AddRef(
signal,
signals //
);
// //
// XSignal signal;
// X121SignalGenerator signalGenerator;
// bool hasSupport = signalGenerator.PrepareDirectionalSupportSignals(
// position,
// parent,
// signal //
// );
// if (!hasSupport)
// {
// return;
// }
//
EQMExecuteSignals(signals);
// //
// XSignal signals[];
// //
// AddRef(
// signal,
// signals //
// );
// //
// EQMExecuteSignals(signals);
}
//