last ...
This commit is contained in:
@@ -396,6 +396,9 @@ public:
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
|
||||
//
|
||||
RemoveEQMOrders();
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
@@ -434,19 +437,282 @@ public:
|
||||
XSCPositionHolder *iHolder = mHolders[i];
|
||||
|
||||
//
|
||||
XPosition iMaxInDP;
|
||||
bool hasMaxInDP = iHolder.GetMaxInDrawdown(iMaxInDP);
|
||||
if (!hasMaxInDP)
|
||||
// We Can Select Multiple Positions for Place EQM Supports ...
|
||||
|
||||
//
|
||||
// Select Max In Drawdown Position and Protect it ...
|
||||
XPosition iSelectedPosition;
|
||||
bool iHasPosition = iHolder.GetMaxInDrawdown(iSelectedPosition);
|
||||
if (iHasPosition)
|
||||
{
|
||||
//
|
||||
// Try to Protect Max In Drawdown Positions Position ...
|
||||
PlaceEQMOrders(iSelectedPosition);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Add Or Update EQM Orders ...
|
||||
void PlaceEQMOrders(XPosition &position)
|
||||
{
|
||||
//
|
||||
// TODO: Make It Configurable ...
|
||||
int maxEQMCount = 5;
|
||||
return;
|
||||
|
||||
//
|
||||
// Position Protection Senarioos ...
|
||||
if (!position.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int descriptorIDX = FindDescriptorIndex(position);
|
||||
if (descriptorIDX <= -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
X121ProviderDescriptor descriptor = mDescriptors[descriptorIDX];
|
||||
|
||||
//
|
||||
XOHCLSupRes slSupRes;
|
||||
bool hasSupRes = descriptor
|
||||
.provider
|
||||
.GenerateSupRes(
|
||||
slSupRes,
|
||||
position.type,
|
||||
5 //
|
||||
);
|
||||
|
||||
//
|
||||
XDrawSpecifications supDrawSpecs;
|
||||
supDrawSpecs.draw = true;
|
||||
supDrawSpecs.rayRight = true;
|
||||
supDrawSpecs.clr = clrLightGreen;
|
||||
|
||||
//,
|
||||
XDrawSpecifications resDrawSpecs;
|
||||
resDrawSpecs.draw = true;
|
||||
resDrawSpecs.rayRight = true;
|
||||
resDrawSpecs.clr = clrLightCoral;
|
||||
|
||||
//
|
||||
// DrawSupRes(
|
||||
// slSupRes,
|
||||
// supDrawSpecs,
|
||||
// resDrawSpecs //
|
||||
// );
|
||||
|
||||
//
|
||||
XSignal supports[];
|
||||
int supportsCount = GenerateEQMOrders(
|
||||
supports,
|
||||
position,
|
||||
slSupRes //
|
||||
);
|
||||
if (!IsValidSize(supportsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XOrder untriggeredOrders[];
|
||||
int untriggeredOrdersCount = mTrader.GetOrders(
|
||||
untriggeredOrders,
|
||||
position.symbol,
|
||||
XEQMSupportToken,
|
||||
position.period,
|
||||
NULL, // All Types ...
|
||||
ORDER_STATE_PLACED,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
XPosition triggereSupports[];
|
||||
int tiggeredSupportsCount = mTrader.GetPositions(
|
||||
triggereSupports,
|
||||
position.symbol,
|
||||
XEQMSupportToken,
|
||||
position.period,
|
||||
NULL, // All Types ...
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
if (untriggeredOrdersCount +
|
||||
tiggeredSupportsCount >=
|
||||
maxEQMCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XSignal filteredSignals[];
|
||||
for (int i = 0; i < supportsCount; i++)
|
||||
{
|
||||
//
|
||||
XSignal iSupport = supports[i];
|
||||
|
||||
//
|
||||
double sl;
|
||||
iSupport.RegularSL(sl);
|
||||
|
||||
//
|
||||
double tp;
|
||||
iSupport.RegularTP(tp);
|
||||
|
||||
//
|
||||
if (!IsValidSize(untriggeredOrdersCount) && !IsValidSize(tiggeredSupportsCount))
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iSupport,
|
||||
filteredSignals //
|
||||
);
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Protect a Position ...
|
||||
ProtectPosition(iMaxInDP);
|
||||
bool isOrdersPassed = true;
|
||||
if (!IsValidSize(untriggeredOrdersCount))
|
||||
{
|
||||
isOrdersPassed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
for (int j = 0; j < untriggeredOrdersCount; j++)
|
||||
{
|
||||
//
|
||||
XOrder jOrder = untriggeredOrders[j];
|
||||
|
||||
//
|
||||
bool isSame =
|
||||
//
|
||||
jOrder.symbol == iSupport.symbol &&
|
||||
jOrder.period == iSupport.period &&
|
||||
jOrder.openPrice == iSupport.entry &&
|
||||
jOrder.sl == sl &&
|
||||
jOrder.tp == tp
|
||||
//
|
||||
;
|
||||
if (isSame)
|
||||
{
|
||||
//
|
||||
isOrdersPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool isPositionsPassed = true;
|
||||
if (!IsValidSize(tiggeredSupportsCount))
|
||||
{
|
||||
isPositionsPassed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
for (int j = 0; j < tiggeredSupportsCount; j++)
|
||||
{
|
||||
//
|
||||
XPosition jPosition = triggereSupports[j];
|
||||
|
||||
//
|
||||
bool isSame =
|
||||
//
|
||||
jPosition.symbol == iSupport.symbol &&
|
||||
jPosition.period == iSupport.period &&
|
||||
jPosition.entry == iSupport.entry &&
|
||||
jPosition.sl == sl &&
|
||||
jPosition.tp == tp
|
||||
//
|
||||
;
|
||||
if (isSame)
|
||||
{
|
||||
//
|
||||
isPositionsPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (isOrdersPassed &&
|
||||
isPositionsPassed)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iSupport,
|
||||
filteredSignals //
|
||||
);
|
||||
}
|
||||
}
|
||||
int filteredSignalsCount = ArraySize(filteredSignals);
|
||||
if (!IsValidSize(filteredSignalsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
|
||||
int placedOrders = mTrader.ExecuteSignals(
|
||||
filteredSignals,
|
||||
states,
|
||||
ORDER_TIME_GTC,
|
||||
NULL,
|
||||
false // Ignore Policies ...
|
||||
);
|
||||
if (placedOrders > 0)
|
||||
{
|
||||
//
|
||||
string message = "EQM Placed (" + ToString(placedOrders) + ") Support Orders ...";
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void RemoveEQMOrders()
|
||||
{
|
||||
//
|
||||
XOrder untriggeredOrders[];
|
||||
int untriggeredOrdersCount = mTrader.GetOrders(
|
||||
untriggeredOrders,
|
||||
NULL,
|
||||
XEQMSupportToken,
|
||||
NULL,
|
||||
NULL, // All Types ...
|
||||
ORDER_STATE_PLACED,
|
||||
true //
|
||||
);
|
||||
if (!IsValidSize(untriggeredOrdersCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int canceleds = mTrader.CancelOrders(
|
||||
untriggeredOrders //
|
||||
);
|
||||
if (canceleds > 0)
|
||||
{
|
||||
//
|
||||
string message = "EQM Cancel Support ...";
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -479,7 +745,7 @@ public:
|
||||
//
|
||||
bool canManageState =
|
||||
//
|
||||
true
|
||||
iPosition.provider != XEQMSupportToken
|
||||
//
|
||||
;
|
||||
|
||||
@@ -1024,6 +1290,9 @@ public:
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
|
||||
//
|
||||
RemoveEQMOrders();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1039,6 +1308,9 @@ public:
|
||||
//
|
||||
// Here i Have to Detect In DrawDown Positions ...
|
||||
|
||||
//
|
||||
RemoveEQMOrders();
|
||||
|
||||
//
|
||||
string mSymbols[];
|
||||
XSCPositionHolder *mHolders[];
|
||||
@@ -1101,6 +1373,9 @@ protected:
|
||||
{
|
||||
//
|
||||
// Here i Can Protect Position ...
|
||||
// This Protect Include One Position in Market Mode ...
|
||||
// If Provided ...
|
||||
// the Positions Selection must passed Some conditions ...
|
||||
|
||||
//
|
||||
string message = "For (" + position.symbol + ") Max In Drawdown Position is: (" +
|
||||
@@ -1130,6 +1405,66 @@ private:
|
||||
return ArraySize(mDescriptors);
|
||||
}
|
||||
|
||||
//
|
||||
// Find Specifc Descriptor ...
|
||||
int FindDescriptorIndex(
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid(symbol) ||
|
||||
!IsValid(period))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int descriptorsCount = CountDescriptors();
|
||||
if (!IsValidSize(descriptorsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < descriptorsCount; i++)
|
||||
{
|
||||
//
|
||||
X121ProviderDescriptor iDescriptor = mDescriptors[i];
|
||||
|
||||
//
|
||||
bool isPassed =
|
||||
//
|
||||
iDescriptor.symbol == symbol &&
|
||||
iDescriptor.period == period
|
||||
//
|
||||
;
|
||||
if (isPassed)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int FindDescriptorIndex(
|
||||
T &item //
|
||||
)
|
||||
{
|
||||
return FindDescriptorIndex(
|
||||
item.symbol,
|
||||
item.period //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Trails Holding ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user