This commit is contained in:
2025-05-30 14:22:12 +03:30
parent 6d9aef6125
commit 6aaed9d03a
6 changed files with 747 additions and 20 deletions
@@ -0,0 +1,32 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: XCXCATBEASignaller ...
// Description: Class for XCATBEA Signaller ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm Class for XCATBEA Signaller"
#property strict
//
// Imports ...
#include "../Libraries/xcatbea.lib.mq5";
#include "../Libraries/xcatbea.signaller.lib.mq5";
//
// Definitions ...
class XCXCATBEASignaller : XCBase
{
};
@@ -114,10 +114,10 @@ class XCXCATBEADataCollector : public XCBase
/**
* Save Specified Content into Specified File Name ...
*
*
* @param fileName: string, file name ...
* @param content: string, content ...
*
*
* @return ( bool )
*/
bool Save(
@@ -153,6 +153,48 @@ class XCXCATBEADataCollector : public XCBase
return result;
}
/**
* Append Specified Content into Specified File Name ...
*
* @param fileName: string, file name ...
* @param content: string, content ...
*
* @return ( bool )
*/
bool Append(
string fileName,
string content //
)
{
//
bool result = false;
//
result = IsValid(content);
if (!result)
{
return result;
}
//
//
int mHandler = GetFileHandlerForWrite(fileName);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
FileSeek(mHandler, 0, SEEK_END);
FileWrite(mHandler, content);
FileFlush(mHandler);
FileClose(mHandler);
//
return result;
}
//
// Protected ...
protected:
+380 -16
View File
@@ -459,15 +459,15 @@ struct XCATBEATrade
//
result =
//
ToString("Swap: ", swap) +
ToString("Profit: ", profit) +
ToString("Commission: ", commission) +
ToString("Finalize: ", ToString(finalize)) +
ToString("PositionID: ", positionID) +
ToString("Swap", swap) +
ToString("Profit", profit) +
ToString("Commission", commission) +
ToString("Finalize", ToString(finalize)) +
ToString("PositionID", positionID) +
ToString("----------------") + "\n" +
ToString("Signaled At: ", ToFormatString(signaledAt)) +
ToString("Executed At: ", ToFormatString(executedAt)) +
ToString("Finalized At: ", ToFormatString(finalizedAt))
ToString("Signaled At", ToFormatString(signaledAt)) +
ToString("Executed At", ToFormatString(executedAt)) +
ToString("Finalized At", ToFormatString(finalizedAt))
//
;
@@ -581,6 +581,111 @@ struct XCATBEATrade
//
return result;
}
string GetConditionsString()
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
conditions
.conditions
.GenerateScore(
bullishScore,
bearishScore //
);
//
string conditionsStr =
conditions
.conditions
.GenerateSummary(
false,
true, // Only Conditions ...
false,
false // Ignore False Conditions ...
);
string condParts[];
int condPartsCount = SplitContent(
condParts,
conditionsStr,
"\n" //
);
if (IsValidSize(condPartsCount))
{
//
conditionsStr = NULL;
while (HasChild(condParts))
{
//
string iStr = condParts[0];
ArrayRemove(
condParts,
0,
1 //
);
//
bool isLast = !HasChild(condParts);
//
bool isCond = Contains(
"is",
iStr,
false //
);
if (isCond)
{
//
string iParts[];
int iPartsCount = SplitContent(
iParts,
iStr,
":" //
);
if (iPartsCount == 2)
{
//
string iVal = iParts[1];
StringTrimLeft(iVal);
StringTrimRight(iVal);
bool isPassed = ToBoolean(iVal);
conditionsStr += (isPassed ? "" : "!") + "conditions." + iParts[0] + (!isLast ? " &&" : "") + "\n";
}
}
}
Clean(condParts);
}
else
{
conditionsStr = NULL;
}
//
result =
"(" + "\n" +
"\\" + "\\" + " " + ToString("Type", ToString(signal.type)) +
"\\" + "\\" + " " + ToString("Profit", profit) +
"\\" + "\\" + " " + ToString("Finalize", ToString(finalize)) +
"\\" + "\\" + " " + ToString("PositionID", positionID) +
"\\" + "\\" + " " + ToString("----------------") + "\n" +
"\\" + "\\" + " " + ToString("Signaled At", ToFormatString(signaledAt)) +
"\\" + "\\" + " " + ToString("Executed At", ToFormatString(executedAt)) +
"\\" + "\\" + " " + ToString("Finalized At", ToFormatString(finalizedAt)) +
"\\" + "\\" + " " + ToString("----------------") + "\n" +
"\\" + "\\" + " " + ToString("Scores:") + "\n" +
"\\" + "\\" + " " + ToString("Bullish", bullishScore) +
"\\" + "\\" + " " + ToString("Bearish", bearishScore) +
"\\" + "\\" + " " + ToString("----------------") + "\n" +
conditionsStr +
(IsValid(conditionsStr) ? "" : "") +
") && ";
//
return result;
}
};
//
@@ -677,6 +782,42 @@ class XCXCATBEATradeManager : public XCBaseAlert
mSaveTrades = value;
}
//
bool SaveSignals()
{
return mSaveSignals;
}
//
void SaveSignals(bool value)
{
mSaveSignals = value;
}
//
bool SaveWins()
{
return mSaveWins;
}
//
void SaveWins(bool value)
{
mSaveWins = value;
}
//
bool SaveLosts()
{
return mSaveLosts;
}
//
void SaveLosts(bool value)
{
mSaveLosts = value;
}
//
void SetForceCloseTradesAt(
string _forceCloseAt //
@@ -1191,6 +1332,9 @@ class XCXCATBEATradeManager : public XCBaseAlert
SendAlert(message);
}
//
SaveSignal(signal);
//
// Check Trade Permission ...
if (!allowTrade)
@@ -1480,7 +1624,8 @@ class XCXCATBEATradeManager : public XCBaseAlert
//
// Save Trade ...
Save(trades[idx]);
SaveWin(trades[idx]);
SaveTrade(trades[idx]);
//
// Handle Balance Reporting ...
@@ -1533,7 +1678,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
//
// Save Trade ...
Save(trades[idx]);
SaveTrade(trades[idx]);
//
// Handle Balance Reporting ...
@@ -1545,6 +1690,14 @@ class XCXCATBEATradeManager : public XCBaseAlert
//
bool isInProfit = trades[idx].profit > 0;
if (isInProfit)
{
SaveWin(trades[idx]);
}
else
{
SaveLost(trades[idx]);
}
//
XCATBEASymbolInfo iSymbolInfo;
@@ -1605,7 +1758,15 @@ class XCXCATBEATradeManager : public XCBaseAlert
//
// Save Trade ...
Save(trades[idx]);
SaveTrade(trades[idx]);
if (isInProfit)
{
SaveWin(trades[idx]);
}
else
{
SaveLost(trades[idx]);
}
//
// Handle Balance Reporting ...
@@ -1863,17 +2024,17 @@ class XCXCATBEATradeManager : public XCBaseAlert
// Tools ...
//
string GetFilePath(XCATBEATrade &trade)
string GetTradeFilePath(XCATBEATrade &trade)
{
//
string fileName = trade.GetFileName();
//
return GetFilePath(fileName);
return GetTradeFilePath(fileName);
}
//
string GetFilePath(string fileName)
string GetTradeFilePath(string fileName)
{
//
string result = NULL;
@@ -1892,6 +2053,72 @@ class XCXCATBEATradeManager : public XCBaseAlert
return result;
}
//
string GetSignalFilePath(string fileName)
{
//
string result = NULL;
//
string mPath = collector.Path();
//
result =
//
mPath + "\\" + "Signals" + "\\" + fileName + ".x121.log"
//
;
//
return result;
}
//
string GetWinsFilePath(XCATBEATrade &trade)
{
//
string result = NULL;
//
string mPath = collector.Path();
//
result =
//
mPath + "\\" +
"Conditions" + "\\" +
trade.signal.symbol + "\\" +
ToString(trade.signal.period) + "_wins.x121.log"
//
;
//
return result;
}
//
string GetLostsFilePath(XCATBEATrade &trade)
{
//
string result = NULL;
//
string mPath = collector.Path();
//
result =
//
mPath + "\\" +
"Conditions" + "\\" +
trade.signal.symbol + "\\" +
ToString(trade.signal.period) + "_losts.x121.log"
//
;
//
return result;
}
//
void HandleReportBalance(string prefix = NULL)
{
@@ -1928,7 +2155,8 @@ class XCXCATBEATradeManager : public XCBaseAlert
}
//
bool Save(
// Save Trades ...
bool SaveTrade(
XCATBEATrade &trade,
bool includeSummary = true,
bool includeSignal = true,
@@ -1945,7 +2173,7 @@ class XCXCATBEATradeManager : public XCBaseAlert
}
//
string filePath = GetFilePath(trade);
string filePath = GetTradeFilePath(trade);
result = IsValid(filePath);
if (!result)
{
@@ -1969,6 +2197,139 @@ class XCXCATBEATradeManager : public XCBaseAlert
return result;
}
//
// Save Signals ...
bool SaveSignal(XSignal &signal)
{
//
bool result = false;
//
// Check Signal Save is Enabled ...
if (!mSaveSignals)
{
return result;
}
//
// Check Signal Validation ...
if (!signal.IsValid())
{
return result;
}
//
// Retrieve Signal File Name ...
string signalFileName = signal.GetFileName();
result = IsValid(signalFileName);
if (!result)
{
return result;
}
//
// Retriev and Validate File Name ...
string filePath = GetSignalFilePath(signalFileName);
result = IsValid(filePath);
if (!result)
{
return result;
}
//
// Generate Content ...
string content = "";
content +=
ToString("----------------") + "\n" +
ToString("Signal: ") + "\n" +
ToString("----------------") + "\n" +
signal.ToString() + "\n";
content +=
ToString("----------------") + "\n" +
ToString("Conditions: ") + "\n" +
ToString("----------------") + "\n" +
signal.conditions + "\n";
//
// Save Content to File ...
result = collector.Save(
filePath,
content //
);
//
// Return Result ...
return result;
}
//
bool SaveWin(XCATBEATrade &trade)
{
//
bool result = false;
//
if (!mSaveWins)
{
return result;
}
//
string filePath = GetWinsFilePath(trade);
result = IsValid(filePath);
if (!result)
{
return result;
}
//
// Preparing Conditions Content ...
string content = trade.GetConditionsString();
//
result = collector.Append(
filePath,
content //
);
//
return result;
}
//
bool SaveLost(XCATBEATrade &trade)
{
//
bool result = false;
//
if (!mSaveLosts)
{
return result;
}
//
string filePath = GetLostsFilePath(trade);
result = IsValid(filePath);
if (!result)
{
return result;
}
//
// Preparing Conditions Content ...
string content = trade.GetConditionsString();
//
result = collector.Append(
filePath,
content //
);
//
return result;
}
//
// Symbol Info ...
@@ -2277,7 +2638,10 @@ class XCXCATBEATradeManager : public XCBaseAlert
ENUM_XCATBEA_TRADE_RESTRICTION_PERIOD restrictionsPeriod;
//
bool mSaveWins;
bool mSaveLosts;
bool mSaveTrades;
bool mSaveSignals;
//
bool reportTrades;