add support for restrictions report and save ...
This commit is contained in:
@@ -146,16 +146,18 @@ input bool eaReportNewDays = true; // Report New Days
|
|||||||
input bool eaReportNewHours = false; // Report New Hours
|
input bool eaReportNewHours = false; // Report New Hours
|
||||||
input bool eaReportTrades = true; // Report Trades
|
input bool eaReportTrades = true; // Report Trades
|
||||||
input bool eaReportSignals = true; // Report Signals
|
input bool eaReportSignals = true; // Report Signals
|
||||||
|
input bool eaReportRestrictions = true; // Report Restrictions
|
||||||
input bool eaReportProtector = true; // Report Protector Actions
|
input bool eaReportProtector = true; // Report Protector Actions
|
||||||
input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Finished
|
input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Finished
|
||||||
|
|
||||||
//
|
//
|
||||||
// Collector ...
|
// Collector ...
|
||||||
input group "Collector";
|
input group "Collector";
|
||||||
input bool eaSaveTrades = false; // Save Trades
|
input bool eaSaveTrades = false; // Save Trades
|
||||||
input bool eaSaveSignals = false; // Save Signals
|
input bool eaSaveSignals = false; // Save Signals
|
||||||
input bool eaSaveWins = false; // Save Winning Conditions
|
input bool eaSaveWins = false; // Save Winning Conditions
|
||||||
input bool eaSaveLosts = false; // Save Lost Conditions
|
input bool eaSaveLosts = false; // Save Lost Conditions
|
||||||
|
input bool eaSaveRestrictions = false; // Save Restriction Reports
|
||||||
|
|
||||||
//
|
//
|
||||||
// Variables ...
|
// Variables ...
|
||||||
@@ -306,6 +308,7 @@ int OnInit()
|
|||||||
eaExpert.eaReportNewHours = eaReportNewHours;
|
eaExpert.eaReportNewHours = eaReportNewHours;
|
||||||
eaExpert.eaReportProtector = eaReportProtector;
|
eaExpert.eaReportProtector = eaReportProtector;
|
||||||
eaExpert.eaReportNewMonths = eaReportNewMonths;
|
eaExpert.eaReportNewMonths = eaReportNewMonths;
|
||||||
|
eaExpert.eaReportRestrictions = eaReportRestrictions;
|
||||||
eaExpert.eaReportAfterTradesBalance = eaReportAfterTradesBalance;
|
eaExpert.eaReportAfterTradesBalance = eaReportAfterTradesBalance;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -314,6 +317,7 @@ int OnInit()
|
|||||||
eaExpert.eaSaveLosts = eaSaveLosts;
|
eaExpert.eaSaveLosts = eaSaveLosts;
|
||||||
eaExpert.eaSaveTrades = eaSaveTrades;
|
eaExpert.eaSaveTrades = eaSaveTrades;
|
||||||
eaExpert.eaSaveSignals = eaSaveSignals;
|
eaExpert.eaSaveSignals = eaSaveSignals;
|
||||||
|
eaExpert.eaSaveRestrictions = eaSaveRestrictions;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Attach Event Handlers ...
|
// Attach Event Handlers ...
|
||||||
|
|||||||
@@ -147,14 +147,16 @@ class XCXCATBEAExpert : public XCBase
|
|||||||
bool eaReportTrades; // Report Trades
|
bool eaReportTrades; // Report Trades
|
||||||
bool eaReportSignals; // Report Signals
|
bool eaReportSignals; // Report Signals
|
||||||
bool eaReportProtector; // Report Protector Actions
|
bool eaReportProtector; // Report Protector Actions
|
||||||
|
bool eaReportRestrictions; // Report Restrictions
|
||||||
bool eaReportAfterTradesBalance; // Report Balance after a Trade Finished
|
bool eaReportAfterTradesBalance; // Report Balance after a Trade Finished
|
||||||
|
|
||||||
//
|
//
|
||||||
// Collector ...
|
// Collector ...
|
||||||
bool eaSaveTrades; // Save Trades
|
bool eaSaveTrades; // Save Trades
|
||||||
bool eaSaveSignals; // Save Signals
|
bool eaSaveSignals; // Save Signals
|
||||||
bool eaSaveWins; // Save Winning Conditions
|
bool eaSaveWins; // Save Winning Conditions
|
||||||
bool eaSaveLosts; // Save Lost Conditions
|
bool eaSaveLosts; // Save Lost Conditions
|
||||||
|
bool eaSaveRestrictions; // Save Restriction Reports
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trade Event Handlers ...
|
// Trade Event Handlers ...
|
||||||
@@ -305,6 +307,7 @@ class XCXCATBEAExpert : public XCBase
|
|||||||
eaTradeManager.SaveLosts(eaSaveLosts);
|
eaTradeManager.SaveLosts(eaSaveLosts);
|
||||||
eaTradeManager.SaveTrades(eaSaveTrades);
|
eaTradeManager.SaveTrades(eaSaveTrades);
|
||||||
eaTradeManager.SaveSignals(eaSaveSignals);
|
eaTradeManager.SaveSignals(eaSaveSignals);
|
||||||
|
eaTradeManager.SaveRestrictions(eaSaveRestrictions);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Enable Force Close At ...
|
// Enable Force Close At ...
|
||||||
@@ -317,6 +320,7 @@ class XCXCATBEAExpert : public XCBase
|
|||||||
eaReportTrades,
|
eaReportTrades,
|
||||||
eaReportSignals,
|
eaReportSignals,
|
||||||
eaReportProtector,
|
eaReportProtector,
|
||||||
|
eaReportRestrictions,
|
||||||
eaReportAfterTradesBalance //
|
eaReportAfterTradesBalance //
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -98,11 +98,18 @@ struct XCATBEASymbolInfo
|
|||||||
int losses; // All Loosing Trades
|
int losses; // All Loosing Trades
|
||||||
int profits; // All Winning Trades
|
int profits; // All Winning Trades
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime managedStart; // Managed Start Time
|
||||||
|
|
||||||
//
|
//
|
||||||
int managedSLs; // Managed SL(s)
|
int managedSLs; // Managed SL(s)
|
||||||
int managedTPs; // Managed TP(s)
|
int managedTPs; // Managed TP(s)
|
||||||
int managedTrades; // Managed Trades
|
int managedTrades; // Managed Trades
|
||||||
|
|
||||||
|
//
|
||||||
|
double managedBalance; // Managed Start Balance
|
||||||
|
double managedProfits; // Managed Profit(s)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Constructor ...
|
// Constructor ...
|
||||||
XCATBEASymbolInfo()
|
XCATBEASymbolInfo()
|
||||||
@@ -131,11 +138,18 @@ struct XCATBEASymbolInfo
|
|||||||
losses = 0;
|
losses = 0;
|
||||||
profits = 0;
|
profits = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
managedStart = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
managedSLs = 0;
|
managedSLs = 0;
|
||||||
managedTPs = 0;
|
managedTPs = 0;
|
||||||
managedTrades = 0;
|
managedTrades = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
managedBalance = 0;
|
||||||
|
managedProfits = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
ZeroMemory(this);
|
ZeroMemory(this);
|
||||||
}
|
}
|
||||||
@@ -168,6 +182,41 @@ struct XCATBEASymbolInfo
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string GetRestrictionDescription(
|
||||||
|
ENUM_XCATBEA_TRADE_RESTRICTION_PERIOD period //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string result = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!IsValid() &&
|
||||||
|
period != XCATBEA_TRADE_RESTRICATION_NONE)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result +=
|
||||||
|
"-------------------" + "\n" +
|
||||||
|
"Restrictions: " + "\n" +
|
||||||
|
"-------------------" + "\n" +
|
||||||
|
"Symbol: " + ToString(symbol) + "\n" +
|
||||||
|
"Period: " + ToString(period) + "\n" +
|
||||||
|
"Start: " + ToFormatString(managedStart) + "\n" +
|
||||||
|
"Balance: " + ToString(managedBalance) + "\n" +
|
||||||
|
"-------------------" + "\n" +
|
||||||
|
"Trades: " + ToString(managedTrades) + "\n" +
|
||||||
|
"SL: " + ToString(managedSLs) + "\n" +
|
||||||
|
"TP: " + ToString(managedTPs) + "\n" +
|
||||||
|
"Profit: " + ToString(managedProfits) + "\n" +
|
||||||
|
"";
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -819,6 +868,18 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
mSaveLosts = value;
|
mSaveLosts = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool SaveRestrictions()
|
||||||
|
{
|
||||||
|
return mSaveRestrictions;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void SaveRestrictions(bool value)
|
||||||
|
{
|
||||||
|
mSaveRestrictions = value;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void SetForceCloseTradesAt(
|
void SetForceCloseTradesAt(
|
||||||
string _forceCloseAt //
|
string _forceCloseAt //
|
||||||
@@ -908,6 +969,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
bool _reportTrades,
|
bool _reportTrades,
|
||||||
bool _reportSignals,
|
bool _reportSignals,
|
||||||
bool _reportProtector,
|
bool _reportProtector,
|
||||||
|
bool _reportRestrictions,
|
||||||
bool _reportAfterTradesBalance //
|
bool _reportAfterTradesBalance //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -915,6 +977,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
reportTrades = _reportTrades;
|
reportTrades = _reportTrades;
|
||||||
reportSignals = _reportSignals;
|
reportSignals = _reportSignals;
|
||||||
reportProtector = _reportProtector;
|
reportProtector = _reportProtector;
|
||||||
|
reportRestrictions = _reportRestrictions;
|
||||||
reportAfterTradesBalance = _reportAfterTradesBalance;
|
reportAfterTradesBalance = _reportAfterTradesBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1603,6 +1666,18 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
iSymbolInfo.shorts = 1;
|
iSymbolInfo.shorts = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Fill Balance for Restrications ...
|
||||||
|
bool hasRestrictions = HasRestrictions();
|
||||||
|
if (hasRestrictions)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Read Balance ...
|
||||||
|
double balance = trader.mAccount.GetBalance();
|
||||||
|
iSymbolInfo.managedBalance = balance;
|
||||||
|
iSymbolInfo.managedStart = TimeCurrent();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
AddOrUpdateSymbolInfo(iSymbolInfo);
|
AddOrUpdateSymbolInfo(iSymbolInfo);
|
||||||
|
|
||||||
@@ -1730,6 +1805,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
iSymbolInfo.profits = 1;
|
iSymbolInfo.profits = 1;
|
||||||
iSymbolInfo.managedTPs = 1;
|
iSymbolInfo.managedTPs = 1;
|
||||||
iSymbolInfo.symbol = trades[idx].signal.symbol;
|
iSymbolInfo.symbol = trades[idx].signal.symbol;
|
||||||
|
iSymbolInfo.managedProfits = trades[idx].profit;
|
||||||
|
|
||||||
//
|
//
|
||||||
AddOrUpdateSymbolInfo(iSymbolInfo);
|
AddOrUpdateSymbolInfo(iSymbolInfo);
|
||||||
@@ -1804,6 +1880,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
iSymbolInfo.managedSLs = 1;
|
iSymbolInfo.managedSLs = 1;
|
||||||
}
|
}
|
||||||
iSymbolInfo.symbol = trades[idx].signal.symbol;
|
iSymbolInfo.symbol = trades[idx].signal.symbol;
|
||||||
|
iSymbolInfo.managedProfits = trades[idx].profit;
|
||||||
|
|
||||||
//
|
//
|
||||||
AddOrUpdateSymbolInfo(iSymbolInfo);
|
AddOrUpdateSymbolInfo(iSymbolInfo);
|
||||||
@@ -1886,6 +1963,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
iSymbolInfo.managedSLs = 1;
|
iSymbolInfo.managedSLs = 1;
|
||||||
}
|
}
|
||||||
iSymbolInfo.symbol = trades[idx].signal.symbol;
|
iSymbolInfo.symbol = trades[idx].signal.symbol;
|
||||||
|
iSymbolInfo.managedProfits = trades[idx].profit;
|
||||||
|
|
||||||
//
|
//
|
||||||
AddOrUpdateSymbolInfo(iSymbolInfo);
|
AddOrUpdateSymbolInfo(iSymbolInfo);
|
||||||
@@ -2207,6 +2285,34 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string GetRestrictionsFilePath(string symbol)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string result = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!IsValid(symbol))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string mPath = collector.Path();
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
mPath + "\\" +
|
||||||
|
"Restrictions" + "\\" +
|
||||||
|
symbol + "\\" + ".x121.log"
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void HandleReportBalance(string prefix = NULL)
|
void HandleReportBalance(string prefix = NULL)
|
||||||
{
|
{
|
||||||
@@ -2418,6 +2524,46 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool SaveRestrictions(XCATBEASymbolInfo &info)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!mSaveRestrictions)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = info.IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string filePath = GetRestrictionsFilePath(info.symbol);
|
||||||
|
result = IsValid(filePath);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string content = info.GetRestrictionDescription(restrictionsPeriod);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = collector.Append(
|
||||||
|
filePath,
|
||||||
|
content //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Symbol Info ...
|
// Symbol Info ...
|
||||||
|
|
||||||
@@ -2536,6 +2682,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
symbols[index].managedSLs += item.managedSLs;
|
symbols[index].managedSLs += item.managedSLs;
|
||||||
symbols[index].managedTPs += item.managedTPs;
|
symbols[index].managedTPs += item.managedTPs;
|
||||||
symbols[index].managedTrades += item.managedTrades;
|
symbols[index].managedTrades += item.managedTrades;
|
||||||
|
symbols[index].managedProfits += item.managedProfits;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Handle Remove on Managed SL based On Managed TP ...
|
// Handle Remove on Managed SL based On Managed TP ...
|
||||||
@@ -2573,14 +2720,41 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
//
|
//
|
||||||
string prefix = "Protector: ";
|
string prefix = "Protector: ";
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime start = TimeCurrent();
|
||||||
|
double balance = trader.mAccount.GetBalance();
|
||||||
|
bool hasRestrictions = HasRestrictions();
|
||||||
|
if (!hasRestrictions)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
balance = 0;
|
||||||
|
start = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
int count = ArraySize(symbols);
|
int count = ArraySize(symbols);
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
XCATBEASymbolInfo iInfo = symbols[i];
|
||||||
|
if (reportRestrictions)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string message = iInfo.GetRestrictionDescription(restrictionsPeriod);
|
||||||
|
SendAlert(message);
|
||||||
|
}
|
||||||
|
SaveRestrictions(iInfo);
|
||||||
|
|
||||||
//
|
//
|
||||||
symbols[i].managedSLs = 0;
|
symbols[i].managedSLs = 0;
|
||||||
symbols[i].managedTPs = 0;
|
symbols[i].managedTPs = 0;
|
||||||
symbols[i].managedTrades = 0;
|
symbols[i].managedTrades = 0;
|
||||||
|
symbols[i].managedProfits = 0;
|
||||||
|
symbols[i].managedStart = start;
|
||||||
|
symbols[i].managedBalance = balance;
|
||||||
|
|
||||||
|
//
|
||||||
|
iInfo.Clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2748,17 +2922,23 @@ class XCXCATBEATradeManager : public XCBaseAlert
|
|||||||
int maxAllowedSLs;
|
int maxAllowedSLs;
|
||||||
int maxAllowedTrades;
|
int maxAllowedTrades;
|
||||||
ENUM_XCATBEA_TRADE_RESTRICTION_PERIOD restrictionsPeriod;
|
ENUM_XCATBEA_TRADE_RESTRICTION_PERIOD restrictionsPeriod;
|
||||||
|
bool HasRestrictions()
|
||||||
|
{
|
||||||
|
return restrictionsPeriod != XCATBEA_TRADE_RESTRICATION_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
bool mSaveWins;
|
bool mSaveWins;
|
||||||
bool mSaveLosts;
|
bool mSaveLosts;
|
||||||
bool mSaveTrades;
|
bool mSaveTrades;
|
||||||
bool mSaveSignals;
|
bool mSaveSignals;
|
||||||
|
bool mSaveRestrictions;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool reportTrades;
|
bool reportTrades;
|
||||||
bool reportSignals;
|
bool reportSignals;
|
||||||
bool reportProtector;
|
bool reportProtector;
|
||||||
|
bool reportRestrictions;
|
||||||
bool reportAfterTradesBalance;
|
bool reportAfterTradesBalance;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user