last works ...
This commit is contained in:
@@ -1825,6 +1825,12 @@ public:
|
||||
return mTrader.GetMagicNumber();
|
||||
}
|
||||
|
||||
//
|
||||
double GetDrawdownPercent()
|
||||
{
|
||||
return mDrawdownPercent;
|
||||
}
|
||||
|
||||
//
|
||||
void AddOnSignalEventHandler(TOnSignal handler)
|
||||
{
|
||||
@@ -1836,9 +1842,66 @@ public:
|
||||
}
|
||||
|
||||
//
|
||||
double GetDrawdownPercent()
|
||||
double MinRequiredProfitPerTrade()
|
||||
{
|
||||
return mDrawdownPercent;
|
||||
return mMinRequiredProfitPerTrade;
|
||||
}
|
||||
|
||||
//
|
||||
void MinRequiredProfitPerTrade(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mMinRequiredProfitPerTrade = value;
|
||||
}
|
||||
|
||||
//
|
||||
double MinRequiredProfitPerVolumeFactor()
|
||||
{
|
||||
return mMinRequiredProfitPerVolumeFactor;
|
||||
}
|
||||
|
||||
//
|
||||
void MinRequiredProfitPerVolumeFactor(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (value > 0 && value < 0.01)
|
||||
{
|
||||
value = 0.01;
|
||||
}
|
||||
|
||||
//
|
||||
mMinRequiredProfitPerVolumeFactor = value;
|
||||
}
|
||||
|
||||
//
|
||||
int RestingAfterHedge()
|
||||
{
|
||||
return mRestingAfterHedge;
|
||||
}
|
||||
|
||||
//
|
||||
void RestingAfterHedge(int value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mRestingAfterHedge = value;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1897,6 +1960,9 @@ public:
|
||||
//
|
||||
HandleProfitManageMent();
|
||||
|
||||
//
|
||||
SyncSupports();
|
||||
|
||||
//
|
||||
// First Check For Any Guard Actions ...
|
||||
// then Handle Guards if Provided ...
|
||||
@@ -2892,6 +2958,186 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Search Positions and Remove
|
||||
// non Exists Positions Support Orders ...
|
||||
void SyncSupports()
|
||||
{
|
||||
//
|
||||
XOrder orders[];
|
||||
int ordersCount = mTrader.GetOrders(
|
||||
orders,
|
||||
NULL, // All Symbols ...
|
||||
NULL, // All Providers ...
|
||||
NULL, // All Periods ...
|
||||
X_POSITION_TYPE_ALL, // All Types ...
|
||||
ORDER_STATE_PLACED, // Placed Untriggered Orders ...
|
||||
true // Filter by Magic ...
|
||||
);
|
||||
if (!IsValidSize(ordersCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(
|
||||
positions //
|
||||
);
|
||||
if (!IsValidSize(positions))
|
||||
{
|
||||
//
|
||||
mTrader.CancelOrders(orders);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XOrder mustCancel[];
|
||||
for (int i = 0; i < ordersCount; i++)
|
||||
{
|
||||
//
|
||||
XOrder iOrder = orders[i];
|
||||
|
||||
//
|
||||
// Check Order is Support or not ...
|
||||
ulong iParentTicket = ExtractSupportedTicket(iOrder.comment);
|
||||
if (iParentTicket <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// We Sure it is support Order ...
|
||||
XPosition parent;
|
||||
bool isParentExists = mTrader.GetPosition(
|
||||
iParentTicket,
|
||||
parent //
|
||||
);
|
||||
if (!isParentExists)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iOrder,
|
||||
mustCancel //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
int mustCancelCount = ArraySize(mustCancel);
|
||||
if (!IsValidSize(mustCancelCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
mTrader.CancelOrders(mustCancel);
|
||||
}
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
|
||||
//
|
||||
// Check Required Properties Setted for Hedge or not ...
|
||||
bool AllowHedge()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
mMinRequiredProfitPerTrade > 0 &&
|
||||
mMinRequiredProfitPerVolumeFactor > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Hedge Conditions is Happens or not ...
|
||||
// if true doing Hedge ...
|
||||
bool DoEQMHedge()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = AllowHedge();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(positions);
|
||||
result = IsValidSize(positions);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check At Least One Support Positions Open For Hedging ...
|
||||
XPosition supports[];
|
||||
int supportsCount = ExtractSupportPositions(
|
||||
positions,
|
||||
supports //
|
||||
);
|
||||
result = IsValidSize(supportsCount);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double profits = SpecifiedCalculatePositionsProfit(positions);
|
||||
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
||||
positions,
|
||||
mMinRequiredProfitPerTrade,
|
||||
mMinRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
result = profits >= requiredProfit;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = XEQMSupportToken + " Hedge ...";
|
||||
|
||||
//
|
||||
int closed = mTrader.Close(
|
||||
positions,
|
||||
comment //
|
||||
);
|
||||
result = IsValidSize(closed);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string message = XEQMSupportToken + " Hedge: " + ToString(profits) + " ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
if (mRestingAfterHedge > 0)
|
||||
{
|
||||
Sleep(mRestingAfterHedge * 1000);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Guards ...
|
||||
|
||||
@@ -3447,6 +3693,11 @@ private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
int mRestingAfterHedge; // Resting Bars After Hedge
|
||||
double mMinRequiredProfitPerTrade; // Minimum Required Profit for Hedging
|
||||
double mMinRequiredProfitPerVolumeFactor; // Minimum Required Profit for Hedging Per Velume
|
||||
|
||||
//
|
||||
// Signal Event Listeners ...
|
||||
TOnSignal mOnSignalEventHandlers[];
|
||||
|
||||
Reference in New Issue
Block a user