From 160dc7fcc0b6a47ed6c8e6ad0506af05dd1768f5 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 18 Jun 2024 19:42:49 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.xczone.class.mq5 | 2 +- Classes/x-saherelm.xtrend.class.mq5 | 557 ++++++++++++++++++++++++++++ Experts/x-saherelm.x121.ea.mq5 | 23 +- 3 files changed, 570 insertions(+), 12 deletions(-) create mode 100644 Classes/x-saherelm.xtrend.class.mq5 diff --git a/Classes/x-saherelm.xczone.class.mq5 b/Classes/x-saherelm.xczone.class.mq5 index ade1cd0c..4ba0f052 100644 --- a/Classes/x-saherelm.xczone.class.mq5 +++ b/Classes/x-saherelm.xczone.class.mq5 @@ -3,7 +3,7 @@ // SaherElm IT Center MQL5 Class Library // ---------------------------------------------- // Name: XSCZone -// Description: provides all Alerts requirements ... +// Description: provides all Zone requirements ... // // // Maintainer: diff --git a/Classes/x-saherelm.xtrend.class.mq5 b/Classes/x-saherelm.xtrend.class.mq5 new file mode 100644 index 00000000..b9cc56aa --- /dev/null +++ b/Classes/x-saherelm.xtrend.class.mq5 @@ -0,0 +1,557 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCTrend +// Description: provides all Trend requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.base.class.mq5" +#include "../Libraries/x-saherelm.draw.lib.mq5" + +// +// All Required Inputs ... +struct XSCTrendInput +{ + // + int numberOfShoulders; // Number of Shoulders + + // + color clrUpper; // Upper Colors + color clrLower; // Lower Colors + color clrHighs; // Highs Colors + color clrLows; // Lows Colors + + // + // Constructor ... + void XSCTrendInput() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + numberOfShoulders = 0; + + // + clrUpper = CLR_NONE; + clrLower = CLR_NONE; + clrHighs = CLR_NONE; + clrLows = CLR_NONE; + } + + // + // Defualt Configs ... + void Default() + { + // + numberOfShoulders = 7; + + // + clrUpper = clrRed; + clrLower = clrGreen; + + // + clrHighs = clrAqua; + clrLows = clrMagenta; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + numberOfShoulders >= 2 + // + ; + + // + return result; + } +}; + +// +// Class Definitions ... +class XSCTrend : public XSCBase +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor ... + void XSCTrend( + string symbol, + ENUM_TIMEFRAMES period // + ) : XSCBase() + { + // + mSymbol = symbol; + mPeriod = period; + } + + // + // Deconstructor ... + void ~XSCTrend() {} + + // + // Initialize ... + bool Init(XSCTrendInput &inputs) + { + // + bool result = false; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + result = zBar.Init( + mSymbol, + mPeriod, + 0 // + ); + + // + int firstSwingLowIndex = FindSwing( + zBar.symbol, + zBar.period, + X_SWING_LOW, + mInputs.numberOfShoulders, + zBar.Index() + 1 // + ); + result = firstSwingLowBar.Init( + zBar.symbol, + zBar.period, + firstSwingLowIndex // + ); + if (!result) + { + return result; + } + + // + int secondSwingLowIndex = FindSwing( + zBar.symbol, + zBar.period, + X_SWING_LOW, + mInputs.numberOfShoulders, + firstSwingLowIndex + 1 // + ); + + // + result = secondSwingLowBar.Init( + zBar.symbol, + zBar.period, + secondSwingLowIndex // + ); + if (!result) + { + return result; + } + + // + int firstSwingHighIndex = FindSwing( + zBar.symbol, + zBar.period, + X_SWING_HIGH, + mInputs.numberOfShoulders, + zBar.Index() + 1 // + ); + result = firstSwingHighBar.Init( + zBar.symbol, + zBar.period, + firstSwingHighIndex // + ); + if (!result) + { + return result; + } + + // + int secondSwingHighIndex = FindSwing( + zBar.symbol, + zBar.period, + X_SWING_HIGH, + mInputs.numberOfShoulders, + firstSwingHighIndex + 1 // + ); + result = secondSwingHighBar.Init( + zBar.symbol, + zBar.period, + secondSwingHighIndex // + ); + if (!result) + { + return result; + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + string GetSymbol() + { + return mSymbol; + } + + // + ENUM_TIMEFRAMES GetPeriod() + { + return mPeriod; + } + + // + XSCTrendInput GetInputs() + { + return mInputs; + } + + // + bool SetInputs(XSCTrendInput &inputs) + { + return Init(inputs); + } + + // + XOHCL GetBar() + { + return zBar; + } + + // + XOHCL GetFirstSwingLowBar() + { + return firstSwingLowBar; + } + + // + XOHCL GetSecondSwingLowBar() + { + return secondSwingLowBar; + } + + // + XOHCL GetFirstSwingHighBar() + { + return firstSwingHighBar; + } + + // + XOHCL GetSecondSwingHighBar() + { + return secondSwingHighBar; + } + + // + // Tools ... + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + zBar.IsValid() && + firstSwingLowBar.IsValid() && + secondSwingLowBar.IsValid() && + firstSwingHighBar.IsValid() && + secondSwingHighBar.IsValid() + // + ; + + // + return result; + } + + // + // Retrieve Title Prefix ... + string GetIdentifier() + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + result = mSymbol + "_" + + ToString(mPeriod) + + ToFormatString(zBar.time); + + // + return result; + } + + // + // Remove Draws ... + bool Remove( + long chartId = 0, + int subWindow = 0 // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + string prefix = GetIdentifier(); + result = IsSpecifiedValid(prefix); + if (!result) + { + return result; + } + + // + result = RemoveDraw( + prefix, + chartId, + subWindow // + ); + + // + return result; + } + + // + bool Draw( + long chartId = 0, + string prefix = NULL, + int subWindow = 0, + string upperPrefix = "Upper", + string lowerPrefix = "Lower", + string highsPrefix = "Highs", + string lowsPrefix = "Lows" // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + // Normalize Prefixes ... + + // + if (!IsSpecifiedValid(upperPrefix)) + { + upperPrefix = "Upper"; + } + + // + if (!IsSpecifiedValid(lowerPrefix)) + { + lowerPrefix = "Lower"; + } + + // + if (!IsSpecifiedValid(highsPrefix)) + { + highsPrefix = "Highs"; + } + + // + if (!IsSpecifiedValid(lowsPrefix)) + { + lowsPrefix = "Lows"; + } + + // + string identifier = GetIdentifier(); + result = IsSpecifiedValid(identifier); + if (!result) + { + return result; + } + + // + double support = secondSwingLowBar.low; + datetime supportTime = secondSwingLowBar.time; + string supportName = + // + identifier + + (IsSpecifiedValid(prefix) + ? "_" + prefix + "_" + : "") + + "_" + lowerPrefix + "_" + + "" + // + ; + + // + double resistance = secondSwingHighBar.high; + datetime resistanceTime = secondSwingLowBar.time; + string resistanceName = + // + identifier + + (IsSpecifiedValid(prefix) + ? "_" + prefix + "_" + : "") + + "_" + upperPrefix + "_" + + "" + // + ; + + // + double newLow = firstSwingLowBar.low; + datetime newLowTime = firstSwingLowBar.time; + + // + double oldLow = secondSwingLowBar.low; + datetime oldLowTime = secondSwingLowBar.time; + string lowsName = + // + identifier + + (IsSpecifiedValid(prefix) + ? "_" + prefix + "_" + : "") + + "_" + lowsPrefix + "_" + + "" + // + ; + + // + double newHigh = firstSwingHighBar.high; + datetime newHighTime = firstSwingHighBar.time; + + // + double oldHigh = secondSwingHighBar.high; + datetime oldHighTime = secondSwingHighBar.time; + string highsName = + // + identifier + + (IsSpecifiedValid(prefix) + ? "_" + prefix + "_" + : "") + + "_" + lowsPrefix + "_" + + "" + // + ; + + // + // Draw Support ... + result = DrawTrendLine( + chartId, + supportName, + subWindow, + supportTime, + support, + newLowTime, + support, + mInputs.clrLower, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + if (!result) + { + return result; + } + + // + // Draw Resistance ... + result = DrawTrendLine( + chartId, + resistanceName, + subWindow, + resistanceTime, + resistance, + newHighTime, + resistance, + mInputs.clrUpper, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + if (!result) + { + return result; + } + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + string mSymbol; // Trading Symbol ... + ENUM_TIMEFRAMES mPeriod; // Trading Period ... + + // + XSCTrendInput mInputs; // Configs ... + + // + XOHCL zBar; + XOHCL firstSwingLowBar; + XOHCL secondSwingLowBar; + XOHCL firstSwingHighBar; + XOHCL secondSwingHighBar; +}; + +// \ No newline at end of file diff --git a/Experts/x-saherelm.x121.ea.mq5 b/Experts/x-saherelm.x121.ea.mq5 index b0f8a8e1..9fd25302 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -39,13 +39,14 @@ input int x121EASlippage = 10; // Slippgae // Signals ... // EURUSDb,GBPUSDb,XAUUSDb,USDCHFb,USDJPYb input group "Signals"; -input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb,XAUUSDb,NZDUSDb,AUDUSDb,USDCADb,BTCUSD,ETHUSD"; // Symbols -input bool x121EAUseAllSymbols = false; // Use All Available Symbols -input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols -input bool x121EAAllowLong = true; // Allow Long Trades -input bool x121EAAllowShort = true; // Allow Short Trades -input int x121EAReuiredSignalVerifications = 5; // Required Verifications for Signals -input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames +// EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb,XAUUSDb,NZDUSDb,AUDUSDb,USDCADb,BTCUSD,ETHUSD +input string x121EASymbols = ""; // Symbols +input bool x121EAUseAllSymbols = false; // Use All Available Symbols +input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols +input bool x121EAAllowLong = true; // Allow Long Trades +input bool x121EAAllowShort = true; // Allow Short Trades +input int x121EAReuiredSignalVerifications = 5; // Required Verifications for Signals +input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames // // Risk Management ... @@ -70,12 +71,12 @@ input group "Trailling"; input bool x121EAAllowTrailStop = true; // Enable Trailling Stop Losses input double x121EAFirstTrailDistance = 110; // Start Trailling Distance input double x121EAFirstTrailPoint = 60; // First Stop Trail -input double x121EANextTrailDistance = 60; // Next Trailling Distance +input double x121EANextTrailDistance = 50; // Next Trailling Distance input double x121EANextTrailPoint = 20; // Next Trailling Step // input group "Supporting"; -input bool x121EAAllowSupport = false; // Allow Support Signals +input bool x121EAAllowSupport = true; // Allow Support Signals double x121EASupportDistance = 50; // Supporting Distance input int x121EAMaxNumberOfSupports = 1; // Max Number of Support Signals input double x121EASupportVolumeMultiplier = 2.0; // Support Signals Volume Multiplier @@ -100,9 +101,9 @@ input double x121EAMaxAllowedRecoveryVolume = 0.08; // Max Allowed Recovery Sign // input group "Hedging"; input int x121EARestingAfterHedge = 1000; // Resting Seconds After Hedge -input double x121EAMinRequiredProfitPerTrade = 0.5; // Minimum Required Profit for Hedging +input double x121EAMinRequiredProfitPerTrade = 0.4; // Minimum Required Profit for Hedging input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume -input double x121EAForceCloseProfit = 40; // Close All Positions Regardless of Policies when Profit Reached +input double x121EAForceCloseProfit = 20; // Close All Positions Regardless of Policies when Profit Reached // // Alert ...