add Guard Event and Attached it to all Realted Classes till Final Handler in eaTradeManager ...
This commit is contained in:
@@ -510,6 +510,16 @@ class XCTradeManager : public XCBase
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XGuard guards[];
|
||||
int guardsCount = CheckForGuard(guards);
|
||||
bool hasGuard = IsValidSize(guardsCount);
|
||||
if (hasGuard)
|
||||
{
|
||||
//
|
||||
guard.DoGuards(guards);
|
||||
}
|
||||
|
||||
//
|
||||
double swapSum = 0;
|
||||
double profitSum = 0;
|
||||
@@ -1022,39 +1032,6 @@ class XCTradeManager : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle All Exists Symbol Configurations Restrictions ...
|
||||
*/
|
||||
void HandleRestrictions()
|
||||
{
|
||||
//
|
||||
// Count Symbol Configurations ...
|
||||
int count = ArraySize(symbolTradeConfigs);
|
||||
bool has = IsValidSize(count);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Restrictions ...
|
||||
datetime cTime = TimeCurrent();
|
||||
bool isNewDay = timeTracker.IsNewDay();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Reset Force Close At Time ...
|
||||
if (isNewDay)
|
||||
{
|
||||
symbolTradeConfigs[i].isForceCloseAtTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Restrictions ...
|
||||
symbolTradeConfigs[i].HandleRestrictions(cTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Signal Recieved ...
|
||||
*
|
||||
@@ -1440,220 +1417,16 @@ class XCTradeManager : public XCBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close Trades ...
|
||||
* Handle Guard Events ...
|
||||
*
|
||||
* @param action: ENUM_X_GUARD_ACTIONS
|
||||
* @param positions: XPosition[]
|
||||
*/
|
||||
bool HandleForceCloseTrades(
|
||||
void HandleGuardEvent(
|
||||
ENUM_X_GUARD_ACTIONS action,
|
||||
XPosition &positions[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = HasChild(positions);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string prefix = "Protector: ";
|
||||
string comment = "Force Close ...";
|
||||
|
||||
//
|
||||
int count = ArraySize(positions);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
HandleForceClose(positions[i]);
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidSize(count);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
string message = prefix + "Force Close (" + ToXString(count) + ") Trades at Specified Time ...";
|
||||
HandleReportProtector(message);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
void HandleGuard()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Signal Volume ...
|
||||
*
|
||||
* @param signal: XSignal
|
||||
*/
|
||||
void HandleSignalVolume(XSignal &signal)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = volume.CalculateVolume(signal);
|
||||
bool has = iVolume > X_MIN_VOLUME &&
|
||||
iVolume != signal.volume;
|
||||
if (has)
|
||||
{
|
||||
signal.volume = iVolume;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Executed Trade by Providing Position Ticket ...
|
||||
*
|
||||
* @param index: int reference, holding founded item index ...
|
||||
* @param ticket: ulong, Specified Position Ticket ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasTrade(
|
||||
int &index,
|
||||
ulong ticket //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
index = -1;
|
||||
|
||||
//
|
||||
result =
|
||||
ticket > 0 &&
|
||||
HasChild(trades);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(trades);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XTradeInfo iTrade = trades[i];
|
||||
|
||||
//
|
||||
result =
|
||||
iTrade.HasSignal() &&
|
||||
iTrade.IsExecuted() &&
|
||||
iTrade.positionID == ticket;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
index = i;
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidIndex(index);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Trade Item By Signal ...
|
||||
*
|
||||
* @param index: int reference, holding founded item index ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasTrade(
|
||||
int &index,
|
||||
XSignal &signal //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
index = -1;
|
||||
|
||||
//
|
||||
result =
|
||||
signal.IsValid() &&
|
||||
HasChild(trades);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(trades);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XTradeInfo iTrade = trades[i];
|
||||
|
||||
//
|
||||
result =
|
||||
iTrade.HasSignal() &&
|
||||
iTrade.signal.IsSameAs(signal);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
index = i;
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidIndex(index);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Trade From List ...
|
||||
*
|
||||
* @param index: int ...
|
||||
*/
|
||||
void RemoveTrade(int index)
|
||||
{
|
||||
//
|
||||
bool has =
|
||||
HasChild(trades) &&
|
||||
IsValidIndex(index) &&
|
||||
index < ArraySize(trades);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ArrayRemove(
|
||||
trades,
|
||||
index,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1787,6 +1560,133 @@ class XCTradeManager : public XCBase
|
||||
alert.SendAlert(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle All Exists Symbol Configurations Restrictions ...
|
||||
*/
|
||||
void HandleRestrictions()
|
||||
{
|
||||
//
|
||||
// Count Symbol Configurations ...
|
||||
int count = ArraySize(symbolTradeConfigs);
|
||||
bool has = IsValidSize(count);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Restrictions ...
|
||||
datetime cTime = TimeCurrent();
|
||||
bool isNewDay = timeTracker.IsNewDay();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Reset Force Close At Time ...
|
||||
if (isNewDay)
|
||||
{
|
||||
symbolTradeConfigs[i].isForceCloseAtTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Restrictions ...
|
||||
symbolTradeConfigs[i].HandleRestrictions(cTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Signal Volume ...
|
||||
*
|
||||
* @param signal: XSignal
|
||||
*/
|
||||
void HandleSignalVolume(XSignal &signal)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = volume.CalculateVolume(signal);
|
||||
bool has = iVolume > X_MIN_VOLUME &&
|
||||
iVolume != signal.volume;
|
||||
if (has)
|
||||
{
|
||||
signal.volume = iVolume;
|
||||
}
|
||||
|
||||
//
|
||||
// Here we Can Implement Custom Signalling Volume Management
|
||||
// based on Different Symbol Configurations ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close Trades ...
|
||||
*/
|
||||
bool HandleForceCloseTrades(
|
||||
XPosition &positions[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = HasChild(positions);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string prefix = "Protector: ";
|
||||
string comment = "Force Close ...";
|
||||
|
||||
//
|
||||
int count = ArraySize(positions);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
HandleForceClose(positions[i]);
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidSize(count);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
string message = prefix + "Force Close (" + ToXString(count) + ") Trades at Specified Time ...";
|
||||
HandleReportProtector(message);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check For Guards ...
|
||||
*
|
||||
* @param dest: XGuard[]
|
||||
*/
|
||||
int CheckForGuard(XGuard &dest[])
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Cleanup Dest ...
|
||||
SpecifiedClean(dest);
|
||||
|
||||
//
|
||||
// Check For Guards ...
|
||||
|
||||
//
|
||||
result = ArraySize(dest);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Save Trades ...
|
||||
bool SaveTrade(
|
||||
@@ -1995,6 +1895,151 @@ class XCTradeManager : public XCBase
|
||||
XTradeInfo trades[];
|
||||
XSymbolTradeConfig symbolTradeConfigs[];
|
||||
|
||||
/**
|
||||
* Find Executed Trade by Providing Position Ticket ...
|
||||
*
|
||||
* @param index: int reference, holding founded item index ...
|
||||
* @param ticket: ulong, Specified Position Ticket ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasTrade(
|
||||
int &index,
|
||||
ulong ticket //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
index = -1;
|
||||
|
||||
//
|
||||
result =
|
||||
ticket > 0 &&
|
||||
HasChild(trades);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(trades);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XTradeInfo iTrade = trades[i];
|
||||
|
||||
//
|
||||
result =
|
||||
iTrade.HasSignal() &&
|
||||
iTrade.IsExecuted() &&
|
||||
iTrade.positionID == ticket;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
index = i;
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidIndex(index);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Trade Item By Signal ...
|
||||
*
|
||||
* @param index: int reference, holding founded item index ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasTrade(
|
||||
int &index,
|
||||
XSignal &signal //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
index = -1;
|
||||
|
||||
//
|
||||
result =
|
||||
signal.IsValid() &&
|
||||
HasChild(trades);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(trades);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XTradeInfo iTrade = trades[i];
|
||||
|
||||
//
|
||||
result =
|
||||
iTrade.HasSignal() &&
|
||||
iTrade.signal.IsSameAs(signal);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
index = i;
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iTrade.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidIndex(index);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Trade From List ...
|
||||
*
|
||||
* @param index: int ...
|
||||
*/
|
||||
void RemoveTrade(int index)
|
||||
{
|
||||
//
|
||||
bool has =
|
||||
HasChild(trades) &&
|
||||
IsValidIndex(index) &&
|
||||
index < ArraySize(trades);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ArrayRemove(
|
||||
trades,
|
||||
index,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void AddOrUpdateSymbolConfiguration(XSymbolTradeConfig &config)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user