last ...
This commit is contained in:
@@ -529,28 +529,18 @@ class XCTradeManager : public XCBase
|
|||||||
// Do Collection Protectiong ...
|
// Do Collection Protectiong ...
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Complete this ...
|
// Handle Force Close At Time ...
|
||||||
// //
|
has = HandleForceCloseAtTime();
|
||||||
// // Check Force Close ...
|
if (has)
|
||||||
// if (IsValid(forceCloseAt))
|
{
|
||||||
// {
|
//
|
||||||
// //
|
Clean(ownPosition);
|
||||||
// datetime forceCloseTime = ParseDateTimeFromTimeString(forceCloseAt);
|
Clean(ownLongPosition);
|
||||||
// bool canForceClose = IsTimeInRange(
|
Clean(ownShortPosition);
|
||||||
// TimeCurrent(),
|
|
||||||
// forceCloseTime //
|
|
||||||
// ) &&
|
|
||||||
// !isForceCloseAtTime;
|
|
||||||
// if (canForceClose)
|
|
||||||
// {
|
|
||||||
// //
|
|
||||||
// isForceCloseAtTime = HandleForceCloseTrades(ownPosition);
|
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // Prevent Moving Forward ...
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Do Signle Protections ...
|
// Do Signle Protections ...
|
||||||
@@ -863,7 +853,7 @@ class XCTradeManager : public XCBase
|
|||||||
*
|
*
|
||||||
* @return ( bool )
|
* @return ( bool )
|
||||||
*/
|
*/
|
||||||
bool AllowTrade(ENUM_POSITIO_TYPE type)
|
bool AllowTrade(ENUM_POSITION_TYPE type)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
bool result = false;
|
||||||
@@ -878,35 +868,12 @@ class XCTradeManager : public XCBase
|
|||||||
//
|
//
|
||||||
result =
|
result =
|
||||||
(IsLong(type) && allowLongs) ||
|
(IsLong(type) && allowLongs) ||
|
||||||
(IsShort(typ) && allowShorts);
|
(IsShort(type) && allowShorts);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
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();
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
symbolTradeConfigs[i].HandleRestrictions(cTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute Specified Signal ...
|
* Execute Specified Signal ...
|
||||||
*
|
*
|
||||||
@@ -1063,6 +1030,39 @@ class XCTradeManager : public XCBase
|
|||||||
return result;
|
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 ...
|
* Handle Signal Recieved ...
|
||||||
*
|
*
|
||||||
@@ -1144,8 +1144,8 @@ class XCTradeManager : public XCBase
|
|||||||
|
|
||||||
//
|
//
|
||||||
int configIdx = FindSymbolConfigurationIndex(
|
int configIdx = FindSymbolConfigurationIndex(
|
||||||
trades[idx].symbol,
|
trades[idx].signal.symbol,
|
||||||
tardes[idx].period //
|
trades[idx].signal.period //
|
||||||
);
|
);
|
||||||
isExists = IsValidIndex(configIdx);
|
isExists = IsValidIndex(configIdx);
|
||||||
if (isExists)
|
if (isExists)
|
||||||
@@ -1214,8 +1214,8 @@ class XCTradeManager : public XCBase
|
|||||||
|
|
||||||
//
|
//
|
||||||
int configIdx = FindSymbolConfigurationIndex(
|
int configIdx = FindSymbolConfigurationIndex(
|
||||||
trades[idx].symbol,
|
trades[idx].signal.symbol,
|
||||||
tardes[idx].period //
|
trades[idx].signal.period //
|
||||||
);
|
);
|
||||||
isExists = IsValidIndex(configIdx);
|
isExists = IsValidIndex(configIdx);
|
||||||
if (isExists)
|
if (isExists)
|
||||||
@@ -1301,8 +1301,8 @@ class XCTradeManager : public XCBase
|
|||||||
|
|
||||||
//
|
//
|
||||||
int configIdx = FindSymbolConfigurationIndex(
|
int configIdx = FindSymbolConfigurationIndex(
|
||||||
trades[idx].symbol,
|
trades[idx].signal.symbol,
|
||||||
tardes[idx].period //
|
trades[idx].signal.period //
|
||||||
);
|
);
|
||||||
isExists = IsValidIndex(configIdx);
|
isExists = IsValidIndex(configIdx);
|
||||||
if (isExists)
|
if (isExists)
|
||||||
@@ -1329,6 +1329,99 @@ class XCTradeManager : public XCBase
|
|||||||
RemoveTrade(idx);
|
RemoveTrade(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle All Symbols Config Force Close At Time ...
|
||||||
|
*
|
||||||
|
* @return ( bool )
|
||||||
|
*/
|
||||||
|
bool HandleForceCloseAtTime()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Symbol Config Exists ...
|
||||||
|
result = HasChild(symbolTradeConfigs);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = false;
|
||||||
|
int count = ArraySize(symbolTradeConfigs);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Can Force Closed At ...
|
||||||
|
bool has = IsSpecifiedValid(symbolTradeConfigs[i].closeAllOpenTradesAt);
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Parse Date ...
|
||||||
|
datetime forceCloseTime = ParseDateTimeFromTimeString(symbolTradeConfigs[i].closeAllOpenTradesAt);
|
||||||
|
has = IsTimeInRange(
|
||||||
|
TimeCurrent(),
|
||||||
|
forceCloseTime //
|
||||||
|
) &&
|
||||||
|
!symbolTradeConfigs[i].isForceCloseAtTime;
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Selecting Positions ...
|
||||||
|
XTradeInfo iTrades[];
|
||||||
|
int iTradesCount = FillSymbolConfigurationTrades(
|
||||||
|
symbolTradeConfigs[i],
|
||||||
|
iTrades //
|
||||||
|
);
|
||||||
|
has = IsValidSize(iTradesCount);
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
SpecifiedClean(iTrades);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converts Trades to Positions ...
|
||||||
|
XPosition iPositions[];
|
||||||
|
int iPositionsCount = ToXPositions(
|
||||||
|
iTrades,
|
||||||
|
iPositions //
|
||||||
|
);
|
||||||
|
has = IsValidSize(iPositionsCount);
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
SpecifiedClean(iTrades);
|
||||||
|
SpecifiedClean(iPositions);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Force Closing ...
|
||||||
|
has = HandleForceCloseTrades(iPositions);
|
||||||
|
if (has && !result)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup Resources ...
|
||||||
|
SpecifiedClean(iTrades);
|
||||||
|
SpecifiedClean(iPositions);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Position Partially Closed Event ...
|
* Handle Position Partially Closed Event ...
|
||||||
*
|
*
|
||||||
@@ -1373,15 +1466,18 @@ class XCTradeManager : public XCBase
|
|||||||
string comment = "Force Close ...";
|
string comment = "Force Close ...";
|
||||||
|
|
||||||
//
|
//
|
||||||
int closedsCount = trader.Close(
|
int count = ArraySize(positions);
|
||||||
positions,
|
for (int i = 0; i < count; i++)
|
||||||
comment //
|
{
|
||||||
);
|
HandleForceClose(positions[i]);
|
||||||
result = IsValidSize(closedsCount);
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValidSize(count);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
string message = prefix + "Force Close (" + ToXString(closedsCount) + ") Trades at Specified Time ...";
|
string message = prefix + "Force Close (" + ToXString(count) + ") Trades at Specified Time ...";
|
||||||
HandleReportProtector(message);
|
HandleReportProtector(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1966,6 +2062,71 @@ class XCTradeManager : public XCBase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int FillSymbolConfigurationTrades(
|
||||||
|
XSymbolTradeConfig &config,
|
||||||
|
XTradeInfo &dest[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
SpecifiedClean(dest);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Trades ...
|
||||||
|
int count = ArraySize(trades);
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Config ...
|
||||||
|
if (!config.IsValid())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Config ...
|
||||||
|
int idx = FindSymbolConfigurationIndex(config);
|
||||||
|
if (!IsValidIndex(idx))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool has = false;
|
||||||
|
string symbol = symbolTradeConfigs[idx].symbol;
|
||||||
|
ENUM_TIMEFRAMES period = symbolTradeConfigs[idx].period;
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
has =
|
||||||
|
trades[i].signal.symbol == symbol &&
|
||||||
|
trades[i].signal.period == period &&
|
||||||
|
trades[i].positionID > 0;
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
AddRef(
|
||||||
|
trades[i],
|
||||||
|
dest //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = ArraySize(dest);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
int FindSymbolConfigurationIndex(
|
int FindSymbolConfigurationIndex(
|
||||||
string symbol,
|
string symbol,
|
||||||
@@ -2006,6 +2167,54 @@ class XCTradeManager : public XCBase
|
|||||||
//
|
//
|
||||||
// Tools ...
|
// Tools ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int ToXPositions(
|
||||||
|
XTradeInfo &source[],
|
||||||
|
XPosition &dest[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
SpecifiedClean(dest);
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(source);
|
||||||
|
bool has = IsValidSize(count);
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iPosition;
|
||||||
|
has = trader.GetPosition(
|
||||||
|
source[i].positionID,
|
||||||
|
iPosition);
|
||||||
|
if (has)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddRef(
|
||||||
|
iPosition,
|
||||||
|
dest //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
iPosition.Clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = ArraySize(dest);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
string EscapeString(string value)
|
string EscapeString(string value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2108,7 +2108,7 @@ class XCTrade : public XCBase
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Retrieve Specific Position by Index ...
|
// Retrieve Specific Position by Index ...
|
||||||
bool GetPosition(
|
bool GetPositionByIndex(
|
||||||
int index, // Specified Index
|
int index, // Specified Index
|
||||||
XPosition &result // Hold's Result
|
XPosition &result // Hold's Result
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2914,6 +2914,7 @@ struct XSymbolTradeConfig
|
|||||||
ENUM_TIMEFRAMES period; // Trading Period
|
ENUM_TIMEFRAMES period; // Trading Period
|
||||||
int maxAllowedPositions; // Max Allowed Same Time Trades
|
int maxAllowedPositions; // Max Allowed Same Time Trades
|
||||||
double maxAllowedSpread; // Max Allowed Spread For Trade
|
double maxAllowedSpread; // Max Allowed Spread For Trade
|
||||||
|
bool isForceCloseAtTime; // a Flag for Determines Force Closed or not
|
||||||
XTradeSession sessions[]; // Trading Sessions
|
XTradeSession sessions[]; // Trading Sessions
|
||||||
string closeAllOpenTradesAt; // Close All Open Trades per Day At Specified Time
|
string closeAllOpenTradesAt; // Close All Open Trades per Day At Specified Time
|
||||||
int restrictionsPeriodMultiplier; // Specified Restrictions Period Multiplier
|
int restrictionsPeriodMultiplier; // Specified Restrictions Period Multiplier
|
||||||
@@ -2964,6 +2965,7 @@ struct XSymbolTradeConfig
|
|||||||
maxAllowedSpread = 25;
|
maxAllowedSpread = 25;
|
||||||
maxAllowedPositions = 5;
|
maxAllowedPositions = 5;
|
||||||
closeAllOpenTradesAt = "";
|
closeAllOpenTradesAt = "";
|
||||||
|
isForceCloseAtTime = false;
|
||||||
restrictionsPeriod = XTRADE_RESTRICATION_NONE;
|
restrictionsPeriod = XTRADE_RESTRICATION_NONE;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -668,6 +668,14 @@ class XCXOM1EAExpert : public XCBase
|
|||||||
*/
|
*/
|
||||||
void HandleOnTick()
|
void HandleOnTick()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Time Report ...
|
||||||
|
HandleTimeReport();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Manage Trades ...
|
||||||
|
eaTradeManager.Manage();
|
||||||
|
|
||||||
//
|
//
|
||||||
int count = ArraySize(eaSignallers);
|
int count = ArraySize(eaSignallers);
|
||||||
bool has = IsValidSize(count);
|
bool has = IsValidSize(count);
|
||||||
@@ -684,6 +692,10 @@ class XCXOM1EAExpert : public XCBase
|
|||||||
// Calling Process Ticks on Signaller ...
|
// Calling Process Ticks on Signaller ...
|
||||||
eaSignallers[i].ProcessTick(0);
|
eaSignallers[i].ProcessTick(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Guard Implememnting ...
|
||||||
|
// TODO: Implement this ...
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user