last works ...

adding some tools to ch helper classes ...
This commit is contained in:
2024-07-26 03:36:40 +03:30
parent 35d814fc9c
commit fc9bca9c37
6 changed files with 1878 additions and 77 deletions
+107 -3
View File
@@ -2107,6 +2107,55 @@ public:
.ByTicket(ticket);
}
//
double GetPositionCommission(
ulong ticket // Specified Ticket
)
{
//
double result = 0;
//
XPosition position;
bool hasPosition = GetPosition(
ticket,
position //
);
if (!hasPosition)
{
return result;
}
//
XDeal deals[];
int dealsCount = GetDeals(
deals,
position.symbol,
position.provider,
position.period,
NULL,
DEAL_ENTRY_IN //
);
if (IsValidSize(dealsCount))
{
//
for (int i = 0; i < dealsCount; i++)
{
//
XDeal iDeal = deals[i];
if (iDeal.positionId == ticket)
{
//
result = iDeal.commission;
break;
}
}
}
//
return result;
}
//
// Retrieve Positions ...
int GetPositions(
@@ -4198,6 +4247,18 @@ public:
mAllowHedging = value;
}
//
bool OnlyHedgeSupportedPositions()
{
return mOnlyHedgeSupportedPositions;
}
//
void OnlyHedgeSupportedPositions(bool value)
{
mOnlyHedgeSupportedPositions = value;
}
//
double HedgeVolumeFactor()
{
@@ -4456,7 +4517,9 @@ public:
{
//
// Check Values Validation ...
if (count > 1 &&
if ((count > 1 ||
(count == 1 &&
mOnlyHedgeSupportedPositions)) &&
mHedgeVolumeFactor > 0 &&
mHedgeMinProfitPerVolumeFactor > 0)
{
@@ -4492,12 +4555,17 @@ public:
//
string msg = ToString(positionsCount) + " Closed Due Hedge Action in: " + ToString(profits) + " ...";
Alert(msg);
//
return;
}
}
}
}
}
//
//
// Do Force Closing ...
@@ -4529,6 +4597,17 @@ public:
continue;
}
//
// Allow Trail Only for Positions Which
// doesnt Have Any Support ...
bool iHasSupport = mTrader.HasSupport(
ticket //
);
if (iHasSupport)
{
continue;
}
//
// Trail ...
if (mData[i].allowTrailStop)
@@ -4562,8 +4641,8 @@ public:
// Calculate new Level SL ...
double sl =
isLong
? iPosition.entry + (trailStepInPoints * points)
: iPosition.entry - (trailStepInPoints * points);
? iPosition.entry + (mData[i].trailLevel * (trailStepInPoints * points))
: iPosition.entry - (mData[i].trailLevel * (trailStepInPoints * points));
sl = NormalizePrice(
sl,
symbol //
@@ -4704,6 +4783,30 @@ public:
}
}
//
// Validate Signal For Execution ...
bool CanExecute(XSignal &signal)
{
//
bool result = false;
//
// Validate Signal ...
result = signal.IsValid();
if (!result)
{
return result;
}
//
// TODO:
// Here we can apply Same type or Opposit Type
// Signals behaviour ...
//
return result;
}
//
// Protected ...
protected:
@@ -4729,6 +4832,7 @@ protected:
//
// Hedging ...
bool mAllowHedging; // Hedge Trades
bool mOnlyHedgeSupportedPositions; // Only Hedge Supported Positions
double mHedgeVolumeFactor; // Hedging Volume Factor
double mHedgeMinProfitPerVolumeFactor; // Hedging Min Required Profit Per Volume Factor