From 59a718a1b5c3322f374a1098d74020d9b7166847 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 5 Mar 2026 01:50:37 +0330 Subject: [PATCH 1/2] last ... --- Classes/x-saherelm.x-guard.class.mq5 | 2 +- Classes/x-saherelm.x-restrictions.class.mq5 | 1599 ++++++++++++++++++- Documents/Boards/common.kanban | 125 ++ Documents/Diagrams/TradeModules.drawio | 246 +++ Documents/Docs/XCAccount.md | 0 Documents/Docs/XCAlert.md | 11 + Documents/Docs/XCBaseSignaller.md | 0 Documents/Docs/XCDataCollector.md | 80 + Documents/Docs/XCRestrictions.md | 0 Documents/Docs/XCSessionDetector.md | 0 Documents/Docs/XCTarget.md | 0 Documents/Docs/XCTrade.md | 11 + Documents/Docs/XCTradeManager.md | 0 Documents/Docs/XCVolume.md | 0 Experts/x-saherelm.x-expert.ea.v2.mq5 | 126 +- Libraries/x-saherelm.x-trade.lib.mq5 | 8 +- 16 files changed, 2199 insertions(+), 9 deletions(-) create mode 100644 Documents/Diagrams/TradeModules.drawio create mode 100644 Documents/Docs/XCAccount.md create mode 100644 Documents/Docs/XCAlert.md create mode 100644 Documents/Docs/XCBaseSignaller.md create mode 100644 Documents/Docs/XCDataCollector.md create mode 100644 Documents/Docs/XCRestrictions.md create mode 100644 Documents/Docs/XCSessionDetector.md create mode 100644 Documents/Docs/XCTarget.md create mode 100644 Documents/Docs/XCTrade.md create mode 100644 Documents/Docs/XCTradeManager.md create mode 100644 Documents/Docs/XCVolume.md diff --git a/Classes/x-saherelm.x-guard.class.mq5 b/Classes/x-saherelm.x-guard.class.mq5 index ca2a63fd..5d661526 100644 --- a/Classes/x-saherelm.x-guard.class.mq5 +++ b/Classes/x-saherelm.x-guard.class.mq5 @@ -4,7 +4,7 @@ // ------------------------------------------------- // Name: XCXGuard ... // Description: Guard Provider Class ... -// +// Ued in XCTradeManager ... // // Maintainer: // ------------ diff --git a/Classes/x-saherelm.x-restrictions.class.mq5 b/Classes/x-saherelm.x-restrictions.class.mq5 index 435b2308..8cfbb328 100644 --- a/Classes/x-saherelm.x-restrictions.class.mq5 +++ b/Classes/x-saherelm.x-restrictions.class.mq5 @@ -22,12 +22,11 @@ // // Imports ... #include "../Classes/x-saherelm.base.class.mq5" +#include "../Libraries/x-saherelm.x-trade.lib.mq5" +// #region Definitions ... // -// Definitions ... - -// -// All awailable Restrictions Period ... +// Awailable Restrictions Period ... enum ENUM_X_TRADE_RESTRICTIONS_PERIOD { X_TRADE_RESTRICATION_NONE, // None @@ -37,6 +36,7 @@ enum ENUM_X_TRADE_RESTRICTIONS_PERIOD X_TRADE_RESTRICATION_MONTHLY, // Per Month }; +// #region Extensions ... // // Converts to String ... string ToXString(ENUM_X_TRADE_RESTRICTIONS_PERIOD value) @@ -53,7 +53,7 @@ string ToXString(ENUM_X_TRADE_RESTRICTIONS_PERIOD value) // // Check Has Restrictions or not ... -bool HasRestrictions(ENUM_X_TRADE_RESTRICTIONS_PERIOD value) +bool HasXRestrictions(ENUM_X_TRADE_RESTRICTIONS_PERIOD value) { // bool result = false; @@ -65,6 +65,124 @@ bool HasRestrictions(ENUM_X_TRADE_RESTRICTIONS_PERIOD value) return result; } +/** + * Get Restrictions Period Delay in Seconds ... + * + * @param value: ENUM_X_TRADE_RESTRICTIONS_PERIOD ... + * + * @return ( int ) + */ +int RestrictionsPeriodSeconds(ENUM_X_TRADE_RESTRICTIONS_PERIOD value) +{ + // + int result = 0; + + // + // Check Restrictions is Valid or not ... + if (!HasXRestrictions(value)) + { + return result; + } + + // + switch (value) + { + // + default: + case X_TRADE_RESTRICATION_NONE: + result = 0; + break; + + // + case X_TRADE_RESTRICATION_HOURLY: + result = PeriodSeconds(PERIOD_H1); + break; + + // + case X_TRADE_RESTRICATION_DAILY: + result = PeriodSeconds(PERIOD_D1); + break; + + // + case X_TRADE_RESTRICATION_WEEKLY: + result = PeriodSeconds(PERIOD_W1); + break; + + // + case X_TRADE_RESTRICATION_MONTHLY: + result = PeriodSeconds(PERIOD_MN1); + break; + } + + // + return result; +} + +/** + * Calculate Restrictions End Time ... + * + * @param value: ENUM_X_TRADE_RESTRICTIONS_PERIOD ... + * @param multiplier: int, Restrictions Period Multiplier ... + * @param fromTime: Restrictions Starts Time ... + * + * @return ( datetime ) + */ +datetime RestrictionsEndTime( + ENUM_X_TRADE_RESTRICTIONS_PERIOD value, + int multiplier = 1, + datetime fromTime = NULL // +) +{ + // + datetime result = NULL; + + // + // Normalize Multiplier ... + if (multiplier < 1) + { + multiplier = 1; + } + if (!IsXValid(fromTime)) + { + fromTime = TimeCurrent(); + } + + // + // Calculate Requirements ... + int periodSeconds = RestrictionsPeriodSeconds(value); + int timeInSeconds = (int)fromTime + (periodSeconds * multiplier); + MqlDateTime timeStruct; + bool hasStruct = TimeToStruct( + (datetime)timeInSeconds, + timeStruct // + ); + if (hasStruct) + { + // + timeStruct.min = 0; + timeStruct.sec = 0; + + // + result = StructToTime(timeStruct); + } + else + { + result = (datetime)timeInSeconds; + } + + // + ZeroMemory(timeStruct); + + // + return result; +} +// #endregion + +// #region Event Handler Types ... +typedef void (*TRestrictionEvent)(); +// #endregion +// #endregion + // // Implementation ... class XCRestrictions : public XCBase @@ -72,13 +190,1484 @@ class XCRestrictions : public XCBase // // Public ... public: + // + // Props ... + + // + // Constructor ... + XCRestrictions() + { + // + Clean(); + Default(); + } + + // + // Deconstructor ... + ~XCRestrictions() + { + // + Clean(); + } + + // #region Properties ... + // #region RestrictionsPeriod ... + /** + * Get Restrictions Period ... + * + * @return ( ENUM_X_TRADE_RESTRICTIONS_PERIOD ) + */ + ENUM_X_TRADE_RESTRICTIONS_PERIOD GetRestrictionsPeriod() + { + return mRestrictionsPeriod; + } + + /** + * Get Restrictions Period ... + * + * @param value: ENUM_X_TRADE_RESTRICTIONS_PERIOD + */ + void SetRestrictionsPeriod(ENUM_X_TRADE_RESTRICTIONS_PERIOD value) + { + mRestrictionsPeriod = value; + } + // #endregion + + // #region Restrictions Period Multiplier ... + /** + * Get Restrictions Period Multiplier ... + * + * @return ( int ) + */ + int GetRestrictionsPeriodMultiplier() + { + return mRestrictionsPeriodMultiplier; + } + + /** + * Set Restrictions Period Multiplier ... + * + * @param value: int ... + */ + void SetRestrictionsPeriodMultiplier(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mRestrictionsPeriodMultiplier = value; + } + // #endregion + + // #region Signals ... + /** + * Get Issued Signals ... + * + * @return ( int ) + */ + int GetSignals() + { + return mSignals; + } + + /** + * Get Issued Long Signals ... + * + * @return ( int ) + */ + int GetLongSignals() + { + return mLongSignals; + } + + /** + * Issued Short Signals ... + * + * @return ( int ) + */ + int GetShortSignals() + { + return mShortSignals; + } + + /** + * Get Issued Signals in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedSignals() + { + return mRestrictedSignals; + } + + /** + * Get Issued Long Signals in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedLongSignals() + { + return mRestrictedLongSignals; + } + + /** + * Get Issued Short Signals in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedShortSignals() + { + return mRestrictedShortSignals; + } + + /** + * Get Allowed Signals in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedSignalsInRestrictions() + { + return mAllowedSignalsInRestrictions; + } + + /** + * Set Allowed Signals in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedSignalsInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedSignalsInRestrictions = value; + } + + /** + * Get Allowed Long Signals in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedLongSignalsInRestrictions() + { + return mAllowedLongSignalsInRestrictions; + } + + /** + * Set Allowed Long Signals in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedLongSignalsInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedLongSignalsInRestrictions = value; + } + + /** + * Get Allowed Short Signals in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedShortSignalsInRestrictions() + { + return mAllowedShortSignalsInRestrictions; + } + + /** + * Set Allowed Short Signals in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedShortSignalsInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedShortSignalsInRestrictions = value; + } + // #endregion + + // #region Trades ... + /** + * Executed Trades ... + * + * @return ( int ) + */ + int GetTrades() + { + return mTrades; + } + + /** + * Executed Long Trades ... + * + * @return ( int ) + */ + int GetLongTrades() + { + return mLongTrades; + } + + /** + * Executed Short Trades ... + * + * @return ( int ) + */ + int GetShortTrades() + { + return mShortTrades; + } + + /** + * Executed Trades in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedTrades() + { + return mRestrictedTrades; + } + + /** + * Executed Long Trades in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedLongTrades() + { + return mRestrictedLongTrades; + } + + /** + * Executed Short Trades in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedShortTrades() + { + return mRestrictedShortTrades; + } + + /** + * Get Allowed Trades in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedTradesInRestrictions() + { + return mAllowedTradesInRestrictions; + } + + /** + * Set Allowed Trades in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedTradesInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedTradesInRestrictions = value; + } + + /** + * Get Allowed Long Trades in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedLongTradesInRestrictions() + { + return mAllowedLongTradesInRestrictions; + } + + /** + * Set Allowed Long Trades in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedLongTradesInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedLongTradesInRestrictions = value; + } + + /** + * Get Allowed Short Trades in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedShortTradesInRestrictions() + { + return mAllowedShortTradesInRestrictions; + } + + /** + * Set Allowed Short Trades in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedShortTradesInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedShortTradesInRestrictions = value; + } + // #endregion + + // #region Wins ... + /** + * Touched Wins ... + * + * @return ( int ) + */ + int GetWins() + { + return mWins; + } + + /** + * Touched Long Wins ... + * + * @return ( int ) + */ + int GetLongWins() + { + return mLongWins; + } + + /** + * Touched Short Wins ... + * + * @return ( int ) + */ + int GetShortWins() + { + return mShortWins; + } + + /** + * Touched Wins in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedWins() + { + return mRestrictedWins; + } + + /** + * Touched Long Wins in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedLongWins() + { + return mRestrictedLongWins; + } + + /** + * Touched Short Wins in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedShortWins() + { + return mRestrictedShortWins; + } + + /** + * Get Allowed Wins in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedWinsInRestrictions() + { + return mAllowedWinsInRestrictions; + } + + /** + * Set Allowed Wins in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedWinsInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedWinsInRestrictions = value; + } + + /** + * Get Allowed Long Wins in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedLongWinsInRestrictions() + { + return mAllowedLongWinsInRestrictions; + } + + /** + * Set Allowed Long Wins in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedLongWinsInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedLongWinsInRestrictions = value; + } + + /** + * Get Allowed Short Wins in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedShortWinsInRestrictions() + { + return mAllowedShortWinsInRestrictions; + } + + /** + * Set Allowed Short Wins in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedShortWinsInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedShortWinsInRestrictions = value; + } + // #endregion + + // #region Losess ... + /** + * Touched Loses ... + * + * @return ( int ) + */ + int GetLoses() + { + return mLoses; + } + + /** + * Touched Long Loses ... + * + * @return ( int ) + */ + int GetLongLoses() + { + return mLongLoses; + } + + /** + * Touched Short Loses ... + * + * @return ( int ) + */ + int GetShortLoses() + { + return mShortLoses; + } + + /** + * Touched Loses in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedLoses() + { + return mRestrictedLoses; + } + + /** + * Touched Long Loses in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedLongLoses() + { + return mRestrictedLongLoses; + } + + /** + * Touched Short Loses in Restrictions Period ... + * + * @return ( int ) + */ + int GetRestrictedShortLoses() + { + return mRestrictedShortLoses; + } + + /** + * Get Allowed Loses in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedLosesInRestrictions() + { + return mAllowedLosesInRestrictions; + } + + /** + * Set Allowed Loses in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedLosesInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedLosesInRestrictions = value; + } + + /** + * Get Allowed Long Loses in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedLongLosesInRestrictions() + { + return mAllowedLongLosesInRestrictions; + } + + /** + * Set Allowed Long Loses in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedLongLosesInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedLongLosesInRestrictions = value; + } + + /** + * Get Allowed Short Loses in Restrictions Period ... + * + * @return ( int ) + */ + int GetAllowedShortLosesInRestrictions() + { + return mAllowedShortLosesInRestrictions; + } + + /** + * Set Allowed Short Loses in Restrictions Period ... + * + * @param value: int ... + */ + void SetAllowedShortLosesInRestrictions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mAllowedShortLosesInRestrictions = value; + } + // #endregion + + // #region Current Restrictions ... + /** + * Get Current Restrictions End Time ... + * + * @return ( datetime ) + */ + datetime GetCurrentRestrictionsEnd() + { + return mRestrictionsEnd; + } + + /** + * Get Current Restrictions Start Time ... + * + * @return ( datetime ) + */ + datetime GetCurrentRestrictionsStart() + { + return mRestrictionsStart; + } + // #endregion + // #endregion + + // #region Tools ... + /** + * Check Restrictions Exists or not ... + * + * @return ( bool ) + */ + bool HasRestrictions() + { + // + bool result = false; + + // + result = + HasXRestrictions(mRestrictionsPeriod); + + // + return result; + } + + /** + * Handle Signal Issued ... + * + * @param signal: XSignal ... + */ + void HandleSignal(XSignal &signal) + { + // + if (!signal.IsValid()) + { + return; + } + + // + bool isLong = IsLong(signal.type); + + // + mSignals++; + + // + if (isLong) + { + mLongSignals++; + } + else + { + mShortSignals++; + } + + // + if (HasRestrictions()) + { + // + mRestrictedSignals++; + + // + if (isLong) + { + mRestrictedLongSignals++; + } + else + { + mRestrictedShortSignals++; + } + } + } + + /** + * Handle Signal Execution ... + * + * @param signal: XSignal ... + */ + void HandleTrade(XSignal &signal) + { + // + if (!signal.IsValid()) + { + return; + } + bool isLong = IsLong(signal.type); + + // + mTrades++; + + // + if (isLong) + { + mLongTrades++; + } + else + { + mShortTrades++; + } + + // + if (HasRestrictions()) + { + // + mRestrictedTrades++; + + // + if (isLong) + { + mRestrictedLongTrades++; + } + else + { + mRestrictedShortTrades++; + } + } + } + + /** + * Handle Trade Win ... + * + * @param type: ENUM_X_POSITION_TYPES ... + */ + void HandleTradeWin(ENUM_X_POSITION_TYPES type) + { + // + if (!IsXValid(type)) + { + return; + } + bool isLong = IsLong(type); + + // + mWins++; + + // + if (isLong) + { + mLongWins++; + } + else + { + mShortWins++; + } + + // + if (HasRestrictions()) + { + // + mRestrictedWins++; + + // + if (isLong) + { + mRestrictedLongWins++; + } + else + { + mRestrictedShortWins++; + } + } + } + + /** + * Handle Trade Lose ... + * + * @param type: ENUM_X_POSITION_TYPES ... + */ + void HandleTradeLose(ENUM_X_POSITION_TYPES type) + { + // + if (!IsXValid(type)) + { + return; + } + bool isLong = IsLong(type); + + // + mLoses++; + + // + if (isLong) + { + mLongLoses++; + } + else + { + mShortLoses++; + } + + // + if (HasRestrictions()) + { + // + mRestrictedLoses++; + + // + if (isLong) + { + mRestrictedLongLoses++; + } + else + { + mRestrictedShortLoses++; + } + } + } + + /** + * Check Allow Issue Signal or not ... + * + * @param signal: XSignal ... + * + * @return ( bool ) + */ + bool CheckAllowIssueSignal(XSignal &signal) + { + // + bool result = false; + + // + // Validate Signal ... + result = signal.IsValid(); + if (!result) + { + return result; + } + bool isLong = IsLong(signal.type); + + // + // Check if Restrictions Exists ... + if (!HasRestrictions()) + { + return result; + } + + // + // Check Signal Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedSignalsInRestrictions)) + { + // + result = + result && + mRestrictedLongSignals < mAllowedSignalsInRestrictions; + } + } + + // + // Check Long Signal Restrictions ... + if (result) + { + // + if (isLong && + IsValidSize(mAllowedLongSignalsInRestrictions)) + { + // + result = + result && + mRestrictedLongSignals < mAllowedLongSignalsInRestrictions; + } + } + + // + // Check Short Signal Restrictions ... + if (result) + { + // + if (!isLong && + IsValidSize(mAllowedShortSignalsInRestrictions)) + { + // + result = + result && + mRestrictedShortSignals < mAllowedShortSignalsInRestrictions; + } + } + + // + return result; + } + + /** + * Check Allow Issue Signal or not ... + * + * @param signal: XSignal ... + * + * @return ( bool ) + */ + int CheckAllowExecuteSignal(XSignal &signal) + { + // + bool result = false; + + // + // Validate Signal ... + result = signal.IsValid(); + if (!result) + { + return result; + } + bool isLong = IsLong(signal.type); + + // + // Check if Restrictions Exists ... + if (!HasRestrictions()) + { + return result; + } + + // + // Check Trade Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedTradesInRestrictions)) + { + // + result = + result && + mRestrictedTrades < mAllowedTradesInRestrictions; + } + } + + // + // Check Long Trade Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedLongTradesInRestrictions)) + { + // + result = + result && + mRestrictedLongTrades < mAllowedLongTradesInRestrictions; + } + } + + // + // Check Short Trade Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedShortTradesInRestrictions)) + { + // + result = + result && + mRestrictedShortTrades < mAllowedShortTradesInRestrictions; + } + } + + // + // Check Wins Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedWinsInRestrictions)) + { + // + result = + result && + mRestrictedWins < mAllowedWinsInRestrictions; + } + } + + // + // Check Long Wins Restriction ... + if (result) + { + // + if (IsValidSize(mAllowedLongWinsInRestrictions)) + { + // + result = + result && + mRestrictedLongWins < mAllowedLongWinsInRestrictions; + } + } + + // + // Check Short Wins Restriction ... + if (result) + { + // + if (IsValidSize(mAllowedShortWinsInRestrictions)) + { + // + result = + result && + mRestrictedShortWins < mAllowedShortWinsInRestrictions; + } + } + + // + // Check Lose Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedLosesInRestrictions)) + { + // + result = + result && + mRestrictedLoses < mAllowedLosesInRestrictions; + } + } + + // + // Check Long Lose Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedLongLosesInRestrictions)) + { + // + result = + result && + mRestrictedLongLoses < mAllowedLongLosesInRestrictions; + } + } + + // + // Check Short Lose Restrictions ... + if (result) + { + // + if (IsValidSize(mAllowedShortLosesInRestrictions)) + { + // + result = + result && + mRestrictedShortLoses < mAllowedShortLosesInRestrictions; + } + } + + // + return result; + } + // #endregion + + // #region Event Handlers Registrations ... + /** + * Register Restrictions Start Event Handler ... + * + * @param handler: TRestrictionEvent ... + */ + void AddRestrictionsStartEventHandler(TRestrictionEvent handler) + { + // + if (handler == NULL) + { + return; + } + + // + Add(handler, mOnRestrictionsStartEventHandlers); + } + + /** + * Register Restrictions End Event Handler ... + * + * @param handler: TRestrictionEvent ... + */ + void AddRestrictionsEndEventHandler(TRestrictionEvent handler) + { + // + if (handler == NULL) + { + return; + } + + // + Add(handler, mOnRestrictionsEndEventHandlers); + } + // #endregion + + /** + * Process Ticks for Restrictions ... + * Applied Eac Secconds ... + */ + void Process() + { + // + // Check Restrictions Exists or not ... + if (!HasRestrictions()) + { + return; + } + + // + // Calculate Requirements ... + datetime currentTime = TimeCurrent(); + + // + // Check Current Restrictions Exists or not ... + // Initial Restrictions Period if not Exists ... + if (!IsXValid(mRestrictionsStart)) + { + // + // Initial Restrictions ... + mRestrictionsStart = currentTime; + mRestrictionsEnd = RestrictionsEndTime( + mRestrictionsPeriod, + mRestrictionsPeriodMultiplier, + mRestrictionsStart // + ); + + // + // Loging Restrictions Start ... + LogRestrictionsStart(); + + // + // Notfy Restrictions Start Event Handlers ... + NotifyRestrictionsStartEventHandlers(); + + // + return; + } + + // + // Validate Current Restrictions ... + + // + // Check Process Exists or not ... + if (IsXValid(mLastCheck)) + { + // + // Validate New Check Must Happens after 1 Minute ... + bool canCheck = currentTime >= mLastCheck + 60; + if (!canCheck) + { + return; + } + } + + // + // Update Last Check ... + mLastCheck = currentTime; + + // + // Check Restrictions End ... + bool isEnded = currentTime >= mRestrictionsEnd; + if (isEnded) + { + // + // Fire Restrictions End Event Handlers ... + NotifyRestrictionsEndEventHandlers(); + + // + // Logging Resrtrictions Summary if Required ... + LogRestrictionsEnd(); + + // + // Reset Restrictions ... + ResetRestrictions(); + + // + return; + } + + // + // TODO: Implement What we want if necessary ... + } + // // Protected ... protected: + // + // Props ... + + /** + * Cleanup ... + */ + void Clean() + { + // + mAllowedWinsInRestrictions = 0; + mAllowedLongWinsInRestrictions = 0; + mAllowedShortWinsInRestrictions = 0; + + // + mAllowedLosesInRestrictions = 0; + mAllowedLongLosesInRestrictions = 0; + mAllowedShortLosesInRestrictions = 0; + + // + mAllowedSignalsInRestrictions = 0; + mAllowedLongSignalsInRestrictions = 0; + mAllowedShortSignalsInRestrictions = 0; + + // + mAllowedTradesInRestrictions = 0; + mAllowedLongTradesInRestrictions = 0; + mAllowedShortTradesInRestrictions = 0; + + // + ResetRestrictions(); + XClean(mOnRestrictionsEndEventHandlers); + XClean(mOnRestrictionsStartEventHandlers); + } + + /** + * Set Default Values ... + */ + void Default() + { + // + mRestrictionsPeriodMultiplier = 1; + mRestrictionsPeriod = X_TRADE_RESTRICATION_NONE; + } + + /** + * Logging Restrictions Start Summary ... + */ + void LogRestrictionsStart() + { + } + + /** + * Logging Restrictions End Summary ... + */ + void LogRestrictionsEnd() + { + } + + // #region Event Handlers Notifier ... + /** + * Notify Registered Restrictions Start Event Handlers ... + */ + void NotifyRestrictionsStartEventHandlers() + { + // + int count = ArraySize(mOnRestrictionsStartEventHandlers); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + mOnRestrictionsStartEventHandlers[i](); + } + } + + /** + * Notify Registered Restrictions End Event Handlers ... + */ + void NotifyRestrictionsEndEventHandlers() + { + // + int count = ArraySize(mOnRestrictionsEndEventHandlers); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + mOnRestrictionsEndEventHandlers[i](); + } + } + // #endregion + + // #region Restrictions Summary Cleaners ... + /** + * Reset all Restricted Counters ... + */ + void ResetRestrictions() + { + // + mRestrictionsEnd = NULL; + mRestrictionsStart = NULL; + + // + ResetTradeRestrictions(); + ResetSignalRestrictions(); + ResetTradeWinRestrictions(); + ResetTradeLoseRestrictions(); + } + + /** + * Resetting Signal Restrictions ... + */ + void ResetSignalRestrictions() + { + // + mRestrictedSignals = 0; + mRestrictedLongSignals = 0; + mRestrictedShortSignals = 0; + } + + /** + * Resetting Trade Restrictions ... + */ + void ResetTradeRestrictions() + { + // + mRestrictedTrades = 0; + mRestrictedLongTrades = 0; + mRestrictedShortTrades = 0; + } + + /** + * Resetting Trade Win Restrictions ... + */ + void ResetTradeWinRestrictions() + { + mWins = 0; + mLongWins = 0; + mShortWins = 0; + } + + /** + * Resetting Trade Lose Restrictions ... + */ + void ResetTradeLoseRestrictions() + { + // + mLoses = 0; + mLongLoses = 0; + mShortLoses = 0; + } + // #endregion ... + // // Private ... private: // + // Props ... + + // + // Last Restrictions Time ... + datetime mLastCheck; // Last Restrictions Check ... + datetime mRestrictionsEnd; // Last Restrictions End Time ... + datetime mRestrictionsStart; // Last Restrictions Start Time ... + + // + // Restrictions Period ... + int mRestrictionsPeriodMultiplier; // Restrictions Period Multiplier ... + ENUM_X_TRADE_RESTRICTIONS_PERIOD mRestrictionsPeriod; // Restrictions Period ... + + // #region Signals ... + // + int mSignals; // Issued Signals ... + int mLongSignals; // Issued Long Signals ... + int mShortSignals; // Issued Short Signals ... + + // + int mRestrictedSignals; // Issued Signals in Restrictions Period ... + int mRestrictedLongSignals; // Issued Long Signals in Restrictions Period ... + int mRestrictedShortSignals; // Issued Short Signals in Restrictions Period ... + + // + int mAllowedSignalsInRestrictions; // Allowed Signals in Restrictions Period ... + int mAllowedLongSignalsInRestrictions; // Allowed Long Signals in Restrictions Period ... + int mAllowedShortSignalsInRestrictions; // Allowed Short Signals in Restrictions Period ... + // #endregion + + // #region Trades ... + // + int mTrades; // Executed Trades ... + int mLongTrades; // Executed Long Trades ... + int mShortTrades; // Executed Short Trades ... + + // + int mRestrictedTrades; // Executed Trades in Restrictions Period ... + int mRestrictedLongTrades; // Executed Long Trades in Restrictions Period ... + int mRestrictedShortTrades; // Executed Short Trades in Restrictions Period ... + + // + int mAllowedTradesInRestrictions; // Allowed Trades in Restrictions Period ... + int mAllowedLongTradesInRestrictions; // Allowed Long Trades in Restrictions Period ... + int mAllowedShortTradesInRestrictions; // Allowed Short Trades in Restrictions Period ... + // #endregion + + // #region Wins ... + // + int mWins; // Touched Wins ... + int mLongWins; // Touched Long Wins ... + int mShortWins; // Touched Short Wins ... + + // + int mRestrictedWins; // Touched Wins in Restrictions Period ... + int mRestrictedLongWins; // Touched Long Wins in Restrictions Period ... + int mRestrictedShortWins; // Touched Short Wins in Restrictions Period ... + + // + int mAllowedWinsInRestrictions; // Allowed Wins in Restrictions Period ... + int mAllowedLongWinsInRestrictions; // Allowed Long Wins in Restrictions Period ... + int mAllowedShortWinsInRestrictions; // Allowed Short Wins in Restrictions Period ... + // #endregion + + // #region Losess ... + // + int mLoses; // Touched Loses ... + int mLongLoses; // Touched Long Loses ... + int mShortLoses; // Touched Short Loses ... + + // + int mRestrictedLoses; // Touched Loses in Restrictions Period ... + int mRestrictedLongLoses; // Touched Long Loses in Restrictions Period ... + int mRestrictedShortLoses; // Touched Short Loses in Restrictions Period ... + + // + int mAllowedLosesInRestrictions; // Allowed Loses in Restrictions Period ... + int mAllowedLongLosesInRestrictions; // Allowed Long Loses in Restrictions Period ... + int mAllowedShortLosesInRestrictions; // Allowed Short Loses in Restrictions Period ... + // #endregion + + // #region Event Handlers ... + TRestrictionEvent mOnRestrictionsEndEventHandlers[]; // Restrictions End Event Handlers ... + TRestrictionEvent mOnRestrictionsStartEventHandlers[]; // Restrictions Start Event Hnadlers ... + // #endregion }; // \ No newline at end of file diff --git a/Documents/Boards/common.kanban b/Documents/Boards/common.kanban index 4e55e272..dc803bb5 100644 --- a/Documents/Boards/common.kanban +++ b/Documents/Boards/common.kanban @@ -27,6 +27,86 @@ "labels": [], "checkboxes": [], "comments": [] + }, + { + "id": "17260152-05db-4ae2-9d26-cd3d9ee75863", + "listId": "43249367-151b-4e78-bea5-b3c3f41b60ab", + "title": "Make Each Modules Separately and Attach Process on Each them ...", + "description": "there are several modules, documents them one by one and make all of them as runnable standalone ...", + "labels": [], + "checkboxes": [ + { + "id": "2f40c757-baa3-40b1-a804-853c78fae93e", + "title": "XCAlert", + "checked": false + }, + { + "id": "03287c82-52da-4084-be05-9ddead05f3c2", + "title": "XCTrade", + "checked": false + }, + { + "id": "cbf27d79-5cab-4b10-b48c-e9317a6c7dff", + "title": "XCSessionDetector", + "checked": false + }, + { + "id": "68f70f06-d649-48d3-8050-6024d1f6b0b3", + "title": "XCAccount", + "checked": false + }, + { + "id": "ab337067-5b35-475e-a16e-48de97a79452", + "title": "XCVolume", + "checked": false + }, + { + "id": "f618df8d-5d6c-4b4d-a6e1-b2f550a77509", + "title": "XCDataCollector", + "checked": false + }, + { + "id": "9aea1e42-e9c9-4efd-85a8-3930335011b4", + "title": "XCRestrictions", + "checked": false + }, + { + "id": "7e08c5e9-74f6-40c6-9a81-b60503d5a625", + "title": "XCBaseSignaller", + "checked": false + }, + { + "id": "cfcc6686-0b3c-48e7-80f6-d3485f7ad717", + "title": "XCTarget", + "checked": false + }, + { + "id": "40a72aea-865d-48b5-a48b-fe9972e8152d", + "title": "XCTradeManager", + "checked": false + } + ], + "comments": [] + }, + { + "id": "05e10aba-f8b4-485c-9c79-bcfb4a58e80b", + "listId": "43249367-151b-4e78-bea5-b3c3f41b60ab", + "title": "Document XCAlert", + "description": "XCAlert is a Module for Alerting Tools Enabling.\nin this task we have to complete it's Documentations and then also we have to complete XCDataCollector and make it Usable.", + "labels": [], + "checkboxes": [ + { + "id": "888d7a95-44c3-4388-9446-8e5d78a0a0d1", + "title": "add Log Saving Methods", + "checked": false + }, + { + "id": "38bfd420-21fb-436a-abc6-7239da6559ae", + "title": "add Support for Per File Logging", + "checked": false + } + ], + "comments": [] } ] }, @@ -34,6 +114,26 @@ "id": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", "title": "Test", "cards": [ + { + "id": "e487c35e-b69d-41b4-bdae-ef8502ecc1dc", + "listId": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", + "title": "Document XCDataCollector", + "description": "since DataCollector is a most commonly used Module in other Modules as Dependency, it is very important to make them completely documented and also add required Features to it.", + "labels": [], + "checkboxes": [ + { + "id": "3357aca6-1906-44e2-8c9c-1c8d3b576f43", + "title": "Add Suppoprt for CSV Read and Writing", + "checked": true + } + ], + "comments": [ + { + "id": "4e454ff4-88d3-41ea-b5d7-0d7cbf70c660", + "comment": "CSV since implemented based on Custom Specified Structures. this module provides all requirements implemented." + } + ] + }, { "id": "5549ff02-ce37-476f-9d91-ed190ca15e90", "listId": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", @@ -51,6 +151,31 @@ "labels": [], "checkboxes": [], "comments": [] + }, + { + "id": "504383b7-0a6d-4c78-afe4-be3cf59ed2bd", + "listId": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", + "title": "Complete Restrictions Class ...", + "description": "", + "labels": [], + "checkboxes": [ + { + "id": "7e422b9e-e5f4-4ea7-ab6e-b2225b8d9a67", + "title": "add multiple symbol support", + "checked": true + }, + { + "id": "65f6807b-f664-4e30-be27-06799032f16e", + "title": "add mutiple tf support", + "checked": true + }, + { + "id": "c8a8c345-7dc2-48c8-bc04-11ccf221493f", + "title": "implement Process function", + "checked": true + } + ], + "comments": [] } ] }, diff --git a/Documents/Diagrams/TradeModules.drawio b/Documents/Diagrams/TradeModules.drawio new file mode 100644 index 00000000..ee7a19d1 --- /dev/null +++ b/Documents/Diagrams/TradeModules.drawio @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Documents/Docs/XCAccount.md b/Documents/Docs/XCAccount.md new file mode 100644 index 00000000..e69de29b diff --git a/Documents/Docs/XCAlert.md b/Documents/Docs/XCAlert.md new file mode 100644 index 00000000..d9fa75fa --- /dev/null +++ b/Documents/Docs/XCAlert.md @@ -0,0 +1,11 @@ +# XCAlert + +it is a module which used for Providing Logs in SaherElm's XTrade Framework. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) diff --git a/Documents/Docs/XCBaseSignaller.md b/Documents/Docs/XCBaseSignaller.md new file mode 100644 index 00000000..e69de29b diff --git a/Documents/Docs/XCDataCollector.md b/Documents/Docs/XCDataCollector.md new file mode 100644 index 00000000..384cd166 --- /dev/null +++ b/Documents/Docs/XCDataCollector.md @@ -0,0 +1,80 @@ +# XCDataCollector + +it is a module which used for Save and Retrieve Data in SaherElm's XTrade Framework. +this tool helps all required modules to save data for next usage and analytics. +we can implement Save To File and Read From File actions to all Structures and Classes and Modules. + +## Dependencies + +there is no Dependencies on this modules. + +## Instancing + +there is not any args in Constructor. + +## Instructions + +- using Path Action of instance for Setting File Path; +- using Save, Append, Read for File Manipulations; + +## Actions + +### Path + +is aProperty Setter and Getter Action for Setting Collector Path. +for setter it's have an input Parameters (string value) which Specified the File's Path. + +### GetFilePath(string fileName) + +retrieve Full path (including provided file name) based on Current Configured Path for instance. + +### GetFileHandlerForWrite(string filePath) + +retrieve File Handler by Write Access for Writing Data to File. +you have to provide Fully File Path for access Handler. +this for Use Implementing Custom Collecting Senarios out of Instance Box. +commonly it's used by built in Actions for Regular Saving Data. + +### GetFileHandlerForRead(string filePath) + +retrieve File Handler by Read Access for Reading Data from File. +you have to provide Fully File Path for access Handler. +this for Use Implementing Custom Retrieving Senarios out of Instance Box. +commonly it's used by built in Actions for Regular Reading Data. + +### Save(string fileName, string content) + +Save Specified Content to Specified File Nmae. +here the file name must Contains fully file path including file name. +it's only one time writing file. if it's file exists before overwrite it's content. + +### Append(string fileName, string content) + +Append Specified Contonet to end of Specified File. +here the file name must Contains fully file path including file name. +if file Exists, add to end of it. if not, Create file at Specified Provided path, then write content. + +### Read(string fileName, string &content) + +Read all of File Content at once from Specified File. +here the file name must Contains fully file path including file name. +content arg is a reference string variable to hold file content. + +### Read(string fileName, string &content[]) + +Read all of File Content Lines at once from Specified File. +here the file name must Contains fully file path including file name. +content arg is a reference string array variable to hold file content lines. + +### IsExists(string fileName) + +Check Specified File Exists or not ... +here the file name must Contains fully file path including file name. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) diff --git a/Documents/Docs/XCRestrictions.md b/Documents/Docs/XCRestrictions.md new file mode 100644 index 00000000..e69de29b diff --git a/Documents/Docs/XCSessionDetector.md b/Documents/Docs/XCSessionDetector.md new file mode 100644 index 00000000..e69de29b diff --git a/Documents/Docs/XCTarget.md b/Documents/Docs/XCTarget.md new file mode 100644 index 00000000..e69de29b diff --git a/Documents/Docs/XCTrade.md b/Documents/Docs/XCTrade.md new file mode 100644 index 00000000..03ff4c6f --- /dev/null +++ b/Documents/Docs/XCTrade.md @@ -0,0 +1,11 @@ +# XCTrade + +it is a module which used for Providing Trade Related Actions in SaherElm's XTrade Framework. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) diff --git a/Documents/Docs/XCTradeManager.md b/Documents/Docs/XCTradeManager.md new file mode 100644 index 00000000..e69de29b diff --git a/Documents/Docs/XCVolume.md b/Documents/Docs/XCVolume.md new file mode 100644 index 00000000..e69de29b diff --git a/Experts/x-saherelm.x-expert.ea.v2.mq5 b/Experts/x-saherelm.x-expert.ea.v2.mq5 index 835b5f3f..e5511268 100644 --- a/Experts/x-saherelm.x-expert.ea.v2.mq5 +++ b/Experts/x-saherelm.x-expert.ea.v2.mq5 @@ -25,6 +25,7 @@ #include "../Classes/x-saherelm.x-alert.class.mq5" #include "../Classes/x-saherelm.x-chart.helper.class.mq5" #include "../Classes/x-saherelm.x-guard.class.mq5" +#include "../Classes/x-saherelm.x-restrictions.class.mq5" #include "../Classes/x-saherelm.x-target.class.mq5" #include "../Classes/x-saherelm.x-trade-manager.class.mq5" #include "../Classes/x-saherelm.x-trade.class.mq5" @@ -90,11 +91,19 @@ input bool eaSaveLosts = true; // Save Lost Conditions input bool eaSaveRestrictions = true; // Save Restriction Reports // #endregion +// #region Configurable Documents ... +bool eaEnableAnalysis = true; // Most Important Flag for Enable Analysis in EA ... +bool processTicksOnlyOnNewBars = false; // Processing Ticks only on new Bars ... +ENUM_X_SESSION_TYPE eaAllowedSessions[]; // Allowed Sessions for Analysis ... +ENUM_X_SESSION_OVERLAP_TYPE eaAllowedOverlaps[]; // Allowed Overlaps for Analysis ... +// #endregion + // #region Global Variables ... #define ShortName "XSessionDetectorTestEA" // -string eaTag; // EA Scoped Tag ... +string eaTag; // EA Scoped Tag ... +bool isNewBar = false; // EA Is New Bar ... // XCAlert *eaAlert; // EA Scope Alert Handler ... @@ -102,7 +111,9 @@ XCGuard *eaGuard; // EA Scope Guard Handler ... XCTrade *eaTrader; // EA Scope Trade Handler ... XCVolume *eaVolume; // EA Scope Voluem Handler ... XCTarget *eaTarget; // EA Scope Target Handler ... +XBarTracker eaBarTracker; // EA Scope Bar Tracker ... XTimeTracker eaTimeTracker; // EA Scope Time Tracker ... +XCRestrictions *eaRestrictions; // EA Scope Restrictions Handler ... XCTradeManager *eaTradeManager; // EA Scope Trade Manager Handler ... XCSessionDetector *eaSessionDetector; // EA Scope Session Detector ... // #endregion @@ -131,6 +142,10 @@ int OnInit() return INIT_FAILED; } + // + // Configure Dynamic Variables ... + ConfigureEA(); + // result = InitializeRequirements(); if (!result) @@ -150,6 +165,35 @@ void OnTick() // // Perform Session Detector Process ... eaSessionDetector.Process(); + + // + // Perform Restrictions Process ... + eaRestrictions.Process(); + + // + // Check if Is New Bar ... + isNewBar = eaBarTracker.IsNewBar(); + + // + // Check Analysis Enabled ... + if (eaEnableAnalysis) + { + // + // Check Bar Tracker ... + if (processTicksOnlyOnNewBars) + { + // + // Check New Bar or not ... + if (!isNewBar) + { + return; + } + } + + // + // Do Analysis ... + // TODO: Implement this ... + } } /** @@ -157,6 +201,9 @@ void OnTick() */ void OnTrade() { + // + // Calling Event Handler ... + eaTrader.HandleOnTrade(); } /** @@ -202,6 +249,7 @@ void OnDeinit(const int reason) ZeroMemory(eaVolume); ZeroMemory(eaTarget); ZeroMemory(eaTradeManager); + ZeroMemory(eaRestrictions); ZeroMemory(eaSessionDetector); } @@ -273,6 +321,32 @@ bool ValidateInputs() return result; } +/** + * Configure EA Commons ... + */ +void ConfigureEA() +{ + // + // Configure Sessions ... + + // + // Configure Overlaps ... + Add( + X_OVERLAP_LONDON_NEWYORK, + eaAllowedOverlaps // + ); + + // + // Startup eaAnalysis State ... + int sessionsCount = ArraySize(eaAllowedSessions); + int overlapsCount = ArraySize(eaAllowedOverlaps); + + // + eaEnableAnalysis = + !IsValidSize(sessionsCount) && + !IsValidSize(overlapsCount); +} + /** * Initial Requirements of EA ... * @@ -291,6 +365,17 @@ bool InitializeRequirements() : "") + ShortName; + // #region Initializing Bar Tracker ... + result = eaBarTracker.Init( + _Symbol, + _Period // + ); + if (!result) + { + return result; + } + // #endregion + // #region Alert ... eaAlert = new XCAlert(); eaAlert.SetPrefix(eaLogSuffix); @@ -415,6 +500,23 @@ bool InitializeRequirements() ); // #endregion + // #region Restrictions Handler ... + eaRestrictions = new XCRestrictions(); + + // + // Configure Restrictions ... + // TODO: Refactor Restrictions Configurations as Input ... + eaRestrictions.SetAllowedLosesInRestrictions(2); + eaRestrictions.SetAllowedTradesInRestrictions(2); + eaRestrictions.SetRestrictionsPeriodMultiplier(2); + eaRestrictions.SetRestrictionsPeriod(X_TRADE_RESTRICATION_DAILY); + + // + // Register Event Handlers ... + eaRestrictions.AddRestrictionsEndEventHandler(OnRestrictionsEnd); + eaRestrictions.AddRestrictionsStartEventHandler(OnRestrictionsStart); + // #endregion + // result = eaSessionDetector != NULL; if (!result) @@ -518,7 +620,11 @@ void OnOverlapStartHandler( datetime startTime // ) { + // Print("Overlap Started: ", EnumToString(overlap), " at ", TimeToString(startTime)); + + // + // Check Over lap Exists in eaSession Everlaps ... } /** @@ -643,6 +749,24 @@ void OnPositionPartialClosed( void OnTradeStateChanged(const XOnTradeHandlerState &state) { } + +/** + * Handle Restrictions Start Event ... + * XCRestrictions ... + */ +void OnRestrictionsStart() +{ + Print("Restrictions Start ..."); +} + +/** + * Handle Restrictions End Event ... + * XCRestrictions ... + */ +void OnRestrictionsEnd() +{ + Print("Restrictions End ..."); +} // #endregion // \ No newline at end of file diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index 57e740cf..dcb5aa19 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -156,6 +156,10 @@ bool IsValid(ENUM_X_POSITION_TYPES value) { return value != X_POSITION_TYPE_NONE; } +bool IsXValid(ENUM_X_POSITION_TYPES value) +{ + return IsValid(value); +} // bool HasSpecifiedType(ENUM_X_POSITION_TYPES value) @@ -4688,8 +4692,8 @@ bool IsProviderFilterPassed( // return !IsValid(provider) ? true - : provider == item.provider || - Contains(provider, item.provider); + : provider == item.provider || + Contains(provider, item.provider); } // From 75e1abd2580ba22ce5c173edc47d3ad8b4358626 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 14 Mar 2026 08:26:58 +0330 Subject: [PATCH 2/2] last ... --- Classes/x-saherelm.x-alert.class.mq5 | 64 +++-- Documents/Boards/common.kanban | 66 +++-- Documents/Diagrams/TradeModules.drawio | 337 ++++++++++++++++++++++++- Documents/Docs/XCAccount.md | 136 ++++++++++ Documents/Docs/XCAlert.md | 132 ++++++++++ Documents/Docs/XCDataCollector.md | 2 +- Documents/Docs/XCVolume.md | 25 ++ 7 files changed, 724 insertions(+), 38 deletions(-) diff --git a/Classes/x-saherelm.x-alert.class.mq5 b/Classes/x-saherelm.x-alert.class.mq5 index 4c06900e..c918a562 100644 --- a/Classes/x-saherelm.x-alert.class.mq5 +++ b/Classes/x-saherelm.x-alert.class.mq5 @@ -86,9 +86,7 @@ class XCAlert : public XCBase return GetSpecificToken(this); } - // - // Properties Getter(s) / Setter(s) ... - + // #region Properties Getter(s) / Setter(s) ... // string GetPrefix() { @@ -174,16 +172,16 @@ class XCAlert : public XCBase { mTerminalAlerts = value; } + // #endregion - // - // Tools Funtions ... + // #region Tools Funtions ... // // Alerts ... // // Logging an Alert ... - void LogAlert(string message) + void LogAlert(string message, bool save = true) { // // Validate Args ... @@ -194,15 +192,20 @@ class XCAlert : public XCBase // message = PrepareMessage(message); - + // Log(message); - Save(message); + + // + if (save) + { + Save(message); + } } // // Terminal Alert ... - void TerminalAlert(string message) + void TerminalAlert(string message, bool save = true) { // // Validate Args ... @@ -217,12 +220,17 @@ class XCAlert : public XCBase // Send Terminal Alert ... Alert(message); - Save(message); + + // + if (save) + { + Save(message); + } } // // Mail Alert ... - void MailAlert(string message) + void MailAlert(string message, bool save = true) { // // Validate Args ... @@ -234,12 +242,17 @@ class XCAlert : public XCBase // // Send Mail Alert ... SendMail(GetPrefix(), message); - Save(message); + + // + if (save) + { + Save(message); + } } // // Send Push Notification ... - void PushAlert(string message) + void PushAlert(string message, bool save = true) { // // Validate Args ... @@ -255,7 +268,12 @@ class XCAlert : public XCBase // // Send Push Notification Alert ... SendNotification(message); - Save(message); + + // + if (save) + { + Save(message); + } } // @@ -265,19 +283,25 @@ class XCAlert : public XCBase { // // Handle Log, if Enabled ... - LogAlert(message); + LogAlert(message, false); // // Handle Mail if Enabled ... - MailAlert(message); + MailAlert(message, false); // // Handle Push if Enabled ... - PushAlert(message); + PushAlert(message, false); // // Handle Terminal if Enabled ... - TerminalAlert(message); + TerminalAlert(message, false); + + // + if (GetEnableAlerts()) + { + Save(message); + } } // @@ -1314,6 +1338,7 @@ class XCAlert : public XCBase // return result; } + // #endregion // // Protected ... @@ -1380,7 +1405,8 @@ class XCAlert : public XCBase } // - string filePath = collector.GetFilePath("XLogs"); + string fileName = mPrefix + "." + "XLogs"; + string filePath = collector.GetFilePath(fileName); if (!IsValid(filePath)) { return; diff --git a/Documents/Boards/common.kanban b/Documents/Boards/common.kanban index dc803bb5..69aaf323 100644 --- a/Documents/Boards/common.kanban +++ b/Documents/Boards/common.kanban @@ -38,7 +38,7 @@ { "id": "2f40c757-baa3-40b1-a804-853c78fae93e", "title": "XCAlert", - "checked": false + "checked": true }, { "id": "03287c82-52da-4084-be05-9ddead05f3c2", @@ -63,7 +63,7 @@ { "id": "f618df8d-5d6c-4b4d-a6e1-b2f550a77509", "title": "XCDataCollector", - "checked": false + "checked": true }, { "id": "9aea1e42-e9c9-4efd-85a8-3930335011b4", @@ -89,23 +89,21 @@ "comments": [] }, { - "id": "05e10aba-f8b4-485c-9c79-bcfb4a58e80b", + "id": "1d9c0541-80fe-4acf-856b-285236628756", "listId": "43249367-151b-4e78-bea5-b3c3f41b60ab", - "title": "Document XCAlert", - "description": "XCAlert is a Module for Alerting Tools Enabling.\nin this task we have to complete it's Documentations and then also we have to complete XCDataCollector and make it Usable.", + "title": "Document XCTrade", + "description": "Document XTrade Class and it's Implementations and also do Refactoring if required.", "labels": [], - "checkboxes": [ - { - "id": "888d7a95-44c3-4388-9446-8e5d78a0a0d1", - "title": "add Log Saving Methods", - "checked": false - }, - { - "id": "38bfd420-21fb-436a-abc6-7239da6559ae", - "title": "add Support for Per File Logging", - "checked": false - } - ], + "checkboxes": [], + "comments": [] + }, + { + "id": "bbe1f927-0744-4f27-a960-89078338ae2b", + "listId": "43249367-151b-4e78-bea5-b3c3f41b60ab", + "title": "Document XCVolume", + "description": "Document XCVolume as a Base Modules which works Stand alone.\n", + "labels": [], + "checkboxes": [], "comments": [] } ] @@ -114,6 +112,15 @@ "id": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", "title": "Test", "cards": [ + { + "id": "e1e98f40-ac5f-495a-ac8e-eccff3a204e7", + "listId": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", + "title": "Document XCAccount", + "description": "Since XCAccount is a Base Class which used in other Modules, we have to Document.\n", + "labels": [], + "checkboxes": [], + "comments": [] + }, { "id": "e487c35e-b69d-41b4-bdae-ef8502ecc1dc", "listId": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", @@ -134,6 +141,31 @@ } ] }, + { + "id": "05e10aba-f8b4-485c-9c79-bcfb4a58e80b", + "listId": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", + "title": "Document XCAlert", + "description": "XCAlert is a Module for Alerting Tools Enabling.\nin this task we have to complete it's Documentations and then also we have to complete XCDataCollector and make it Usable.", + "labels": [], + "checkboxes": [ + { + "id": "888d7a95-44c3-4388-9446-8e5d78a0a0d1", + "title": "add Log Saving Methods", + "checked": true + }, + { + "id": "38bfd420-21fb-436a-abc6-7239da6559ae", + "title": "add Support for Per File Logging", + "checked": true + } + ], + "comments": [ + { + "id": "6c821cac-1457-4df7-af20-61fa00f6bb55", + "comment": "apply some fix and Prevent Double Saving Log Messages, and also add Prefix as XLog file name instancing ..." + } + ] + }, { "id": "5549ff02-ce37-476f-9d91-ed190ca15e90", "listId": "0c9df632-b6cd-4d3f-9c08-fbe7010ecc4e", diff --git a/Documents/Diagrams/TradeModules.drawio b/Documents/Diagrams/TradeModules.drawio index ee7a19d1..fc473edc 100644 --- a/Documents/Diagrams/TradeModules.drawio +++ b/Documents/Diagrams/TradeModules.drawio @@ -1,6 +1,6 @@ - + @@ -19,6 +19,23 @@ + + + + + + + + + + + + + + + + + @@ -240,6 +257,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documents/Docs/XCAccount.md b/Documents/Docs/XCAccount.md index e69de29b..e7c18763 100644 --- a/Documents/Docs/XCAccount.md +++ b/Documents/Docs/XCAccount.md @@ -0,0 +1,136 @@ +# XCAccount + +it is a module which used for Accoess Trading Account Data in SaherElm's XTrade Framework. + +## Dependencies + +there is no Dependencies on this modules. + +## Instancing + +there is not any args in Constructor. + +## Instructions + +use provided Actions for Access Account informations in where you need. + +## Actions + +### long GetUserAccount() + +retrieve Current User Identifier. + +### long GetLeverage() + +retrieve Current Account Leverage. + +### bool CanExpertTrade() + +retrieve Flag which Specified Trading using Experts or Manual. + +### ENUM_ACCOUNT_TRADE_MODE GetTradeMode() + +retrieve Current Account Trading Mode. + +- ACCOUNT_TRADE_MODE_DEMO; +- ACCOUNT_TRADE_MODE_CONTEST; +- ACCOUNT_TRADE_MODE_REAL; + +### double GetBalance() + +retrieve Current Account Balance. + +### double GetCredit() + +retrieve Current Account Credit. + +### double GetProfit() + +retrieve Current Account's Amount of Profits. + +### double GetEquity() + +retrieve Current Account's Amount of Equity. + +### double GetMargin() + +retrieve Current Account's Amount of Margin. + +### double GetFreeMargin() + +retrieve Current Account's Amount of Free Margin. + +### double GetMarginLevel() + +retrieve Current Account's Margin Level. + +### double GetMarginCall() + +retrieve Current Account's Margin Call Level. + +### double GetMarginStopOut() + +retrieve Current Account's Margin Stopout Level. + +### string GetName() + +retrieve Current Account's User Name. + +### string GetServerName() + +retrieve Current Account's Server Name. + +### string GetCurrency() + +retrieve Current Account's Currency. + +### string GetCompany() + +retrieve Current Account's Market Name. + +### double CalculateTradeProfit(const string symbol, ENUM_ORDER_TYPE type, double volume, double entry, double exit) + +Calculate and Retrieved Trade Profit based on Account Currency. + +### double CalculateMarging(const string symbol, ENUM_ORDER_TYPE type, double volume, double entry) + +Calculate and Retrieved Specified Trades used Marigin. + +### double CalculateFreeMarging(const string symbol, ENUM_ORDER_TYPE type, double volume, double entry) + +Calculate and Retrieved Specified Trades Free Marigin. + +### double CalculateMaxVolume(const string symbol, ENUM_ORDER_TYPE type, double entry, double percent = 100) + +Calculate Max Allowed Specified Trade's Volume for Entry. + +### double GetPointValue(string symbol) + +Retrieve Specified Symbol's Point Value. + +### double CalculateRiskAmount(string symbol, double points, double volume) + +Calculate How many Risk Currency in a Trade when risk Points and Trade Volume is Specified. +used when we have to know how many risk in $ Currency, for a Trade when we risk 100 Point, by Providing 0.01 Lot as Volume. + +### double CalculateRiskPoints(string symbol, double volume, double amount) + +Calculate Risk Points in a Trade when Volume and Curreny Amount is Specified. +used when we want to know How many points risk in a Trade when we have to risk 5$ in a Trade by 0.01 Lot as Volume. + +### double CalculateVolume(string symbol, double amount, double points) + +Calculate Trade Volume when Risk Amount in Currency and Risk Amount in Points Specified. +used when we want to know Open a Trade by how Size of Volume when we have to risk 5$ in a Trade when 100 points risking. + +### string GetBalanceReportMessage() + +Prepare and Retrieve Balance Report Message for Current Account. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) diff --git a/Documents/Docs/XCAlert.md b/Documents/Docs/XCAlert.md index d9fa75fa..6b7316f2 100644 --- a/Documents/Docs/XCAlert.md +++ b/Documents/Docs/XCAlert.md @@ -2,6 +2,138 @@ it is a module which used for Providing Logs in SaherElm's XTrade Framework. +## Dependencies + +this Module used XCDataCollector for Saving Logs in Files. + +## Instancing + +using this syntax for instancing : + +```mql5 +XCAlert( + string prefix = "X-Alert", // Alerts Prefixe + 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 + bool saveAlerts = false // Save Alerts +) {} +``` + +all of Constructor Input args is Optional, means have default values. +you can set them after instancing using Properties Setter/Getter (s). + +## Instructions + +- Prefix: string, Specified Logger Prefix. this for Separate Different Logger Instances. +- EnableAlerts: boolean, Specified Logging is Enabled or not. +- SaveAlerts: boolean, Specified Saving Log(s) or not. +- LogAlerts: boolean, Specified Can Print Logs on Console or not. +- TerminalAlerts: boolean, Specified Send Logs in Terminal or not. +- MailAlerts: boolean, Specified Send Logs as Mail or not. +- PushAlerts: boolean, Specified Send Logs as Push or not. + +## Actions + +### LogAlert(string message) + +do specified type of Logs. +do log by Print in Console. + +### TerminalAlert(string message) + +do specified type of Logs. +do log by sending Terminal Alert. + +### MailAlert(string message) + +do specified type of Logs. +do log by sending Mail Alert. + +### PushAlert(string message) + +do specified type of Logs. +do log by sending Push Notification Alert. + +### SendAlert(string message) + +do sending log by configuration. +retrieve log and based on configuration send each specified enabled logs separately. + +### Log(string message) + +Checking Log Flag and Print Message. + +### Log(string tag, string message) + +Checking Log Flag and Print Specified Tag & Message. + +### LogEmpty() + +Checking Log Flag and Print Empty Message. + +### LogArray(T &array[], string label = NULL) + +Checking Log Flag and Print Array. + +### LogError(int error = -1) + +Checking Log Flag and then Generate Error Message based on provided error number, +then Print Tag Specified Message. + +### string GetErrorDescription(int err_code) + +Generate Specified Error Messaged based on Provided error code. + +### string GetTradeServerReturnCodeDescription(int return_code) + +Generate Specified Error Message based on Provided server error code. + +### bool CanLog() + +protected +return a Flag for Specified Flag which allowed Print Logs or not. + +### bool CanLogAlert() + +protected +return a Flag for Specified Flag which allowed Print Logs and also Enabled or not. + +### bool CanTerminalAlert() + +protected +return a Flag for Specified Flag which allowed Sending Logs to Terminal and also Enabled or not. + +### bool CanMailAlert() + +protected +return a Flag for Specified Flag which allowed Sending Logs as Mail and also Enabled or not. + +### bool CanPushAlert() + +protected +return a Flag for Speified Flag which allowed Sending Logs as Push and also Enabled or not. + +### Save(string message) + +protected +Saving Specified Message into Logger File. if alert Saving is Enabled. + +#### Descriptions + +- Preparing a File Name by Combining setted Prefix + ".XLogs". +- Generating File Path based on XCDataCollector instance Path. +- Validate Generated filePath. +- Preparing Log Message for Saving in Log File by attaching Current Time. +- Append prepared Message to Log File using XCDataCollector instance. + +### string PrepareMessage(string message) + +private +Replace Escaped strings and Attach Prefix to Message. + ## Maintainer Hadi Khazaee asl diff --git a/Documents/Docs/XCDataCollector.md b/Documents/Docs/XCDataCollector.md index 384cd166..314b2b3d 100644 --- a/Documents/Docs/XCDataCollector.md +++ b/Documents/Docs/XCDataCollector.md @@ -21,7 +21,7 @@ there is not any args in Constructor. ### Path -is aProperty Setter and Getter Action for Setting Collector Path. +is a Property Setter and Getter Action for Setting Collector Path. for setter it's have an input Parameters (string value) which Specified the File's Path. ### GetFilePath(string fileName) diff --git a/Documents/Docs/XCVolume.md b/Documents/Docs/XCVolume.md index e69de29b..369d6604 100644 --- a/Documents/Docs/XCVolume.md +++ b/Documents/Docs/XCVolume.md @@ -0,0 +1,25 @@ +# XCVolume + +it is a module which used for Accoess Trading Account Data in SaherElm's XTrade Framework. + +## Dependencies + +there is no Dependencies on this modules. + +## Instancing + +there is not any args in Constructor. + +## Instructions + +use provided Actions for Access Account informations in where you need. + +## Actions + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com)