last works ...
must Fix Refactoring X_POSITION_TYPE side affects ...
This commit is contained in:
@@ -48,6 +48,9 @@ public:
|
||||
int slippage, // Specify Slippage
|
||||
ulong magicNumber, // Specify Magic Number
|
||||
//
|
||||
// Time Management ...
|
||||
// TODO: ...
|
||||
//
|
||||
// XSCTrade Event Handlers ...
|
||||
TOnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
|
||||
TOnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
|
||||
@@ -278,7 +281,7 @@ public:
|
||||
// - Check Same Time Open Positions ...
|
||||
// - Check Signal Age for new Trade ...
|
||||
// and etc ...
|
||||
int HandleSignalManagement(XSignal &signals[])
|
||||
int HandleSignalManagement(XSignal &signals[]) override
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
@@ -502,6 +505,133 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle State Management ....
|
||||
// here we can manage current state ...
|
||||
// - Check for Long Positions for each Signaller to Close ...
|
||||
// - Handle Hedging Signaller's Positions if it's enabled ...
|
||||
// - Force Closing Position when Specified Time reached ...
|
||||
// - Check Start and End time or Trading Dates ...
|
||||
// - handle Trailing or Risk free Signals based on several conditions ...
|
||||
// and etc ...
|
||||
bool HandleStateManagement(XSignal &signals[]) override
|
||||
{
|
||||
//
|
||||
const bool result = false;
|
||||
|
||||
//
|
||||
// Check Descriptor ...
|
||||
int descriptorsCount = CountDescriptors();
|
||||
if (!IsValidSize(descriptorsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Descriptors ...
|
||||
for (int i = 0; i < descriptorsCount; i++)
|
||||
{
|
||||
//
|
||||
// Check Signallers ...
|
||||
int signallersCount = mDescriptors[i].CountSignallers();
|
||||
if (!IsValidSize(signallersCount))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Signallers ...
|
||||
for (int j = 0; j < signallersCount; j++)
|
||||
{
|
||||
//
|
||||
// Retrieve Specified Signaller's Position ...
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(
|
||||
positions,
|
||||
mDescriptors[i].symbol,
|
||||
mDescriptors[i].signallers[j].GetName(),
|
||||
mDescriptors[i].period);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signaller Enable Hedge or not and Handle it if enabled ...
|
||||
if (mDescriptors[i].signallers[j].AllowHedge())
|
||||
{
|
||||
//
|
||||
// Check Profits Enough for Hedge or not ...
|
||||
double profit = SpecifiedCalculatePositionsProfit(positions);
|
||||
bool isReadyForHedge = SpecifiedIsPositionsReadyForHedge(
|
||||
positions,
|
||||
mDescriptors[i].signallers[j].minRequiredProfitPerTrade,
|
||||
mDescriptors[i].signallers[j].minRequiredProfitPerTradeVolumeFactor //
|
||||
);
|
||||
if (isReadyForHedge)
|
||||
{
|
||||
//
|
||||
string comment = "Close due Hedge ...";
|
||||
int closeds = mTrader.Close(
|
||||
positions,
|
||||
comment //
|
||||
);
|
||||
|
||||
//
|
||||
if (closeds > 0)
|
||||
{
|
||||
//
|
||||
string message = "Hedge (" + ToString(closeds) + ") Positions In Profit: " + ToString(profit);
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Closing Long Age Position's Enabled or not ...
|
||||
if (mDescriptors[i].signallers[j].maxAllowedOpenPositionAge > 0)
|
||||
{
|
||||
//
|
||||
// Handle Close Long Time Trades ...
|
||||
|
||||
//
|
||||
// Find Oldest ...
|
||||
XPosition oldest;
|
||||
int oldestAge = GetOldest(
|
||||
oldest,
|
||||
positions //
|
||||
);
|
||||
if (oldestAge >= mDescriptors[i].signallers[j].maxAllowedOpenPositionAge)
|
||||
{
|
||||
//
|
||||
string comment = "Close due Long Age ...";
|
||||
bool isClosed = mTrader.Close(
|
||||
oldest.ticket,
|
||||
comment //
|
||||
);
|
||||
|
||||
//
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
string message = "Position (" + ToString(oldest.ticket) + ") Closed due Long Age Policy ...";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// if Returns true, Signal Execution failed ...
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user