Apply XAGUSDb Level 2 Fix ...
This commit is contained in:
@@ -4704,6 +4704,21 @@ public:
|
||||
mHedgeMinProfitPerVolumeFactor = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Position Protecting ...
|
||||
|
||||
//
|
||||
bool AllowProtectPositions()
|
||||
{
|
||||
return mAllowProtectPositions;
|
||||
}
|
||||
|
||||
//
|
||||
void AllowProtectPositions(bool value)
|
||||
{
|
||||
mAllowProtectPositions = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
@@ -5719,6 +5734,134 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Do Position Protecting ...
|
||||
void HandlePositionProtecting()
|
||||
{
|
||||
//
|
||||
if (!mAllowProtectPositions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition mainPositions[];
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(
|
||||
positions,
|
||||
NULL, // All Symbols ...
|
||||
NULL, // All Providers ...
|
||||
NULL, // All Periods ...
|
||||
NULL, // All Types ...
|
||||
true // Filter By Magic ...
|
||||
);
|
||||
if (!IsValidSize(positions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Filter Main Positions ...
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
if (!iPosition.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Support or Recovery ...
|
||||
bool isSupport = IsSupport(iPosition.comment);
|
||||
bool isRecovery = ExtractRecoveredTicket(iPosition.comment) > 0;
|
||||
if (isSupport || isRecovery)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
iPosition,
|
||||
mainPositions //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
int mainPositionsCount = ArraySize(mainPositions);
|
||||
if (!IsValidSize(mainPositionsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Main Positions ...
|
||||
for (int i = 0; i < mainPositionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = mainPositions[i];
|
||||
if (!iPosition.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Find iPosition Related TradeData ...
|
||||
int idx = -1;
|
||||
bool hasItem = HasItem(
|
||||
iPosition.ticket,
|
||||
idx //
|
||||
);
|
||||
if (!hasItem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
XTradeData iData = mData[idx];
|
||||
if (!iData.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we Have a Main Positions and
|
||||
// we Make Sure this Position has a TradeData Model ...
|
||||
// Next things is Extract it's Support Positions ...
|
||||
XPosition supports[];
|
||||
for (int j = 0; j < positionsCount; j++)
|
||||
{
|
||||
//
|
||||
XPosition jPosition = positions[j];
|
||||
|
||||
//
|
||||
bool isSupport = IsSupport(jPosition.comment);
|
||||
if (!isSupport)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
ulong parentTicket = ExtractSupportedTicket(jPosition.comment);
|
||||
if (parentTicket != iPosition.ticket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
jPosition,
|
||||
supports //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
int supportsCount = ArraySize(supports);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Signal For Execution ...
|
||||
bool CanExecute(XSignal &signal)
|
||||
@@ -5960,6 +6103,12 @@ protected:
|
||||
double mHedgeVolumeFactor; // Hedging Volume Factor
|
||||
double mHedgeMinProfitPerVolumeFactor; // Hedging Min Required Profit Per Volume Factor
|
||||
|
||||
//
|
||||
// Position Protecting ...
|
||||
|
||||
//
|
||||
bool mAllowProtectPositions; // Allow Protect Positions
|
||||
|
||||
//
|
||||
XTradeData mData[]; // Hold Trade Data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user