This commit is contained in:
2025-08-27 19:46:21 +03:30
parent a08e067236
commit 068394f629
6 changed files with 1766 additions and 19 deletions
+271
View File
@@ -0,0 +1,271 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class
// -------------------------------------------------
// Name: XCXOM1EAExpret ...
// Description: XCXOM1EA Expert Class ...
//
//
// 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 XCXOM1EA Expert Class"
#property strict
//
// Imports ...
#include "../../Classes/x-saherelm.base.class.mq5"
#include "../../Classes/x-saherelm.x-alert.class.mq5"
#include "../../Classes/x-saherelm.x-volume.class.mq5"
#include "../Classes/xom1ea.signaller.class.mq5"
//
// Definitions ...
//
// Implementation ...
class XCXOM1EAExpert : public XCBase
{
//
// Public ...
public:
//
// Props ...
//
// Common ...
long eaMagicNumber; // Magic Number
int eaSlippage; // Slippgae
string eaLogSuffix; // Log Suffix
//
// Volume ...
ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect; // Volume Applying Type
double eaStaticVoluem; // Static Volume
double eaDynamicVolumeStepBalance; // Step of Balance for Increase Volume
double eaDynamicVolumeStepVolume; // Step of Volume Increasing
double eaConstantRiskBalance; // Constant Risk Balance per Trade
double eaConstantPercent; // Constant Percent of Balance Per Trade
double eaConstantBalance; // Constant Balance for Calculations
//
// Alert ...
bool eaEnableAlerts; // Enable Alerts
bool eaSaveAlerts; // Save Alerts
bool eaLogAlerts; // Log Alerts
bool eaMailAlerts; // Mail Alerts
bool eaPushAlerts; // Push Alerts
bool eaTerminalAlerts; // Terminal Alerts
//
// Requirements ...
//
XCAlert *eaAlert; // EA Scope Alert Handler ...
XCVolume *eaVolume; // EA Scope Voluem Handler ...
//
// Validators ...
/**
* Validate Inputs ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
// TODO: Handle this ...
result = true;
//
return result;
}
//
// Expert Advisor Event Handlers ...
/**
* Handle Initialization of Expert ...
*
* @return ( bool )
*/
bool HandleOnInit()
{
//
bool result = false;
//
// Validate Inputs ...
result = ValidateInputs();
if (!result)
{
return result;
}
//
// Initialize Alert Handler ...
eaAlert = new XCAlert();
eaAlert.SetPrefix(eaLogSuffix);
eaAlert.SetLogAlerts(eaLogAlerts);
eaAlert.SetMailAlerts(eaMailAlerts);
eaAlert.SetPushAlerts(eaPushAlerts);
eaAlert.SetSaveAlerts(eaSaveAlerts);
eaAlert.SetEnableAlerts(eaEnableAlerts);
eaAlert.SetTerminalAlerts(eaTerminalAlerts);
//
// Initialize Volume Manager ...
// eaVolume = new XCVolume();
// result = eaVolume.Init(
// eaVolumeSelect,
// eaStaticVoluem,
// eaDynamicVolumeStepBalance,
// eaDynamicVolumeStepVolume,
// eaConstantRiskBalance,
// eaConstantPercent,
// eaConstantBalance //
// );
// if (!result)
// {
// return result;
// }
//
// Here we Apply Symbols,Periods and Configs ...
//
XOM1Inputs iDZoneOMInputs;
iDZoneOMInputs.Default();
//
XOM1SignallerConfig iDZoneSignallerConfig;
iDZoneSignallerConfig.processAllTicks = false;
//
XCXOM1SignallerBase *iDZoneSignaller = NULL;
iDZoneSignaller = new XCXOM1SignallerBase(
"XDZN",
"EURUSDb",
PERIOD_M5,
iDZoneOMInputs,
iDZoneSignallerConfig);
if (iDZoneSignaller != NULL)
{
//
Add(
iDZoneSignaller,
signallers //
);
}
//
// Cleanup Resources ...
iDZoneOMInputs.Clean();
iDZoneSignallerConfig.Clean();
ZeroMemory(iDZoneSignaller);
//
return result;
}
/**
* Handle De Initialization of Expert ...
*/
void HandleOnDeInit()
{
//
//
delete eaVolume;
ZeroMemory(eaVolume);
//
string message = "DeInitialized Successfully ...";
eaAlert.SendAlert(message);
//
delete eaAlert;
ZeroMemory(eaAlert);
}
/**
* Handle Tick ...
*/
void HandleOnTick()
{
//
int count = ArraySize(signallers);
bool has = IsValidSize(count);
if (!has) {
return;
}
//
// Loop through Signallers ...
for (int i = 0; i < count; i++) {
//
// Calling Process Ticks on Signaller ...
signallers[i].ProcessTick(0);
}
}
/**
* Handle Trade ...
*/
void HandleOnTrade()
{
}
/**
* Handle Timer ...
*/
void HandleOnTimer()
{
}
/**
* Handle Chart Event ...
*
* @param id: int, Event id ...
* @param lparam: long, Event Long Parameter ...
* @param dparam: double, Event Double Parameter ...
* @param sparam: string, Event String Parameter ...
*/
void HandleOnChartEvent(
const int id,
const long &lparam,
const double &dparam,
const string &sparam //
)
{
}
//
// Trade Event Handlers ...
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
//
XCXOM1SignallerBase *signallers[]; // All Registered Signallers ...
};
//
+384
View File
@@ -0,0 +1,384 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class
// -------------------------------------------------
// Name: XCXOM1Signaller ...
// Description: XOM1EA Signaller Class ...
//
//
// 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 XOM1EA Signaller Class"
#property strict
//
// Imports ...
#include "../../Helpers/x-saherelm.xom1.helper.mq5"
#include "../Libraries/xom1ea.lib.mq5"
//
// Definitions ...
//
// All Available Signaller Configurations
// which allow to Decide Based on Zones ...
struct XOM1SignallerConfig
{
//
// Props ...
bool processAllTicks; // Do Process All Ticks ...
//
// Constructor ...
XOM1SignallerConfig() {
Clean();
}
//
// Tools ...
/**
* Cleanup ...
*/
void Clean() {
ZeroMemory(this);
}
};
//
// Implementation ...
//
// Base Signaller Class ...
// Provides Zone Detection Mechanism ...
class XCXOM1SignallerBase
{
//
// Public ...
public:
//
// Props ...
string name; // Name ...
string symbol; // Symbol ...
XOM1Zone zones[]; // Detected Zones ...
XOM1Inputs inputs; // Indicator Inputs ...
ENUM_TIMEFRAMES period; // Period ...
XOM1SignallerConfig config; // Configuration ...
//
// Constructor ...
XCXOM1SignallerBase(
string _name, // Name ...
string _symbol, // Symbol ...
ENUM_TIMEFRAMES _period, // Period ...
XOM1Inputs &_inputs, // Indicator Inputs ...
XOM1SignallerConfig &_config // Config ...
)
{
//
// Validate ...
bool isValid =
IsSpecifiedValid(_name) &&
IsSpecifiedValid(_symbol) &&
IsSpecifiedValid(_period) &&
_inputs.IsValid();
if (!isValid)
{
return;
}
//
// Make Helper Class Instance ...
mHelper = new XCXOM1Helper();
bool isInited = mHelper.Init(
_symbol,
_period,
_inputs //
);
if (!isInited)
{
//
delete mHelper;
ZeroMemory(mHelper);
return;
}
//
// Set Props ...
name = _name;
symbol = _symbol;
period = _period;
inputs = _inputs;
config = _config;
//
// Set Dfault Values ...
mProcessedTicksCount = 0;
mLastCheckedBarTime = NULL;
}
//
// Deconstructor ...
~XCXOM1SignallerBase()
{
//
inputs.Clean();
//
SpecifiedClean(zones);
//
delete mHelper;
ZeroMemory(mHelper);
}
//
// Actions ...
/**
* Handle Ticks Process ...
*
* @param barIndex: int
*/
void ProcessTick(int barIndex = 0)
{
//
// Normalize Bar Index ...
if (barIndex < 0)
{
barIndex = 0;
}
//
// Define Requirements ...
XOHCL iBar;
bool has = false;
bool isNewBar = false;
//
// Get Current Bar Time ...
datetime cBarTime = GetBarTime(
symbol,
period,
barIndex //
);
//
// Validate Bar Time ...
has = IsSpecifiedValid(cBarTime);
if (!has)
{
return;
}
//
// Check if new Bar, Reset Processed Ticks Count ...
isNewBar = cBarTime > mLastCheckedBarTime;
if (isNewBar)
{
//
mProcessedTicksCount = 0;
ProcessNewBar(barIndex);
}
//
// Check Allow Process ...
// Process All Ticks ...
// Process New Bars ...
has = config.processAllTicks ||
(!config.processAllTicks && isNewBar);
if (!has)
{
return;
}
//
// Initialize iBar ...
has = iBar.Init(
symbol,
period,
barIndex //
);
if (!has)
{
//
iBar.Clean();
return;
}
//
// Update Indicator Helper ...
mHelper.Update(barIndex);
//
// Do All Processing Mechanism ...
//
// Reading Conditions from Helper ...
XOM1Conditions iConditions;
has = mHelper.GetConditions(
iConditions,
barIndex //
);
if (!has)
{
//
iBar.Clean();
iConditions.Clean();
return;
}
//
int zIdx = 0;
int cIdx = zIdx++;
int pIdx = cIdx++;
int p2Idx = pIdx++;
//
// Check New Peak or Vale Happens ...
// New Peak Under Last ...
// New Vale Over Last ...
bool isValeReason = iConditions.valeBuffer[cIdx] > iConditions.valeBuffer[pIdx];
bool isPeakReason = iConditions.peakBuffer[cIdx] < iConditions.peakBuffer[pIdx];
has = isValeReason || isPeakReason;
if (!has)
{
//
iBar.Clean();
iConditions.Clean();
return;
}
//
// Prepare Reason ...
ENUM_XOM1_ZONE_REASON iReason = isValeReason
? X_OM1_ZONE_REASON_VALE
: X_OM1_ZONE_REASON_PEAK;
//
// Extract Upper / Lower Values ...
double iUpper = iConditions.peakBuffer[pIdx];
double iLower = iConditions.valeBuffer[pIdx];
//
// Calculate Mid Range ...
double iMiddle = iLower + ((iUpper - iLower) / 2);
if (iMiddle > 0)
{
iMiddle = NormalizePrice(iMiddle, symbol);
}
//
// Detect Reason Price ...
double iPrice =
isValeReason
? iConditions.valeBuffer[cIdx]
: iConditions.peakBuffer[cIdx];
if (iPrice > 0)
{
iPrice = NormalizePrice(iPrice, symbol);
}
//
// Detect Reason Direction ...
ENUM_X_DIRECTION iDir = iPrice > iMiddle
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Try to Initialize Zone ...
XOM1Zone iZone;
has = iZone.Init(
symbol,
period,
name, // Signaller Name ...
iUpper,
iLower,
iPrice,
iDir,
iReason,
iConditions.bars[pIdx].time // From ...
);
if (has)
{
//
// Add New Detected Zone to Zones ...
AddRef(
iZone,
zones //
);
}
//
// Set Last Works ...
mProcessedTicksCount++;
mLastCheckedBarTime = cBarTime;
//
// Clean Resources ...
iBar.Clean();
iZone.Clean();
iConditions.Clean();
}
//
// Virtuals ...
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
//
XCXOM1Helper *mHelper; // Indicator Helper ...
//
int mProcessedTicksCount; // Prcoessed Ticks Count ...
datetime mLastCheckedBarTime; // Last Checked Bar Time ...
/**
* Handle New Bar's Process ...
*
* @param barIndex: int
*/
void ProcessNewBar(int barIndex = 0)
{
//
// Normalize Bar Index ...
if (barIndex < 0)
{
barIndex = 0;
}
//
// Try to Update Zone's Lifetime ...
int count = ArraySize(zones);
bool has = count > 0;
if (has)
{
//
// Loop through Zones ...
for (int i = 0; i < count; i++)
{
//
// Update Lifetime by Bar Index ...
zones[i].UpdateByBarIndex(barIndex);
}
}
}
};
//