diff --git a/Classes/x-saherelm.x121.setup.xea.mq5 b/Classes/x-saherelm.x121.setup.xea.mq5 index d4fd1711..bf9b4309 100644 --- a/Classes/x-saherelm.x121.setup.xea.mq5 +++ b/Classes/x-saherelm.x121.setup.xea.mq5 @@ -32,35 +32,37 @@ // // Model all Trades Data as this Structure ... -struct XTradeInfo { +struct XTradeInfo +{ // - int pushers; // Signal Pushers - datetime time; // Issue Time (Open Position) - string symbol; // Trading Symbol - double entry; // Entry Price - double volume; // Volume - string provider; // Signaller - ENUM_TIMEFRAMES period; // Trading Timeframe - ENUM_X_POSITION_TYPES type; // Position Type + int pushers; // Signal Pushers + datetime time; // Issue Time (Open Position) + string symbol; // Trading Symbol + double entry; // Entry Price + double volume; // Volume + string provider; // Signaller + ENUM_TIMEFRAMES period; // Trading Timeframe + ENUM_X_POSITION_TYPES type; // Position Type // - ulong ticket; // Position Ticket - double profit; // Profit on Close - double commission; // Commission - double swap; // Swap - string message; // Close Reason - datetime endTime; // End Time + ulong ticket; // Position Ticket + double profit; // Profit on Close + double commission; // Commission + double swap; // Swap + string message; // Close Reason + datetime endTime; // End Time // - X121SetupConditions cConditions; // Generated Current Conditions - X121SetupConditions sConditions; // Generated Short Conditions - X121SetupConditions mConditions; // Generated Medium Conditions - X121SetupConditions lConditions; // Generated Long Conditions - X121SetupConditions hConditions; // Generated Hind Conditions + X121SetupConditions cConditions; // Generated Current Conditions + X121SetupConditions sConditions; // Generated Short Conditions + X121SetupConditions mConditions; // Generated Medium Conditions + X121SetupConditions lConditions; // Generated Long Conditions + X121SetupConditions hConditions; // Generated Hind Conditions // // Constructor ... - void XTradeInfo() { + void XTradeInfo() + { Clean(); } @@ -69,23 +71,24 @@ struct XTradeInfo { // // Cleanup ... - void Clean() { + void Clean() + { // - time = NULL; - type = NULL; - symbol = NULL; - period = NULL; - endTime = NULL; - message = NULL; + time = NULL; + type = NULL; + symbol = NULL; + period = NULL; + endTime = NULL; + message = NULL; provider = NULL; // - swap = 0; - entry = 0; - ticket = 0; - profit = 0; - volume = 0; - pushers = 0; + swap = 0; + entry = 0; + ticket = 0; + profit = 0; + volume = 0; + pushers = 0; commission = 0; // @@ -103,17 +106,18 @@ struct XTradeInfo { // bool Fill( - const XSignal &_signal, - int _pushers, - bool _allowGrid, - bool _allowRecover, - bool _allowSupport, + const XSignal &_signal, + int _pushers, + bool _allowGrid, + bool _allowRecover, + bool _allowSupport, X121SetupConditions &_cConditions, X121SetupConditions &_sConditions, X121SetupConditions &_mConditions, X121SetupConditions &_lConditions, - X121SetupConditions &_hConditions // - ) { + X121SetupConditions &_hConditions // + ) + { // bool result = false; @@ -127,19 +131,20 @@ struct XTradeInfo { ; // - if(!result) { + if (!result) + { return result; } // - pushers = _pushers; - time = _signal.time; - entry = _signal.entry; - symbol = _signal.symbol; - period = _signal.period; - volume = _signal.volume; + pushers = _pushers; + time = _signal.time; + entry = _signal.entry; + symbol = _signal.symbol; + period = _signal.period; + volume = _signal.volume; provider = _signal.provider; - type = ToPositionType(_signal.type); + type = ToPositionType(_signal.type); // cConditions = _cConditions; @@ -149,7 +154,7 @@ struct XTradeInfo { hConditions = _hConditions; // - allowGrid = _allowGrid; + allowGrid = _allowGrid; allowRecover = _allowRecover; allowSupport = _allowSupport; @@ -159,8 +164,9 @@ struct XTradeInfo { // bool IsOwn( - ulong _ticket // - ) { + ulong _ticket // + ) + { // bool result = false; @@ -173,10 +179,11 @@ struct XTradeInfo { // bool IsOwn( - string _symbol, - string _provider, - ENUM_TIMEFRAMES _period // - ) { + string _symbol, + string _provider, + ENUM_TIMEFRAMES _period // + ) + { // bool result = false; @@ -201,7 +208,8 @@ struct XTradeInfo { // Data Collector ... // - bool IsValid() { + bool IsValid() + { // bool result = false; @@ -220,15 +228,17 @@ struct XTradeInfo { } // - int GetAge() { + int GetAge() + { // int result = -1; // - if(!IsValid(symbol) || - !IsValid(time) || - !IsValid(endTime) || - !IsValid(period)) { + if (!IsValid(symbol) || + !IsValid(time) || + !IsValid(endTime) || + !IsValid(period)) + { return result; } @@ -237,7 +247,7 @@ struct XTradeInfo { symbol, period, time, - false // + false // ); // @@ -245,7 +255,7 @@ struct XTradeInfo { symbol, period, endTime, - false // + false // ); // @@ -256,12 +266,14 @@ struct XTradeInfo { } // - string GetFileName() { + string GetFileName() + { // string result = NULL; // - if(!IsValid()) { + if (!IsValid()) + { return result; } @@ -284,7 +296,8 @@ struct XTradeInfo { } // - string GetSignalFileName() { + string GetSignalFileName() + { // string result = NULL; @@ -304,46 +317,47 @@ struct XTradeInfo { // string ToString( - bool onlySignals = false // - ) { + bool onlySignals = false // + ) + { // string result = NULL; // string cConditionsStr = cConditions .GenerateSummary( - false, // Only Commons ... - true, // Only Conditions ... - false, // Include Score ... - false // Include False Conditions ... + false, // Only Commons ... + true, // Only Conditions ... + false, // Include Score ... + false // Include False Conditions ... ); string sConditionsStr = sConditions .GenerateSummary( - false, // Only Commons ... - true, // Only Conditions ... - false, // Include Score ... - false // Include False Conditions ... + false, // Only Commons ... + true, // Only Conditions ... + false, // Include Score ... + false // Include False Conditions ... ); string mConditionsStr = mConditions .GenerateSummary( - false, // Only Commons ... - true, // Only Conditions ... - false, // Include Score ... - false // Include False Conditions ... + false, // Only Commons ... + true, // Only Conditions ... + false, // Include Score ... + false // Include False Conditions ... ); string lConditionsStr = lConditions .GenerateSummary( - false, // Only Commons ... - true, // Only Conditions ... - false, // Include Score ... - false // Include False Conditions ... + false, // Only Commons ... + true, // Only Conditions ... + false, // Include Score ... + false // Include False Conditions ... ); string hConditionsStr = hConditions .GenerateSummary( - false, // Only Commons ... - true, // Only Conditions ... - false, // Include Score ... - false // Include False Conditions ... + false, // Only Commons ... + true, // Only Conditions ... + false, // Include Score ... + false // Include False Conditions ... ); // @@ -401,18 +415,20 @@ struct XTradeInfo { // Supporting ... // - bool allowSupport; // Allow Support + bool allowSupport; // Allow Support // - void ResetSupport() { + void ResetSupport() + { allowSupport = false; } // // Retrieve Support Signal ... bool HasSupport( - XSignal &support // - ) { + XSignal &support // + ) + { // bool result = false; @@ -424,16 +440,17 @@ struct XTradeInfo { // Grid System Calculations ... // - int gLevel; // Number of Grids - bool allowGrid; // Allow Grid - double gEntry; // Represents Next Grid Signal's Entry - double gVolume; // Represent Next Grid Signal's Volume + int gLevel; // Number of Grids + bool allowGrid; // Allow Grid + double gEntry; // Represents Next Grid Signal's Entry + double gVolume; // Represent Next Grid Signal's Volume // - void ResetGrid() { + void ResetGrid() + { // - gEntry = 0; - gLevel = 0; + gEntry = 0; + gLevel = 0; gVolume = 0; // @@ -443,10 +460,11 @@ struct XTradeInfo { // void SetGrid( double nextEntry, - double nextVolume // - ) { + double nextVolume // + ) + { // - gEntry = nextEntry; + gEntry = nextEntry; gVolume = nextVolume; } @@ -454,8 +472,9 @@ struct XTradeInfo { // Prepare Data For Next Grid ... void PrepareNextGrid( double distance, - double volumeMultiplier // - ) { + double volumeMultiplier // + ) + { // bool isValid = // @@ -471,7 +490,7 @@ struct XTradeInfo { // double distancePrice = PointToPrice( distance, - symbol // + symbol // ); // @@ -488,7 +507,7 @@ struct XTradeInfo { // SetGrid( nextEntry, - nextVolume // + nextVolume // ); } @@ -496,10 +515,11 @@ struct XTradeInfo { // Check if a Grid Signal Exists Prepared and // Provide it ... bool HasGrid( - XSignal &signal, // Result Signal - double distance, - double volumeMultiplier // - ) { + XSignal &signal, // Result Signal + double distance, + double volumeMultiplier // + ) + { // bool result = false; @@ -510,7 +530,8 @@ struct XTradeInfo { result = IsValid() && distance > 0 && volumeMultiplier > 0; - if(!result) { + if (!result) + { return result; } @@ -524,13 +545,14 @@ struct XTradeInfo { // double cEntry = GetEntry( symbol, - gType // + gType // ); // result = isLong ? cEntry <= gEntry : cEntry >= gEntry; - if(!result) { + if (!result) + { return result; } @@ -543,12 +565,13 @@ struct XTradeInfo { X_ORDER_MODE_MARKET, cEntry, gVolume, - 0, // SL ... - 0 // TP ... + 0, // SL ... + 0 // TP ... ); // - if(result) { + if (result) + { // // set Support Token ... string comment = GenerateSupportTag(ticket); @@ -557,7 +580,7 @@ struct XTradeInfo { // PrepareNextGrid( distance, - volumeMultiplier // + volumeMultiplier // ); // @@ -572,23 +595,24 @@ struct XTradeInfo { // Recovery Zone System ... // - bool allowRecover; // Allow Recover - ENUM_POSITION_TYPE rLastRecoveryType; // Last Executed Recovery Signal's Type - double rLongEntry; // Represent Next Recovery Long Signal's Entry - double rShortEntry; // Represent Next Recovery Short Signal's Entry - double rVolume; // Represent Next Recovery Signal's Volume - double rZoneUpper; // Zone Recovery Upper Bound - double rZoneLower; // Zone Recovery Lower Bound - int rLevel; // Number of Recoveries + bool allowRecover; // Allow Recover + ENUM_POSITION_TYPE rLastRecoveryType; // Last Executed Recovery Signal's Type + double rLongEntry; // Represent Next Recovery Long Signal's Entry + double rShortEntry; // Represent Next Recovery Short Signal's Entry + double rVolume; // Represent Next Recovery Signal's Volume + double rZoneUpper; // Zone Recovery Upper Bound + double rZoneLower; // Zone Recovery Lower Bound + int rLevel; // Number of Recoveries // - void ResetRecovery() { + void ResetRecovery() + { // - rLevel = 0; - rVolume = 0; - rLongEntry = 0; - rZoneUpper = 0; - rZoneLower = 0; + rLevel = 0; + rVolume = 0; + rLongEntry = 0; + rZoneUpper = 0; + rZoneLower = 0; rShortEntry = 0; // @@ -601,22 +625,24 @@ struct XTradeInfo { double nextShortEntry, double zoneUpper, double zoneLower, - double nextVolume // - ) { + double nextVolume // + ) + { // - rVolume = nextVolume; - rZoneUpper = zoneUpper; - rZoneLower = zoneLower; - rLongEntry = nextLongEntry; + rVolume = nextVolume; + rZoneUpper = zoneUpper; + rZoneLower = zoneLower; + rLongEntry = nextLongEntry; rShortEntry = nextShortEntry; } // void PrepareNextRecovery( - double distance, // Define Target Based On Zones - double volumeMultiplier, // Volume Multiplier - ENUM_POSITION_TYPE lastType // Last Type - ) { + double distance, // Define Target Based On Zones + double volumeMultiplier, // Volume Multiplier + ENUM_POSITION_TYPE lastType // Last Type + ) + { // bool isValid = // @@ -634,13 +660,13 @@ struct XTradeInfo { // double distancePrice = PointToPrice( distance, - symbol // + symbol // ); // double selectedEntry = - isLong ? rLongEntry <= 0 ? entry : rLongEntry : rShortEntry <= 0 ? entry : - rShortEntry; + isLong ? rLongEntry <= 0 ? entry : rLongEntry : rShortEntry <= 0 ? entry + : rShortEntry; double selectedVolume = rVolume <= 0 ? volume : rVolume; @@ -658,11 +684,11 @@ struct XTradeInfo { // double zoneUpper = - rZoneUpper > 0 ? rZoneUpper : isLong ? entry + distancePrice : - entry + (distancePrice * 2); + rZoneUpper > 0 ? rZoneUpper : isLong ? entry + distancePrice + : entry + (distancePrice * 2); double zoneLower = - rZoneLower > 0 ? rZoneLower : isLong ? entry + (distancePrice * 2) : - entry - distancePrice; + rZoneLower > 0 ? rZoneLower : isLong ? entry + (distancePrice * 2) + : entry - distancePrice; // SetRecovery( @@ -670,7 +696,7 @@ struct XTradeInfo { nextShortEntry, zoneUpper, zoneLower, - nextVolume // + nextVolume // ); // @@ -681,10 +707,11 @@ struct XTradeInfo { // Check if a Recovery Signal Exists Prepared and // Provide it ... bool HasRecovery( - XSignal &signal, // Result Signal ... - double distance, - double volumeMultiplier // - ) { + XSignal &signal, // Result Signal ... + double distance, + double volumeMultiplier // + ) + { // bool result = false; @@ -701,25 +728,26 @@ struct XTradeInfo { volumeMultiplier > 0 // ; - if(!result) { + if (!result) + { return result; } // double distancePrice = PointToPrice( distance, - symbol // + symbol // ); // - bool isLong = IsLong(type); + bool isLong = IsLong(type); bool isLastLong = IsLong(rLastRecoveryType); // // Check For Long Recovery ... double cLongEntry = GetEntry( symbol, - POSITION_TYPE_BUY // + POSITION_TYPE_BUY // ); bool hasLongRecovery = !isLastLong && @@ -729,7 +757,7 @@ struct XTradeInfo { // Check For Short Recovery ... double cShortEntry = GetEntry( symbol, - POSITION_TYPE_SELL // + POSITION_TYPE_SELL // ); bool hasShortRecovery = isLastLong && @@ -738,7 +766,8 @@ struct XTradeInfo { // result = hasLongRecovery || hasShortRecovery; - if(!result) { + if (!result) + { return result; } @@ -767,10 +796,11 @@ struct XTradeInfo { X_ORDER_MODE_MARKET, rEntry, rVolume, - 0, // rSL, // SL ... - 0 // rTP // TP ... + 0, // rSL, // SL ... + 0 // rTP // TP ... ); - if(result) { + if (result) + { // // set Support Token ... string comment = GenerateSupportTag(ticket); @@ -783,7 +813,7 @@ struct XTradeInfo { PrepareNextRecovery( distance, volumeMultiplier, - rType // + rType // ); } @@ -794,25 +824,30 @@ struct XTradeInfo { // // a Class For Read and Write Trade Info Data in Files ... -class XTradeInfoCollector { +class XTradeInfoCollector +{ // // Public ... - public: +public: // // Props ... // // Constructor(s) ... void XTradeInfoCollector( - string _path = NULL // Base Path - ) { + string _path = NULL // Base Path + ) + { // mAccount = new XSCAccount(); // - if(IsValid(_path)) { + if (IsValid(_path)) + { mPath = _path; - } else { + } + else + { mPath = "XTradeInfo" + "\\" + mAccount.GetCompany(); } } @@ -822,13 +857,14 @@ class XTradeInfoCollector { void ~XTradeInfoCollector() {} // - bool IsExists(XTradeInfo &item) { + bool IsExists(XTradeInfo &item) + { // bool result = false; // int mHandler = GetFileHandlerForRead(item); - result = mHandler != INVALID_HANDLE; + result = mHandler != INVALID_HANDLE; FileClose(mHandler); // @@ -836,28 +872,32 @@ class XTradeInfoCollector { } // - bool Save(XTradeInfo &item) { + bool Save(XTradeInfo &item) + { // bool result = false; // // Check info is Valid ... result = item.IsValid(); - if(!result) { + if (!result) + { return result; } // string content = item.ToString(); - result = IsValid(content); - if(!result) { + result = IsValid(content); + if (!result) + { return result; } // int mHandler = GetFileHandlerForWrite(item); - result = mHandler != INVALID_HANDLE; - if(!result) { + result = mHandler != INVALID_HANDLE; + if (!result) + { return result; } @@ -871,21 +911,24 @@ class XTradeInfoCollector { } // - bool SaveSignal(XTradeInfo &item) { + bool SaveSignal(XTradeInfo &item) + { // bool result = false; // string content = item.ToString(); - result = IsValid(content); - if(!result) { + result = IsValid(content); + if (!result) + { return result; } // int mHandler = GetSignalFileHandlerForWrite(item); - result = mHandler != INVALID_HANDLE; - if(!result) { + result = mHandler != INVALID_HANDLE; + if (!result) + { return result; } @@ -900,28 +943,30 @@ class XTradeInfoCollector { // // Protected ... - protected: +protected: // // Private ... - private: +private: // // Props ... // - string mPath; // Base Path ... + string mPath; // Base Path ... // XSCAccount *mAccount; // - string GetFilePath(XTradeInfo &item) { + string GetFilePath(XTradeInfo &item) + { // string fileName = item.GetFileName(); // return GetFilePath(fileName); } - string GetFilePath(string fileName) { + string GetFilePath(string fileName) + { // string result = ""; @@ -937,14 +982,16 @@ class XTradeInfoCollector { } // - string GetSignalFilePath(XTradeInfo &item) { + string GetSignalFilePath(XTradeInfo &item) + { // string fileName = item.GetSignalFileName(); // return GetSignalFilePath(fileName); } - string GetSignalFilePath(string fileName) { + string GetSignalFilePath(string fileName) + { // string result = ""; @@ -960,39 +1007,43 @@ class XTradeInfoCollector { } // - int GetFileHandlerForRead(XTradeInfo &item) { + int GetFileHandlerForRead(XTradeInfo &item) + { // int result = INVALID_HANDLE; // string filePath = GetFilePath(item); - if(!IsValid(filePath)) { + if (!IsValid(filePath)) + { return result; } // result = FileOpen( filePath, - FILE_READ | FILE_TXT // + FILE_READ | FILE_TXT // ); // return result; } - int GetFileHandlerForWrite(XTradeInfo &item) { + int GetFileHandlerForWrite(XTradeInfo &item) + { // int result = INVALID_HANDLE; // string filePath = GetFilePath(item); - if(!IsValid(filePath)) { + if (!IsValid(filePath)) + { return result; } // result = FileOpen( filePath, - FILE_READ | FILE_WRITE | FILE_TXT // + FILE_READ | FILE_WRITE | FILE_TXT // ); // @@ -1000,39 +1051,43 @@ class XTradeInfoCollector { } // - int GetSignalFileHandlerForRead(XTradeInfo &item) { + int GetSignalFileHandlerForRead(XTradeInfo &item) + { // int result = INVALID_HANDLE; // string filePath = GetSignalFilePath(item); - if(!IsValid(filePath)) { + if (!IsValid(filePath)) + { return result; } // result = FileOpen( filePath, - FILE_READ | FILE_TXT // + FILE_READ | FILE_TXT // ); // return result; } - int GetSignalFileHandlerForWrite(XTradeInfo &item) { + int GetSignalFileHandlerForWrite(XTradeInfo &item) + { // int result = INVALID_HANDLE; // string filePath = GetSignalFilePath(item); - if(!IsValid(filePath)) { + if (!IsValid(filePath)) + { return result; } // result = FileOpen( filePath, - FILE_READ | FILE_WRITE | FILE_TXT // + FILE_READ | FILE_WRITE | FILE_TXT // ); // @@ -1048,21 +1103,23 @@ class XTradeInfoCollector { // - Conditions; // - Scores; // - etc ... -class XTradeHandler { +class XTradeHandler +{ // - public: +public: // // Props ... // // Constructor ... void XTradeHandler( - XSCTrade *trade // an Instance of Trader Class - ) { + XSCTrade *trade // an Instance of Trader Class + ) + { // Clean(data); SetSave(false); - mTrader = trade; + mTrader = trade; collector = new XTradeInfoCollector(); } @@ -1073,22 +1130,26 @@ class XTradeHandler { // Others ... // - bool GetSave() { + bool GetSave() + { return mSave; } // - void SetSave(bool value) { + void SetSave(bool value) + { mSave = value; } // - bool GetSaveSignalsOnly() { + bool GetSaveSignalsOnly() + { return mSaveSignalsOnly; } // - void SetSaveSignalsOnly(bool value) { + void SetSaveSignalsOnly(bool value) + { mSaveSignalsOnly = value; } @@ -1096,14 +1157,17 @@ class XTradeHandler { // Hedging ... // - double MinProfitPerTrade() { + double MinProfitPerTrade() + { return mMinProfitPerTrade; } // - void MinProfitPerTrade(double value) { + void MinProfitPerTrade(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1112,19 +1176,23 @@ class XTradeHandler { } // - double MinProfitPerVolumeFactor() { + double MinProfitPerVolumeFactor() + { return mMinProfitPerVolumeFactor; } // - void MinProfitPerVolumeFactor(double value) { + void MinProfitPerVolumeFactor(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } // - if(value > 0 && value < 0.01) { + if (value > 0 && value < 0.01) + { value = 0.01; } @@ -1136,34 +1204,41 @@ class XTradeHandler { // Trailling Stop ... // - bool AllowTrailStop() { + bool AllowTrailStop() + { return mAllowTrailStop; } // - void AllowTrailStop(bool value) { + void AllowTrailStop(bool value) + { mAllowTrailStop = value; } // - bool DisableTrailingWhenOpposit() { + bool DisableTrailingWhenOpposit() + { return mDisableTrailingWhenOpposit; } // - void DisableTrailingWhenOpposit(bool value) { + void DisableTrailingWhenOpposit(bool value) + { mDisableTrailingWhenOpposit = value; } // - double NextTrailPoint() { + double NextTrailPoint() + { return mNextTrailPoint; } // - void NextTrailPoint(double value) { + void NextTrailPoint(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1172,14 +1247,17 @@ class XTradeHandler { } // - double FirstTrailPoint() { + double FirstTrailPoint() + { return mFirstTrailPoint; } // - void FirstTrailPoint(double value) { + void FirstTrailPoint(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1188,14 +1266,17 @@ class XTradeHandler { } // - double NextTrailDistance() { + double NextTrailDistance() + { return mNextTrailDistance; } // - void NextTrailDistance(double value) { + void NextTrailDistance(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1204,14 +1285,17 @@ class XTradeHandler { } // - double FirstTrailDistance() { + double FirstTrailDistance() + { return mFirstTrailDistance; } // - void FirstTrailDistance(double value) { + void FirstTrailDistance(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1220,7 +1304,8 @@ class XTradeHandler { } // - bool EnableTrailling() { + bool EnableTrailling() + { // bool result = false; @@ -1243,34 +1328,41 @@ class XTradeHandler { // Supporting ... // - bool AllowSupport() { + bool AllowSupport() + { return mAllowSupport; } // - void AllowSupport(bool value) { + void AllowSupport(bool value) + { mAllowSupport = value; } // - bool SupportOnlyForces() { + bool SupportOnlyForces() + { return mSupportOnlyForces; } // - void SupportOnlyForces(bool value) { + void SupportOnlyForces(bool value) + { mSupportOnlyForces = value; } // - double SupportDistance() { + double SupportDistance() + { return mSupportDistance; } // - void SupportDistance(double value) { + void SupportDistance(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1279,14 +1371,17 @@ class XTradeHandler { } // - int MaxNumberOfSupports() { + int MaxNumberOfSupports() + { return mMaxNumberOfSupports; } // - void MaxNumberOfSupports(int value) { + void MaxNumberOfSupports(int value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1295,14 +1390,17 @@ class XTradeHandler { } // - double SupportVolumeMultiplier() { + double SupportVolumeMultiplier() + { return mSupportVolumeMultiplier; } // - void SupportVolumeMultiplier(double value) { + void SupportVolumeMultiplier(double value) + { // - if(value < 1) { + if (value < 1) + { value = 1; } @@ -1311,14 +1409,17 @@ class XTradeHandler { } // - double MaxAllowedSupportVolume() { + double MaxAllowedSupportVolume() + { return mMaxAllowedSupportVolume; } // - void MaxAllowedSupportVolume(double value) { + void MaxAllowedSupportVolume(double value) + { // - if(value < 0.01) { + if (value < 0.01) + { value = 0.01; } @@ -1327,7 +1428,8 @@ class XTradeHandler { } // - bool EnableSupport() { + bool EnableSupport() + { // bool result = false; @@ -1349,34 +1451,41 @@ class XTradeHandler { // Grid ... // - bool AllowGrid() { + bool AllowGrid() + { return mAllowGrid; } // - void AllowGrid(bool value) { + void AllowGrid(bool value) + { mAllowGrid = value; } // - bool GridOnlyForces() { + bool GridOnlyForces() + { return mGridOnlyForces; } // - void GridOnlyForces(bool value) { + void GridOnlyForces(bool value) + { mGridOnlyForces = value; } // - int MaxNumberOfGrids() { + int MaxNumberOfGrids() + { return mMaxNumberOfGrids; } // - void MaxNumberOfGrids(int value) { + void MaxNumberOfGrids(int value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1385,14 +1494,17 @@ class XTradeHandler { } // - double GridDistance() { + double GridDistance() + { return mGridDistance; } // - void GridDistance(double value) { + void GridDistance(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1401,14 +1513,17 @@ class XTradeHandler { } // - double GridVolumeMultiplier() { + double GridVolumeMultiplier() + { return mGridVolumeMultiplier; } // - void GridVolumeMultiplier(double value) { + void GridVolumeMultiplier(double value) + { // - if(value < 1) { + if (value < 1) + { value = 1; } @@ -1417,14 +1532,17 @@ class XTradeHandler { } // - double MaxAllowedGridVolume() { + double MaxAllowedGridVolume() + { return mMaxAllowedGridVolume; } // - void MaxAllowedGridVolume(double value) { + void MaxAllowedGridVolume(double value) + { // - if(value < 0.01) { + if (value < 0.01) + { value = 0.01; } @@ -1434,7 +1552,8 @@ class XTradeHandler { // // Check Grid Properties to Validate it's Enable or not ... - bool EnableGrid() { + bool EnableGrid() + { // bool result = false; @@ -1456,34 +1575,41 @@ class XTradeHandler { // Recovery System ... // - bool AllowRecovery() { + bool AllowRecovery() + { return mAllowRecovery; } // - void AllowRecovery(bool value) { + void AllowRecovery(bool value) + { mAllowRecovery = value; } // - bool RecoverOnlyForces() { + bool RecoverOnlyForces() + { return mRecoverOnlyForces; } // - void RecoverOnlyForces(bool value) { + void RecoverOnlyForces(bool value) + { mRecoverOnlyForces = value; } // - int MaxNumberOfRecoveries() { + int MaxNumberOfRecoveries() + { return mMaxNumberOfRecoveries; } // - void MaxNumberOfRecoveries(int value) { + void MaxNumberOfRecoveries(int value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1492,14 +1618,17 @@ class XTradeHandler { } // - double RecoveryDistance() { + double RecoveryDistance() + { return mRecoveryDistance; } // - void RecoveryDistance(double value) { + void RecoveryDistance(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -1508,14 +1637,17 @@ class XTradeHandler { } // - double RecoveryVolumeMultiplier() { + double RecoveryVolumeMultiplier() + { return mRecoveryVolumeMultiplier; } // - void RecoveryVolumeMultiplier(double value) { + void RecoveryVolumeMultiplier(double value) + { // - if(value < 1) { + if (value < 1) + { value = 1; } @@ -1524,14 +1656,17 @@ class XTradeHandler { } // - double MaxAllowedRecoveryVolume() { + double MaxAllowedRecoveryVolume() + { return mMaxAllowedRecoveryVolume; } // - void MaxAllowedRecoveryVolume(double value) { + void MaxAllowedRecoveryVolume(double value) + { // - if(value < 0.01) { + if (value < 0.01) + { value = 0.01; } @@ -1541,7 +1676,8 @@ class XTradeHandler { // // Check Recovery Properties to Validate it's Enable or not ... - bool EnableRecovery() { + bool EnableRecovery() + { // bool result = false; @@ -1563,31 +1699,36 @@ class XTradeHandler { // Tools ... // - int Count() { + int Count() + { return ArraySize(data); } // - int FindIndex(ulong ticket) { + int FindIndex(ulong ticket) + { // int result = -1; // int count = Count(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // XTradeInfo iInfo = data[i]; // bool isOwn = iInfo.IsOwn( - ticket // + ticket // ); - if(isOwn) { + if (isOwn) + { // result = i; break; @@ -1599,18 +1740,21 @@ class XTradeHandler { } // - int FindIndex(XSignal &signal) { + int FindIndex(XSignal &signal) + { // int result = -1; // int count = Count(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // XTradeInfo iInfo = data[i]; @@ -1627,7 +1771,8 @@ class XTradeHandler { ; // - if(isOWN) { + if (isOWN) + { // result = i; break; @@ -1640,20 +1785,21 @@ class XTradeHandler { // void Add( - XSignal &signal, - int pushers, - bool allowGrid, - bool allowRecover, - bool allowSupport, + XSignal &signal, + int pushers, + bool allowGrid, + bool allowRecover, + bool allowSupport, X121SetupConditions &cConditions, X121SetupConditions &sConditions, X121SetupConditions &mConditions, X121SetupConditions &lConditions, - X121SetupConditions &hConditions // - ) { + X121SetupConditions &hConditions // + ) + { // XTradeInfo info; - bool isFilled = info.Fill( + bool isFilled = info.Fill( signal, pushers, allowGrid, @@ -1663,29 +1809,33 @@ class XTradeHandler { sConditions, mConditions, lConditions, - hConditions // + hConditions // ); - if(!isFilled) { + if (!isFilled) + { return; } // AddRef( info, - data // + data // ); // - if(GetSaveSignalsOnly()) { + if (GetSaveSignalsOnly()) + { collector.SaveSignal(info); } } // - void Remove(XSignal &signal) { + void Remove(XSignal &signal) + { // int infoIDX = FindIndex(signal); - if(!IsValidIndex(infoIDX)) { + if (!IsValidIndex(infoIDX)) + { return; } @@ -1693,20 +1843,23 @@ class XTradeHandler { ArrayRemove( data, infoIDX, - 1 // + 1 // ); } // - void Update(XSignal &signal) { + void Update(XSignal &signal) + { // - if(!signal.IsValid() || !signal.IsExecuted()) { + if (!signal.IsValid() || !signal.IsExecuted()) + { return; } // int infoIDX = FindIndex(signal); - if(!IsValidIndex(infoIDX)) { + if (!IsValidIndex(infoIDX)) + { return; } @@ -1716,73 +1869,81 @@ class XTradeHandler { // // Find Orders for Accessing Commission ... XDeal deals[]; - int dealsCount = mTrader.GetDeals( + int dealsCount = mTrader.GetDeals( deals, signal.symbol, signal.provider, signal.period, NULL, - DEAL_ENTRY_IN // Position Open Deal ... + DEAL_ENTRY_IN // Position Open Deal ... ); - if(!IsValidSize(dealsCount)) { + if (!IsValidSize(dealsCount)) + { return; } // - for(int i = 0; i < dealsCount; i++) { + for (int i = 0; i < dealsCount; i++) + { // XDeal iDeal = deals[i]; // - if(iDeal.positionId == signal.positionId) { + if (iDeal.positionId == signal.positionId) + { data[infoIDX].commission = iDeal.commission; } } // // Check if Grid System Enable or Not ... - if(EnableGrid()) { + if (EnableGrid()) + { // // Here we Prepare Handler Structure for // Next Grid Position ... data[infoIDX].PrepareNextGrid( GridDistance(), - GridVolumeMultiplier() // + GridVolumeMultiplier() // ); } // // Check if Recovery System Enable or Not ... - if(EnableRecovery()) { + if (EnableRecovery()) + { // data[infoIDX].PrepareNextRecovery( GridDistance(), GridVolumeMultiplier(), - signal.type // + signal.type // ); } } // - void Update(XDeal &deal) { + void Update(XDeal &deal) + { // - if(!deal.IsValid()) { + if (!deal.IsValid()) + { return; } // int infoIDX = FindIndex(deal.positionId); - if(!IsValidIndex(infoIDX)) { + if (!IsValidIndex(infoIDX)) + { return; } // - data[infoIDX].swap = deal.swap; + data[infoIDX].swap = deal.swap; data[infoIDX].endTime = deal.time; - data[infoIDX].profit = deal.profit; + data[infoIDX].profit = deal.profit; // - string message = deal.reason == DEAL_REASON_TP ? "TP" : "SL"; + string message = deal.reason == DEAL_REASON_TP ? "TP" : "SL"; data[infoIDX].message = message; // @@ -1790,22 +1951,25 @@ class XTradeHandler { } // - void Update(XPosition &position) { + void Update(XPosition &position) + { // - if(!position.IsValid()) { + if (!position.IsValid()) + { return; } // int infoIDX = FindIndex(position.ticket); - if(!IsValidIndex(infoIDX)) { + if (!IsValidIndex(infoIDX)) + { return; } // - data[infoIDX].swap = position.swap; + data[infoIDX].swap = position.swap; data[infoIDX].endTime = TimeCurrent(); - data[infoIDX].profit = position.profit; + data[infoIDX].profit = position.profit; data[infoIDX].message = position.comment; // @@ -1814,42 +1978,48 @@ class XTradeHandler { // // Sync ... - void Sync() { + void Sync() + { // int count = Count(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return; } // int mustRemoved[]; - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // XTradeInfo iInfo = data[i]; // - if(iInfo.ticket > 0 && !mTrader.IsOpen(iInfo.ticket)) { + if (iInfo.ticket > 0 && !mTrader.IsOpen(iInfo.ticket)) + { // AddSpecific( i, - mustRemoved // + mustRemoved // ); } } // int mustRemovedCount = ArraySize(mustRemoved); - if(!IsValidSize(mustRemovedCount)) { + if (!IsValidSize(mustRemovedCount)) + { return; } // - for(int i = 0; i < mustRemovedCount; i++) { + for (int i = 0; i < mustRemovedCount; i++) + { // ArrayRemove( data, i, - 1 // + 1 // ); } } @@ -1860,9 +2030,10 @@ class XTradeHandler { // // Handle Do All Protecting ... int DoProtect( - XSignal &signals[], // if PRotecting Generate Some Support Signals, Holds them here - XSCX121SetupCycles *&setups[] // Number of Setups - ) { + XSignal &signals[], // if PRotecting Generate Some Support Signals, Holds them here + XSCX121SetupCycles *&setups[] // Number of Setups + ) + { // int result = 0; @@ -1871,58 +2042,65 @@ class XTradeHandler { // // Trailling ... - if(EnableTrailling()) { + if (EnableTrailling()) + { int traillings = HandleTrailling(); } // - if(AllowSupport()) { + if (AllowSupport()) + { // XSignal supports[]; - int supportsCount = RequestForSupport( + int supportsCount = RequestForSupport( supports, - setups // + setups // ); // - if(IsValidSize(supportsCount)) { + if (IsValidSize(supportsCount)) + { // Copy( supports, signals, - false // + false // ); } } // // Grid ... - if(EnableGrid()) { + if (EnableGrid()) + { // XSignal grids[]; - int gridsCount = RequestForGrid(grids); - if(IsValidSize(gridsCount)) { + int gridsCount = RequestForGrid(grids); + if (IsValidSize(gridsCount)) + { // Copy( grids, signals, - false // + false // ); } } // // Recovery ... - if(EnableRecovery()) { + if (EnableRecovery()) + { // XSignal recoveries[]; - int recoveriesCount = RequestForRecovery(recoveries); - if(IsValidSize(recoveriesCount)) { + int recoveriesCount = RequestForRecovery(recoveries); + if (IsValidSize(recoveriesCount)) + { // Copy( recoveries, signals, - false // + false // ); } } @@ -1935,7 +2113,8 @@ class XTradeHandler { } // - int GetBreakoutsSignals(XSignal &signals[]) { + int GetBreakoutsSignals(XSignal &signals[]) + { // int result = 0; @@ -1944,36 +2123,39 @@ class XTradeHandler { // int count = Count(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // - double iEntry = data[i].entry; - string iSymbol = data[i].symbol; - ENUM_TIMEFRAMES iPeriod = data[i].period; - ENUM_X_POSITION_TYPES iType = data[i].type; + double iEntry = data[i].entry; + string iSymbol = data[i].symbol; + ENUM_TIMEFRAMES iPeriod = data[i].period; + ENUM_X_POSITION_TYPES iType = data[i].type; // - bool isLong = IsLong(iType); + bool isLong = IsLong(iType); ENUM_POSITION_TYPE iPType = isLong ? POSITION_TYPE_BUY : POSITION_TYPE_SELL; // double cEntry = GetEntry( iSymbol, - iPType // + iPType // ); // XOHCL cBar; - bool isInited = cBar.Init( + bool isInited = cBar.Init( iSymbol, iPeriod, - 1 // + 1 // ); - if(!isInited) { + if (!isInited) + { continue; } @@ -1982,7 +2164,7 @@ class XTradeHandler { bool isBreakUp = cBar.IsBreakUp(iEntry); // - bool isBearish = cBar.IsBearish(); + bool isBearish = cBar.IsBearish(); bool isBreakDown = cBar.IsBreakDown(iEntry); // @@ -1990,16 +2172,17 @@ class XTradeHandler { isLong ? isBullish && isBreakUp && cEntry > iEntry : isBearish && isBreakDown && cEntry < iEntry; // - if(isBreaked) { + if (isBreaked) + { // // Update Date of TradeInfo ... data[i].entry = cEntry; - data[i].time = TimeCurrent(); + data[i].time = TimeCurrent(); // // Generate Signal ... XSignal iSignal; - bool isPrepared = iSignal.Prepare( + bool isPrepared = iSignal.Prepare( data[i].symbol, data[i].provider, data[i].period, @@ -2008,16 +2191,17 @@ class XTradeHandler { data[i].entry, data[i].volume, 0, - 0 // + 0 // ); // // Add Signal to Result ... - if(isPrepared) { + if (isPrepared) + { // AddRef( iSignal, - signals // + signals // ); } } @@ -2107,66 +2291,68 @@ class XTradeHandler { // // Protected ... - protected: +protected: // // Props ... - XSCTrade *mTrader; - XTradeInfo data[]; + XSCTrade *mTrader; + XTradeInfo data[]; XTradeInfoCollector *collector; // - bool mSave; // Save Results ... - bool mSaveSignalsOnly; // Save Only Signals and COnditions + bool mSave; // Save Results ... + bool mSaveSignalsOnly; // Save Only Signals and COnditions // // Hedging ... - double mMinProfitPerTrade; // Minimum Required Profit for Hedging - double mMinProfitPerVolumeFactor; // Minimum Required Profit for Hedging Per Volume + double mMinProfitPerTrade; // Minimum Required Profit for Hedging + double mMinProfitPerVolumeFactor; // Minimum Required Profit for Hedging Per Volume // // Trailling ... - bool mAllowTrailStop; // Enable Trailling Stop Losses - bool mDisableTrailingWhenOpposit; // Disable Trailling When has Opposite In Drawdown - double mNextTrailPoint; // Next Trailling Step - double mFirstTrailPoint; // First Stop Trail - double mFirstTrailDistance; // Start Trailling Distance - double mNextTrailDistance; // Next Trailling Distance + bool mAllowTrailStop; // Enable Trailling Stop Losses + bool mDisableTrailingWhenOpposit; // Disable Trailling When has Opposite In Drawdown + double mNextTrailPoint; // Next Trailling Step + double mFirstTrailPoint; // First Stop Trail + double mFirstTrailDistance; // Start Trailling Distance + double mNextTrailDistance; // Next Trailling Distance // // Supporting ... - bool mAllowSupport; // Allow Support Signals - bool mSupportOnlyForces; // Support Only Force Signals - double mSupportDistance; // Supporting Distance - int mMaxNumberOfSupports; // Max Number of Support Signals - double mSupportVolumeMultiplier; // Support Signals Volume Multiplier - double mMaxAllowedSupportVolume; // Max Allowed Support Signals Volume + bool mAllowSupport; // Allow Support Signals + bool mSupportOnlyForces; // Support Only Force Signals + double mSupportDistance; // Supporting Distance + int mMaxNumberOfSupports; // Max Number of Support Signals + double mSupportVolumeMultiplier; // Support Signals Volume Multiplier + double mMaxAllowedSupportVolume; // Max Allowed Support Signals Volume // // Grid ... - bool mAllowGrid; // Allow Grid Signals - bool mGridOnlyForces; // Grid Only Force Signals - int mMaxNumberOfGrids; // Max Number of Grid Signals - double mGridDistance; // Grid Distance - double mGridVolumeMultiplier; // Grid Volume Multiplier - double mMaxAllowedGridVolume; // Max Allowed Grid Signals Volume + bool mAllowGrid; // Allow Grid Signals + bool mGridOnlyForces; // Grid Only Force Signals + int mMaxNumberOfGrids; // Max Number of Grid Signals + double mGridDistance; // Grid Distance + double mGridVolumeMultiplier; // Grid Volume Multiplier + double mMaxAllowedGridVolume; // Max Allowed Grid Signals Volume // // Recovery ... - bool mAllowRecovery; // Allow Recovery Signals - bool mRecoverOnlyForces; // Recover Only Force Signals - int mMaxNumberOfRecoveries; // Max Number of Recovery Signals - double mRecoveryDistance; // Recovery Distance - double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier - double mMaxAllowedRecoveryVolume; // Max Allowed Recovery Signals Volume + bool mAllowRecovery; // Allow Recovery Signals + bool mRecoverOnlyForces; // Recover Only Force Signals + int mMaxNumberOfRecoveries; // Max Number of Recovery Signals + double mRecoveryDistance; // Recovery Distance + double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier + double mMaxAllowedRecoveryVolume; // Max Allowed Recovery Signals Volume // // Tools ... // - void Finish(int index) { + void Finish(int index) + { // XTradeInfo info = data[index]; - if(!info.IsValid()) { + if (!info.IsValid()) + { return; } @@ -2174,11 +2360,12 @@ class XTradeHandler { ArrayRemove( data, index, - 1 // + 1 // ); // - if(GetSave()) { + if (GetSave()) + { collector.Save(info); } } @@ -2187,13 +2374,15 @@ class XTradeHandler { // Protection Methods ... // - int HandleTrailling() { + int HandleTrailling() + { // int result = 0; // // Check Trailling is Enabled or not ... - if(!EnableTrailling()) { + if (!EnableTrailling()) + { return result; } @@ -2207,48 +2396,54 @@ class XTradeHandler { XPosition positions[]; XPosition inDPositions[]; XPosition inPPositions[]; - int positionsCount = mTrader.GetPositions(positions); - if(!IsValidSize(positionsCount)) { + int positionsCount = mTrader.GetPositions(positions); + if (!IsValidSize(positionsCount)) + { return result; } // int inDPositionsCount = ExtractInDrawdownPositions( positions, - inDPositions // + inDPositions // ); int inPPositionsCount = ExtractInProfitPositions( positions, - inPPositions // + inPPositions // ); - if(!IsValidSize(inPPositionsCount)) { + if (!IsValidSize(inPPositionsCount)) + { return result; } // - for(int i = 0; i < inPPositionsCount; i++) { + for (int i = 0; i < inPPositionsCount; i++) + { // XPosition iPosition = inPPositions[i]; // // ignore Support Positions ... bool isSupport = IsSupport(iPosition.comment); - if(isSupport) { + if (isSupport) + { continue; } // // Only Trail Positions which they Hasnt any Support ... bool hasSupport = mTrader.HasSupport(iPosition.ticket); - result = !hasSupport; - if(!result) { + result = !hasSupport; + if (!result) + { return result; } // // Find Positin Info Index ... int idx = FindIndex(iPosition.ticket); - if(!IsValidIndex(idx)) { + if (!IsValidIndex(idx)) + { continue; } @@ -2258,31 +2453,43 @@ class XTradeHandler { // // Here we Select Price for SL Trailling ... double usedPrice = 0; - if(iPosition.sl != 0) { + if (iPosition.sl != 0) + { // - if(isLong) { + if (isLong) + { // - if(iPosition.sl < iPosition.entry) { + if (iPosition.sl < iPosition.entry) + { usedPrice = iPosition.entry; - } else { - usedPrice = iPosition.sl; } - } else { - // - if(iPosition.sl > iPosition.entry) { - usedPrice = iPosition.entry; - } else { + else + { usedPrice = iPosition.sl; } } - } else { + else + { + // + if (iPosition.sl > iPosition.entry) + { + usedPrice = iPosition.entry; + } + else + { + usedPrice = iPosition.sl; + } + } + } + else + { usedPrice = iPosition.entry; } // - double nextTrailPoint = NextTrailPoint(); - double firstTrailPoint = FirstTrailPoint(); - double nextTrailDistance = NextTrailDistance(); + double nextTrailPoint = NextTrailPoint(); + double firstTrailPoint = FirstTrailPoint(); + double nextTrailDistance = NextTrailDistance(); double firstTrailDistance = FirstTrailDistance(); // @@ -2295,28 +2502,31 @@ class XTradeHandler { // double iExit = GetExit( iPosition.symbol, - iPosition.type // + iPosition.type // ); - double iPriceDistance = MathAbs(usedPrice - iExit); + double iPriceDistance = MathAbs(usedPrice - iExit); double iPriceDistanceInPoint = PriceToPoint( iPriceDistance, - iPosition.symbol // + iPosition.symbol // ); // bool canTrail = iPriceDistanceInPoint >= usedTrailDiff; - if(!canTrail) { + if (!canTrail) + { continue; } // // Check Opposit Side Position ... // if Exists, dont Trail ... - if(DisableTrailingWhenOpposit() && IsValidSize(inDPositionsCount)) { + if (DisableTrailingWhenOpposit() && IsValidSize(inDPositionsCount)) + { // - bool canTrail = true; + bool canTrail = true; ENUM_POSITION_TYPE oppositType = GetOpposit(iPosition.type); - for(int j = 0; j < inDPositionsCount; j++) { + for (int j = 0; j < inDPositionsCount; j++) + { // XPosition inDPosition = inDPositions[j]; @@ -2324,7 +2534,8 @@ class XTradeHandler { bool isOpposit = inDPosition.symbol == iPosition.symbol && inDPosition.type == oppositType; - if(isOpposit) { + if (isOpposit) + { // canTrail = false; break; @@ -2332,7 +2543,8 @@ class XTradeHandler { } // - if(!canTrail) { + if (!canTrail) + { continue; } } @@ -2342,7 +2554,7 @@ class XTradeHandler { isFirstTrail ? MathMin(firstTrailPoint, firstTrailDistance) : MathMin(nextTrailPoint, nextTrailDistance); double usedTrailDiffPrice = PointToPrice( usedTrailDiff, - iPosition.symbol // + iPosition.symbol // ); // @@ -2355,9 +2567,10 @@ class XTradeHandler { iPosition.ticket, sl, iPosition.tp, - comment // + comment // ); - if(isModified) { + if (isModified) + { result++; } } @@ -2368,9 +2581,10 @@ class XTradeHandler { // int RequestForSupport( - XSignal &signals[], - XSCX121SetupCycles *&setups[] // - ) { + XSignal &signals[], + XSCX121SetupCycles *&setups[] // + ) + { // int result = 0; @@ -2378,7 +2592,8 @@ class XTradeHandler { Clean(signals); // - if(!AllowSupport()) { + if (!AllowSupport()) + { return result; } @@ -2387,24 +2602,27 @@ class XTradeHandler { // int count = Count(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // XSignal iSupport; - double iPivot = -1; - int iPivotIDX = -1; - bool hasSupport = data[i].HasSupport( - iSupport // + double iPivot = -1; + int iPivotIDX = -1; + bool hasSupport = data[i].HasSupport( + iSupport // ); - if(hasSupport) { + if (hasSupport) + { // AddRef( iSupport, - signals // + signals // ); } } @@ -2520,7 +2738,8 @@ class XTradeHandler { } // - int RequestForGrid(XSignal &signals[]) { + int RequestForGrid(XSignal &signals[]) + { // int result = 0; @@ -2528,40 +2747,45 @@ class XTradeHandler { Clean(signals); // - if(!EnableGrid()) { + if (!EnableGrid()) + { return result; } // - int maxAllowed = MaxNumberOfGrids(); + int maxAllowed = MaxNumberOfGrids(); double maxAllowedVolume = MaxAllowedGridVolume(); // int count = Count(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // // Check Count ... bool isMaxPassed = maxAllowed <= 0 ? true : data[i].gLevel < maxAllowed; - if(!isMaxPassed) { + if (!isMaxPassed) + { continue; } // XSignal iSignal; - bool hasGrid = data[i].HasGrid( + bool hasGrid = data[i].HasGrid( iSignal, GridDistance(), - GridVolumeMultiplier() // + GridVolumeMultiplier() // ); // - if(hasGrid) { + if (hasGrid) + { // // Check Max Volume ... iSignal.volume = @@ -2570,7 +2794,7 @@ class XTradeHandler { // AddRef( iSignal, - signals // + signals // ); } } @@ -2583,7 +2807,8 @@ class XTradeHandler { } // - int RequestForRecovery(XSignal &signals[]) { + int RequestForRecovery(XSignal &signals[]) + { // int result = 0; @@ -2591,40 +2816,45 @@ class XTradeHandler { Clean(signals); // - if(!EnableRecovery()) { + if (!EnableRecovery()) + { return result; } // - int maxAllowed = MaxNumberOfRecoveries(); + int maxAllowed = MaxNumberOfRecoveries(); double maxAllowedVolume = MaxAllowedRecoveryVolume(); // int count = Count(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // // Check Count ... bool isMaxPassed = maxAllowed <= 0 ? true : data[i].rLevel < maxAllowed; - if(!isMaxPassed) { + if (!isMaxPassed) + { continue; } // XSignal iSignal; - bool hasRecovery = data[i].HasRecovery( + bool hasRecovery = data[i].HasRecovery( iSignal, RecoveryDistance(), - RecoveryVolumeMultiplier() // + RecoveryVolumeMultiplier() // ); // - if(hasRecovery) { + if (hasRecovery) + { // // Check Max Volume ... iSignal.volume = @@ -2633,7 +2863,7 @@ class XTradeHandler { // AddRef( iSignal, - signals // + signals // ); } } @@ -2647,21 +2877,25 @@ class XTradeHandler { // int FindSetupIndex( - string symbol, - XSCX121SetupCycles *&setups[] // - ) { + string symbol, + XSCX121SetupCycles *&setups[] // + ) + { // int result = 0; // - if(!IsValid(symbol)) { + if (!IsValid(symbol)) + { return result; } // - for(int i = 0; i < ArraySize(setups); i++) { + for (int i = 0; i < ArraySize(setups); i++) + { // - if(setups[i].GetSymbol() == symbol) { + if (setups[i].GetSymbol() == symbol) + { // result = i; break; @@ -2674,30 +2908,32 @@ class XTradeHandler { // void AddHotLevelsToZones( - XSCZones *zones // - ) { + XSCZones *zones // + ) + { // zones.AddLevelColor( 0.25, - clrRed // + clrRed // ); zones.AddLevelColor( 0.20, - clrOrange // + clrOrange // ); zones.AddLevelColor( 0.15, - clrYellow // + clrYellow // ); } }; // // Class ... -class XSCX121SetupEA : public XSCBaseEA { +class XSCX121SetupEA : public XSCBaseEA +{ // // Public ... - public: +public: // // Props ... X121SignalGenerator signalGenerator; @@ -2707,20 +2943,20 @@ class XSCX121SetupEA : public XSCBaseEA { XSCX121SetupEA( // // XTrade Class Requirements ... - int slippage, // Specify Slippage - ulong magicNumber, // Specify Magic Number + int slippage, // Specify Slippage + ulong magicNumber, // Specify Magic Number // // XSCTrade Event Handlers ... - TOnSignal onSignal = NULL, // On Signal Recieved Event Handler - TOnModify onModifyPosition = NULL, // On Modify Position Event Handler - TOnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler - TOnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler - TOnForceClose onForceClosePosition = NULL, // On Force Close Position Event Handler - TOnPartialClose onPartialClosePosition = NULL, // On Partial Close Position 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 onSignal = NULL, // On Signal Recieved Event Handler + TOnModify onModifyPosition = NULL, // On Modify Position Event Handler + TOnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler + TOnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler + TOnForceClose onForceClosePosition = NULL, // On Force Close Position Event Handler + TOnPartialClose onPartialClosePosition = NULL, // On Partial Close Position 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 ) : XSCBaseEA(slippage, magicNumber, onSignal, @@ -2732,8 +2968,9 @@ class XSCX121SetupEA : public XSCBaseEA { onDealsChangedHandler, onOrdersChangedHandler, onPositionsChangedHandler, - onTradeStateChangedHandler // - ) { + onTradeStateChangedHandler // + ) + { // mTradeHandler = new XTradeHandler(mTrader); @@ -2744,7 +2981,8 @@ class XSCX121SetupEA : public XSCBaseEA { // // Deconstructor ... - ~XSCX121SetupEA() { + ~XSCX121SetupEA() + { // delete mTradeHandler; @@ -2753,20 +2991,22 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool AddSetup(XSCX121SetupCycles *setup) { + bool AddSetup(XSCX121SetupCycles *setup) + { // bool result = false; // result = setup != NULL; - if(!result) { + if (!result) + { return result; } // Add( setup, - mSetups // + mSetups // ); // @@ -2780,34 +3020,41 @@ class XSCX121SetupEA : public XSCBaseEA { /// Signals ... // - bool AllowLong() { + bool AllowLong() + { return mAllowLong; } // - void AllowLong(bool value) { + void AllowLong(bool value) + { mAllowLong = value; } // - bool AllowShort() { + bool AllowShort() + { return mAllowShort; } // - void AllowShort(bool value) { + void AllowShort(bool value) + { mAllowShort = value; } // - int DelayBetweenTwoSignal() { + int DelayBetweenTwoSignal() + { return mDelayBetweenTwoSignal; } // - void DelayBetweenTwoSignal(int value) { + void DelayBetweenTwoSignal(int value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -2816,14 +3063,17 @@ class XSCX121SetupEA : public XSCBaseEA { } // - int ReuiredSignalVerifications() { + int ReuiredSignalVerifications() + { return mReuiredSignalVerifications; } // - void ReuiredSignalVerifications(int value) { + void ReuiredSignalVerifications(int value) + { // - if(value < 1) { + if (value < 1) + { value = 1; } @@ -2832,22 +3082,26 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool GetVerificationFromOtherTimeFrames() { + bool GetVerificationFromOtherTimeFrames() + { return mGetVerificationFromOtherTimeFrames; } // - void GetVerificationFromOtherTimeFrames(bool value) { + void GetVerificationFromOtherTimeFrames(bool value) + { mGetVerificationFromOtherTimeFrames = value; } // - bool ExecuteSignalsOnBreakout() { + bool ExecuteSignalsOnBreakout() + { return mExecuteSignalsOnBreakout; } // - void ExecuteSignalsOnBreakout(bool value) { + void ExecuteSignalsOnBreakout(bool value) + { mExecuteSignalsOnBreakout = value; } @@ -2855,14 +3109,17 @@ class XSCX121SetupEA : public XSCBaseEA { // Risk Management ... // - double Volume() { + double Volume() + { return mVolume; } // - void Volume(double value) { + void Volume(double value) + { // - if(value < 0.01) { + if (value < 0.01) + { value = 0.01; } @@ -2871,14 +3128,17 @@ class XSCX121SetupEA : public XSCBaseEA { } // - double TPPoint() { + double TPPoint() + { return mTPPoint; } // - void TPPoint(double value) { + void TPPoint(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -2887,14 +3147,17 @@ class XSCX121SetupEA : public XSCBaseEA { } // - double SLPoint() { + double SLPoint() + { return mSLPoint; } // - void SLPoint(double value) { + void SLPoint(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -2903,14 +3166,17 @@ class XSCX121SetupEA : public XSCBaseEA { } // - int MaxAllowedTrades() { + int MaxAllowedTrades() + { return mMaxAllowedTrades; } // - void MaxAllowedTrades(int value) { + void MaxAllowedTrades(int value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -2920,54 +3186,65 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool UseMaxAllowedPerDirection() { + bool UseMaxAllowedPerDirection() + { return mUseMaxAllowedPerDirection; } // - void UseMaxAllowedPerDirection(bool value) { + void UseMaxAllowedPerDirection(bool value) + { mUseMaxAllowedPerDirection = value; } // - bool IgnoreTP() { + bool IgnoreTP() + { return mIgnoreTP; } // - void IgnoreTP(bool value) { + void IgnoreTP(bool value) + { mIgnoreTP = value; } // - bool IgnoreSL() { + bool IgnoreSL() + { return mIgnoreSL; } // - void IgnoreSL(bool value) { + void IgnoreSL(bool value) + { mIgnoreSL = value; } // - bool IncreaseNextSignalsVolume() { + bool IncreaseNextSignalsVolume() + { return mIncreaseNextSignalsVolume; } // - void IncreaseNextSignalsVolume(bool value) { + void IncreaseNextSignalsVolume(bool value) + { mIncreaseNextSignalsVolume = value; } // - double IncreaseNextSignalsVolumeMultiplier() { + double IncreaseNextSignalsVolumeMultiplier() + { return mIncreaseNextSignalsVolumeMultiplier; } // - void IncreaseNextSignalsVolumeMultiplier(double value) { + void IncreaseNextSignalsVolumeMultiplier(double value) + { // - if(value <= 0) { + if (value <= 0) + { value = 0; } @@ -2976,12 +3253,14 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool AcceptNextDirectionalSignalsWhenFirstInProfit() { + bool AcceptNextDirectionalSignalsWhenFirstInProfit() + { return mAcceptNextDirectionalSignalsWhenFirstInProfit; } // - void AcceptNextDirectionalSignalsWhenFirstInProfit(bool value) { + void AcceptNextDirectionalSignalsWhenFirstInProfit(bool value) + { mAcceptNextDirectionalSignalsWhenFirstInProfit = value; } @@ -2989,14 +3268,17 @@ class XSCX121SetupEA : public XSCBaseEA { // Signalling ... // - int StartSignallingHoure() { + int StartSignallingHoure() + { return mStartSignallingHoure; } // - void StartSignallingHoure(int value) { + void StartSignallingHoure(int value) + { // - if(value < -1) { + if (value < -1) + { value = -1; } @@ -3005,14 +3287,17 @@ class XSCX121SetupEA : public XSCBaseEA { } // - int EndSignallingHoure() { + int EndSignallingHoure() + { return mEndSignallingHoure; } // - void EndSignallingHoure(int value) { + void EndSignallingHoure(int value) + { // - if(value < -1) { + if (value < -1) + { value = -1; } @@ -3021,14 +3306,17 @@ class XSCX121SetupEA : public XSCBaseEA { } // - int CloseOnSpecificTime() { + int CloseOnSpecificTime() + { return mCloseOnSpecificTime; } // - void CloseOnSpecificTime(int value) { + void CloseOnSpecificTime(int value) + { // - if(value < -1) { + if (value < -1) + { value = -1; } @@ -3037,12 +3325,14 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool CloseOnOpposit() { + bool CloseOnOpposit() + { return mCloseOnOpposit; } // - void CloseOnOpposit(bool value) { + void CloseOnOpposit(bool value) + { mCloseOnOpposit = value; } @@ -3050,62 +3340,74 @@ class XSCX121SetupEA : public XSCBaseEA { // Trailling ... // - bool AllowTrailStop() { + bool AllowTrailStop() + { return mTradeHandler.AllowTrailStop(); } // - void AllowTrailStop(bool value) { + void AllowTrailStop(bool value) + { mTradeHandler.AllowTrailStop(value); } // - bool DisableTrailingWhenOpposit() { + bool DisableTrailingWhenOpposit() + { return mTradeHandler.DisableTrailingWhenOpposit(); } // - void DisableTrailingWhenOpposit(bool value) { + void DisableTrailingWhenOpposit(bool value) + { mTradeHandler.DisableTrailingWhenOpposit(value); } // - double NextTrailPoint() { + double NextTrailPoint() + { return mTradeHandler.NextTrailPoint(); } // - void NextTrailPoint(double value) { + void NextTrailPoint(double value) + { mTradeHandler.NextTrailPoint(value); } // - double FirstTrailPoint() { + double FirstTrailPoint() + { return mTradeHandler.FirstTrailPoint(); } // - void FirstTrailPoint(double value) { + void FirstTrailPoint(double value) + { mTradeHandler.FirstTrailPoint(value); } // - double NextTrailDistance() { + double NextTrailDistance() + { return mTradeHandler.NextTrailDistance(); } // - void NextTrailDistance(double value) { + void NextTrailDistance(double value) + { mTradeHandler.NextTrailDistance(value); } // - double FirstTrailDistance() { + double FirstTrailDistance() + { return mTradeHandler.FirstTrailDistance(); } // - void FirstTrailDistance(double value) { + void FirstTrailDistance(double value) + { mTradeHandler.FirstTrailDistance(value); } @@ -3113,67 +3415,80 @@ class XSCX121SetupEA : public XSCBaseEA { // Supporting ... // - bool AllowSupport() { + bool AllowSupport() + { return mTradeHandler.AllowSupport(); } // - void AllowSupport(bool value) { + void AllowSupport(bool value) + { mTradeHandler.AllowSupport(value); } // - bool SupportOnlyForces() { + bool SupportOnlyForces() + { return mTradeHandler.SupportOnlyForces(); } // - void SupportOnlyForces(bool value) { + void SupportOnlyForces(bool value) + { mTradeHandler.SupportOnlyForces(value); } // - bool EnableSupport() { + bool EnableSupport() + { return mTradeHandler.EnableSupport(); } // - double SupportDistance() { + double SupportDistance() + { return mTradeHandler.SupportDistance(); } // - void SupportDistance(double value) { + void SupportDistance(double value) + { mTradeHandler.SupportDistance(value); } // - int MaxNumberOfSupports() { + int MaxNumberOfSupports() + { return mTradeHandler.MaxNumberOfSupports(); } // - void MaxNumberOfSupports(int value) { + void MaxNumberOfSupports(int value) + { mTradeHandler.MaxNumberOfSupports(value); } // - double SupportVolumeMultiplier() { + double SupportVolumeMultiplier() + { return mTradeHandler.SupportVolumeMultiplier(); } // - void SupportVolumeMultiplier(double value) { + void SupportVolumeMultiplier(double value) + { mTradeHandler.SupportVolumeMultiplier(value); } // - double MaxAllowedSupportVolume() { + double MaxAllowedSupportVolume() + { return mTradeHandler.MaxAllowedSupportVolume(); } // - void MaxAllowedSupportVolume(double value) { + void MaxAllowedSupportVolume(double value) + { mTradeHandler.MaxAllowedSupportVolume(value); } @@ -3181,67 +3496,80 @@ class XSCX121SetupEA : public XSCBaseEA { // Grid ... // - bool AllowGrid() { + bool AllowGrid() + { return mTradeHandler.AllowGrid(); } // - void AllowGrid(bool value) { + void AllowGrid(bool value) + { mTradeHandler.AllowGrid(value); } // - bool GridOnlyForces() { + bool GridOnlyForces() + { return mTradeHandler.GridOnlyForces(); } // - void GridOnlyForces(bool value) { + void GridOnlyForces(bool value) + { mTradeHandler.GridOnlyForces(value); } // - bool EnableGrid() { + bool EnableGrid() + { return mTradeHandler.EnableGrid(); } // - int MaxNumberOfGrids() { + int MaxNumberOfGrids() + { return mTradeHandler.MaxNumberOfGrids(); } // - void MaxNumberOfGrids(int value) { + void MaxNumberOfGrids(int value) + { mTradeHandler.MaxNumberOfGrids(value); } // - double GridDistance() { + double GridDistance() + { return mTradeHandler.GridDistance(); } // - void GridDistance(double value) { + void GridDistance(double value) + { mTradeHandler.GridDistance(value); } // - double GridVolumeMultiplier() { + double GridVolumeMultiplier() + { return mTradeHandler.GridVolumeMultiplier(); } // - void GridVolumeMultiplier(double value) { + void GridVolumeMultiplier(double value) + { mTradeHandler.GridVolumeMultiplier(value); } // - double MaxAllowedGridVolume() { + double MaxAllowedGridVolume() + { return mTradeHandler.MaxAllowedGridVolume(); } // - void MaxAllowedGridVolume(double value) { + void MaxAllowedGridVolume(double value) + { mTradeHandler.MaxAllowedGridVolume(value); } @@ -3249,67 +3577,80 @@ class XSCX121SetupEA : public XSCBaseEA { // Recovery System ... // - bool AllowRecovery() { + bool AllowRecovery() + { return mTradeHandler.AllowRecovery(); } // - void AllowRecovery(bool value) { + void AllowRecovery(bool value) + { mTradeHandler.AllowRecovery(value); } // - bool RecoverOnlyForces() { + bool RecoverOnlyForces() + { return mTradeHandler.RecoverOnlyForces(); } // - void RecoverOnlyForces(bool value) { + void RecoverOnlyForces(bool value) + { mTradeHandler.RecoverOnlyForces(value); } // - bool EnableRecovery() { + bool EnableRecovery() + { return mTradeHandler.EnableRecovery(); } // - int MaxNumberOfRecoveries() { + int MaxNumberOfRecoveries() + { return mTradeHandler.MaxNumberOfRecoveries(); } // - void MaxNumberOfRecoveries(int value) { + void MaxNumberOfRecoveries(int value) + { mTradeHandler.MaxNumberOfRecoveries(value); } // - double RecoveryDistance() { + double RecoveryDistance() + { return mTradeHandler.RecoveryDistance(); } // - void RecoveryDistance(double value) { + void RecoveryDistance(double value) + { mTradeHandler.RecoveryDistance(value); } // - double RecoveryVolumeMultiplier() { + double RecoveryVolumeMultiplier() + { return mTradeHandler.RecoveryVolumeMultiplier(); } // - void RecoveryVolumeMultiplier(double value) { + void RecoveryVolumeMultiplier(double value) + { mTradeHandler.RecoveryVolumeMultiplier(value); } // - double MaxAllowedRecoveryVolume() { + double MaxAllowedRecoveryVolume() + { return mTradeHandler.MaxAllowedRecoveryVolume(); } // - void MaxAllowedRecoveryVolume(double value) { + void MaxAllowedRecoveryVolume(double value) + { mTradeHandler.MaxAllowedRecoveryVolume(value); } @@ -3317,34 +3658,41 @@ class XSCX121SetupEA : public XSCBaseEA { // Others ... // - bool SaveResults() { + bool SaveResults() + { return mTradeHandler.GetSave(); } // - void SaveResults(bool value) { + void SaveResults(bool value) + { mTradeHandler.SetSave(value); } // - bool SaveSignalsOnly() { + bool SaveSignalsOnly() + { return mTradeHandler.GetSaveSignalsOnly(); } // - void SaveSignalsOnly(bool value) { + void SaveSignalsOnly(bool value) + { mTradeHandler.SetSaveSignalsOnly(value); } // - double MinFreeMargingForOpenTrades() { + double MinFreeMargingForOpenTrades() + { return mMinFreeMargingForOpenTrades; } // - void MinFreeMargingForOpenTrades(double value) { + void MinFreeMargingForOpenTrades(double value) + { // - if(value < 0) { + if (value < 0) + { value = 0; } @@ -3356,24 +3704,28 @@ class XSCX121SetupEA : public XSCBaseEA { // Hedging ... // - double MinProfitPerTrade() { + double MinProfitPerTrade() + { return mTradeHandler.MinProfitPerTrade(); } // - void MinProfitPerTrade(double value) { + void MinProfitPerTrade(double value) + { // MinRequiredProfitPerTrade(value); mTradeHandler.MinProfitPerTrade(value); } // - double MinProfitPerVolumeFactor() { + double MinProfitPerVolumeFactor() + { return mTradeHandler.MinProfitPerVolumeFactor(); } // - void MinProfitPerVolumeFactor(double value) { + void MinProfitPerVolumeFactor(double value) + { // MinRequiredProfitPerVolumeFactor(value); mTradeHandler.MinProfitPerVolumeFactor(value); @@ -3384,12 +3736,14 @@ class XSCX121SetupEA : public XSCBaseEA { // // Customize Token ... - string GetToken() override { + string GetToken() override + { return GetSpecificToken(this); } // - string GetTag() override { + string GetTag() override + { return this.GetToken(); } @@ -3398,7 +3752,8 @@ class XSCX121SetupEA : public XSCBaseEA { // // Check Provider for any Guards ... - bool CheckForGuard(XGuard &guards[]) override { + bool CheckForGuard(XGuard &guards[]) override + { // bool result = false; @@ -3412,8 +3767,9 @@ class XSCX121SetupEA : public XSCBaseEA { // filters theme here and passed them // for Executing ... int RequestForSignal( - XSignal &signals[] // Holds Signals ... - ) override { + XSignal &signals[] // Holds Signals ... + ) override + { // bool result = 0; @@ -3421,66 +3777,68 @@ class XSCX121SetupEA : public XSCBaseEA { Clean(signals); // - if(!IsEnable()) { + if (!IsEnable()) + { return result; } // // IMPLEMENT ... int count = CountSetups(); - result = IsValidSize(count); - if(!result) { + result = IsValidSize(count); + if (!result) + { return result; } // // Current ... - double cTP = 0; - double cSL = 0; - XSignal cSignal; - int cPusher = 0; - bool cHasSignal = false; - string cProvider = NULL; + double cTP = 0; + double cSL = 0; + XSignal cSignal; + int cPusher = 0; + bool cHasSignal = false; + string cProvider = NULL; X121SetupConditions cConditions; // // Short ... - double sTP = 0; - double sSL = 0; - XSignal sSignal; - int sPusher = 0; - bool sHasSignal = false; - string sProvider = NULL; + double sTP = 0; + double sSL = 0; + XSignal sSignal; + int sPusher = 0; + bool sHasSignal = false; + string sProvider = NULL; X121SetupConditions sConditions; // // Medium ... - double mTP = 0; - double mSL = 0; - XSignal mSignal; - int mPusher = 0; - bool mHasSignal = false; - string mProvider = NULL; + double mTP = 0; + double mSL = 0; + XSignal mSignal; + int mPusher = 0; + bool mHasSignal = false; + string mProvider = NULL; X121SetupConditions mConditions; // // Long ... - double lTP = 0; - double lSL = 0; - XSignal lSignal; - int lPusher = 0; - bool lHasSignal = false; - string lProvider = NULL; + double lTP = 0; + double lSL = 0; + XSignal lSignal; + int lPusher = 0; + bool lHasSignal = false; + string lProvider = NULL; X121SetupConditions lConditions; // // Hind ... - double hTP = 0; - double hSL = 0; - XSignal hSignal; - int hPusher = 0; - bool hHasSignal = false; - string hProvider = NULL; + double hTP = 0; + double hSL = 0; + XSignal hSignal; + int hPusher = 0; + bool hHasSignal = false; + string hProvider = NULL; X121SetupConditions hConditions; // @@ -3504,13 +3862,13 @@ class XSCX121SetupEA : public XSCBaseEA { ; // - double volume = Volume(); - double slPoint = SLPoint(); - double tpPoint = TPPoint(); - bool ignoreSL = IgnoreSL(); - bool ignoreTP = IgnoreTP(); - bool allowLong = AllowLong(); - bool allowShort = AllowShort(); + double volume = Volume(); + double slPoint = SLPoint(); + double tpPoint = TPPoint(); + bool ignoreSL = IgnoreSL(); + bool ignoreTP = IgnoreTP(); + bool allowLong = AllowLong(); + bool allowShort = AllowShort(); // bool useCMarket = true; @@ -3520,20 +3878,21 @@ class XSCX121SetupEA : public XSCBaseEA { bool useHMarket = true; // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // // Current Market ... // cPusher = 0; cSignal.Clean(); - cProvider = NULL; + cProvider = NULL; cHasSignal = false; cConditions.Clean(); // cHasSignal = !useCMarket ? false : mSetups[i].ProcessMarket(cSignal, cConditions, cPusher, cProvider, cTP, cSL, X_MARKET_CYCLE_UNKNOWN, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0, - 5 // + 5 // ); // @@ -3542,13 +3901,13 @@ class XSCX121SetupEA : public XSCBaseEA { // sPusher = 0; sSignal.Clean(); - sProvider = NULL; + sProvider = NULL; sHasSignal = false; sConditions.Clean(); // sHasSignal = !useSMarket ? false : mSetups[i].ProcessMarket(sSignal, sConditions, sPusher, sProvider, sTP, sSL, X_MARKET_CYCLE_SHORT, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0, - 5 // + 5 // ); // @@ -3557,13 +3916,13 @@ class XSCX121SetupEA : public XSCBaseEA { // mPusher = 0; mSignal.Clean(); - mProvider = NULL; + mProvider = NULL; mHasSignal = false; mConditions.Clean(); // mHasSignal = !useMMarket ? false : mSetups[i].ProcessMarket(mSignal, mConditions, mPusher, mProvider, mTP, mSL, X_MARKET_CYCLE_MEDIUM, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0, - 5 // + 5 // ); // @@ -3572,13 +3931,13 @@ class XSCX121SetupEA : public XSCBaseEA { // lPusher = 0; lSignal.Clean(); - lProvider = NULL; + lProvider = NULL; lHasSignal = false; lConditions.Clean(); // lHasSignal = !useLMarket ? false : mSetups[i].ProcessMarket(lSignal, lConditions, lPusher, lProvider, lTP, lSL, X_MARKET_CYCLE_LONG, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0, - 5 // + 5 // ); // @@ -3587,13 +3946,13 @@ class XSCX121SetupEA : public XSCBaseEA { // hPusher = 0; hSignal.Clean(); - hProvider = NULL; + hProvider = NULL; hHasSignal = false; hConditions.Clean(); // hHasSignal = !useHMarket ? false : mSetups[i].ProcessMarket(hSignal, hConditions, hPusher, hProvider, hTP, hSL, X_MARKET_CYCLE_HIND, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0, - 5 // + 5 // ); // @@ -3602,24 +3961,26 @@ class XSCX121SetupEA : public XSCBaseEA { // // Check if there is a Signal or Not ... bool hasSignal = cHasSignal || sHasSignal || mHasSignal || lHasSignal || hHasSignal; - if(hasSignal) { + if (hasSignal) + { // - XSignal signal; + XSignal signal; X121SetupConditions otherConditions[]; // - if(cHasSignal) { + if (cHasSignal) + { // signal = cSignal; // AddRef( sConditions, - otherConditions // + otherConditions // ); AddRef( mConditions, - otherConditions // + otherConditions // ); // AddRef( // lConditions, @@ -3632,18 +3993,19 @@ class XSCX121SetupEA : public XSCBaseEA { } // - if(sHasSignal) { + if (sHasSignal) + { // signal = sSignal; // AddRef( cConditions, - otherConditions // + otherConditions // ); AddRef( mConditions, - otherConditions // + otherConditions // ); // AddRef( // lConditions, @@ -3656,23 +4018,25 @@ class XSCX121SetupEA : public XSCBaseEA { } // - if(mHasSignal) { + if (mHasSignal) + { // signal = mSignal; // AddRef( sConditions, - otherConditions // + otherConditions // ); AddRef( lConditions, - otherConditions // + otherConditions // ); } // - if(lHasSignal) { + if (lHasSignal) + { // signal = lSignal; @@ -3683,39 +4047,40 @@ class XSCX121SetupEA : public XSCBaseEA { // ); AddRef( mConditions, - otherConditions // + otherConditions // ); AddRef( hConditions, - otherConditions // + otherConditions // ); } // - if(hHasSignal) { + if (hHasSignal) + { // signal = hSignal; // AddRef( cConditions, - otherConditions // + otherConditions // ); AddRef( sConditions, - otherConditions // + otherConditions // ); AddRef( mConditions, - otherConditions // + otherConditions // ); AddRef( lConditions, - otherConditions // + otherConditions // ); AddRef( hConditions, - otherConditions // + otherConditions // ); } @@ -3735,8 +4100,8 @@ class XSCX121SetupEA : public XSCBaseEA { && // // Handle Other Conditions Validations ... - (!mGetVerificationFromOtherTimeFrames ? true : isLong ? signalGenerator.HasLongVerifications(otherConditions) : - signalGenerator.HasShortVerifications(otherConditions)) + (!mGetVerificationFromOtherTimeFrames ? true : isLong ? signalGenerator.HasLongVerifications(otherConditions) + : signalGenerator.HasShortVerifications(otherConditions)) // ; @@ -3745,12 +4110,13 @@ class XSCX121SetupEA : public XSCBaseEA { bool forceState = mForce; // - if(!forceState) { + if (!forceState) + { // // Add Signal to Execution Result ... AddRef( signal, - signals // + signals // ); // @@ -3765,9 +4131,11 @@ class XSCX121SetupEA : public XSCBaseEA { sConditions, mConditions, lConditions, - hConditions // + hConditions // ); - } else { + } + else + { // // Clear Other Conditions ... Clean(otherConditions); @@ -3776,23 +4144,23 @@ class XSCX121SetupEA : public XSCBaseEA { // Fill All Conditions to Other Conditions ... AddRef( cConditions, - otherConditions // + otherConditions // ); AddRef( sConditions, - otherConditions // + otherConditions // ); AddRef( mConditions, - otherConditions // + otherConditions // ); AddRef( lConditions, - otherConditions // + otherConditions // ); AddRef( hConditions, - otherConditions // + otherConditions // ); // @@ -3802,7 +4170,7 @@ class XSCX121SetupEA : public XSCBaseEA { signal, pushers, isValid, - otherConditions // + otherConditions // ); } } @@ -3821,33 +4189,36 @@ class XSCX121SetupEA : public XSCBaseEA { // - Check Same Time Open Positions ... // - Check Signal Age for new Trade ... // and etc ... - int HandleSignalManagement(XSignal &signals[]) override { + int HandleSignalManagement(XSignal &signals[]) override + { // int result = 0; // int signalsCount = ArraySize(signals); - if(!IsValidSize(signalsCount)) { + if (!IsValidSize(signalsCount)) + { return result; } // XSignal tmpSignals[]; - XSignal eSignals[]; // Must Executed + XSignal eSignals[]; // Must Executed Copy( signals, - tmpSignals // + tmpSignals // ); // Clean(signals); // - int maxAllowed = MaxAllowedTrades(); + int maxAllowed = MaxAllowedTrades(); bool perDirection = UseMaxAllowedPerDirection(); // - for(int i = 0; i < signalsCount; i++) { + for (int i = 0; i < signalsCount; i++) + { // XSignal iSignal = tmpSignals[i]; @@ -3856,38 +4227,42 @@ class XSCX121SetupEA : public XSCBaseEA { // isSignalValid = IsSignalDelayPassed(iSignal); - if(!isSignalValid) { + if (!isSignalValid) + { continue; } // // Handle Close All Positions when Opposit Signal Recieved ... - if(mCloseOnOpposit) { + if (mCloseOnOpposit) + { // // Select Signal Opposit Positions ... ENUM_X_POSITION_TYPES iOpposit = GetOppositPositionType(iSignal.type); // XPosition iPositions[]; - int iPositionsCount = mTrader.GetPositions( + int iPositionsCount = mTrader.GetPositions( iPositions, iSignal.symbol, - NULL, // All Providers ... - NULL, // All Periods ... - iOpposit // Opposit Positions ... + NULL, // All Providers ... + NULL, // All Periods ... + iOpposit // Opposit Positions ... ); // - if(IsValidSize(iPositionsCount)) { + if (IsValidSize(iPositionsCount)) + { // string comment = "Close due Opposit ..."; // int closeds = Close( iPositions, - comment // + comment // ); - if(IsValidSize(closeds)) { + if (IsValidSize(closeds)) + { // string message = XEQMSupportToken + " Closed " + ToString(iPositionsCount) + " due Opposit Signal ..."; @@ -3909,99 +4284,109 @@ class XSCX121SetupEA : public XSCBaseEA { // // Filter Signals Based On Max Allowed ... - if(maxAllowed > 0) { + if (maxAllowed > 0) + { // // Here we Get Opposite Signals of Same Symbol Valid ... ENUM_X_POSITION_TYPES iType = perDirection ? ToPositionType(iSignal.type) : X_POSITION_TYPE_ALL; XPosition iSymbolsPositions[]; - int iSymbolsPositionsCount = mTrader.GetPositions( + int iSymbolsPositionsCount = mTrader.GetPositions( iSymbolsPositions, iSignal.symbol, - NULL, // Provider - NULL, // Period - iType, // Type - true // + NULL, // Provider + NULL, // Period + iType, // Type + true // ); // int iSupportsCount = 0; - if(IsValidSize(iSymbolsPositionsCount)) { + if (IsValidSize(iSymbolsPositionsCount)) + { // // Filter Support Positions ... XPosition iSupports[]; iSupportsCount = ExtractSupports( iSymbolsPositions, - iSupports // + iSupports // ); } // isSignalValid = iSupportsCount <= 0 ? iSymbolsPositionsCount < maxAllowed : iSymbolsPositionsCount - iSupportsCount < maxAllowed; - if(!isSignalValid) { + if (!isSignalValid) + { continue; } - } else { + } + else + { isSignalValid = true; } // // Only Accept Next Same Type when Previous in Profit ... bool isSameTypeExists = false; - if(isSignalValid) { + if (isSignalValid) + { // ENUM_X_POSITION_TYPES iType = ToPositionType(iSignal.type); XPosition iSymbolsPositions[]; - int iSymbolsPositionsCount = mTrader.GetPositions( + int iSymbolsPositionsCount = mTrader.GetPositions( iSymbolsPositions, iSignal.symbol, - NULL, // Provider - NULL, // Period - iType, // Type - true // + NULL, // Provider + NULL, // Period + iType, // Type + true // ); // int iSupportsCount = 0; - if(IsValidSize(iSymbolsPositionsCount)) { + if (IsValidSize(iSymbolsPositionsCount)) + { // // Filter Support Positions ... XPosition iSupports[]; iSupportsCount = ExtractSupports( iSymbolsPositions, - iSupports // + iSupports // ); // // Filter Support Positions ... - if(IsValidSize(iSupportsCount)) { + if (IsValidSize(iSupportsCount)) + { // XPosition tmpPositions[]; Copy( iSymbolsPositions, - tmpPositions // + tmpPositions // ); // Clean(iSymbolsPositions); // - for(int i = 0; i < iSymbolsPositionsCount; i++) { + for (int i = 0; i < iSymbolsPositionsCount; i++) + { // XPosition iPosition = tmpPositions[i]; // bool isSupport = IsSupport(iPosition.comment); - if(isSupport) { + if (isSupport) + { continue; } // AddRef( iPosition, - iSymbolsPositions // + iSymbolsPositions // ); } @@ -4012,13 +4397,14 @@ class XSCX121SetupEA : public XSCBaseEA { // bool acceptNewOnlyWhenLastInProfit = AcceptNextDirectionalSignalsWhenFirstInProfit(); - isSameTypeExists = IsValidSize(iSymbolsPositionsCount); - if(isSameTypeExists && acceptNewOnlyWhenLastInProfit) { + isSameTypeExists = IsValidSize(iSymbolsPositionsCount); + if (isSameTypeExists && acceptNewOnlyWhenLastInProfit) + { // XPosition youngest; - int youngestAge = GetYoungest( + int youngestAge = GetYoungest( youngest, - iSymbolsPositions // + iSymbolsPositions // ); // @@ -4026,62 +4412,70 @@ class XSCX121SetupEA : public XSCBaseEA { } // - if(!isSignalValid) { + if (!isSignalValid) + { continue; } } // // Multiply Signal Volume ... - if(isSignalValid) { + if (isSignalValid) + { // XPosition iSymbolsPositions[]; - int iSymbolsPositionsCount = mTrader.GetPositions( + int iSymbolsPositionsCount = mTrader.GetPositions( iSymbolsPositions, iSignal.symbol, - NULL, // Provider - NULL, // Period - NULL, // Type - true // + NULL, // Provider + NULL, // Period + NULL, // Type + true // ); // int iSupportsCount = 0; - if(IsValidSize(iSymbolsPositionsCount)) { + if (IsValidSize(iSymbolsPositionsCount)) + { // // Filter Support Positions ... XPosition iSupports[]; iSupportsCount = ExtractSupports( iSymbolsPositions, - iSupports // + iSupports // ); } // int multiplier = iSupportsCount <= 0 ? iSymbolsPositionsCount : iSymbolsPositionsCount - iSupportsCount; - if(multiplier <= 0) { + if (multiplier <= 0) + { multiplier = 1; - } else { + } + else + { multiplier++; } // bool canIncreaseVolume = IncreaseNextSignalsVolume(); - if(canIncreaseVolume) { + if (canIncreaseVolume) + { // double volumeMultiplier = IncreaseNextSignalsVolumeMultiplier(); - iSignal.volume = iSignal.volume * (multiplier * volumeMultiplier); + iSignal.volume = iSignal.volume * (multiplier * volumeMultiplier); } } // // Handle Signal ... - if(isSignalValid) { + if (isSignalValid) + { // AddRef( iSignal, - eSignals // + eSignals // ); } } @@ -4091,11 +4485,12 @@ class XSCX121SetupEA : public XSCBaseEA { // // Cutom Signal Execution ... - if(IsValidSize(result)) { + if (IsValidSize(result)) + { // Copy( eSignals, - signals // + signals // ); // @@ -4115,7 +4510,8 @@ class XSCX121SetupEA : public XSCBaseEA { // - Check Start and End time or Trading Dates ... // - handle Trailing or Risk free Signals based on several conditions ... // and etc ... - bool HandleStateManagement(XSignal &signals[]) override { + bool HandleStateManagement(XSignal &signals[]) override + { // bool result = false; @@ -4150,12 +4546,14 @@ class XSCX121SetupEA : public XSCBaseEA { // Signal Info ... // - void OnSignalExecuted(const XSignal &signal) override { + void OnSignalExecuted(const XSignal &signal) override + { // // Signal Info Manager ... - XSignal tSignal = signal; - bool isSupport = IsSupport(signal.comment); - if(!isSupport) { + XSignal tSignal = signal; + bool isSupport = IsSupport(signal.comment); + if (!isSupport) + { mTradeHandler.Update(tSignal); } @@ -4165,9 +4563,10 @@ class XSCX121SetupEA : public XSCBaseEA { // void OnSignalExecutionFailed( - const XSignal &signal, - const ENUM_X_SIGNAL_EXECUTION_RESULT reason // - ) override { + const XSignal &signal, + const ENUM_X_SIGNAL_EXECUTION_RESULT reason // + ) override + { // // Signal Info Manager ... XSignal tSignal = signal; @@ -4178,16 +4577,18 @@ class XSCX121SetupEA : public XSCBaseEA { // void OnPositionClosed( const XPosition &position, - const string comment // - ) override { + const string comment // + ) override + { // // When a Position Closed Manually ... // Signal Info Manager ... - XPosition tPosition = position; - bool isSupport = ExtractSupportedTicket(position.comment) > 0; - bool isEQMSupport = ExtractEQMSupportedTicket(position.comment) > 0; - tPosition.comment = comment; - if(!isSupport && !isEQMSupport) { + XPosition tPosition = position; + bool isSupport = ExtractSupportedTicket(position.comment) > 0; + bool isEQMSupport = ExtractEQMSupportedTicket(position.comment) > 0; + tPosition.comment = comment; + if (!isSupport && !isEQMSupport) + { mTradeHandler.Update(tPosition); } @@ -4196,7 +4597,8 @@ class XSCX121SetupEA : public XSCBaseEA { } // - void OnStopLossTriggered(const XDeal &deal) override { + void OnStopLossTriggered(const XDeal &deal) override + { // // When a Position's Stop Loss Triggered ... // Signal Info Manager ... @@ -4206,7 +4608,8 @@ class XSCX121SetupEA : public XSCBaseEA { } // - void OnTakeProfitTriggered(const XDeal &deal) override { + void OnTakeProfitTriggered(const XDeal &deal) override + { // // When a Position's Take Profit Triggered ... // Signal Info Manager ... @@ -4217,13 +4620,14 @@ class XSCX121SetupEA : public XSCBaseEA { // // Protected ... - protected: +protected: // // Tools ... // // Check Signalling Enable or not ... - bool IsEnable() { + bool IsEnable() + { // bool result = false; @@ -4234,10 +4638,10 @@ class XSCX121SetupEA : public XSCBaseEA { // // Check Signalling Time ... MqlDateTime cTime; - bool isTimeRecieved = TimeCurrent(cTime); + bool isTimeRecieved = TimeCurrent(cTime); // - int endHour = EndSignallingHoure(); + int endHour = EndSignallingHoure(); int startHour = StartSignallingHoure(); // @@ -4255,20 +4659,23 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool CanCloseOnTime() { + bool CanCloseOnTime() + { // bool result = false; // result = mCloseOnSpecificTime >= 0 && mCloseOnSpecificTime <= 23; - if(!result) { + if (!result) + { return result; } // MqlDateTime timeStruct; result = TimeCurrent(timeStruct); - if(!result) { + if (!result) + { return result; } @@ -4281,17 +4688,20 @@ class XSCX121SetupEA : public XSCBaseEA { // // Custom Signal Execution ... - void HandleSignals(XSignal &signals[]) { + void HandleSignals(XSignal &signals[]) + { // int signalsCount = ArraySize(signals); - if(!IsValidSize(signals)) { + if (!IsValidSize(signals)) + { return; } // - bool isMarginPassed = IsMarginPassed(); + bool isMarginPassed = IsMarginPassed(); bool isDrawdownPassed = IsDrawdownPassed(); - if(!isDrawdownPassed) { + if (!isDrawdownPassed) + { // string message = "Desn't Have Good State For Execute Signals ..."; @@ -4304,32 +4714,38 @@ class XSCX121SetupEA : public XSCBaseEA { // EQMHandleForceSignals(signals); return; - } else { + } + else + { mForce = false; } // bool executeOnBreakouts = ExecuteSignalsOnBreakout(); - if(executeOnBreakouts) { + if (executeOnBreakouts) + { // XSignal bSignals[]; - int bSignalsCount = mTradeHandler.GetBreakoutsSignals(bSignals); - if(IsValidSize(bSignalsCount)) { + int bSignalsCount = mTradeHandler.GetBreakoutsSignals(bSignals); + if (IsValidSize(bSignalsCount)) + { // ENUM_X_SIGNAL_EXECUTION_RESULT states[]; - int executedSignalsCount = ExecuteSignals( + int executedSignalsCount = ExecuteSignals( signals, states, - false // + false // ); } - } else { + } + else + { // ENUM_X_SIGNAL_EXECUTION_RESULT states[]; - int executedSignalsCount = ExecuteSignals( + int executedSignalsCount = ExecuteSignals( signals, states, - false // + false // ); } } @@ -4337,23 +4753,26 @@ class XSCX121SetupEA : public XSCBaseEA { // // Check Delay Between Two Signals ... bool IsSignalDelayPassed( - XSignal &signal // - ) { + XSignal &signal // + ) + { // bool result = false; // // Check Signal Validation ... result = signal.IsValid(); - if(!result) { + if (!result) + { return result; } // // Check Delay Signals Allowed ... int delay = DelayBetweenTwoSignal(); - result = delay <= 0; - if(result) { + result = delay <= 0; + if (result) + { return result; } @@ -4361,24 +4780,25 @@ class XSCX121SetupEA : public XSCBaseEA { // Retrieve Positions ... // Based On Provider and Symbol and TimeFrame ... XPosition positions[]; - int positionsCount = mTrader.GetPositions( + int positionsCount = mTrader.GetPositions( positions, signal.symbol, - NULL, // signal.provider, - NULL, // signal.period, + NULL, // signal.provider, + NULL, // signal.period, ToPositionType(signal.type), - true // Filter By Magic ... + true // Filter By Magic ... ); result = !IsValidSize(positionsCount); - if(result) { + if (result) + { return result; } // XPosition youngest; - int youngestAge = GetYoungest( + int youngestAge = GetYoungest( youngest, - positions // + positions // ); result = youngestAge >= delay; @@ -4387,9 +4807,10 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool IsMarginPassed() { + bool IsMarginPassed() + { // - double freeMargin = mTrader.mAccount.GetFreeMargin(); + double freeMargin = mTrader.mAccount.GetFreeMargin(); double minFreeMargingForHandleForce = MinFreeMargingForOpenTrades(); // @@ -4400,13 +4821,14 @@ class XSCX121SetupEA : public XSCBaseEA { } // - bool IsDrawdownPassed() { + bool IsDrawdownPassed() + { // bool result = false; // - double maxAllowedDrawdownPercent = 5; // MaxAllowedDrawdownPercent(); - double drawdownPercent = GetDrawdownPercent(); + double maxAllowedDrawdownPercent = 5; // MaxAllowedDrawdownPercent(); + double drawdownPercent = GetDrawdownPercent(); // result = maxAllowedDrawdownPercent <= 0 ? true : drawdownPercent <= maxAllowedDrawdownPercent; @@ -4420,33 +4842,36 @@ class XSCX121SetupEA : public XSCBaseEA { // // Force Close All Positions Due EQM Hedge ... - bool DoEQMForceClose() { + bool DoEQMForceClose() + { // bool result = false; // XPosition positions[]; - int positionsCount = mTrader.GetPositions(positions); - result = IsValidSize(positionsCount); - if(!result) { + int positionsCount = mTrader.GetPositions(positions); + result = IsValidSize(positionsCount); + if (!result) + { return result; } // double profit = SpecifiedCalculatePositionsProfit( - positions // + positions // ); // string comment = XEQMSupportToken + " Hedge ..."; - int closed = Close( + int closed = Close( positions, - comment // + comment // ); // result = IsValidSize(closed); - if(result) { + if (result) + { // mTradeHandler.Sync(); EQMClearAllForceStates(); @@ -4455,7 +4880,8 @@ class XSCX121SetupEA : public XSCBaseEA { // // Handle Sleeping ... int restingTime = RestingAfterHedge(); - if(result && IsValidSize(restingTime)) { + if (result && IsValidSize(restingTime)) + { Sleeping(restingTime); } @@ -4465,33 +4891,38 @@ class XSCX121SetupEA : public XSCBaseEA { // // Do All Protecting Mechanism ... - void DoEQMProtect() { + void DoEQMProtect() + { // XSignal supports[]; - int supportsCount = mTradeHandler.DoProtect( + int supportsCount = mTradeHandler.DoProtect( supports, - mSetups // + mSetups // ); // - if(IsValidSize(supportsCount)) { + if (IsValidSize(supportsCount)) + { EQMExecuteSignals(supports); } } // // Handle Close Trades on Specific Time ... - void DoEQMCloseOnSpecificTime() { + void DoEQMCloseOnSpecificTime() + { // bool canClose = CanCloseOnTime(); - if(!canClose) { + if (!canClose) + { return; } // XPosition positions[]; - int positionsCount = mTrader.GetPositions(positions); - if(!IsValidSize(positionsCount)) { + int positionsCount = mTrader.GetPositions(positions); + if (!IsValidSize(positionsCount)) + { return; } @@ -4501,9 +4932,10 @@ class XSCX121SetupEA : public XSCBaseEA { // int closed = Close( positions, - comment // + comment // ); - if(IsValidSize(closed)) { + if (IsValidSize(closed)) + { // string message = XEQMSupportToken + " Closed " + ToString(closed) + " Positions on Specified Time ..."; @@ -4517,20 +4949,23 @@ class XSCX121SetupEA : public XSCBaseEA { // this Signals passed From Request For Signal Function ... // these need to add to Trade Handler .... void EQMHandleInvalidSignal( - XSignal &signal, // Invalid Signal - int pushers, // Pushers - bool isValid, // IsValid Signal ... - X121SetupConditions &conditions[] // All Time Frames Conditions - ) { + XSignal &signal, // Invalid Signal + int pushers, // Pushers + bool isValid, // IsValid Signal ... + X121SetupConditions &conditions[] // All Time Frames Conditions + ) + { // int setupIDX = FindSetupIndex(signal.symbol); - if(!IsValidIndex(setupIDX)) { + if (!IsValidIndex(setupIDX)) + { return; } // // bool isForce = mSetups[setupIDX].ForceState(); - if(!mForce) { + if (!mForce) + { return; } @@ -4542,7 +4977,8 @@ class XSCX121SetupEA : public XSCBaseEA { XSignal signals[]; // - if(isValid) { + if (isValid) + { // bool canSupport = // @@ -4566,7 +5002,7 @@ class XSCX121SetupEA : public XSCBaseEA { // AddRef( signal, - signals // + signals // ); // @@ -4581,12 +5017,13 @@ class XSCX121SetupEA : public XSCBaseEA { conditions[1], conditions[2], conditions[3], - conditions[4] // + conditions[4] // ); } // - if(ArraySize(signals) > 0) { + if (ArraySize(signals) > 0) + { EQMExecuteSignals(signals); } } @@ -4596,16 +5033,19 @@ class XSCX121SetupEA : public XSCBaseEA { // HandleSignals Functions passed Signals to this Method ... // these Signals Added to Trade Handler Before ... void EQMHandleForceSignals( - XSignal &signals[] // - ) { + XSignal &signals[] // + ) + { // - if(!mForce) { + if (!mForce) + { return; } // int count = ArraySize(signals); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return; } @@ -4615,9 +5055,11 @@ class XSCX121SetupEA : public XSCBaseEA { } // - void EQMHandleForceState() { + void EQMHandleForceState() + { // - if(!mForce) { + if (!mForce) + { return; } @@ -4627,8 +5069,9 @@ class XSCX121SetupEA : public XSCBaseEA { // // One: Based On Positions Count ... XPosition positions[]; - int positionsCount = mTrader.GetPositions(positions); - if(!IsValidSize(positionsCount)) { + int positionsCount = mTrader.GetPositions(positions); + if (!IsValidSize(positionsCount)) + { // mForce = false; return; @@ -4636,9 +5079,10 @@ class XSCX121SetupEA : public XSCBaseEA { // // Two: Based On Free Margin ... - bool isMarginPassed = IsMarginPassed(); + bool isMarginPassed = IsMarginPassed(); bool isDrawdownPassed = IsDrawdownPassed(); - if(isDrawdownPassed) { + if (isDrawdownPassed) + { // mForce = false; return; @@ -4654,11 +5098,13 @@ class XSCX121SetupEA : public XSCBaseEA { // EQM Protecting Senarios and must be Executed withouth // any Policies ... void EQMExecuteSignals( - XSignal &signals[] // - ) { + XSignal &signals[] // + ) + { // int signalsCount = ArraySize(signals); - if(!IsValidSize(signals)) { + if (!IsValidSize(signals)) + { return; } @@ -4666,12 +5112,13 @@ class XSCX121SetupEA : public XSCBaseEA { // // Execute Supports ... ENUM_X_SIGNAL_EXECUTION_RESULT states[]; - int executed = ExecuteSignals( + int executed = ExecuteSignals( signals, states, - false // Ignore Policies ... + false // Ignore Policies ... ); - if(executed != signalsCount) { + if (executed != signalsCount) + { // // TODO: Dow What We Want ... // Print("Error On Executing Support Signal ..."); @@ -4679,53 +5126,61 @@ class XSCX121SetupEA : public XSCBaseEA { // // Remove Supported Signals TP and SL and leave them for Handling using HEDGE Mechanism ... - if(IsValidSize(executed)) { + if (IsValidSize(executed)) + { // - for(int i = 0; i < signalsCount; i++) { + for (int i = 0; i < signalsCount; i++) + { // ENUM_X_SIGNAL_EXECUTION_RESULT iState = states[i]; - if(iState != X_SIGNAL_EXECUTION_SUCCEED) { + if (iState != X_SIGNAL_EXECUTION_SUCCEED) + { continue; } // XSignal iSignal = signals[i]; - if(!iSignal.IsValid() || !iSignal.IsExecuted()) { + if (!iSignal.IsValid() || !iSignal.IsExecuted()) + { continue; } // ulong iParentTicket = ExtractParentTicket(iSignal.comment); - if(iParentTicket <= 0) { + if (iParentTicket <= 0) + { continue; } // XPosition iParent; - bool hasParent = mTrader.GetPosition( + bool hasParent = mTrader.GetPosition( iParentTicket, - iParent // + iParent // ); - if(!hasParent) { + if (!hasParent) + { continue; } // // Check Parent Has TP or SL ... - if(iParent.tp == 0 && iParent.sl == 0) { + if (iParent.tp == 0 && iParent.sl == 0) + { continue; } // // Remove TP and SL of Supported Positions ... - string comment = "EQM Remove TPSL ..."; - bool isModified = Modify( + string comment = "EQM Remove TPSL ..."; + bool isModified = Modify( iParentTicket, 0, 0, - comment // + comment // ); - if(isModified) { + if (isModified) + { // // TODO: // do What we want ... @@ -4736,52 +5191,55 @@ class XSCX121SetupEA : public XSCBaseEA { // // Clear All Force States of Setups ... - void EQMClearAllForceStates() { + void EQMClearAllForceStates() + { // int setupsCount = CountSetups(); - if(!IsValidSize(setupsCount)) { + if (!IsValidSize(setupsCount)) + { return; } // - for(int i = 0; i < setupsCount; i++) { + for (int i = 0; i < setupsCount; i++) + { mSetups[i].ForceState(false); } } // // Private ... - private: +private: // // Props ... // // Signals ... - bool mAllowLong; // Allow Long - bool mAllowShort; // Allow Short - int mReuiredSignalVerifications; // Required Verifications for Validate Signals - bool mExecuteSignalsOnBreakout; // Execute Signals On Breakouts - bool mGetVerificationFromOtherTimeFrames; // Get Verifications from Other Time Frames + bool mAllowLong; // Allow Long + bool mAllowShort; // Allow Short + int mReuiredSignalVerifications; // Required Verifications for Validate Signals + bool mExecuteSignalsOnBreakout; // Execute Signals On Breakouts + bool mGetVerificationFromOtherTimeFrames; // Get Verifications from Other Time Frames // // Risk Management ... - double mVolume; // Volume - double mTPPoint; // TP Point - double mSLPoint; // SL Point - bool mIgnoreTP; // Ignore Calculated TP - bool mIgnoreSL; // Ignore Calculated SL - int mMaxAllowedTrades; // Max Alloed Positions - bool mUseMaxAllowedPerDirection; // Use Max Allowed Positions Per Direction - bool mIncreaseNextSignalsVolume; // Increase Next Signals Volume - double mIncreaseNextSignalsVolumeMultiplier; // Increase Next Signals Volume Multiplier - bool mAcceptNextDirectionalSignalsWhenFirstInProfit; // Accept Same Symbol/Type Signal when Last in Profit + double mVolume; // Volume + double mTPPoint; // TP Point + double mSLPoint; // SL Point + bool mIgnoreTP; // Ignore Calculated TP + bool mIgnoreSL; // Ignore Calculated SL + int mMaxAllowedTrades; // Max Alloed Positions + bool mUseMaxAllowedPerDirection; // Use Max Allowed Positions Per Direction + bool mIncreaseNextSignalsVolume; // Increase Next Signals Volume + double mIncreaseNextSignalsVolumeMultiplier; // Increase Next Signals Volume Multiplier + bool mAcceptNextDirectionalSignalsWhenFirstInProfit; // Accept Same Symbol/Type Signal when Last in Profit // // Signalling ... - bool mCloseOnOpposit; // Close all Positions on Opposit - int mEndSignallingHoure; // End Signalling at Specific Time - int mCloseOnSpecificTime; // Close All Trades in Specific Time - int mStartSignallingHoure; // Start Signalling at Specific Time + bool mCloseOnOpposit; // Close all Positions on Opposit + int mEndSignallingHoure; // End Signalling at Specific Time + int mCloseOnSpecificTime; // Close All Trades in Specific Time + int mStartSignallingHoure; // Start Signalling at Specific Time // // Force State: @@ -4790,17 +5248,18 @@ class XSCX121SetupEA : public XSCBaseEA { // - Receive Signals with minimal Verifications; // - Increase Volume Size of in Profit Positions; // - etc ... - bool mForce; // Determine in Force State or not - int mDelayBetweenTwoSignal; // Delay between two same signal - double mMinFreeMargingForOpenTrades; // Min Free Margin for Open Trades + bool mForce; // Determine in Force State or not + int mDelayBetweenTwoSignal; // Delay between two same signal + double mMinFreeMargingForOpenTrades; // Min Free Margin for Open Trades // - XSCX121SetupCycles *mSetups[]; // Number of Setups - XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions + XSCX121SetupCycles *mSetups[]; // Number of Setups + XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions // // Apply Default Configurations ... - void DefaultConfigs() { + void DefaultConfigs() + { // // Signals ... AllowLong(false); @@ -4869,27 +5328,31 @@ class XSCX121SetupEA : public XSCBaseEA { // // Tools ... - int CountSetups() { + int CountSetups() + { return ArraySize(mSetups); } // // Find Setup Index by Symbol and Period ... int FindSetupIndex( - string symbol, - ENUM_TIMEFRAMES period // - ) { + string symbol, + ENUM_TIMEFRAMES period // + ) + { // int result = -1; // int count = CountSetups(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // XSCX121SetupCycles *iSetup = mSetups[i]; @@ -4897,7 +5360,8 @@ class XSCX121SetupEA : public XSCBaseEA { X121SetupInputs iInputs = iSetup.GetInputs(); // - if(iInputs.symbol == symbol && iInputs.period == period) { + if (iInputs.symbol == symbol && iInputs.period == period) + { // result = i; break; @@ -4911,19 +5375,22 @@ class XSCX121SetupEA : public XSCBaseEA { // // Find Setup Index by Providing Symbol ... int FindSetupIndex( - string symbol // - ) { + string symbol // + ) + { // int result = -1; // int count = CountSetups(); - if(!IsValidSize(count)) { + if (!IsValidSize(count)) + { return result; } // - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) + { // XSCX121SetupCycles *iSetup = mSetups[i]; @@ -4931,7 +5398,8 @@ class XSCX121SetupEA : public XSCBaseEA { X121SetupInputs iInputs = iSetup.GetInputs(); // - if(iInputs.symbol == symbol) { + if (iInputs.symbol == symbol) + { // result = i; break; diff --git a/Experts/x-test.ea.mq5 b/Experts/x-test.ea.mq5 new file mode 100644 index 00000000..bd176b90 --- /dev/null +++ b/Experts/x-test.ea.mq5 @@ -0,0 +1,304 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XTest MQL5 Expert Advisor +// ------------------------------------------------- +// Name: XTestEA +// Description: an Exper Advisor which used XTestSetup +// to Analyse Market ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////x +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XTestEA" +#property strict + +// +#define ShortName "XTestEA" + +// +// Imports ... +#include "../Test/x-saherelm.test.xea.mq5" +#include "../Helpers/x-saherelm.xct.helper.mq5" +#include "../Helpers/x-saherelm.xcc.helper.mq5" + +// +// Inputs ... +long mMagicNumber = 78692110; // Magic Number +int mSlippage = 10; // Slippgae + +// +double eaVolume = 0.01; +double eaAllowLong = true; +double eaAllowShort = true; + +// +// Variables ... +XSCXTestSetupEA *mSetupEA; +XSCXCTHelper *mCTHelper; +XSCXCCHelper *mCCHelper; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitialEA()) + { + return INIT_FAILED; + } + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + // De Initialize XSampleEA Providers ... + delete mSetupEA; + delete mCTHelper; + delete mCCHelper; +} + +// +// On Tick Handler ... +void OnTick() +{ + mSetupEA.OnTick(); +} + +// +// Custom Functions ... + +// +bool ValidateInputs() +{ + // + bool result = false; + + // + result = true; + + // + return result; +} + +// +bool InitialEA() +{ + // + bool result = false; + + // + + // + // Bar Timer ... + XCTInputs ctInputs; + ctInputs.Default(); + mCTHelper = new XSCXCTHelper(); + result = mCTHelper.Init( + _Symbol, + _Period, + ctInputs // + ); + if (!result) + { + return result; + } + + // + // Bar Styles ... + XCCInputs ccInputs; + ccInputs.Default(); + mCCHelper = new XSCXCCHelper(); + result = mCCHelper.Init( + _Symbol, + _Period, + ccInputs // + ); + if (!result) + { + return result; + } + + // + // Preparing EA Class ... + mSetupEA = new XSCXTestSetupEA( + mSlippage, + mMagicNumber // + ); + + // + // Configuring EA Class ... + mSetupEA.Volume(eaVolume); + mSetupEA.AllowLong(eaAllowLong); + mSetupEA.AllowShort(eaAllowShort); + + // + // Configure Indicators ... + XTestInputs setupInputsDefault; + setupInputsDefault.Default(); + PreConfigureStyles(setupInputsDefault); + + // + // Instantiate Per Symbol ... + + // + string iSymbol = _Symbol; + ENUM_TIMEFRAMES iPeriod = _Period; + + // + XTestInputs iInputs; + iInputs = setupInputsDefault; + iInputs.tpPoint = 60; + iInputs.slPoint = 60; + iInputs.symbol = iSymbol; + iInputs.period = iPeriod; + iInputs.volume = eaVolume; + result = iInputs.IsValid(); + if (!result) + { + return result; + } + + // + XSCXTestSetup *iSetup = new XSCXTestSetup(); + result = iSetup.Init(iInputs); + if (!result) + { + return result; + } + + // + result = mSetupEA.AddSetup(iSetup); + + // + return result; +} + +// +void PreConfigureStyles(XTestInputs &inputs) +{ + // + // XRL ... + inputs.rlInputs.showFast = true; + inputs.rlInputs.showSlow = true; + inputs.rlInputs.showVerifier = true; + + // + // XHTD ... + inputs.htdInputs.show = false; + + // + // XATSL ... + inputs.atslInputs.show = true; + + // + // XSLN ... + inputs.slnInputs.show = false; + + // + // XDMNT ... + inputs.dmntInputs.showBull = false; + inputs.dmntInputs.showBear = false; + + // + // XSTR ... + inputs.strInputs.showTrends = false; + inputs.strInputs.fillTrends = false; + + // + // XPV ... + inputs.pvInputs.showPeaksAndVales = true; + inputs.pvInputs.showLevels = false; + inputs.pvInputs.showConsolidations = false; + inputs.pvInputs.showFibo1Levels = false; + inputs.pvInputs.showFibo2Levels = false; + inputs.pvInputs.showFibo3Levels = true; + inputs.pvInputs.showFibo4Levels = false; + inputs.pvInputs.showFibo5Levels = false; + + // + // XMC ... + inputs.mcInputs.showSar = false; + inputs.mcInputs.showFastMa = false; + inputs.mcInputs.showSlowMa = false; + inputs.mcInputs.showVerifierMa = false; + + // + // XHK ... + inputs.hkInputs.drawHikenAshi = false; + inputs.hkInputs.drawSmoothedHikenAshi = false; + + // + // XCHE ... + inputs.cheInputs.showLongExit1Line = false; + inputs.cheInputs.showShortExit1Line = false; + inputs.cheInputs.showLongExit2Line = false; + inputs.cheInputs.showShortExit2Line = false; + + // + // XICH ... + inputs.ichInputs.showTenkanSen = false; + inputs.ichInputs.showKijunSen = false; + inputs.ichInputs.showKijunSenPlus = false; + inputs.ichInputs.showKijunSenNegative = false; + inputs.ichInputs.showChikouSpan = false; + inputs.ichInputs.showSenkouSpanA = false; + inputs.ichInputs.showSenkouSpanB = false; + inputs.ichInputs.showKumo = false; + + // + // XMRB ... + inputs.mrbInputs.showFastMa = false; + inputs.mrbInputs.showSlowMa = false; + inputs.mrbInputs.showRibbon = false; + + // + // XASCT ... + inputs.asctInputs.showLongs = false; + inputs.asctInputs.showShorts = false; + + // + // XSSLC ... + inputs.sslcInputs.showUp = false; + inputs.sslcInputs.showDown = false; + + // + // XHULL ... + inputs.hullInputs.showUpZone = false; + inputs.hullInputs.showDownZone = false; +} + +// \ No newline at end of file diff --git a/Helpers/x-saherelm.xrl.helper.mq5 b/Helpers/x-saherelm.xrl.helper.mq5 index 87882e9d..14d0b633 100644 --- a/Helpers/x-saherelm.xrl.helper.mq5 +++ b/Helpers/x-saherelm.xrl.helper.mq5 @@ -40,7 +40,7 @@ enum ENUM_XRL_BUFFERS { // XRL_FAST_LINE = 0, - XRL_SLOW_LINE = 1, + XRL_SLOW_LINE = 2, XRL_VERIFIER_LINE = 2, // XRL_FAST_STATE_LINE = 8, diff --git a/Test/x-saherelm.test.setup.mq5 b/Test/x-saherelm.test.setup.mq5 new file mode 100644 index 00000000..c6bf927a --- /dev/null +++ b/Test/x-saherelm.test.setup.mq5 @@ -0,0 +1,1728 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XTestSetup +// Description: provides implementation of Test +// Setup ... +// +// +// 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 "../Libraries/x-saherelm.xtrade.lib.mq5" +#include "../Classes/x-saherelm.xalert.class.mq5" + +// +#include "../Helpers/x-saherelm.xrl.helper.mq5" +#include "../Helpers/x-saherelm.xmc.helper.mq5" +#include "../Helpers/x-saherelm.xpv.helper.mq5" +#include "../Helpers/x-saherelm.xtd.helper.mq5" +#include "../Helpers/x-saherelm.xhk.helper.mq5" +#include "../Helpers/x-saherelm.xsln.helper.mq5" +#include "../Helpers/x-saherelm.xstr.helper.mq5" +#include "../Helpers/x-saherelm.xche.helper.mq5" +#include "../Helpers/x-saherelm.xich.helper.mq5" +#include "../Helpers/x-saherelm.xmrb.helper.mq5" +#include "../Helpers/x-saherelm.xosc.helper.mq5" +#include "../Helpers/x-saherelm.xvlm.helper.mq5" +#include "../Helpers/x-saherelm.xhtd.helper.mq5" +#include "../Helpers/x-saherelm.xatsl.helper.mq5" +#include "../Helpers/x-saherelm.xdmnt.helper.mq5" +#include "../Helpers/x-saherelm.xasct.helper.mq5" +#include "../Helpers/x-saherelm.xsslc.helper.mq5" +#include "../Helpers/x-saherelm.xhull.helper.mq5" +#include "../Helpers/x-saherelm.xadxtd.helper.mq5" + +// +struct XTestInputs +{ + // + // Props ... + + // + // Commons ... + string symbol; // Symbol + ENUM_TIMEFRAMES period; // Time Frame + + // + double volume; // + double tpPoint; // + double slPoint; // + + // + // Helpers Inputs ... + XRLInputs rlInputs; // XRL Inputs + XMCInputs mcInputs; // XMC Inputs + XPVInputs pvInputs; // XPV Inputs + XTDInputs tdInputs; // XTD Inputs + XHKInputs hkInputs; // XHK Inputs + XHTDInputs htdInputs; // XHTD Inputs + XCHEInputs cheInputs; // XCHE Inputs + XICHInputs ichInputs; // XICH Inputs + XSTRInputs strInputs; // XSTR Inputs + XMRBInputs mrbInputs; // XMRB Inputs + XOSCInputs oscInputs; // XOSC Inputs + XVLMInputs vlmInputs; // XVLM Inputs + XSLNInputs slnInputs; // XSLN Inputs + XATSLInputs atslInputs; // XATSL Inputs + XDMNTInputs dmntInputs; // XDMNT Inputs + XASCTInputs asctInputs; // XASCT Inputs + XSSLCInputs sslcInputs; // XSSLC Inputs + XHULLInputs hullInputs; // XHULL Inputs + XADXTDInputs adxtdInputs; // XADXTD Inputs + + // + // Constructor ... + XTestInputs() + { + Clean(); + } + + // + // Tools ... + // + bool Init() + { + // + Default(); + + // + bool result = IsValid(); + + // + return result; + } + bool Init( + string _symbol, // Symbol + ENUM_TIMEFRAMES _period, // Time Frame + XRLInputs &_rlInputs, // XRL Inputs + XMCInputs &_mcInputs, // XMC Inputs + XPVInputs &_pvInputs, // XPV Inputs + XTDInputs &_tdInputs, // XTD Inputs + XHKInputs &_hkInputs, // XHK Inputs + XHTDInputs &_htdInputs, // XHTD Inputs + XCHEInputs &_cheInputs, // XCHE Inputs + XICHInputs &_ichInputs, // XICH Inputs + XSTRInputs &_strInputs, // XSTR Inputs + XMRBInputs &_mrbInputs, // XMRB Inputs + XOSCInputs &_oscInputs, // XOSC Inputs + XVLMInputs &_vlmInputs, // XVLM Inputs + XSLNInputs &_slnInputs, // XSLN Inputs + XATSLInputs &_atslInputs, // XATSL Inputs + XDMNTInputs &_dmntInputs, // XDMNT Inputs + XASCTInputs &_asctInputs, // XASCT Inputs + XSSLCInputs &_sslcInputs, // XSSLC Inputs + XHULLInputs &_hullInputs, // XHULL Inputs + XADXTDInputs &_adxtdInputs // XADXTD Inputs + ) + { + // + this.symbol = _symbol; + this.period = _period; + + // + // Helpers Inputs ... + this.rlInputs = _rlInputs; + this.mcInputs = _mcInputs; + this.pvInputs = _pvInputs; + this.tdInputs = _tdInputs; + this.hkInputs = _hkInputs; + this.htdInputs = _htdInputs; + this.cheInputs = _cheInputs; + this.ichInputs = _ichInputs; + this.strInputs = _strInputs; + this.mrbInputs = _mrbInputs; + this.oscInputs = _oscInputs; + this.vlmInputs = _vlmInputs; + this.atslInputs = _atslInputs; + this.dmntInputs = _dmntInputs; + this.asctInputs = _asctInputs; + this.sslcInputs = _sslcInputs; + this.hullInputs = _hullInputs; + this.adxtdInputs = _adxtdInputs; + + // + bool result = IsValid(); + + // + return result; + } + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + period = NULL; + + // + tpPoint = 0; + slPoint = 0; + + // + rlInputs.Clean(); + mcInputs.Clean(); + pvInputs.Clean(); + tdInputs.Clean(); + hkInputs.Clean(); + cheInputs.Clean(); + ichInputs.Clean(); + strInputs.Clean(); + mrbInputs.Clean(); + oscInputs.Clean(); + vlmInputs.Clean(); + slnInputs.Clean(); + htdInputs.Clean(); + asctInputs.Clean(); + sslcInputs.Clean(); + hullInputs.Clean(); + atslInputs.Clean(); + dmntInputs.Clean(); + adxtdInputs.Clean(); + } + + // + // Default ... + void Default() + { + // + tpPoint = 0; + slPoint = 0; + + // + rlInputs.Default(); + mcInputs.Default(); + pvInputs.Default(); + tdInputs.Default(); + hkInputs.Default(); + cheInputs.Default(); + ichInputs.Default(); + strInputs.Default(); + mrbInputs.Default(); + oscInputs.Default(); + vlmInputs.Default(); + slnInputs.Default(); + htdInputs.Default(); + asctInputs.Default(); + sslcInputs.Default(); + hullInputs.Default(); + atslInputs.Default(); + dmntInputs.Default(); + adxtdInputs.Default(); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + IsValid(period) + // + ; + if (!result) + { + return result; + } + + // + result = rlInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = tdInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = slnInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = pvInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = hkInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = cheInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = ichInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = strInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = mrbInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = oscInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = vlmInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = mcInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = asctInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = sslcInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = hullInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = adxtdInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = htdInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = atslInputs.IsValid(); + if (!result) + { + return result; + } + + // + result = dmntInputs.IsValid(); + if (!result) + { + return result; + } + + // + return result; + } +}; + +// +struct XTestConditions +{ + // + // Props ... + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Conditions ... + XRLConditions rlConditions; + XMCConditions mcConditions; + XPVConditions pvConditions; + XTDConditions tdConditions; + XHKConditions hkConditions; + XCHEConditions cheConditions; + XICHConditions ichConditions; + XSTRConditions strConditions; + XMRBConditions mrbConditions; + XVLMConditions vlmConditions; + XHTDConditions htdConditions; + XSLNConditions slnConditions; + XATSLConditions atslConditions; + XASCTConditions asctConditions; + XSSLCConditions sslcConditions; + XHULLConditions hullConditions; + XDMNTConditions dmntConditions; + XADXTDConditions adxtdConditions; + + // + // Oscillators ... + double cci[]; + double rsi[]; + double macd[]; + double macdSignal[]; + + // + // Signal ... + + // + // Conditions Provided Signal ... + XSignal signal; + + // + // Signal Verifications ... + int pushers; + + // + // Signal Providers .... + string providers[]; + + // + // Conditions Verifications ... + int longVerifications; + int shortVerifications; + + // + void CleanSignal() + { + // + signal.Clean(); + Clean(providers); + + // + pushers = 0; + longVerifications = 0; + shortVerifications = 0; + } + + // + // Generate Conditions Based Signals ... + bool GenerateSignal( + double &tp, + double &sl, + double volume, + double tpPoint, + double slPoint // + ) + { + // + bool result = false; + + // + bool hasLong = GenerateLongSignal( + tp, + sl, + volume, + tpPoint, + slPoint // + ); + if (hasLong) + { + // + result = hasLong; + return result; + } + + // + bool hasShort = GenerateShortSignal( + tp, + sl, + volume, + tpPoint, + slPoint // + ); + if (hasShort) + { + // + result = hasShort; + return result; + } + + // + return result; + } + + // + bool GenerateLongSignal( + double &tp, + double &sl, + double volume, + double tpPoint, + double slPoint // + ) + { + // + bool result = false; + + // + double mTP = 0; + double mSL = 0; + double mR2R = 1.5; + double mEntry = 0; + + // + ENUM_POSITION_TYPE mType = POSITION_TYPE_BUY; + ENUM_X_ORDER_MODES mMode = X_ORDER_MODE_MARKET; + + // + mEntry = GetEntry( + symbol, + mType // + ); + + // + // XATRL ... + bool long1 = + // + // Start Conditions ... + (rlConditions.isVerifierSwitchedToBullish && + rlConditions.isFastBullish && + rlConditions.isSlowBearish && + rlConditions.isFastOverSlow) + // + && + // + // Verifications ... + // XSTR ... + (strConditions.isTrendBullish || + strConditions.isTrendSwitchedToBullish) + // + && + // + // XATSL ... + (atslConditions.isBullish || + atslConditions.isSwitchedToBullish) + // + && + // + // XHTD ... + (htdConditions.isBullish || + htdConditions.isSwitchedToBullish) + // + && + // + // XVLM ... + (vlmConditions.isVolumeBullish || + vlmConditions.isVolumeChangedToBullish) + // + && + // + // XCHE ... + (cheConditions.isBullish || + cheConditions.isStrongBullish || + cheConditions.isSwitchedToBullish || + cheConditions.isStrongSwitchedToBullish) + // + && + // + // XHK ... + (hkConditions.isHKBullish || + hkConditions.isSMHKBullish || + hkConditions.isHKSwitchedToBullish || + hkConditions.isSMHKSwitchedToBullish) + // + ; + if (long1) + { + // + Add( + "XATRL", + providers // + ); + + // + pushers++; + + // + // Calculate TP and SL ... + + // + mSL = atslConditions.atsl[1]; + + // + double risk = MathAbs(mSL - mEntry); + double reward = risk * mR2R; + + // + mTP = mEntry + reward; + + // + tp = mTP; + sl = mSL; + } + + // + result = + // + long1 + // + ; + if (result) + { + // + result = signal.Prepare( + symbol, + "XATRL", + period, + mType, + mMode, + mEntry, + volume, + 0, //mSL, + mTP // + ); + // if (result) + // { + // // + // XSignal opposit; + // bool canSupport = signal.GenerateOpposit(opposit); + // if (canSupport) + // { + // // + // AddRef( + // opposit, + // signal.supports // + // ); + // } + // } + } + + // + return result; + } + + // + bool GenerateShortSignal( + double &tp, + double &sl, + double volume, + double tpPoint, + double slPoint // + ) + { + // + bool result = false; + + // + return result; + + // + double mTP = 0; + double mSL = 0; + double mR2R = 1.5; + double mEntry = 0; + + // + ENUM_POSITION_TYPE mType = POSITION_TYPE_SELL; + ENUM_X_ORDER_MODES mMode = X_ORDER_MODE_MARKET; + + // + mEntry = GetEntry( + symbol, + mType // + ); + + // + // XATRL ... + bool long1 = + // + (rlConditions.isVerifierSwitchedToBullish && + rlConditions.isFastBullish && + rlConditions.isSlowBearish && + rlConditions.isFastOverSlow && + atslConditions.isBullish) + // + ; + if (long1) + { + // + Add( + "XATRL", + providers // + ); + + // + pushers++; + + // + // Calculate TP and SL ... + + // + mSL = atslConditions.atsl[1]; + + // + double risk = MathAbs(mSL - mEntry); + double reward = risk * mR2R; + + // + mSL = mEntry + risk; + mTP = mEntry - reward; + + // + tp = mTP; + sl = mSL; + } + + // + result = + // + long1 + // + ; + if (result) + { + // + result = signal.Prepare( + symbol, + "XATRL", + period, + mType, + mMode, + mEntry, + volume, + mSL, + mTP // + ); + } + + // + return result; + } + + // + // Generate Supports ... + // TODO: + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + time = NULL; + symbol = NULL; + period = NULL; + + // + Clean(cci); + Clean(rsi); + Clean(macd); + Clean(macdSignal); + + // + rlConditions.Clean(); + mcConditions.Clean(); + tdConditions.Clean(); + hkConditions.Clean(); + cheConditions.Clean(); + ichConditions.Clean(); + strConditions.Clean(); + mrbConditions.Clean(); + vlmConditions.Clean(); + slnConditions.Clean(); + htdConditions.Clean(); + atslConditions.Clean(); + asctConditions.Clean(); + sslcConditions.Clean(); + hullConditions.Clean(); + dmntConditions.Clean(); + adxtdConditions.Clean(); + + // + CleanSignal(); + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + double tempBullishScore = 0; + double tempBearishScore = 0; + + // + rlConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + mcConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + pvConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + slnConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + adxtdConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + strConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + cheConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + asctConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + tdConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + ichConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + hkConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + mrbConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + vlmConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + sslcConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + hullConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + htdConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + atslConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + dmntConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string pvSummary = pvConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string rlSummary = rlConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string mcSummary = mcConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string tdSummary = tdConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string hkSummary = hkConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string strSummary = strConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string cheSummary = cheConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string ichSummary = ichConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string mrbSummary = mrbConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string vlmSummary = vlmConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string slnSummary = slnConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string htdSummary = htdConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string atsSummary = atslConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string asctSummary = asctConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string sslcSummary = sslcConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string hullSummary = hullConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string dmntSummary = dmntConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string adxtdSummary = adxtdConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + + // + string conditionsStr = + // + pvSummary + separator + + rlSummary + separator + + mcSummary + separator + + tdSummary + separator + + hkSummary + separator + + ichSummary + separator + + mrbSummary + separator + + vlmSummary + separator + + slnSummary + separator + + strSummary + separator + + cheSummary + separator + + asctSummary + separator + + sslcSummary + separator + + hullSummary + separator + + adxtdSummary + separator + + htdSummary + separator + + atsSummary + separator + + dmntSummary + separator + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XTestSetup"; + } + + // +}; + +// +// Class ... +class XSCXTestSetup : public XSCBaseAlert +{ + // + // Public ... +public: + // + // Props ... + XSCXRLHelper *rlHelper; + XSCXMCHelper *mcHelper; + XSCXPVHelper *pvHelper; + XSCXTDHelper *tdHelper; + XSCXHKHelper *hkHelper; + XSCXCHEHelper *cheHelper; + XSCXICHHelper *ichHelper; + XSCXSTRHelper *strHelper; + XSCXMRBHelper *mrbHelper; + XSCXOSCHelper *oscHelper; + XSCXVLMHelper *vlmHelper; + XSCXSLNHelper *slnHelper; + XSCXHTDHelper *hdtHelper; + XSCXASCTHelper *asctHelper; + XSCXSSLCHelper *sslcHelper; + XSCXHULLHelper *hullHelper; + XSCXATSLHelper *atslHelper; + XSCXDMNTHelper *dmntHelper; + XSCXADXTDHelper *adxtdHelper; + + // + XBarTracker barTracker; + + // + // Constructor(s) ... + void XSCXTestSetup() {} + + // + // Deconstructor ... + void ~XSCXTestSetup() + { + // + delete rlHelper; + delete mcHelper; + delete pvHelper; + delete tdHelper; + delete hkHelper; + delete cheHelper; + delete ichHelper; + delete strHelper; + delete mrbHelper; + delete oscHelper; + delete vlmHelper; + delete hdtHelper; + delete asctHelper; + delete sslcHelper; + delete hullHelper; + delete atslHelper; + delete dmntHelper; + delete adxtdHelper; + } + + // + // Initializer ... + bool Init( + XTestInputs &_inputs // Configurations + ) + { + // + bool result = false; + + // + result = _inputs.IsValid(); + if (!result) + { + return result; + } + + // + inputs = _inputs; + + // + // Initialize Helpers ... + + // + // XRL ... + rlHelper = new XSCXRLHelper(); + result = rlHelper.Init( + inputs.symbol, + inputs.period, + inputs.rlInputs // + ); + if (!result) + { + return result; + } + + // + // XPV ... + pvHelper = new XSCXPVHelper(); + result = pvHelper.Init( + inputs.symbol, + inputs.period, + inputs.pvInputs // + ); + if (!result) + { + return result; + } + + // + // XSLN ... + slnHelper = new XSCXSLNHelper(); + result = slnHelper.Init( + inputs.symbol, + inputs.period, + inputs.slnInputs // + ); + if (!result) + { + return result; + } + + // + // XTD ... + tdHelper = new XSCXTDHelper(); + result = tdHelper.Init( + inputs.symbol, + inputs.period, + inputs.tdInputs // + ); + if (!result) + { + return result; + } + + // + // XHTD ... + hdtHelper = new XSCXHTDHelper(); + result = hdtHelper.Init( + inputs.symbol, + inputs.period, + inputs.htdInputs // + ); + if (!result) + { + return result; + } + + // + // XATSL ... + atslHelper = new XSCXATSLHelper(); + result = atslHelper.Init( + inputs.symbol, + inputs.period, + inputs.atslInputs // + ); + if (!result) + { + return result; + } + + // + // XDMNT ... + dmntHelper = new XSCXDMNTHelper(); + result = dmntHelper.Init( + inputs.symbol, + inputs.period, + inputs.dmntInputs // + ); + if (!result) + { + return result; + } + + // + // XHK ... + hkHelper = new XSCXHKHelper(); + result = hkHelper.Init( + inputs.symbol, + inputs.period, + inputs.hkInputs // + ); + if (!result) + { + return result; + } + + // + // XCHE ... + cheHelper = new XSCXCHEHelper(); + result = cheHelper.Init( + inputs.symbol, + inputs.period, + inputs.cheInputs // + ); + if (!result) + { + return result; + } + + // + // XICH ... + ichHelper = new XSCXICHHelper(); + result = ichHelper.Init( + inputs.symbol, + inputs.period, + inputs.ichInputs // + ); + if (!result) + { + return result; + } + + // + // XSTR ... + strHelper = new XSCXSTRHelper(); + result = strHelper.Init( + inputs.symbol, + inputs.period, + inputs.strInputs // + ); + if (!result) + { + return result; + } + + // + // XMRB ... + mrbHelper = new XSCXMRBHelper(); + result = mrbHelper.Init( + inputs.symbol, + inputs.period, + inputs.mrbInputs // + ); + if (!result) + { + return result; + } + + // + // XOSC ... + oscHelper = new XSCXOSCHelper(); + result = oscHelper.Init( + inputs.symbol, + inputs.period, + inputs.oscInputs // + ); + if (!result) + { + return result; + } + + // + // XVLM ... + vlmHelper = new XSCXVLMHelper(); + result = vlmHelper.Init( + inputs.symbol, + inputs.period, + inputs.vlmInputs // + ); + if (!result) + { + return result; + } + + // + // XMC ... + mcHelper = new XSCXMCHelper(); + result = mcHelper.Init( + inputs.symbol, + inputs.period, + inputs.mcInputs // + ); + if (!result) + { + return result; + } + + // + // XASCT ... + asctHelper = new XSCXASCTHelper(); + result = asctHelper.Init( + inputs.symbol, + inputs.period, + inputs.asctInputs // + ); + if (!result) + { + return result; + } + + // + // XSSLC ... + sslcHelper = new XSCXSSLCHelper(); + result = sslcHelper.Init( + inputs.symbol, + inputs.period, + inputs.sslcInputs // + ); + if (!result) + { + return result; + } + + // + // XHULL ... + hullHelper = new XSCXHULLHelper(); + result = hullHelper.Init( + inputs.symbol, + inputs.period, + inputs.hullInputs // + ); + if (!result) + { + return result; + } + + // + // XADXTD ... + adxtdHelper = new XSCXADXTDHelper(); + result = adxtdHelper.Init( + inputs.symbol, + inputs.period, + inputs.adxtdInputs // + ); + if (!result) + { + return result; + } + + // + // Initial Bar Tracker ... + result = barTracker.Init( + inputs.symbol, + inputs.period // + ); + if (!result) + { + return result; + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + string GetSymbol() + { + return inputs.symbol; + } + + // + ENUM_TIMEFRAMES GetPeriod() + { + return inputs.period; + } + + // + XTestInputs GetInputs() + { + return inputs; + } + + // + bool SetInputs( + XTestInputs &_inputs // Configurations + ) + { + return Init(_inputs); + } + + // + // Tools ... + + // + // Retrieve Conditions ... + bool GetConditions( + XTestConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = false; + + // + conditions.Clean(); + + // + conditions.symbol = GetSymbol(); + conditions.period = GetPeriod(); + conditions.time = TimeCurrent(); + + // + // Checking Can Process Bar ... + result = barTracker.CanProcessBar(); + if (!result) + { + return result; + } + + // + result = rlHelper.GetConditions( + conditions.rlConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = hdtHelper.GetConditions( + conditions.htdConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = slnHelper.GetConditions( + conditions.slnConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = atslHelper.GetConditions( + conditions.atslConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = dmntHelper.GetConditions( + conditions.dmntConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = pvHelper.GetConditions( + conditions.pvConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = tdHelper.GetConditions( + conditions.tdConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = hkHelper.GetConditions( + conditions.hkConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = cheHelper.GetConditions( + conditions.cheConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = ichHelper.GetConditions( + conditions.ichConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = strHelper.GetConditions( + conditions.strConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = mrbHelper.GetConditions( + conditions.mrbConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = mcHelper.GetConditions( + conditions.mcConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = asctHelper.GetConditions( + conditions.asctConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = vlmHelper.GetConditions( + conditions.vlmConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = sslcHelper.GetConditions( + conditions.sslcConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = hullHelper.GetConditions( + conditions.hullConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = adxtdHelper.GetConditions( + conditions.adxtdConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + oscHelper.CopyCCI( + barIndex, + loopback, + conditions.cci // + ); + oscHelper.CopyRSI( + barIndex, + loopback, + conditions.rsi // + ); + oscHelper.CopyMACD( + barIndex, + loopback, + conditions.macd // + ); + oscHelper.CopyMACDSignal( + barIndex, + loopback, + conditions.macdSignal // + ); + + // + // Generating Signal ... + double mTP = 0; + double mSL = 0; + bool hasSignal = conditions.GenerateSignal( + mTP, + mSL, + inputs.volume, + inputs.tpPoint, + inputs.slPoint // + ); + if (hasSignal) + { + barTracker.Waits(); + } + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XTestInputs inputs; // Setup Configurations ... +}; + +// \ No newline at end of file diff --git a/Test/x-saherelm.test.xea.mq5 b/Test/x-saherelm.test.xea.mq5 new file mode 100644 index 00000000..95efcd5f --- /dev/null +++ b/Test/x-saherelm.test.xea.mq5 @@ -0,0 +1,354 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCXTestSetupEA +// Description: provides implementation of XTest +// Setup EA ... +// +// +// 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 "../Test/x-saherelm.test.setup.mq5" +#include "../Classes/x-saherelm.xea.class.mq5" + +// +class XSCXTestSetupEA : public XSCBaseEA +{ + // + // Public ... +public: + // + // Constructors ... + XSCXTestSetupEA( + // + // XTrade Class Requirements ... + int slippage, // Specify Slippage + ulong magicNumber, // Specify Magic Number + // + // XSCTrade Event Handlers ... + TOnSignal onSignal = NULL, // On Signal Recieved Event Handler + TOnModify onModifyPosition = NULL, // On Modify Position Event Handler + TOnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler + TOnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler + TOnForceClose onForceClosePosition = NULL, // On Force Close Position Event Handler + TOnPartialClose onPartialClosePosition = NULL, // On Partial Close Position 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 + ) : XSCBaseEA(slippage, + magicNumber, + onSignal, + onModifyPosition, + onStopLossTriggered, + onTakeProfitTriggered, + onForceClosePosition, + onPartialClosePosition, + onDealsChangedHandler, + onOrdersChangedHandler, + onPositionsChangedHandler, + onTradeStateChangedHandler // + ) + { + // + DefaultConfig(); + } + + // + // Deconstructor ... + ~XSCXTestSetupEA() {} + + // + // Getter(s) / Setter(s) ... + + // + double Volume() + { + return mVolume; + } + + // + void Volume(double value) + { + // + if (value < 0.01) + { + value = 0.01; + } + + // + mVolume = value; + } + + // + bool AllowLong() + { + return mAllowLong; + } + + // + void AllowLong(bool value) + { + mAllowLong = value; + } + + // + bool AllowShort() + { + return mAllowShort; + } + + // + void AllowShort(bool value) + { + mAllowShort = value; + } + + // + // Add Setup ... + bool AddSetup(XSCXTestSetup *setup) + { + // + bool result = false; + + // + result = setup != NULL; + if (!result) + { + return result; + } + + // + Add( + setup, + setups // + ); + + // + return result; + } + + // + // Overrides ... + + // + // Customize Token ... + string GetToken() override + { + return GetSpecificToken(this); + } + + // + string GetTag() override + { + return this.GetToken(); + } + + // + // Check Provider for any Guards ... + bool CheckForGuard(XGuard &guards[]) override + { + // + bool result = false; + + // + return result; + } + + // + // Request Fro Signals ... + int RequestForSignal( + XSignal &signals[] // Holds Signals ... + ) override + { + // + int result = 0; + + // + int count = CountSetups(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XTestConditions iConditions; + bool iHasConditions = setups[i].GetConditions( + iConditions, + 0, + 5 // + ); + if (!iHasConditions) + { + continue; + } + + // + // Check iConditions Signal is Valid or not ... + bool hasSignal = iConditions.signal.IsValid(); + if (!hasSignal) + { + continue; + } + + // + bool isLong = IsLong(iConditions.signal.type); + + // + // TODO: Implement Management ... + + // + AddRef( + iConditions.signal, + signals // + ); + } + + // + result = ArraySize(signals); + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + + // + bool mVolume; + bool mAllowLong; + bool mAllowShort; + + // + void DefaultConfig() + { + // + Volume(0.01); + AllowLong(true); + AllowShort(true); + } + + // + // Provider(s) ... + + // + XSCXTestSetup *setups[]; + + // + int CountSetups() + { + return ArraySize(setups); + } + + // + int FindSetupIndex( + string _symbol // + ) + { + // + int result = -1; + + // + if (!IsValid(_symbol)) + { + return result; + } + + // + int count = CountSetups(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isOwn = _symbol == setups[i].GetSymbol(); + if (isOwn) + { + // + result = i; + break; + } + } + + // + return result; + } + + // + int FindSetupIndex( + string _symbol, // + ENUM_TIMEFRAMES _period // + ) + { + // + int result = -1; + + // + if (!IsValid(_symbol)) + { + return result; + } + + // + if (!IsValid(_period)) + { + return result; + } + + // + int count = CountSetups(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isOwn = + _symbol == setups[i].GetSymbol() && + _period == setups[i].GetPeriod(); + if (isOwn) + { + // + result = i; + break; + } + } + + // + return result; + } + + // +}; + +// \ No newline at end of file