diff --git a/Classes/x-saherelm.x121.setup.xea.mq5 b/Classes/x-saherelm.x121.setup.xea.mq5 index 35342f91..d4fd1711 100644 --- a/Classes/x-saherelm.x121.setup.xea.mq5 +++ b/Classes/x-saherelm.x121.setup.xea.mq5 @@ -24,45 +24,43 @@ // Imports ... // -#include "../Classes/x-saherelm.xea.class.mq5" #include "../Classes/x-saherelm.x121.setup.cycle.class.mq5" +#include "../Classes/x-saherelm.xea.class.mq5" // // Definitions ... // // 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(); } @@ -71,24 +69,23 @@ 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; // @@ -106,18 +103,17 @@ 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; @@ -131,20 +127,19 @@ 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; @@ -154,7 +149,7 @@ struct XTradeInfo hConditions = _hConditions; // - allowGrid = _allowGrid; + allowGrid = _allowGrid; allowRecover = _allowRecover; allowSupport = _allowSupport; @@ -164,9 +159,8 @@ struct XTradeInfo // bool IsOwn( - ulong _ticket // - ) - { + ulong _ticket // + ) { // bool result = false; @@ -179,11 +173,10 @@ struct XTradeInfo // bool IsOwn( - string _symbol, - string _provider, - ENUM_TIMEFRAMES _period // - ) - { + string _symbol, + string _provider, + ENUM_TIMEFRAMES _period // + ) { // bool result = false; @@ -208,8 +201,7 @@ struct XTradeInfo // Data Collector ... // - bool IsValid() - { + bool IsValid() { // bool result = false; @@ -228,17 +220,15 @@ 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; } @@ -247,7 +237,7 @@ struct XTradeInfo symbol, period, time, - false // + false // ); // @@ -255,7 +245,7 @@ struct XTradeInfo symbol, period, endTime, - false // + false // ); // @@ -266,14 +256,12 @@ struct XTradeInfo } // - string GetFileName() - { + string GetFileName() { // string result = NULL; // - if (!IsValid()) - { + if(!IsValid()) { return result; } @@ -282,9 +270,7 @@ struct XTradeInfo // symbol + "\\" + ToString(type) + "\\" + - (profit >= 0 - ? "Profit" - : "Loss") + + (profit >= 0 ? "Profit" : "Loss") + "\\" + provider + "_" + ToString(ticket) + "_" + @@ -298,8 +284,7 @@ struct XTradeInfo } // - string GetSignalFileName() - { + string GetSignalFileName() { // string result = NULL; @@ -319,47 +304,46 @@ 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 ... ); // @@ -368,9 +352,7 @@ struct XTradeInfo // result = // - (onlySignals - ? "" - : ToString("Ticket", ticket)) + + (onlySignals ? "" : ToString("Ticket", ticket)) + ToString("Symbol", symbol) + ToString("Period", period) + ToString("Entry", entry) + @@ -378,16 +360,7 @@ struct XTradeInfo ToString("Type", ToString(type)) + ToString("Time", time) + ToString("Pushers", pushers) + - (onlySignals - ? "" - : "-------------" + "\n" + - ToString("Volume", volume) + - ToString("Profit", profit) + - ToString("Commission", commission) + - ToString("Swap", swap) + - ToString("End Time", endTime) + - ToString("Age", age) + - ToString("Message", message)) + + (onlySignals ? "" : "-------------" + "\n" + ToString("Volume", volume) + ToString("Profit", profit) + ToString("Commission", commission) + ToString("Swap", swap) + ToString("End Time", endTime) + ToString("Age", age) + ToString("Message", message)) + "-------------" + "\n" + "Conditions" + "\n" + "-------------" + "\n" + @@ -428,20 +401,18 @@ 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; @@ -453,17 +424,16 @@ 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; // @@ -473,11 +443,10 @@ struct XTradeInfo // void SetGrid( double nextEntry, - double nextVolume // - ) - { + double nextVolume // + ) { // - gEntry = nextEntry; + gEntry = nextEntry; gVolume = nextVolume; } @@ -485,9 +454,8 @@ struct XTradeInfo // Prepare Data For Next Grid ... void PrepareNextGrid( double distance, - double volumeMultiplier // - ) - { + double volumeMultiplier // + ) { // bool isValid = // @@ -503,30 +471,24 @@ struct XTradeInfo // double distancePrice = PointToPrice( distance, - symbol // + symbol // ); // double selectedEntry = - gEntry <= 0 - ? entry - : gEntry; + gEntry <= 0 ? entry : gEntry; double selectedVolume = - gVolume <= 0 - ? volume - : gVolume; + gVolume <= 0 ? volume : gVolume; // double nextEntry = - isLong - ? selectedEntry - distancePrice - : selectedEntry + distancePrice; + isLong ? selectedEntry - distancePrice : selectedEntry + distancePrice; double nextVolume = selectedVolume * volumeMultiplier; // SetGrid( nextEntry, - nextVolume // + nextVolume // ); } @@ -534,11 +496,10 @@ 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; @@ -549,8 +510,7 @@ struct XTradeInfo result = IsValid() && distance > 0 && volumeMultiplier > 0; - if (!result) - { + if(!result) { return result; } @@ -559,23 +519,18 @@ struct XTradeInfo // ENUM_POSITION_TYPE gType = - isLong - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; + isLong ? POSITION_TYPE_BUY : POSITION_TYPE_SELL; // double cEntry = GetEntry( symbol, - gType // + gType // ); // result = - isLong - ? cEntry <= gEntry - : cEntry >= gEntry; - if (!result) - { + isLong ? cEntry <= gEntry : cEntry >= gEntry; + if(!result) { return result; } @@ -588,13 +543,12 @@ 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); @@ -603,7 +557,7 @@ struct XTradeInfo // PrepareNextGrid( distance, - volumeMultiplier // + volumeMultiplier // ); // @@ -618,24 +572,23 @@ 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; // @@ -648,24 +601,22 @@ 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 = // @@ -683,32 +634,21 @@ 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; + rVolume <= 0 ? volume : rVolume; // double nextLongEntry = - isLong - ? selectedEntry - : selectedEntry + distancePrice; + isLong ? selectedEntry : selectedEntry + distancePrice; double nextShortEntry = - isLong - ? selectedEntry - distancePrice - : selectedEntry; + isLong ? selectedEntry - distancePrice : selectedEntry; // double nextVolume = selectedVolume * volumeMultiplier; @@ -718,17 +658,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( @@ -736,7 +670,7 @@ struct XTradeInfo nextShortEntry, zoneUpper, zoneLower, - nextVolume // + nextVolume // ); // @@ -747,11 +681,10 @@ 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; @@ -768,26 +701,25 @@ 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 && @@ -797,7 +729,7 @@ struct XTradeInfo // Check For Short Recovery ... double cShortEntry = GetEntry( symbol, - POSITION_TYPE_SELL // + POSITION_TYPE_SELL // ); bool hasShortRecovery = isLastLong && @@ -806,34 +738,25 @@ struct XTradeInfo // result = hasLongRecovery || hasShortRecovery; - if (!result) - { + if(!result) { return result; } // ENUM_POSITION_TYPE rType = - hasLongRecovery - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; + hasLongRecovery ? POSITION_TYPE_BUY : POSITION_TYPE_SELL; // double rEntry = - hasLongRecovery - ? cLongEntry - : cShortEntry; + hasLongRecovery ? cLongEntry : cShortEntry; // double rTP = - hasLongRecovery - ? rZoneUpper - : rZoneLower; + hasLongRecovery ? rZoneUpper : rZoneLower; // double rSL = - hasLongRecovery - ? rZoneLower - : rZoneUpper; + hasLongRecovery ? rZoneLower : rZoneUpper; // result = signal.Prepare( @@ -844,11 +767,10 @@ 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); @@ -861,7 +783,7 @@ struct XTradeInfo PrepareNextRecovery( distance, volumeMultiplier, - rType // + rType // ); } @@ -872,30 +794,25 @@ 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(); } } @@ -905,14 +822,13 @@ public: 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); // @@ -920,32 +836,28 @@ public: } // - 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; } @@ -959,24 +871,21 @@ public: } // - 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; } @@ -991,30 +900,28 @@ public: // // 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 = ""; @@ -1030,16 +937,14 @@ private: } // - 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 = ""; @@ -1055,43 +960,39 @@ private: } // - 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 // ); // @@ -1099,43 +1000,39 @@ private: } // - 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 // ); // @@ -1151,23 +1048,21 @@ private: // - 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(); } @@ -1178,26 +1073,22 @@ public: // 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; } @@ -1205,17 +1096,14 @@ public: // Hedging ... // - double MinProfitPerTrade() - { + double MinProfitPerTrade() { return mMinProfitPerTrade; } // - void MinProfitPerTrade(double value) - { + void MinProfitPerTrade(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -1224,23 +1112,19 @@ public: } // - 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; } @@ -1252,41 +1136,34 @@ public: // 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; } @@ -1295,17 +1172,14 @@ public: } // - double FirstTrailPoint() - { + double FirstTrailPoint() { return mFirstTrailPoint; } // - void FirstTrailPoint(double value) - { + void FirstTrailPoint(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -1314,17 +1188,14 @@ public: } // - double NextTrailDistance() - { + double NextTrailDistance() { return mNextTrailDistance; } // - void NextTrailDistance(double value) - { + void NextTrailDistance(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -1333,17 +1204,14 @@ public: } // - double FirstTrailDistance() - { + double FirstTrailDistance() { return mFirstTrailDistance; } // - void FirstTrailDistance(double value) - { + void FirstTrailDistance(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -1352,8 +1220,7 @@ public: } // - bool EnableTrailling() - { + bool EnableTrailling() { // bool result = false; @@ -1376,41 +1243,34 @@ public: // 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; } @@ -1419,17 +1279,14 @@ public: } // - int MaxNumberOfSupports() - { + int MaxNumberOfSupports() { return mMaxNumberOfSupports; } // - void MaxNumberOfSupports(int value) - { + void MaxNumberOfSupports(int value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -1438,17 +1295,14 @@ public: } // - double SupportVolumeMultiplier() - { + double SupportVolumeMultiplier() { return mSupportVolumeMultiplier; } // - void SupportVolumeMultiplier(double value) - { + void SupportVolumeMultiplier(double value) { // - if (value < 1) - { + if(value < 1) { value = 1; } @@ -1457,17 +1311,14 @@ public: } // - 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; } @@ -1476,8 +1327,7 @@ public: } // - bool EnableSupport() - { + bool EnableSupport() { // bool result = false; @@ -1499,41 +1349,34 @@ public: // 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; } @@ -1542,17 +1385,14 @@ public: } // - double GridDistance() - { + double GridDistance() { return mGridDistance; } // - void GridDistance(double value) - { + void GridDistance(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -1561,17 +1401,14 @@ public: } // - double GridVolumeMultiplier() - { + double GridVolumeMultiplier() { return mGridVolumeMultiplier; } // - void GridVolumeMultiplier(double value) - { + void GridVolumeMultiplier(double value) { // - if (value < 1) - { + if(value < 1) { value = 1; } @@ -1580,17 +1417,14 @@ public: } // - 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; } @@ -1600,8 +1434,7 @@ public: // // Check Grid Properties to Validate it's Enable or not ... - bool EnableGrid() - { + bool EnableGrid() { // bool result = false; @@ -1623,41 +1456,34 @@ public: // 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; } @@ -1666,17 +1492,14 @@ public: } // - double RecoveryDistance() - { + double RecoveryDistance() { return mRecoveryDistance; } // - void RecoveryDistance(double value) - { + void RecoveryDistance(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -1685,17 +1508,14 @@ public: } // - double RecoveryVolumeMultiplier() - { + double RecoveryVolumeMultiplier() { return mRecoveryVolumeMultiplier; } // - void RecoveryVolumeMultiplier(double value) - { + void RecoveryVolumeMultiplier(double value) { // - if (value < 1) - { + if(value < 1) { value = 1; } @@ -1704,17 +1524,14 @@ public: } // - 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; } @@ -1724,8 +1541,7 @@ public: // // Check Recovery Properties to Validate it's Enable or not ... - bool EnableRecovery() - { + bool EnableRecovery() { // bool result = false; @@ -1747,36 +1563,31 @@ public: // 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; @@ -1788,21 +1599,18 @@ public: } // - 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]; @@ -1819,8 +1627,7 @@ public: ; // - if (isOWN) - { + if(isOWN) { // result = i; break; @@ -1833,21 +1640,20 @@ public: // 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, @@ -1857,33 +1663,29 @@ public: 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; } @@ -1891,23 +1693,20 @@ public: 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; } @@ -1917,83 +1716,73 @@ public: // // 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; // @@ -2001,25 +1790,22 @@ public: } // - 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; // @@ -2028,48 +1814,42 @@ public: // // 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 // ); } } @@ -2080,10 +1860,9 @@ public: // // 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; @@ -2092,65 +1871,58 @@ public: // // 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 // ); } } @@ -2163,8 +1935,7 @@ public: } // - int GetBreakoutsSignals(XSignal &signals[]) - { + int GetBreakoutsSignals(XSignal &signals[]) { // int result = 0; @@ -2173,41 +1944,36 @@ public: // 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); - ENUM_POSITION_TYPE iPType = isLong - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; + 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; } @@ -2216,27 +1982,24 @@ public: bool isBreakUp = cBar.IsBreakUp(iEntry); // - bool isBearish = cBar.IsBearish(); + bool isBearish = cBar.IsBearish(); bool isBreakDown = cBar.IsBreakDown(iEntry); // bool isBreaked = - isLong - ? isBullish && isBreakUp && cEntry > iEntry - : isBearish && isBreakDown && cEntry < iEntry; + 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, @@ -2245,17 +2008,16 @@ public: data[i].entry, data[i].volume, 0, - 0 // + 0 // ); // // Add Signal to Result ... - if (isPrepared) - { + if(isPrepared) { // AddRef( iSignal, - signals // + signals // ); } } @@ -2345,68 +2107,66 @@ public: // // 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; } @@ -2414,12 +2174,11 @@ protected: ArrayRemove( data, index, - 1 // + 1 // ); // - if (GetSave()) - { + if(GetSave()) { collector.Save(info); } } @@ -2428,15 +2187,13 @@ protected: // Protection Methods ... // - int HandleTrailling() - { + int HandleTrailling() { // int result = 0; // // Check Trailling is Enabled or not ... - if (!EnableTrailling()) - { + if(!EnableTrailling()) { return result; } @@ -2450,54 +2207,48 @@ protected: 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; } @@ -2507,43 +2258,31 @@ protected: // // 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 - { + } else { + // + if(iPosition.sl > iPosition.entry) { + usedPrice = iPosition.entry; + } else { usedPrice = iPosition.sl; } } - else - { - // - if (iPosition.sl > iPosition.entry) - { - usedPrice = iPosition.entry; - } - else - { - usedPrice = iPosition.sl; - } - } - } - else - { + } 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(); // @@ -2551,38 +2290,33 @@ protected: // double usedTrailDiff = - isFirstTrail - ? MathMax(firstTrailPoint, firstTrailDistance) - : MathMax(nextTrailPoint, nextTrailDistance); + isFirstTrail ? MathMax(firstTrailPoint, firstTrailDistance) : MathMax(nextTrailPoint, nextTrailDistance); // 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]; @@ -2590,8 +2324,7 @@ protected: bool isOpposit = inDPosition.symbol == iPosition.symbol && inDPosition.type == oppositType; - if (isOpposit) - { + if(isOpposit) { // canTrail = false; break; @@ -2599,27 +2332,22 @@ protected: } // - if (!canTrail) - { + if(!canTrail) { continue; } } // usedTrailDiff = - isFirstTrail - ? MathMin(firstTrailPoint, firstTrailDistance) - : MathMin(nextTrailPoint, nextTrailDistance); + isFirstTrail ? MathMin(firstTrailPoint, firstTrailDistance) : MathMin(nextTrailPoint, nextTrailDistance); double usedTrailDiffPrice = PointToPrice( usedTrailDiff, - iPosition.symbol // + iPosition.symbol // ); // double sl = - isLong - ? usedPrice + usedTrailDiffPrice - : usedPrice - usedTrailDiffPrice; + isLong ? usedPrice + usedTrailDiffPrice : usedPrice - usedTrailDiffPrice; string comment = PrepareSLTrailTag(iPosition.comment); // @@ -2627,10 +2355,9 @@ protected: iPosition.ticket, sl, iPosition.tp, - comment // + comment // ); - if (isModified) - { + if(isModified) { result++; } } @@ -2641,10 +2368,9 @@ protected: // int RequestForSupport( - XSignal &signals[], - XSCX121SetupCycles *&setups[] // - ) - { + XSignal &signals[], + XSCX121SetupCycles *&setups[] // + ) { // int result = 0; @@ -2652,8 +2378,7 @@ protected: Clean(signals); // - if (!AllowSupport()) - { + if(!AllowSupport()) { return result; } @@ -2662,27 +2387,24 @@ protected: // 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 // ); } } @@ -2798,8 +2520,7 @@ protected: } // - int RequestForGrid(XSignal &signals[]) - { + int RequestForGrid(XSignal &signals[]) { // int result = 0; @@ -2807,58 +2528,49 @@ protected: 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) - { + maxAllowed <= 0 ? true : data[i].gLevel < maxAllowed; + 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 = - maxAllowedVolume <= 0 - ? iSignal.volume - : MathMin(iSignal.volume, maxAllowedVolume); + maxAllowedVolume <= 0 ? iSignal.volume : MathMin(iSignal.volume, maxAllowedVolume); // AddRef( iSignal, - signals // + signals // ); } } @@ -2871,8 +2583,7 @@ protected: } // - int RequestForRecovery(XSignal &signals[]) - { + int RequestForRecovery(XSignal &signals[]) { // int result = 0; @@ -2880,58 +2591,49 @@ protected: 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) - { + maxAllowed <= 0 ? true : data[i].rLevel < maxAllowed; + 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 = - maxAllowedVolume <= 0 - ? iSignal.volume - : MathMin(iSignal.volume, maxAllowedVolume); + maxAllowedVolume <= 0 ? iSignal.volume : MathMin(iSignal.volume, maxAllowedVolume); // AddRef( iSignal, - signals // + signals // ); } } @@ -2945,25 +2647,21 @@ protected: // 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; @@ -2976,32 +2674,30 @@ protected: // 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; @@ -3011,20 +2707,20 @@ public: 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, @@ -3036,9 +2732,8 @@ public: onDealsChangedHandler, onOrdersChangedHandler, onPositionsChangedHandler, - onTradeStateChangedHandler // - ) - { + onTradeStateChangedHandler // + ) { // mTradeHandler = new XTradeHandler(mTrader); @@ -3049,8 +2744,7 @@ public: // // Deconstructor ... - ~XSCX121SetupEA() - { + ~XSCX121SetupEA() { // delete mTradeHandler; @@ -3059,22 +2753,20 @@ public: } // - bool AddSetup(XSCX121SetupCycles *setup) - { + bool AddSetup(XSCX121SetupCycles *setup) { // bool result = false; // result = setup != NULL; - if (!result) - { + if(!result) { return result; } // Add( setup, - mSetups // + mSetups // ); // @@ -3088,41 +2780,34 @@ public: /// 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; } @@ -3131,17 +2816,14 @@ public: } // - int ReuiredSignalVerifications() - { + int ReuiredSignalVerifications() { return mReuiredSignalVerifications; } // - void ReuiredSignalVerifications(int value) - { + void ReuiredSignalVerifications(int value) { // - if (value < 1) - { + if(value < 1) { value = 1; } @@ -3150,26 +2832,22 @@ public: } // - 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; } @@ -3177,17 +2855,14 @@ public: // 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; } @@ -3196,17 +2871,14 @@ public: } // - double TPPoint() - { + double TPPoint() { return mTPPoint; } // - void TPPoint(double value) - { + void TPPoint(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -3215,17 +2887,14 @@ public: } // - double SLPoint() - { + double SLPoint() { return mSLPoint; } // - void SLPoint(double value) - { + void SLPoint(double value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -3234,17 +2903,14 @@ public: } // - int MaxAllowedTrades() - { + int MaxAllowedTrades() { return mMaxAllowedTrades; } // - void MaxAllowedTrades(int value) - { + void MaxAllowedTrades(int value) { // - if (value < 0) - { + if(value < 0) { value = 0; } @@ -3254,65 +2920,54 @@ public: } // - 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; } @@ -3321,14 +2976,12 @@ public: } // - bool AcceptNextDirectionalSignalsWhenFirstInProfit() - { + bool AcceptNextDirectionalSignalsWhenFirstInProfit() { return mAcceptNextDirectionalSignalsWhenFirstInProfit; } // - void AcceptNextDirectionalSignalsWhenFirstInProfit(bool value) - { + void AcceptNextDirectionalSignalsWhenFirstInProfit(bool value) { mAcceptNextDirectionalSignalsWhenFirstInProfit = value; } @@ -3336,17 +2989,14 @@ public: // Signalling ... // - int StartSignallingHoure() - { + int StartSignallingHoure() { return mStartSignallingHoure; } // - void StartSignallingHoure(int value) - { + void StartSignallingHoure(int value) { // - if (value < -1) - { + if(value < -1) { value = -1; } @@ -3355,17 +3005,14 @@ public: } // - int EndSignallingHoure() - { + int EndSignallingHoure() { return mEndSignallingHoure; } // - void EndSignallingHoure(int value) - { + void EndSignallingHoure(int value) { // - if (value < -1) - { + if(value < -1) { value = -1; } @@ -3374,17 +3021,14 @@ public: } // - int CloseOnSpecificTime() - { + int CloseOnSpecificTime() { return mCloseOnSpecificTime; } // - void CloseOnSpecificTime(int value) - { + void CloseOnSpecificTime(int value) { // - if (value < -1) - { + if(value < -1) { value = -1; } @@ -3393,14 +3037,12 @@ public: } // - bool CloseOnOpposit() - { + bool CloseOnOpposit() { return mCloseOnOpposit; } // - void CloseOnOpposit(bool value) - { + void CloseOnOpposit(bool value) { mCloseOnOpposit = value; } @@ -3408,74 +3050,62 @@ public: // 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); } @@ -3483,80 +3113,67 @@ public: // 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); } @@ -3564,80 +3181,67 @@ public: // 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); } @@ -3645,80 +3249,67 @@ public: // 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); } @@ -3726,41 +3317,34 @@ public: // 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; } @@ -3772,28 +3356,24 @@ public: // 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); @@ -3804,14 +3384,12 @@ public: // // Customize Token ... - string GetToken() override - { + string GetToken() override { return GetSpecificToken(this); } // - string GetTag() override - { + string GetTag() override { return this.GetToken(); } @@ -3820,8 +3398,7 @@ public: // // Check Provider for any Guards ... - bool CheckForGuard(XGuard &guards[]) override - { + bool CheckForGuard(XGuard &guards[]) override { // bool result = false; @@ -3835,9 +3412,8 @@ public: // filters theme here and passed them // for Executing ... int RequestForSignal( - XSignal &signals[] // Holds Signals ... - ) override - { + XSignal &signals[] // Holds Signals ... + ) override { // bool result = 0; @@ -3845,68 +3421,66 @@ public: 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; // @@ -3930,13 +3504,13 @@ public: ; // - 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; @@ -3946,41 +3520,21 @@ public: 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 // - ); + 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 // + ); // // Short Market ... @@ -3988,33 +3542,14 @@ public: // 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 // - ); + 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 // + ); // // Medium Market ... @@ -4022,33 +3557,14 @@ public: // 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 // - ); + 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 // + ); // // Long Market ... @@ -4056,33 +3572,14 @@ public: // 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 // - ); + 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 // + ); // // Hind Market ... @@ -4090,33 +3587,14 @@ public: // 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 // - ); + 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 // + ); // // Parse Signals and Add them for Executing ... @@ -4124,26 +3602,24 @@ public: // // 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, @@ -4156,19 +3632,18 @@ public: } // - if (sHasSignal) - { + if(sHasSignal) { // signal = sSignal; // AddRef( cConditions, - otherConditions // + otherConditions // ); AddRef( mConditions, - otherConditions // + otherConditions // ); // AddRef( // lConditions, @@ -4181,25 +3656,23 @@ public: } // - if (mHasSignal) - { + if(mHasSignal) { // signal = mSignal; // AddRef( sConditions, - otherConditions // + otherConditions // ); AddRef( lConditions, - otherConditions // + otherConditions // ); } // - if (lHasSignal) - { + if(lHasSignal) { // signal = lSignal; @@ -4210,40 +3683,39 @@ public: // ); 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 // ); } @@ -4258,18 +3730,13 @@ public: bool isValid = // // Handle Pusher Validations ... - (mReuiredSignalVerifications <= 0 - ? true - : pushers >= mReuiredSignalVerifications) + (mReuiredSignalVerifications <= 0 ? true : pushers >= mReuiredSignalVerifications) // && // // Handle Other Conditions Validations ... - (!mGetVerificationFromOtherTimeFrames - ? true - : isLong - ? signalGenerator.HasLongVerifications(otherConditions) - : signalGenerator.HasShortVerifications(otherConditions)) + (!mGetVerificationFromOtherTimeFrames ? true : isLong ? signalGenerator.HasLongVerifications(otherConditions) : + signalGenerator.HasShortVerifications(otherConditions)) // ; @@ -4278,13 +3745,12 @@ public: bool forceState = mForce; // - if (!forceState) - { + if(!forceState) { // // Add Signal to Execution Result ... AddRef( signal, - signals // + signals // ); // @@ -4299,11 +3765,9 @@ public: sConditions, mConditions, lConditions, - hConditions // + hConditions // ); - } - else - { + } else { // // Clear Other Conditions ... Clean(otherConditions); @@ -4312,23 +3776,23 @@ public: // 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 // ); // @@ -4338,7 +3802,7 @@ public: signal, pushers, isValid, - otherConditions // + otherConditions // ); } } @@ -4357,36 +3821,33 @@ public: // - 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]; @@ -4395,42 +3856,38 @@ public: // 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 ..."; @@ -4452,113 +3909,99 @@ public: // // 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; + 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) - { + iSupportsCount <= 0 ? iSymbolsPositionsCount < maxAllowed : iSymbolsPositionsCount - iSupportsCount < maxAllowed; + 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 // ); } @@ -4569,14 +4012,13 @@ public: // 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 // ); // @@ -4584,72 +4026,62 @@ public: } // - 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) - { + iSupportsCount <= 0 ? iSymbolsPositionsCount : iSymbolsPositionsCount - iSupportsCount; + 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 // ); } } @@ -4659,12 +4091,11 @@ public: // // Cutom Signal Execution ... - if (IsValidSize(result)) - { + if(IsValidSize(result)) { // Copy( eSignals, - signals // + signals // ); // @@ -4684,8 +4115,7 @@ public: // - 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; @@ -4720,14 +4150,12 @@ public: // 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); } @@ -4737,10 +4165,9 @@ public: // 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; @@ -4751,18 +4178,16 @@ public: // 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); } @@ -4771,8 +4196,7 @@ public: } // - void OnStopLossTriggered(const XDeal &deal) override - { + void OnStopLossTriggered(const XDeal &deal) override { // // When a Position's Stop Loss Triggered ... // Signal Info Manager ... @@ -4782,8 +4206,7 @@ public: } // - void OnTakeProfitTriggered(const XDeal &deal) override - { + void OnTakeProfitTriggered(const XDeal &deal) override { // // When a Position's Take Profit Triggered ... // Signal Info Manager ... @@ -4794,14 +4217,13 @@ public: // // Protected ... -protected: + protected: // // Tools ... // // Check Signalling Enable or not ... - bool IsEnable() - { + bool IsEnable() { // bool result = false; @@ -4812,21 +4234,17 @@ protected: // // Check Signalling Time ... MqlDateTime cTime; - bool isTimeRecieved = TimeCurrent(cTime); + bool isTimeRecieved = TimeCurrent(cTime); // - int endHour = EndSignallingHoure(); + int endHour = EndSignallingHoure(); int startHour = StartSignallingHoure(); // bool isStartHourPassed = - startHour <= -1 - ? true - : cTime.hour >= startHour; + startHour <= -1 ? true : cTime.hour >= startHour; bool isEndHourPassed = - endHour <= -1 - ? true - : cTime.hour < endHour; + endHour <= -1 ? true : cTime.hour < endHour; bool isTimePassed = isTimeRecieved && isStartHourPassed && isEndHourPassed; // @@ -4837,23 +4255,20 @@ protected: } // - 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; } @@ -4866,20 +4281,17 @@ protected: // // 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 ..."; @@ -4892,38 +4304,32 @@ protected: // 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 // ); } } @@ -4931,26 +4337,23 @@ protected: // // 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; } @@ -4958,25 +4361,24 @@ protected: // 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; @@ -4985,16 +4387,13 @@ protected: } // - bool IsMarginPassed() - { + bool IsMarginPassed() { // - double freeMargin = mTrader.mAccount.GetFreeMargin(); + double freeMargin = mTrader.mAccount.GetFreeMargin(); double minFreeMargingForHandleForce = MinFreeMargingForOpenTrades(); // - bool result = minFreeMargingForHandleForce <= 0 - ? true - : freeMargin >= minFreeMargingForHandleForce; + bool result = minFreeMargingForHandleForce <= 0 ? true : freeMargin >= minFreeMargingForHandleForce; // return result; @@ -5006,13 +4405,11 @@ protected: bool result = false; // - double maxAllowedDrawdownPercent = 5; // MaxAllowedDrawdownPercent(); - double drawdownPercent = GetDrawdownPercent(); + double maxAllowedDrawdownPercent = 5; // MaxAllowedDrawdownPercent(); + double drawdownPercent = GetDrawdownPercent(); // - result = maxAllowedDrawdownPercent <=0 - ? true - : drawdownPercent <= maxAllowedDrawdownPercent; + result = maxAllowedDrawdownPercent <= 0 ? true : drawdownPercent <= maxAllowedDrawdownPercent; // return result; @@ -5023,36 +4420,33 @@ protected: // // 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(); @@ -5061,8 +4455,7 @@ protected: // // Handle Sleeping ... int restingTime = RestingAfterHedge(); - if (result && IsValidSize(restingTime)) - { + if(result && IsValidSize(restingTime)) { Sleeping(restingTime); } @@ -5072,38 +4465,33 @@ protected: // // 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; } @@ -5113,10 +4501,9 @@ protected: // int closed = Close( positions, - comment // + comment // ); - if (IsValidSize(closed)) - { + if(IsValidSize(closed)) { // string message = XEQMSupportToken + " Closed " + ToString(closed) + " Positions on Specified Time ..."; @@ -5130,23 +4517,20 @@ protected: // 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; } @@ -5158,8 +4542,7 @@ protected: XSignal signals[]; // - if (isValid) - { + if(isValid) { // bool canSupport = // @@ -5183,7 +4566,7 @@ protected: // AddRef( signal, - signals // + signals // ); // @@ -5198,13 +4581,12 @@ protected: conditions[1], conditions[2], conditions[3], - conditions[4] // + conditions[4] // ); } // - if (ArraySize(signals) > 0) - { + if(ArraySize(signals) > 0) { EQMExecuteSignals(signals); } } @@ -5214,19 +4596,16 @@ protected: // 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; } @@ -5236,32 +4615,30 @@ protected: } // - void EQMHandleForceState() - { + void EQMHandleForceState() { // - if (!mForce) - { + if(!mForce) { return; } - + // // Exit From Force State ... // // 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; } // - // Two: Based On Free Margin ... - bool isMarginPassed = IsMarginPassed(); + // Two: Based On Free Margin ... + bool isMarginPassed = IsMarginPassed(); bool isDrawdownPassed = IsDrawdownPassed(); - if (isDrawdownPassed) { + if(isDrawdownPassed) { // mForce = false; return; @@ -5277,13 +4654,11 @@ protected: // 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; } @@ -5291,13 +4666,12 @@ protected: // // 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 ..."); @@ -5305,61 +4679,53 @@ protected: // // 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 ... @@ -5370,55 +4736,52 @@ protected: // // 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: @@ -5427,18 +4790,17 @@ private: // - 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); @@ -5507,31 +4869,27 @@ private: // // 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]; @@ -5539,8 +4897,7 @@ private: X121SetupInputs iInputs = iSetup.GetInputs(); // - if (iInputs.symbol == symbol && iInputs.period == period) - { + if(iInputs.symbol == symbol && iInputs.period == period) { // result = i; break; @@ -5554,22 +4911,19 @@ private: // // 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]; @@ -5577,8 +4931,7 @@ private: X121SetupInputs iInputs = iSetup.GetInputs(); // - if (iInputs.symbol == symbol) - { + if(iInputs.symbol == symbol) { // result = i; break;