diff --git a/Classes/x-saherelm.x-signaller.class.mq5 b/Classes/x-saherelm.x-signaller.class.mq5 new file mode 100644 index 00000000..90e09ef2 --- /dev/null +++ b/Classes/x-saherelm.x-signaller.class.mq5 @@ -0,0 +1,479 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class +// ------------------------------------------------- +// Name: XCXBaseSignaller ... +// Description: Base Signaller Class ... +// +// - Create an Instance based on this ... +// - Attach Required Helpers for Indicator Usages ... +// - Override Virtual Methdos: +// - [] ProcessTick: Processing All Ticks +// - [] ProcessNewBar: Processing All New Bars +// - [] CheckForGuard: Check For Guards +// - [] CheckAdditionslSignallerValidations: Additional Class Validations +// +// - Dont Forget to Call OnSignal Event in Process Methods when +// a signal Appears ... +// +// - also Whenever you want you can call PrepareSignal Action to +// provide a Signal based on Current Market State ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Base Signaller Class" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.base.class.mq5" +#include "../Libraries/x-saherelm.x-trade.lib.mq5" + +// +// Definitions ... + +// +// a Event Listener for Checking Can Analyse Market or not ... +// Usually for Time Based Session Handling ... +typedef bool (*TXCSignallerCanAnalyse)( + string _symbol, + ENUM_TIMEFRAMES _period, + datetime _time // +); + +// +// a Event Listener for Notifying a Signal ... +// Usually for Time Based Session Handling ... +typedef bool (*TXCSignallerOnSignalEvent)(XSignal &signal); + +// +// Implementations ... +class XCXBaseSignaller : public XCBase +{ + // + // Public ... + public: + // + // Props ... + string name; // Name ... + string symbol; // Symbol ... + ENUM_TIMEFRAMES period; // Period ... + + // + TXCSignallerCanAnalyse canAnalyseEventListener; + + // + // Constructor ... + XCXBaseSignaller( + string _name, // Name ... + string _symbol, // Symbol ... + ENUM_TIMEFRAMES _period, // Period ... + bool _processAllTicks = false, // Process All Ticks ... + double _defaultSignalR2R = 1.5, // Default Signal Risk To Reward Ratio ... + double _defaultSignalRiskInPoint = 50, // Default Signal Risk In Point ... + double _defaultSignalVolume = 0.01 // Default Signal Volume ... + ) + { + // + // Assign Properties ... + name = _name; + symbol = _symbol; + period = _period; + + // + processAllTicks = _processAllTicks; + defaultSignalR2R = _defaultSignalR2R; + defaultSignalVolume = _defaultSignalVolume; + defaultSignalRiskInPoint = _defaultSignalRiskInPoint; + + // + // Normalize ... + defaultSignalR2R = NormalizeDouble(defaultSignalR2R, 1, 10); + defaultSignalVolume = NormalizeDouble(defaultSignalVolume, 0.01); + defaultSignalVolume = NormalizeVolume(defaultSignalVolume, symbol, 2); + defaultSignalRiskInPoint = NormalizeDouble(defaultSignalRiskInPoint, 10); + + // + // Set Dfault Values ... + mProcessedTicksCount = 0; + mLastCheckedBarTime = NULL; + } + + // + // Deconstructor ... + ~XCXBaseSignaller() + { + // + // Cleanup Event Listeners ... + SpecifiedClean(onSignalEventListeners); + } + + // + // Event Listeners ... + + /** + * Add On Signal Event Listener ... + * + * @param listener: TXCSignallerOnSignalEvent instance ... + */ + void AddOnSignalEventListener(TXCSignallerOnSignalEvent listener) + { + // + // Validate ... + if (listener == NULL) + { + return; + } + + // + Add( + listener, + onSignalEventListeners // + ); + } + + // + // Actions ... + + /** + * Check Signaller Validation ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsSpecifiedValid(name) && + IsSpecifiedValid(symbol) && + IsSpecifiedValid(period) && + // + CheckAdditionslSignallerValidations() + // + ; + + // + return result; + } + + /** + * Handling On Tick Event ... + * + * @param barIndex: int, Specified Bar Index ... + */ + void OnTick(int barIndex = 0) + { + // + // Normalize Bar Index ... + if (barIndex < 0) + { + barIndex = 0; + } + + // + // Define Requirements ... + XOHCL iBar; + bool has = false; + bool isNewBar = false; + + // + // Get Current Bar Time ... + datetime cBarTime = GetBarTime( + symbol, + period, + barIndex // + ); + + // + // Validate Bar Time ... + has = IsSpecifiedValid(cBarTime); + if (!has) + { + return; + } + + // + // Check Process Permissions ... + has = CanAnalyseMarket(cBarTime); + if (!has) + { + return; + } + + // + // Check if new Bar, Reset Processed Ticks Count ... + isNewBar = cBarTime > mLastCheckedBarTime; + if (isNewBar) + { + // + mProcessedTicksCount = 0; + ProcessNewBar(barIndex); + } + + // + // Check Allow Process ... + // Process All Ticks ... + // Process New Bars ... + has = processAllTicks || + (!processAllTicks && isNewBar); + if (!has) + { + return; + } + + // + // Set Last Works ... + mProcessedTicksCount++; + mLastCheckedBarTime = cBarTime; + + // + ProcessTick(barIndex); + } + + // + // Virtuals ... + + /** + * Processing Tick ... + * + * @param barIndex: int, Specified Bar Index ... + */ + virtual void ProcessTick(int barIndex = 0) + { + } + + /** + * Processing New Bar ... + * + * @param barIndex: int, Specified Bar Index ... + */ + virtual void ProcessNewBar(int barIndex = 0) + { + } + + /** + * Check Guards Based on MarketConditions ... + * + * @param guards: XGuard[] + * @param barIndex: int + * + * @return ( int ) + */ + int virtual CheckForGuard( + XGuard &guards[], + int barIndex = 0 // + ) + { + // + int result = 0; + + // + SpecifiedClean(guards); + + // + result = ArraySize(guards); + + // + return result; + } + + /** + * Check Additional Validations on Childs Instances ... + * + * @return ( bool virtual ) + */ + bool virtual CheckAdditionslSignallerValidations() + { + return true; + } + + // + // Protected ... + protected: + // + // Props ... + + // + bool processAllTicks; // Specified Processing All Ticks or not ... + + // + int mProcessedTicksCount; // Prcoessed Ticks Count ... + datetime mLastCheckedBarTime; // Last Checked Bar Time ... + + // + double defaultSignalR2R; // Default Signal Risk To Reward Ratio ... + double defaultSignalVolume; // Default Signal Volume ... + double defaultSignalRiskInPoint; // Default Signal Risk In Point ... + + // + // Event Notifiers ... + + /** + * Notify OnSignal Event Listeners ... + * + * @param signal: XSignal, Specified Signal to Notify ... + */ + void NotifySignalEventListeners(XSignal &signal) + { + // + int count = ArraySize(onSignalEventListeners); + + // + // Validate ... + if (!IsValidSize(count) || !signal.IsValid()) + { + return; + } + + // + // Do Notify ... + for (int i = 0; i < count; i++) + { + onSignalEventListeners[i](signal); + } + } + + /** + * Calling Can Analyse Event Listeners ... + * Check Can Analayse Market or not ... + * + * @param time: datetime, Specified Time for Checking ... + * + * @return ( bool ) + */ + bool CanAnalyseMarket(datetime time = NULL) + { + // + bool result = false; + + // + // Normalize ... + time = NormalizeTime(time); + + // + // Validation ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = canAnalyseEventListener == NULL; + if (result) + { + return result; + } + + // + // Calling Can Analyse Event Listener ... + result = canAnalyseEventListener( + symbol, + period, + time // + ); + + // + return result; + } + + /** + * Preparing Default Signal ... + * + * @param signal: XSignal, holding result Signal ... + * @param forDir: ENUM_X_DIRECTION + * @return ( bool ) + */ + bool PrepareSignal( + XSignal &signal, + ENUM_X_DIRECTION forDir // + ) + { + // + bool result = false; + + // + // Prepare ... + signal.Clean(); + + // + // Normalize ... + + // + // Validate ... + result = IsValid() && + HasDirection(forDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsSpecifiedBullish(forDir); + + // + double point = GetPoints(symbol); + double spread = GetSpread(symbol); + double volume = defaultSignalVolume; + double entry = GetEntry(symbol, forDir); + + // + double risk = (defaultSignalRiskInPoint * point); + double reward = (risk * defaultSignalR2R) + spread; + + // + double tp = + isBullish + ? entry + reward + : entry - reward; + + // + double sl = + isBullish + ? entry - risk + : entry + risk; + + // + // Filling Values ... + signal.tp = tp; + signal.sl = sl; + signal.entry = entry; + signal.provider = name; + signal.symbol = symbol; + signal.period = period; + signal.volume = volume; + signal.time = TimeCurrent(); + + // + // Validate Signal ... + result = signal.IsValid(); + + // + return result; + } + + // + // Private ... + private: + // + // Props ... + + // + // Event Listeners ... + TXCSignallerOnSignalEvent onSignalEventListeners[]; +}; + +// diff --git a/Experts/x-saherelm.xfima.backtester.ea.mq5 b/Experts/x-saherelm.xfima.backtester.ea.mq5 index 84214a65..41328ec1 100644 --- a/Experts/x-saherelm.xfima.backtester.ea.mq5 +++ b/Experts/x-saherelm.xfima.backtester.ea.mq5 @@ -16,6 +16,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm XBackTester" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // @@ -84,19 +85,20 @@ input ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method // // Others ... -input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level -input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_382; // Lower Zone Level -input double sarStep = 0.02; // SAR Step -input double sarMax = 0.2; // SAR Maximum -input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method -input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To -input int maFastLength = 7; // Fast MA Length -input int maSlowLength = 20; // Slow MA Length -input int zigzagDepth = 12; // ZigZag Depth -input int zigzagDeviation = 5; // ZigZag Deviation -input int zigzagBackStep = 3; // ZigZag Back Step -input ENUM_X_PRICE zigzagUppersMode = X_PRICE_HIGH; // ZigZag High Detect Mode -input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low Detect Mode +input ENUM_X_FIBO_LEVELS fiboUpperZoneLevel = X_FIBO_LEVEL_382; // Upper Zone Level +input ENUM_X_FIBO_LEVELS fiboMiddleZoneLevel = X_FIBO_LEVEL_500; // Middle Zone Level +input ENUM_X_FIBO_LEVELS fiboLowerZoneLevel = X_FIBO_LEVEL_618; // Lower Zone Level +input double sarStep = 0.02; // SAR Step +input double sarMax = 0.2; // SAR Maximum +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To +input int maFastLength = 7; // Fast MA Length +input int maSlowLength = 20; // Slow MA Length +input int zigzagDepth = 12; // ZigZag Depth +input int zigzagDeviation = 5; // ZigZag Deviation +input int zigzagBackStep = 3; // ZigZag Back Step +input ENUM_X_PRICE zigzagUppersMode = X_PRICE_HIGH; // ZigZag High Detect Mode +input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low Detect Mode // input group "Bar Timer"; @@ -108,13 +110,13 @@ input ENUM_BASE_CORNER barTimeCorner = CORNER_RIGHT_LOWER; // Text Position // // Presentation ... input group "Presentation"; -input bool showPV = true; // Show PV -input bool showSAR = true; // Show Sar -input bool showMAFast = true; // Show MA Fast -input bool showMASlow = true; // Show MA Slow -input bool showBarTime = true; // Show Bar Time -input bool showZigZag = true; // Show ZigZag -input bool showFiboZone = false; // Show Fibo Zone +input bool showPV = true; // Show PV +input bool showSAR = true; // Show Sar +input bool showMAFast = true; // Show MA Fast +input bool showMASlow = true; // Show MA Slow +input bool showBarTime = true; // Show Bar Time +input bool showZigZag = true; // Show ZigZag +input bool showFiboZone = true; // Show Fibo Zone // input int startCalculationForLastBars = 1500; // Calculate Last n Bars @@ -249,8 +251,9 @@ int OnInit() hcPeriod, upperMode, lowerMode, - upperZoneLevel, - lowerZoneLevel, + fiboUpperZoneLevel, + fiboMiddleZoneLevel, + fiboLowerZoneLevel, sarStep, sarMax, maMethod, diff --git a/Helpers/x-saherelm.xfima.helper.mq5 b/Helpers/x-saherelm.xfima.helper.mq5 new file mode 100644 index 00000000..21fcf156 --- /dev/null +++ b/Helpers/x-saherelm.xfima.helper.mq5 @@ -0,0 +1,2338 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XCXFIMAHelper +// Description: provides all Indicator +// Helper 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.x-helper.class.mq5" + +// +// Definitions ... + +// +// Buffers ... +enum ENUM_XFIMA_BUFFERS +{ + XFIMA_MA_FAST_LINE = 0, + XFIMA_MA_FAST_COLOR_LINE = 1, + XFIMA_MA_FAST_STATE_LINE = 12, + XFIMA_MA_SLOW_LINE = 2, + XFIMA_MA_SLOW_COLOR_LINE = 3, + XFIMA_MA_SLOW_STATE_LINE = 13, + XFIMA_SAR_LINE = 4, + XFIMA_SAR_COLOR_LINE = 5, + XFIMA_SAR_STATE_LINE = 14, + XFIMA_PEAK_LINE = 6, + XFIMA_VALE_LINE = 7, + XFIMA_FINO_UPPER_LINE = 8, + XFIMA_FINO_MIDDLE_LINE = 9, + XFIMA_FINO_LOWER_LINE = 10, + XFIMA_ZIGZAG_LINE = 11, + XFIMA_ZIGZAG_HIGHS_LINE = 23, + XFIMA_ZIGZAG_HIGHS_TIME_LINE = 24, + XFIMA_ZIGZAG_LOWS_LINE = 25, + XFIMA_ZIGZAG_LOWS_TIME_LINE = 26, + // 12 Ma Fast State + // 13 Ma Slow State + // 14 Sar State + XFIMA_SC_HH_LINE = 15, + XFIMA_SC_LL_LINE = 16, + XFIMA_MC_HH_LINE = 17, + XFIMA_MC_LL_LINE = 18, + XFIMA_LC_HH_LINE = 19, + XFIMA_LC_LL_LINE = 20, + XFIMA_HC_HH_LINE = 21, + XFIMA_HC_LL_LINE = 22, + // 23 ZigZag Highs + // 24 ZigZag Highs Time + // 25 ZigZag Lows + // 26 ZigZag Lows Time +}; + +// +// Input Models ... +struct XFIMAInputs +{ + // + // Props ... + + // + // Calculation ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Short Period + ENUM_TIMEFRAMES scPeriod; // Short Period + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Medium Period + ENUM_TIMEFRAMES mcPeriod; // Medium Period + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Long Period + ENUM_TIMEFRAMES lcPeriod; // Long Period + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Hind Period + ENUM_TIMEFRAMES hcPeriod; // Hind Period + ENUM_SERIESMODE upperMode; // Peak Method + ENUM_SERIESMODE lowerMode; // Vale Method + ENUM_X_FIBO_LEVELS fiboUpperZoneLevel; // Upper Zone Level + ENUM_X_FIBO_LEVELS fiboMiddleZoneLevel; // Upper Zone Level + ENUM_X_FIBO_LEVELS fiboLowerZoneLevel; // Lower Zone Level + double sarStep; // SAR Step + double sarMax; // SAR Maximum + ENUM_MA_METHOD maMethod; // MA Method + ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To + int maFastLength; // Fast MA Length + int maSlowLength; // Slow MA Length + int zigzagDepth; // ZigZag Depth + int zigzagDeviation; // ZigZag Deviation + int zigzagBackStep; // ZigZag Back Step + ENUM_X_PRICE zigzagUppersMode; // ZigZag High Detect Mode + ENUM_X_PRICE zigzagLowersMode; // ZigZag Low Detect Mode + + // + // Presentation ... + bool showPV; // Show PV + bool showSAR; // Show Sar + bool showMAFast; // Show MA Fast + bool showMASlow; // Show MA Slow + bool showZigZag; // Show ZigZag + bool showFiboZone; // Show Fibo Zone + int startCalculationForLastBars; // Calculate Last n Bars + int sarArrowCode; // Parabolic Sar Arrow Code + int peakArrowCode; // Peaks Arrow Code + int valeArrowCode; // Vales Arrow Code + + // + // Constructor(s) ... + XFIMAInputs() + { + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + ZeroMemory(this); + } + + // + // Default ... + void Default() + { + // + // Calculations ... + scMethod = X_PERIOD_AUTO; // How to Find Short Period + scPeriod = NULL; // Short Period + mcMethod = X_PERIOD_AUTO; // How to Find Medium Period + mcPeriod = NULL; // Medium Period + lcMethod = X_PERIOD_AUTO; // How to Find Long Period + lcPeriod = NULL; // Long Period + hcMethod = X_PERIOD_AUTO; // How to Find Hind Period + hcPeriod = NULL; // Hind Period + upperMode = MODE_HIGH; // Peak Method + lowerMode = MODE_LOW; // Vale Method + fiboUpperZoneLevel = X_FIBO_LEVEL_382; // Upper Zone Level + fiboMiddleZoneLevel = X_FIBO_LEVEL_500; // Upper Zone Level + fiboLowerZoneLevel = X_FIBO_LEVEL_618; // Lower Zone Level + sarStep = 0.02; // SAR Step + sarMax = 0.2; // SAR Maximum + maMethod = MODE_EMA; // MA Method + maAppliedTo = PRICE_CLOSE; // MA Applied To + maFastLength = 7; // Fast MA Length + maSlowLength = 20; // Slow MA Length + zigzagDepth = 12; // ZigZag Depth + zigzagDeviation = 5; // ZigZag Deviation + zigzagBackStep = 3; // ZigZag Back Step + zigzagUppersMode = X_PRICE_HIGH; // ZigZag High Detect Mode + zigzagLowersMode = X_PRICE_LOW; // ZigZag Low Detect Mode + + // + // Presentation ... + showPV = true; // Show PV + showSAR = true; // Show Sar + showMAFast = true; // Show MA Fast + showMASlow = true; // Show MA Slow + showZigZag = true; // Show ZigZag + showFiboZone = true; // Show Fibo Zone + startCalculationForLastBars = 1500; // Calculate Last n Bars + sarArrowCode = 159; // Parabolic Sar Arrow Code + peakArrowCode = 159; // Peaks Arrow Code + valeArrowCode = 159; // Vales Arrow Code + } + + // + // Hide all Visible Buffers ... + void Hide() + { + // + showPV = false; + showSAR = false; + showMAFast = false; + showMASlow = false; + showZigZag = false; + showFiboZone = false; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + // MA ... + maFastLength >= 2 && + maSlowLength >= 2 && + maSlowLength > maFastLength && + // + // SAR ... + sarMax > 0 && + sarStep > 0 && + sarMax > sarStep && + // + // CYCLES ... + (IsSpecifiedValid(scMethod, scPeriod) && + IsSpecifiedValid(mcMethod, mcPeriod) && + IsSpecifiedValid(lcMethod, lcPeriod) && + IsSpecifiedValid(hcMethod, hcPeriod)) && + // + // ZIGZAG ... + zigzagDepth > 0 && + zigzagDeviation > 0 && + zigzagBackStep > 0 && + // + // Validate Upper Mode Detection ... + IsXValid(zigzagUppersMode) && + // + // Validate Lower Mode Detection ... + IsXValid(zigzagLowersMode) + // + ; + + // + return result; + } +}; + +// +// Conditions ... +struct XFIMAConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + datetime to; + datetime from; + XOHCL bars[]; + + // + // Buffers ... + double maFastBuffer[]; + double maFastColorBuffer[]; + double maFastStateBuffer[]; + double maSlowBuffer[]; + double maSlowColorBuffer[]; + double maSlowStateBuffer[]; + double sarBuffer[]; + double sarColorBuffer[]; + double sarStateBuffer[]; + double peakBuffer[]; + double valeBuffer[]; + double fiboUpperBuffer[]; + double fiboMiddleBuffer[]; + double fiboLowerBuffer[]; + double zigzagBuffer[]; + double sHHBuffer[]; + double sLLBuffer[]; + double mHHBuffer[]; + double mLLBuffer[]; + double lHHBuffer[]; + double lLLBuffer[]; + double hHHBuffer[]; + double hLLBuffer[]; + double highsBuffer[]; + double highsTimeBuffer[]; + double lowsBuffer[]; + double lowsTimeBuffer[]; + + // + // Conditions ... + + // + // Constructor ... + XFIMAConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + // Commons ... + to = NULL; + from = NULL; + time = NULL; + symbol = NULL; + period = NULL; + + // + // Buffers ... + + // + SpecifiedClean(bars); + + // + SpecifiedClean(maFastBuffer); + SpecifiedClean(maFastColorBuffer); + SpecifiedClean(maFastStateBuffer); + SpecifiedClean(maSlowBuffer); + SpecifiedClean(maSlowColorBuffer); + SpecifiedClean(maSlowStateBuffer); + SpecifiedClean(sarBuffer); + SpecifiedClean(sarColorBuffer); + SpecifiedClean(sarStateBuffer); + SpecifiedClean(peakBuffer); + SpecifiedClean(valeBuffer); + SpecifiedClean(fiboUpperBuffer); + SpecifiedClean(fiboMiddleBuffer); + SpecifiedClean(fiboLowerBuffer); + SpecifiedClean(zigzagBuffer); + SpecifiedClean(sHHBuffer); + SpecifiedClean(sLLBuffer); + SpecifiedClean(mHHBuffer); + SpecifiedClean(mLLBuffer); + SpecifiedClean(lHHBuffer); + SpecifiedClean(lLLBuffer); + SpecifiedClean(hHHBuffer); + SpecifiedClean(hLLBuffer); + SpecifiedClean(highsBuffer); + SpecifiedClean(highsTimeBuffer); + SpecifiedClean(lowsBuffer); + SpecifiedClean(lowsTimeBuffer); + + // + // Conditions ... + + // + ArraySetAsSeries(bars, true); + + // + ArraySetAsSeries(maFastBuffer, true); + ArraySetAsSeries(maFastColorBuffer, true); + ArraySetAsSeries(maFastStateBuffer, true); + ArraySetAsSeries(maSlowBuffer, true); + ArraySetAsSeries(maSlowColorBuffer, true); + ArraySetAsSeries(maSlowStateBuffer, true); + ArraySetAsSeries(sarBuffer, true); + ArraySetAsSeries(sarColorBuffer, true); + ArraySetAsSeries(sarStateBuffer, true); + ArraySetAsSeries(peakBuffer, true); + ArraySetAsSeries(valeBuffer, true); + ArraySetAsSeries(fiboUpperBuffer, true); + ArraySetAsSeries(fiboMiddleBuffer, true); + ArraySetAsSeries(fiboLowerBuffer, true); + ArraySetAsSeries(zigzagBuffer, true); + ArraySetAsSeries(sHHBuffer, true); + ArraySetAsSeries(sLLBuffer, true); + ArraySetAsSeries(mHHBuffer, true); + ArraySetAsSeries(mLLBuffer, true); + ArraySetAsSeries(lHHBuffer, true); + ArraySetAsSeries(lLLBuffer, true); + ArraySetAsSeries(hHHBuffer, true); + ArraySetAsSeries(hLLBuffer, true); + ArraySetAsSeries(highsBuffer, true); + ArraySetAsSeries(highsTimeBuffer, true); + ArraySetAsSeries(lowsBuffer, true); + ArraySetAsSeries(lowsTimeBuffer, true); + + // + ZeroMemory(this); + } + + /** + * Generate Conditions Scores ... + * + * @param bullishScore: Double, Directional Scores Reference ... + * @param bearishScore: Double, Directional Scores Reference ... + */ + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + } + + /** + * Generate Summary String for Represent Conditions State ... + * + * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... + * @param onlyConditions: Boolean, Just Generate Only Conditions ... + * @param includeScores: Boolean, Attach Scores Representations on Result ... + * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... + * @param separator: String, Separate Lines ... + * + * @return ( string ) + */ + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + return ""; + } + + /** + * Retrieve Unique Tag Identifier ... + * + * @return ( string ) + */ + string GetTag() + { + return GetToken(this); + } +}; + +// +// Class ... +class XCXFIMAHelper : public XCBaseHelper +{ + // + // Public ... + public: + // + // Props ... + + // + // Buffers ... + double maFastBuffer[]; + double maFastColorBuffer[]; + double maFastStateBuffer[]; + double maSlowBuffer[]; + double maSlowColorBuffer[]; + double maSlowStateBuffer[]; + double sarBuffer[]; + double sarColorBuffer[]; + double sarStateBuffer[]; + double peakBuffer[]; + double valeBuffer[]; + double fiboUpperBuffer[]; + double fiboMiddleBuffer[]; + double fiboLowerBuffer[]; + double zigzagBuffer[]; + double sHHBuffer[]; + double sLLBuffer[]; + double mHHBuffer[]; + double mLLBuffer[]; + double lHHBuffer[]; + double lLLBuffer[]; + double hHHBuffer[]; + double hLLBuffer[]; + double highsBuffer[]; + double highsTimeBuffer[]; + double lowsBuffer[]; + double lowsTimeBuffer[]; + + // + // Constructors ... + XCXFIMAHelper() + : XCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XCXFIMAHelper() + { + } + + // + // Tools ... + + // + // Initialize Helper Cleass ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XFIMAInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + ArraySetAsSeries(maFastBuffer, true); + ArraySetAsSeries(maFastColorBuffer, true); + ArraySetAsSeries(maFastStateBuffer, true); + ArraySetAsSeries(maSlowBuffer, true); + ArraySetAsSeries(maSlowColorBuffer, true); + ArraySetAsSeries(maSlowStateBuffer, true); + ArraySetAsSeries(sarBuffer, true); + ArraySetAsSeries(sarColorBuffer, true); + ArraySetAsSeries(sarStateBuffer, true); + ArraySetAsSeries(peakBuffer, true); + ArraySetAsSeries(valeBuffer, true); + ArraySetAsSeries(fiboUpperBuffer, true); + ArraySetAsSeries(fiboMiddleBuffer, true); + ArraySetAsSeries(fiboLowerBuffer, true); + ArraySetAsSeries(zigzagBuffer, true); + ArraySetAsSeries(sHHBuffer, true); + ArraySetAsSeries(sLLBuffer, true); + ArraySetAsSeries(mHHBuffer, true); + ArraySetAsSeries(mLLBuffer, true); + ArraySetAsSeries(lHHBuffer, true); + ArraySetAsSeries(lLLBuffer, true); + ArraySetAsSeries(hHHBuffer, true); + ArraySetAsSeries(hLLBuffer, true); + ArraySetAsSeries(highsBuffer, true); + ArraySetAsSeries(highsTimeBuffer, true); + ArraySetAsSeries(lowsBuffer, true); + ArraySetAsSeries(lowsTimeBuffer, true); + + // + mInputs = inputs; + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xfima", + "", // Calculation ... + mInputs.scMethod, + mInputs.scPeriod, + mInputs.mcMethod, + mInputs.mcPeriod, + mInputs.lcMethod, + mInputs.lcPeriod, + mInputs.hcMethod, + mInputs.hcPeriod, + mInputs.upperMode, + mInputs.lowerMode, + mInputs.fiboUpperZoneLevel, + mInputs.fiboMiddleZoneLevel, + mInputs.fiboLowerZoneLevel, + mInputs.sarStep, + mInputs.sarMax, + mInputs.maMethod, + mInputs.maAppliedTo, + mInputs.maFastLength, + mInputs.maSlowLength, + mInputs.zigzagDepth, + mInputs.zigzagDeviation, + mInputs.zigzagBackStep, + mInputs.zigzagUppersMode, + mInputs.zigzagLowersMode, + "", // Presentation ... + mInputs.showPV, + mInputs.showSAR, + mInputs.showMAFast, + mInputs.showMASlow, + mInputs.showZigZag, + mInputs.showFiboZone, + mInputs.startCalculationForLastBars, + mInputs.sarArrowCode, + mInputs.peakArrowCode, + mInputs.valeArrowCode + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XFIMAInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XFIMAInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs // + ); + } + + // + // Tools ... + + // + void Update( + int barIndex // Bar Index + ) + { + Calculate(barIndex); + } + + // + void Free() override + { + Cleanup(10); + } + + // + bool GetConditions( + XFIMAConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + // Filling Bars ... + int barsCount = GetBars( + conditions.bars, + mSymbol, + mPeriod, + barIndex, + loopback // + ); + result = barsCount == loopback; + if (!result) + { + // + conditions.Clean(); + + // + return result; + } + + // + int zIDX = 0; + int cIDX = 1; + int pIDX = cIDX + 1; + int p2IDX = pIDX + 1; + int p3IDX = p2IDX + 1; + int p4IDX = p3IDX + 1; + + // + conditions.to = conditions.bars[0].time; + conditions.from = conditions.bars[ArraySize(conditions.bars) - 1].time; + + // + int zIndex = barIndex; + + // + // Buffers ... + + // + CopyMAFast( + zIndex, + loopback, + conditions.maFastBuffer // + ); + + // + CopyMAFastState( + zIndex, + loopback, + conditions.maFastStateBuffer // + ); + + // + CopyMASlow( + zIndex, + loopback, + conditions.maSlowBuffer // + ); + + // + CopyMASlowState( + zIndex, + loopback, + conditions.maSlowStateBuffer // + ); + + // + CopySar( + zIndex, + loopback, + conditions.sarBuffer // + ); + + // + CopySarState( + zIndex, + loopback, + conditions.sarStateBuffer // + ); + + // + CopyPeak( + zIndex, + loopback, + conditions.peakBuffer // + ); + + // + CopyVale( + zIndex, + loopback, + conditions.valeBuffer // + ); + + // + CopyFiboUpper( + zIndex, + loopback, + conditions.fiboUpperBuffer // + ); + + // + CopyFiboMiddle( + zIndex, + loopback, + conditions.fiboMiddleBuffer // + ); + + // + CopyFiboLower( + zIndex, + loopback, + conditions.fiboLowerBuffer // + ); + + // + CopyZigZag( + zIndex, + loopback, + conditions.zigzagBuffer // + ); + + // + CopySHH( + zIndex, + loopback, + conditions.sHHBuffer // + ); + + // + CopySLL( + zIndex, + loopback, + conditions.sLLBuffer // + ); + + // + CopyMHH( + zIndex, + loopback, + conditions.mHHBuffer // + ); + + // + CopyMLL( + zIndex, + loopback, + conditions.mLLBuffer // + ); + + // + CopyLHH( + zIndex, + loopback, + conditions.lHHBuffer // + ); + + // + CopyLLL( + zIndex, + loopback, + conditions.lLLBuffer // + ); + + // + CopyHHH( + zIndex, + loopback, + conditions.hHHBuffer // + ); + + // + CopyHLL( + zIndex, + loopback, + conditions.hLLBuffer // + ); + + // + // Conditions ... + + // + return result; + } + + // + // Values Retrievers ... + + // + // Fast MA ... + + // + double GetMAFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(maFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return maFastBuffer[barIndex]; + } + + // + int CopyMAFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + maFastBuffer, + buffer, + forceClean + // + ); + } + + // + // Fast MA State ... + + // + double GetMAFastState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(maFastStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return maFastStateBuffer[barIndex]; + } + + // + int CopyMAFastState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + maFastStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow MA ... + + // + double GetMASlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(maSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return maSlowBuffer[barIndex]; + } + + // + int CopyMASlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + maSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow MA State ... + + // + double GetMASlowState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(maSlowStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return maSlowStateBuffer[barIndex]; + } + + // + int CopyMASlowState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + maSlowStateBuffer, + buffer, + forceClean + // + ); + } + + // + // SAR ... + + // + double GetSar( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(sarBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sarBuffer[barIndex]; + } + + // + int CopySar( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + sarBuffer, + buffer, + forceClean + // + ); + } + + // + // SAR State ... + + // + double GetSarState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(sarStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sarStateBuffer[barIndex]; + } + + // + int CopySarState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + sarStateBuffer, + buffer, + forceClean + // + ); + } + + // + // PEAK ... + + // + double GetPeak( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(peakBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return peakBuffer[barIndex]; + } + + // + int CopyPeak( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + peakBuffer, + buffer, + forceClean + // + ); + } + + // + // VALE ... + + // + double GetVale( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(valeBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return valeBuffer[barIndex]; + } + + // + int CopyVale( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + valeBuffer, + buffer, + forceClean + // + ); + } + + // + // FIBO Zone ... + + // + // FIBO Upper ... + + // + double GetFiboUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(fiboUpperBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fiboUpperBuffer[barIndex]; + } + + // + int CopyFiboUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + fiboUpperBuffer, + buffer, + forceClean + // + ); + } + + // + // FIBO Middle ... + + // + double GetFiboMiddle( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(fiboMiddleBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fiboMiddleBuffer[barIndex]; + } + + // + int CopyFiboMiddle( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + fiboMiddleBuffer, + buffer, + forceClean + // + ); + } + + // + // FIBO Lower ... + + // + double GetFiboLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(fiboLowerBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fiboLowerBuffer[barIndex]; + } + + // + int CopyFiboLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + fiboLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // ZigZag ... + + // + double GetZigZag( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(zigzagBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return zigzagBuffer[barIndex]; + } + + // + int CopyZigZag( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + zigzagBuffer, + buffer, + forceClean + // + ); + } + + // + // CYCLES Range ... + + // + // SHORT ... + + // + // HH ... + + // + double GetSHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(sHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sHHBuffer[barIndex]; + } + + // + int CopySHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + sHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetSLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(sLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sLLBuffer[barIndex]; + } + + // + int CopySLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + sLLBuffer, + buffer, + forceClean + // + ); + } + + // + // MEDIUM ... + + // + // HH ... + + // + double GetMHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(mHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mHHBuffer[barIndex]; + } + + // + int CopyMHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + mHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetMLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(mLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mLLBuffer[barIndex]; + } + + // + int CopyMLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + mLLBuffer, + buffer, + forceClean + // + ); + } + + // + // LONG ... + + // + // HH ... + + // + double GetLHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(lHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lHHBuffer[barIndex]; + } + + // + int CopyLHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + lHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetLLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(lLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lLLBuffer[barIndex]; + } + + // + int CopyLLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + lLLBuffer, + buffer, + forceClean + // + ); + } + + // + // HIND ... + + // + // HH ... + + // + double GetHHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(hHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hHHBuffer[barIndex]; + } + + // + int CopyHHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + hHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetHLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(barIndex); + + // + int count = ArraySize(hLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hLLBuffer[barIndex]; + } + + // + int CopyHLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(start); + + // + // Copy Items ... + return Copy( + 0, + count, + hLLBuffer, + buffer, + forceClean + // + ); + } + + // + // Protected ... + protected: + // + // Private ... + private: + // + // Props ... + XFIMAInputs mInputs; // Inputs ... + + // + // Buffers ... + // Define in Public ... + + // + void Calculate( + int barIndex = 0, + int maxRequiredBars = 100 // + ) + { + // + // Buffers ... + if (barIndex < 0) + { + barIndex = 0; + } + + // + CopyBuffer( + mHandler, + XFIMA_MA_FAST_LINE, + barIndex, + maxRequiredBars, + maFastBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_MA_FAST_COLOR_LINE, + barIndex, + maxRequiredBars, + maFastColorBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_MA_FAST_STATE_LINE, + barIndex, + maxRequiredBars, + maFastStateBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_MA_SLOW_LINE, + barIndex, + maxRequiredBars, + maSlowBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_MA_SLOW_COLOR_LINE, + barIndex, + maxRequiredBars, + maSlowColorBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_MA_SLOW_STATE_LINE, + barIndex, + maxRequiredBars, + maSlowStateBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_SAR_LINE, + barIndex, + maxRequiredBars, + sarBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_SAR_COLOR_LINE, + barIndex, + maxRequiredBars, + sarColorBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_SAR_STATE_LINE, + barIndex, + maxRequiredBars, + sarStateBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_PEAK_LINE, + barIndex, + maxRequiredBars, + peakBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_VALE_LINE, + barIndex, + maxRequiredBars, + valeBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_FINO_UPPER_LINE, + barIndex, + maxRequiredBars, + fiboUpperBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_FINO_MIDDLE_LINE, + barIndex, + maxRequiredBars, + fiboMiddleBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_FINO_LOWER_LINE, + barIndex, + maxRequiredBars, + fiboLowerBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_ZIGZAG_LINE, + barIndex, + maxRequiredBars, + zigzagBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_SC_HH_LINE, + barIndex, + maxRequiredBars, + sHHBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_SC_LL_LINE, + barIndex, + maxRequiredBars, + sLLBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_MC_HH_LINE, + barIndex, + maxRequiredBars, + mHHBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_MC_LL_LINE, + barIndex, + maxRequiredBars, + mLLBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_LC_HH_LINE, + barIndex, + maxRequiredBars, + lHHBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_LC_LL_LINE, + barIndex, + maxRequiredBars, + lLLBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_HC_HH_LINE, + barIndex, + maxRequiredBars, + hHHBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_HC_LL_LINE, + barIndex, + maxRequiredBars, + hLLBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_ZIGZAG_HIGHS_LINE, + barIndex, + maxRequiredBars, + highsBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_ZIGZAG_HIGHS_TIME_LINE, + barIndex, + maxRequiredBars, + highsTimeBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_ZIGZAG_LOWS_LINE, + barIndex, + maxRequiredBars, + lowsBuffer // + ); + + // + CopyBuffer( + mHandler, + XFIMA_ZIGZAG_LOWS_TIME_LINE, + barIndex, + maxRequiredBars, + lowsTimeBuffer // + ); + } + + // + void Cleanup( + int maxAllowed = 100 // + ) + { + // + CleanupArray( + maFastBuffer, + maxAllowed // + ); + + // + CleanupArray( + maFastColorBuffer, + maxAllowed // + ); + + // + CleanupArray( + maFastStateBuffer, + maxAllowed // + ); + + // + CleanupArray( + maSlowBuffer, + maxAllowed // + ); + + // + CleanupArray( + maSlowColorBuffer, + maxAllowed // + ); + + // + CleanupArray( + maSlowStateBuffer, + maxAllowed // + ); + + // + CleanupArray( + sarBuffer, + maxAllowed // + ); + + // + CleanupArray( + sarColorBuffer, + maxAllowed // + ); + + // + CleanupArray( + sarStateBuffer, + maxAllowed // + ); + + // + CleanupArray( + peakBuffer, + maxAllowed // + ); + + // + CleanupArray( + valeBuffer, + maxAllowed // + ); + + // + CleanupArray( + fiboUpperBuffer, + maxAllowed // + ); + + // + CleanupArray( + fiboMiddleBuffer, + maxAllowed // + ); + + // + CleanupArray( + fiboLowerBuffer, + maxAllowed // + ); + + // + CleanupArray( + zigzagBuffer, + maxAllowed // + ); + + // + CleanupArray( + sHHBuffer, + maxAllowed // + ); + + // + CleanupArray( + sLLBuffer, + maxAllowed // + ); + + // + CleanupArray( + mHHBuffer, + maxAllowed // + ); + + // + CleanupArray( + mLLBuffer, + maxAllowed // + ); + + // + CleanupArray( + lHHBuffer, + maxAllowed // + ); + + // + CleanupArray( + lLLBuffer, + maxAllowed // + ); + + // + CleanupArray( + hHHBuffer, + maxAllowed // + ); + + // + CleanupArray( + hLLBuffer, + maxAllowed // + ); + + // + CleanupArray( + highsBuffer, + maxAllowed // + ); + + // + CleanupArray( + highsTimeBuffer, + maxAllowed // + ); + + // + CleanupArray( + lowsBuffer, + maxAllowed // + ); + + // + CleanupArray( + lowsTimeBuffer, + maxAllowed // + ); + } +}; + +// \ No newline at end of file diff --git a/Indicators/x-saherelm.x121.xcatb.mq5 b/Indicators/x-saherelm.x121.xcatb.mq5 index 81c63b57..83f7eb5f 100644 --- a/Indicators/x-saherelm.x121.xcatb.mq5 +++ b/Indicators/x-saherelm.x121.xcatb.mq5 @@ -33,6 +33,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm X121 XCATB Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // diff --git a/Indicators/x-saherelm.x121.xcatb.v1.mq5 b/Indicators/x-saherelm.x121.xcatb.v1.mq5 index 73ac97a9..70f72ec3 100644 --- a/Indicators/x-saherelm.x121.xcatb.v1.mq5 +++ b/Indicators/x-saherelm.x121.xcatb.v1.mq5 @@ -33,6 +33,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm X121 XCATB Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // diff --git a/Indicators/x-saherelm.x121.xcc.mq5 b/Indicators/x-saherelm.x121.xcc.mq5 index 2f45b84b..8ff56b75 100644 --- a/Indicators/x-saherelm.x121.xcc.mq5 +++ b/Indicators/x-saherelm.x121.xcc.mq5 @@ -17,6 +17,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm X121 XCC Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // diff --git a/Indicators/x-saherelm.x121.xct.mq5 b/Indicators/x-saherelm.x121.xct.mq5 index c267a557..dc8542c0 100644 --- a/Indicators/x-saherelm.x121.xct.mq5 +++ b/Indicators/x-saherelm.x121.xct.mq5 @@ -17,6 +17,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm X121 XCT Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // diff --git a/Indicators/x-saherelm.x121.xma.mq5 b/Indicators/x-saherelm.x121.xma.mq5 index b003e335..0e71ed37 100644 --- a/Indicators/x-saherelm.x121.xma.mq5 +++ b/Indicators/x-saherelm.x121.xma.mq5 @@ -18,6 +18,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm X121 XMA Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // diff --git a/Indicators/x-saherelm.xfima.mq5 b/Indicators/x-saherelm.xfima.mq5 index e0f16f04..0fed6230 100644 --- a/Indicators/x-saherelm.xfima.mq5 +++ b/Indicators/x-saherelm.xfima.mq5 @@ -18,6 +18,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm XFIMA Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // @@ -73,19 +74,20 @@ input ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method // // Others ... -input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level -input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_382; // Lower Zone Level -input double sarStep = 0.02; // SAR Step -input double sarMax = 0.2; // SAR Maximum -input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method -input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To -input int maFastLength = 7; // Fast MA Length -input int maSlowLength = 20; // Slow MA Length -input int zigzagDepth = 12; // ZigZag Depth -input int zigzagDeviation = 5; // ZigZag Deviation -input int zigzagBackStep = 3; // ZigZag Back Step -input ENUM_X_PRICE zigzagUppersMode = X_PRICE_HIGH; // ZigZag High Detect Mode -input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low Detect Mode +input ENUM_X_FIBO_LEVELS fiboUpperZoneLevel = X_FIBO_LEVEL_382; // Upper Zone Level +input ENUM_X_FIBO_LEVELS fiboMiddleZoneLevel = X_FIBO_LEVEL_500; // Upper Zone Level +input ENUM_X_FIBO_LEVELS fiboLowerZoneLevel = X_FIBO_LEVEL_618; // Lower Zone Level +input double sarStep = 0.02; // SAR Step +input double sarMax = 0.2; // SAR Maximum +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To +input int maFastLength = 7; // Fast MA Length +input int maSlowLength = 20; // Slow MA Length +input int zigzagDepth = 12; // ZigZag Depth +input int zigzagDeviation = 5; // ZigZag Deviation +input int zigzagBackStep = 3; // ZigZag Back Step +input ENUM_X_PRICE zigzagUppersMode = X_PRICE_HIGH; // ZigZag High Detect Mode +input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low Detect Mode // // Presentation ... @@ -129,8 +131,8 @@ input int valeArrowCode = 159; // Vales Arrow Code #property indicator_chart_window // -#property indicator_buffers 26 -#property indicator_plots 8 +#property indicator_buffers 27 +#property indicator_plots 9 // // Plot Buffers ... @@ -150,8 +152,8 @@ double maFastColorBuffer[]; // #property indicator_label1 "FastMA" #property indicator_type1 DRAW_COLOR_LINE -#property indicator_color1 CLR_NONE, clrYellow, clrOrangeRed, clrGray -#property indicator_width1 2 +#property indicator_color1 CLR_NONE, clrAquamarine, clrAquamarine, clrAquamarine // clrYellow, clrOrangeRed, clrGray +#property indicator_width1 3 // // Slow MA ... @@ -168,8 +170,8 @@ double maSlowColorBuffer[]; // #property indicator_label2 "SlowMA" #property indicator_type2 DRAW_COLOR_LINE -#property indicator_color2 CLR_NONE, clrLime, clrRed, clrGray -#property indicator_width2 2 +#property indicator_color2 CLR_NONE, clrLightCoral, clrLightCoral, clrLightCoral // clrLime, clrRed, clrGray +#property indicator_width2 3 // // SAR ... @@ -231,39 +233,53 @@ double fiboUpperBuffer[]; #property indicator_color6 clrAqua #property indicator_width6 2 +// +// FIBO Middle ... + +// +#define fiboMiddleBufferIndex 9 +#define fiboMiddleBufferPlotIndex 6 +double fiboMiddleBuffer[]; + +// +#property indicator_label7 "FIBMID" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrBrown +#property indicator_width7 2 + // // FIBO Lower ... // -#define fiboLowerBufferIndex 9 -#define fiboLowerBufferPlotIndex 6 +#define fiboLowerBufferIndex 10 +#define fiboLowerBufferPlotIndex 7 double fiboLowerBuffer[]; // -#property indicator_label7 "FIBLO" -#property indicator_type7 DRAW_LINE -#property indicator_color7 clrMagenta -#property indicator_width7 2 +#property indicator_label8 "FIBLO" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrMagenta +#property indicator_width8 2 // // ZigZag ... // -#define zigzagBufferIndex 10 -#define zigzagBufferPlotIndex 7 +#define zigzagBufferIndex 11 +#define zigzagBufferPlotIndex 8 double zigzagBuffer[]; // -#property indicator_label8 "XZG" -#property indicator_type8 DRAW_SECTION -#property indicator_color8 clrYellow -#property indicator_width8 2 +#property indicator_label9 "XZG" +#property indicator_type9 DRAW_SECTION +#property indicator_color9 clrYellow +#property indicator_width9 2 // // Data Buffers ... // -#define mLastBufferIndex 10 +#define mLastBufferIndex 11 // // MA ... @@ -825,6 +841,16 @@ void DefineBuffers() PlotIndexSetInteger(fiboUpperBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType); PlotIndexSetDouble(fiboUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + // + // Middle ... + ArraySetAsSeries(fiboMiddleBuffer, true); + SetIndexBuffer(fiboMiddleBufferIndex, fiboMiddleBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(fiboMiddleBufferPlotIndex, PLOT_SHOW_DATA, showFiboZone); + PlotIndexSetInteger(fiboMiddleBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType); + PlotIndexSetDouble(fiboMiddleBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + // // Lower ... ArraySetAsSeries(fiboLowerBuffer, true); @@ -1294,18 +1320,29 @@ void CalculateValues( double iFiboUp = GetFibonacciLevel( iPeak, iVale, - upperZoneLevel, - X_DIRECTION_BULLISH); + fiboUpperZoneLevel, + X_DIRECTION_BULLISH // + ); + + // + double iFiboMid = GetFibonacciLevel( + iPeak, + iVale, + fiboMiddleZoneLevel, + X_DIRECTION_BULLISH // + ); // double iFiboLo = GetFibonacciLevel( iPeak, iVale, - lowerZoneLevel, - X_DIRECTION_BULLISH); + fiboLowerZoneLevel, + X_DIRECTION_BULLISH // + ); // fiboUpperBuffer[barIndex] = iFiboUp; + fiboMiddleBuffer[barIndex] = iFiboMid; fiboLowerBuffer[barIndex] = iFiboLo; } diff --git a/Indicators/x-saherelm.xom1.mq5 b/Indicators/x-saherelm.xom1.mq5 index 36589db3..ca0ef31b 100644 --- a/Indicators/x-saherelm.xom1.mq5 +++ b/Indicators/x-saherelm.xom1.mq5 @@ -18,6 +18,7 @@ #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm XOM1 Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" #property strict // diff --git a/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5 new file mode 100644 index 00000000..6b41f5b7 --- /dev/null +++ b/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -0,0 +1,24 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class +// ------------------------------------------------- +// Name: XCXFIMASignaller ... +// Description: XFIMA Signaller Class ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Base Signaller Class" +#property strict + +// +// Imports ...