last works ...

This commit is contained in:
2024-05-22 13:15:20 +03:30
parent 23c989f083
commit 4a69e7edf8
17 changed files with 6815 additions and 78 deletions
File diff suppressed because it is too large Load Diff
+329
View File
@@ -0,0 +1,329 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121EA
// Description: provides all X121 EA requirements ...
// - X5 Provider;
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.xea.class.mq5"
#include "../Classes/x-saherelm.x121.provider.class.mq5"
//
// Define On Signal Event Handler Type Specified for X5 ...
typedef void (*TX121OnSignal)(X121ProviderDescriptor &descriptor);
//
// Class Definition ...
class XSCX121EA : public XSCBaseEA
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX121EA(
//
// XTrade Class Requirements ...
int slippage, // Specify Slippage
ulong magicNumber, // Specify Magic Number
int manageInterval, // Manager Check Intervals Seconds
double maxAllowedSpread, // Max Allowed Spred for Opening Trades
int maxAllowedPositions, // Max Allowed Positions
double maxAllowedDrawdownFactor, // Max Allowed Drawdown Factor
//
// Position Management ...
bool allowLong = true, // Allow Long Trades
bool allowShort = true, // Allow Short Trades
double minProfitPerTrade = 0, // Min Profit Per Trade based On Volume Factor (Hedge)
double minProfitPerVolumeFactor = 0, // Min Volume Factor for Calculating Profit (Hedge)
//
// Event Handlers ...
TOnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
TOnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
TOnDealsChanged onDealsChangedHandler = NULL, // On Deals Changed Event Handler
TOnOrdersChanged onOrdersChangedHandler = NULL, // On Orders Changed Event Handler
TOnPositionsChanged onPositionsChangedHandler = NULL, // On Positions Changed Event Handler
TOnTradeStateChanged onTradeStateChangedHandler = NULL, // On Trade State Changed Event Handler
//
TOnSignal onSignalHandler = NULL, // On Signal Event Handler
//
// Log Handler ...
bool enableAlerts = true, // Enable Alerts
bool logAlerts = true, // Log Alerts
bool terminalAlerts = false, // Terminal Alerts
bool mailAlerts = false, // Mail Alerts
bool pushAlerts = false // Push Alerts
) : XSCBaseEA(slippage,
magicNumber,
manageInterval,
maxAllowedSpread,
maxAllowedPositions,
maxAllowedDrawdownFactor,
allowLong,
allowShort,
minProfitPerTrade,
minProfitPerVolumeFactor,
onStopLossTriggered,
onTakeProfitTriggered,
onDealsChangedHandler,
onOrdersChangedHandler,
onPositionsChangedHandler,
onTradeStateChangedHandler,
enableAlerts,
logAlerts,
terminalAlerts,
mailAlerts,
pushAlerts //
)
{
}
//
// Deconstructor ...
~XSCX121EA() {}
//
// Properties Getter(s) / Setter(s) ...
//
// Add X5 Specified Signal Event Handler ...
void AddOnSignalEventHandler(TX121OnSignal listener)
{
//
Add(
listener,
mX121OnSignalEventHandlers
//
);
}
//
// Add Specified X5 Provider ...
bool AddProvider(X121ProviderDescriptor &descriptor)
{
//
bool result = false;
//
// Validate Inputs ...
result = descriptor.Init();
if (!result)
{
return result;
}
//
AddRef(
descriptor,
mDescriptors //
);
//
return result;
}
//
// Overrides ...
//
// Customize Token ...
string GetToken() override
{
return GetSpecificToken(this);
}
//
string GetTag() override
{
return this.GetToken();
}
//
void Draw() override
{
//
int descriptorsCount = CountDescriptors();
if (descriptorsCount <= 0)
{
return;
}
//
for (int i = 0; i < descriptorsCount; i++)
{
//
X121ProviderDescriptor iDescriptor = mDescriptors[i];
//
iDescriptor.provider.Draw();
}
}
//
// Check Provider for any Guards ...
bool CheckForGuard(XGuard &guards[]) override
{
//
// TODO: Implement this ...
return false;
}
//
// Request Provider to Collect all
// Potentially Signals and then
// filters theme here and passed them
// for Executing ...
int RequestForSignal(
XSignal &signals[] // Holds Signals ...
) override
{
//
bool result = 0;
//
Clean(signals);
//
int descriptorsCount = CountDescriptors();
if (descriptorsCount <= 0)
{
return result;
}
//
for (int i = 0; i < descriptorsCount; i++)
{
//
X121ProviderDescriptor iDescriptor = mDescriptors[i];
//
bool iHasSignal = iDescriptor.HasSignal();
if (iHasSignal)
{
//
// Here we Can double check Signals by Conditions
// for Score Base Filtering ...
//
AddRef(
iDescriptor.signal,
signals
//
);
//
NotifyX121OnSignalEventHandlers(iDescriptor);
}
}
//
result = ArraySize(signals);
//
return result;
}
//
// Handl Management Actions ...
// if returns true, it is going to prevent for processing forward ...
bool HandleStateManagement() override
{
//
// TODO: Implement this ...
return false;
}
//
// Request for Support Signals using Guard ...
bool RequestForSupport(
XSignal &support, // Holds Support Signal, if Provided
string provider, // Positions Provided by Specific Provider
string symbol, // Trading Symbol
ENUM_POSITION_TYPE type, // Trading Type
ENUM_TIMEFRAMES period // Specified Time Frame
) override
{
//
// TODO: Implement this ...
return false;
}
//
// Tools ...
//
// Protected ...
protected:
//
// Tools ...
//
void NotifyX121OnSignalEventHandlers(X121ProviderDescriptor &descriptor)
{
//
int listenersCount = ArraySize(mX121OnSignalEventHandlers);
if (listenersCount <= 0)
{
return;
}
//
for (int i = 0; i < listenersCount; i++)
{
//
TX121OnSignal iListener = mX121OnSignalEventHandlers[i];
//
iListener(descriptor);
}
}
//
// Private ...
private:
//
// Props ...
//
// Collection of Signal Event Listeners ...
TX121OnSignal mX121OnSignalEventHandlers[];
//
// a Collection of X5 Provider Descriptors ...
X121ProviderDescriptor mDescriptors[];
//
int CountDescriptors()
{
return ArraySize(mDescriptors);
}
//
// Tools ...
};
//
// Tools ...
//
File diff suppressed because it is too large Load Diff
+150 -35
View File
@@ -2,7 +2,7 @@
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCBaseX5Provider
// Name: XSCX5Provider
// Description: provides all Base Provider
// requirements For X5 ...
//
@@ -547,6 +547,7 @@ public:
bool isXCHMALCFastCrossedUnderSlow;
//
// Tools ...
//
// Conditions ...
@@ -1757,6 +1758,41 @@ public:
//
string result = NULL;
//
result = GenerateSummaryBody(
onlySummary,
multiplier,
separator,
ignoreFalseConditions
//
);
//
// Generating Full Result by Combining parts ...
result =
//
"[" + GetToken() + "]" + separator +
"-----------------------------" + separator +
result +
""
//
;
//
return result;
}
//
string GenerateSummaryBody(
const bool onlySummary = false, // Only Generate Conditions Summary
double multiplier = 1, // Score Multiplier
const string separator = "\n", // Separator
const bool ignoreFalseConditions = true // Ignore False Conditions
)
{
//
string result = NULL;
//
double bullScore = 0;
double bearScore = 0;
@@ -2007,8 +2043,6 @@ public:
// Generating Full Result by Combining parts ...
result =
//
"[" + GetToken() + "]" + separator +
"-----------------------------" + separator +
commonStr +
(onlySummary
? ""
@@ -2031,6 +2065,43 @@ public:
return result;
}
//
string GenerateSummary(
string provided, // Additional Info about Type, Provider and Symbol
const bool onlySummary = false, // Only Generate Conditions Summary
double multiplier = 1, // Score Multiplier
const string separator = "\n", // Separator
const bool ignoreFalseConditions = true // Ignore False Conditions
)
{
//
string result = NULL;
//
result = GenerateSummaryBody(
onlySummary,
multiplier,
separator,
ignoreFalseConditions
//
);
//
// Generating Full Result by Combining parts ...
result =
//
"[" + GetToken() + "]" + separator +
provided + separator +
"-----------------------------" + separator +
result +
""
//
;
//
return result;
}
//
// For Data Collector ...
string GetToken()
@@ -2109,11 +2180,33 @@ public:
// Properties Gettr(s) / Setter(s) ...
//
// Inheritance ...
// Overrides ...
//
// DeInit all Requirements ...
void DeInit() override
{
//
delete tsHelper;
delete fiHelper;
delete tdHelper;
delete lhHelper;
delete tmHelper;
delete ccHelper;
delete ctHelper;
delete obdHelper;
delete rsiHelper;
delete amaHelper;
delete chmaHelper;
delete chlhHelper;
}
//
// Functions ...
//
// Init all Requirements ...
virtual bool Init(X5ProviderInputs &inputs)
bool Init(X5ProviderInputs &inputs)
{
//
bool result = false;
@@ -2289,28 +2382,6 @@ public:
return result;
}
//
// DeInit all Requirements ...
virtual void DeInit()
{
//
delete tsHelper;
delete fiHelper;
delete tdHelper;
delete lhHelper;
delete tmHelper;
delete ccHelper;
delete ctHelper;
delete obdHelper;
delete rsiHelper;
delete amaHelper;
delete chmaHelper;
delete chlhHelper;
}
//
// Functions ...
//
// Set Default Position's Type ...
// Enable / Disable Long (Buy), Short (Sell) ...
@@ -2783,16 +2854,59 @@ public:
if (result)
{
//
mWaitsUntilNewBar = true;
// Here We Have to Prepare Signal ...
//
string mConditionsStr = mConditions.GenerateSummary(true);
// TODO: Make this Configurable ...
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
double tpPoint = 30;
double volume = 0.01;
double tpPrice = PointToPrice(
tpPoint,
symbol //
);
ENUM_POSITION_TYPE type = hasLong
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
double entry = GetEntry(
symbol,
type //
);
double tp = hasLong
? entry + tpPrice
: entry - tpPrice;
double sl = 0;
ENUM_X_SIGNAL_MANAGING_ACTIONS action = X_SIGNAL_USE_NOTHING;
//
string providerTypeStr = GetSymbol() + ", " + provider + "(" + (hasLong ? "Long" : "Short") + ")";
mConditionsStr = providerTypeStr + "\n" + mConditionsStr;
mConditionsCollector.Add(mConditionsStr);
Print(mConditionsStr);
result = mSignal.Prepare(
symbol,
provider,
period,
type,
mode,
entry,
volume,
action,
sl,
tp
//
);
//
if (result)
{
//
mWaitsUntilNewBar = true;
//
string providerTypeStr = GetSymbol() + ", " + provider + "(" + (hasLong ? "Long" : "Short") + ")";
string mConditionsStr = mConditions.GenerateSummary(providerTypeStr, true);
mConditionsCollector.Add(mConditionsStr);
Print(mConditionsStr);
}
}
//
@@ -95066,7 +95180,7 @@ struct X5ProviderDescriptor
//
ENUM_X5_SIGNAL_PROVIDERS tmp[];
Copy(
mSignallers,
mSignallers,
tmp //
);
Copy(
@@ -95171,7 +95285,8 @@ struct X5ProviderDescriptor
result = provider.HasSignal(
barIndex,
signal,
conditions);
conditions //
);
//
return result;
+3
View File
@@ -210,6 +210,9 @@ public:
signals
//
);
//
NotifyX5OnSignalEventHandlers(iDescriptor);
}
}
+20
View File
@@ -385,6 +385,10 @@ public:
// OnTick Handler ...
virtual void OnTick()
{
//
// Draw ...
Draw();
//
// Check Trade Events ...
OnTrade();
@@ -528,6 +532,10 @@ public:
// TODO: Implement this ...
}
//
// Draw On Chart if anything is required ...
virtual void Draw() {}
//
// Check For any Guard Actions ...
virtual bool CheckForGuard(XGuard &guards[])
@@ -628,7 +636,19 @@ public:
string message = NULL;
if (executedSignalsCount == 0)
{
//
message = "(" + ToString(filteredSignalsCount) + ") Signals Execution Failed ...";
//
for (int j = 0; j < ArraySize(reasons); j++)
{
//
string iReason = ToString(reasons[j]);
//
// ToString(GetSpread(filteredSignals[j].symbol)) + ","
message += "\n" + ToString(j) + ": " + iReason;
}
}
else if (executedSignalsCount < filteredSignalsCount)
{