From 3d4e39a8d8454bfd051368636ce2d8c640cca1d4 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 29 Jun 2024 13:19:47 +0330 Subject: [PATCH] complete xrl indicator and it's related helper class ... --- Helpers/x-saherelm.xrl.helper.mq5 | 1131 +++++++++++++++++++++++++++++ Indicators/x-saherelm.xrl.mq5 | 214 ++++-- MQL5.code-workspace | 9 +- 3 files changed, 1271 insertions(+), 83 deletions(-) create mode 100644 Helpers/x-saherelm.xrl.helper.mq5 diff --git a/Helpers/x-saherelm.xrl.helper.mq5 b/Helpers/x-saherelm.xrl.helper.mq5 new file mode 100644 index 00000000..87882e9d --- /dev/null +++ b/Helpers/x-saherelm.xrl.helper.mq5 @@ -0,0 +1,1131 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXRLHelper +// 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.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XRL_STATES +{ + // + XRL_STATE_BULLISH = 1, + XRL_STATE_BEARISH = -1, +}; + +// +enum ENUM_XRL_BUFFERS +{ + // + XRL_FAST_LINE = 0, + XRL_SLOW_LINE = 1, + XRL_VERIFIER_LINE = 2, + // + XRL_FAST_STATE_LINE = 8, + XRL_SLOW_STATE_LINE = 9, + XRL_VERIFIER_STATE_LINE = 10, +}; + +// +// Input Models ... +struct XRLInputs +{ + // + // Props ... + + // + // Market ... + // Fast ... + int fastLength; // Length + ENUM_APPLIED_PRICE fastAppliedTo; // Applied To + // + // Slow ... + int slowLength; // Length + ENUM_APPLIED_PRICE slowAppliedTo; // Applied To + + // + // Presentation ... + bool showFast; // Show Fast + bool showSlow; // Show Slow + bool showVerifier; // Show Verifier + + // + // Constructor(s) ... + XRLInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + fastLength = 0; + fastAppliedTo = PRICE_CLOSE; + + // + slowLength = 0; + slowAppliedTo = PRICE_CLOSE; + + // + showFast = false; + showSlow = false; + showVerifier = false; + } + + // + // Default ... + void Default() + { + // + fastLength = 9; + fastAppliedTo = PRICE_CLOSE; + + // + slowLength = 18; + slowAppliedTo = PRICE_CLOSE; + + // + showFast = true; + showSlow = true; + showVerifier = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + fastLength >= 2 && + slowLength > fastLength + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(fastLength, slowLength); + + // + return result; + } +}; + +// +// Define Conditions ... +struct XRLConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double fast[]; + double fastState[]; + double slow[]; + double slowState[]; + double verifier[]; + double verifierState[]; + + // + // Conditions ... + + // + bool isFastBullish; + bool isFastBearish; + + // + bool isFastSwitchedToBullish; + bool isFastSwitchedToBearish; + + // + bool isSlowBullish; + bool isSlowBearish; + + // + bool isSlowSwitchedToBullish; + bool isSlowSwitchedToBearish; + + // + bool isFastOverSlow; + bool isFastCrossedOverSlow; + + // + bool isFastUnderSlow; + bool isFastCrossedUnderSlow; + + // + bool isVerifierBullish; + bool isVerifierSwitchedToBullish; + + // + bool isVerifierBearish; + bool isVerifierSwitchedToBearish; + + // + void Clean() + { + // + Clean(fast); + Clean(slow); + Clean(verifier); + + // + Clean(fastState); + Clean(slowState); + Clean(verifierState); + + // + ArraySetAsSeries(fast, true); + ArraySetAsSeries(slow, true); + ArraySetAsSeries(verifier, true); + + // + ArraySetAsSeries(fastState, true); + ArraySetAsSeries(slowState, true); + ArraySetAsSeries(verifierState, true); + + // + isFastBullish = false; + isFastBearish = false; + isSlowBullish = false; + isSlowBearish = false; + isFastOverSlow = false; + isFastUnderSlow = false; + isVerifierBullish = false; + isVerifierBearish = false; + isFastCrossedOverSlow = false; + isFastCrossedUnderSlow = false; + isVerifierSwitchedToBullish = false; + isVerifierSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isFastBullish) + { + bullishScore++; + } + if (isSlowBullish) + { + bullishScore++; + } + if (isFastOverSlow) + { + bullishScore++; + } + if (isFastCrossedOverSlow) + { + bullishScore++; + } + if (isVerifierBullish) + { + bullishScore++; + } + if (isVerifierSwitchedToBullish) + { + bullishScore++; + } + + // + if (isFastBearish) + { + bearishScore++; + } + if (isSlowBearish) + { + bearishScore++; + } + if (isFastUnderSlow) + { + bearishScore++; + } + if (isFastCrossedUnderSlow) + { + bearishScore++; + } + if (isVerifierBearish) + { + bearishScore++; + } + if (isVerifierSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isFastBullish", isFastBullish, ignoreFalseConditions, separator) + + ToString("isFastBearish", isFastBearish, ignoreFalseConditions, separator) + + ToString("isSlowBullish", isSlowBullish, ignoreFalseConditions, separator) + + ToString("isSlowBearish", isSlowBearish, ignoreFalseConditions, separator) + + ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isVerifierBullish", isVerifierBullish, ignoreFalseConditions, separator) + + ToString("isVerifierSwitchedToBullish", isVerifierSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isVerifierBearish", isVerifierBearish, ignoreFalseConditions, separator) + + ToString("isVerifierSwitchedToBearish", isVerifierSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions ? "" : commonStr) + + (!includeScores ? "" : scoresStr) + + " " + separator + + (onlyCommons ? "" : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XRL"; + } +}; + +// +// Class ... +class XSCXRLHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXRLHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXRLHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XRLInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(fastBuffer, true); + ArraySetAsSeries(slowBuffer, true); + ArraySetAsSeries(verifierBuffer, true); + + // + ArraySetAsSeries(fastStateBuffer, true); + ArraySetAsSeries(slowStateBuffer, true); + ArraySetAsSeries(verifierStateBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xrl", + // + // Inputs ... + // + // Market ... + "", + // + // Fast ... + "", + mInputs.fastLength, + mInputs.fastAppliedTo, + // + // Slow ... + "", + mInputs.slowLength, + mInputs.slowAppliedTo, + // + // Presentation ... + "", + mInputs.showFast, + mInputs.showSlow, + mInputs.showVerifier + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XRLInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XRLInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Fast ... + + // + double GetFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fastBuffer, + buffer, + forceClean + // + ); + } + + // + // Fast State ... + + // + double GetFastState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fastStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fastStateBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFastState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fastStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow ... + + // + double GetSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(slowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return slowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + slowBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow State ... + + // + double GetSlowState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(slowStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return slowStateBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySlowState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + slowStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Verifier ... + + // + double GetVerifier( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(verifierBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return verifierBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyVerifier( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + verifierBuffer, + buffer, + forceClean + // + ); + } + + // + // Verifier State ... + + // + double GetVerifierState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(verifierStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return verifierStateBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyVerifierState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + verifierStateBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsBullish(double state) + { + // + bool result = state == XRL_STATE_BULLISH; + + // + return result; + } + + // + bool IsBearish(double state) + { + // + bool result = state == XRL_STATE_BEARISH; + + // + return result; + } + + // + // Conditions ... + bool GetConditions( + XRLConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Fast ... + CopyFast( + zIndex, + loopback, + conditions.fast // + ); + + // + // Fast State ... + CopyFastState( + zIndex, + loopback, + conditions.fastState // + ); + + // + // Slow ... + CopySlow( + zIndex, + loopback, + conditions.slow // + ); + + // + // Slow State ... + CopySlowState( + zIndex, + loopback, + conditions.slowState // + ); + + // + // Verifier ... + CopyVerifier( + zIndex, + loopback, + conditions.verifier // + ); + + // + // Verifier State ... + CopyVerifierState( + zIndex, + loopback, + conditions.verifierState // + ); + + // + // Conditions ... + + // + bool isFastBullish = IsBullish(conditions.fastState[cIndex]); + bool isFastBullishPrev = IsBullish(conditions.fastState[pIndex]); + + // + bool isFastBearish = IsBearish(conditions.fastState[cIndex]); + bool isFastBearishPrev = IsBearish(conditions.fastState[pIndex]); + + // + bool isFastSwitchedToBullish = isFastBullish && + !isFastBullishPrev; + bool isFastSwitchedToBearish = isFastBearish && + !isFastBearishPrev; + + // + bool isSlowBullish = IsBullish(conditions.slowState[cIndex]); + bool isSlowBullishPrev = IsBullish(conditions.slowState[pIndex]); + + // + bool isSlowBearish = IsBearish(conditions.slowState[cIndex]); + bool isSlowBearishPrev = IsBearish(conditions.slowState[pIndex]); + + // + bool isSlowSwitchedToBullish = isSlowBullish && + !isSlowBullishPrev; + bool isSlowSwitchedToBearish = isSlowBearish && + !isSlowBearishPrev; + + // + bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex]; + bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex]; + + // + bool isFastCrossedOverSlow = isFastOverSlow && + !isFastOverSlowPrev; + + // + bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex]; + bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex]; + + // + bool isFastCrossedUnderSlow = isFastUnderSlow && + !isFastUnderSlowPrev; + + // + bool isVerifierBullish = IsBullish(conditions.verifierState[cIndex]); + bool isVerifierBullishPrev = IsBullish(conditions.verifierState[pIndex]); + + // + bool isVerifierSwitchedToBullish = isVerifierBullish && + !isVerifierBullishPrev; + + // + bool isVerifierBearish = IsBearish(conditions.verifierState[cIndex]); + bool isVerifierBearishPrev = IsBearish(conditions.verifierState[pIndex]); + + // + bool isVerifierSwitchedToBearish = isVerifierBearish && + !isVerifierBearishPrev; + + // + conditions.isFastBullish = isFastBullish; + conditions.isFastBearish = isFastBearish; + + // + conditions.isFastSwitchedToBullish = isFastSwitchedToBullish; + conditions.isFastSwitchedToBearish = isFastSwitchedToBearish; + + // + conditions.isSlowBullish = isSlowBullish; + conditions.isSlowBearish = isSlowBearish; + + // + conditions.isSlowSwitchedToBullish = isSlowSwitchedToBullish; + conditions.isSlowSwitchedToBearish = isSlowSwitchedToBearish; + + // + conditions.isFastOverSlow = isFastOverSlow; + conditions.isFastCrossedOverSlow = isFastCrossedOverSlow; + + // + conditions.isFastUnderSlow = isFastUnderSlow; + conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow; + + // + conditions.isVerifierBullish = isVerifierBullish; + conditions.isVerifierSwitchedToBullish = isVerifierSwitchedToBullish; + + // + conditions.isVerifierBearish = isVerifierBearish; + conditions.isVerifierSwitchedToBearish = isVerifierSwitchedToBearish; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XRLInputs mInputs; // Inputs ... + + // + // Buffers ... + double fastBuffer[]; + double fastStateBuffer[]; + // + double slowBuffer[]; + double slowStateBuffer[]; + // + double verifierBuffer[]; + double verifierStateBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Fast Buffer ... + CopyBuffer( + mHandler, + XRL_FAST_LINE, + 0, + totalBars, + fastBuffer + // + ); + + // + // Fast State Buffer ... + CopyBuffer( + mHandler, + XRL_FAST_STATE_LINE, + 0, + totalBars, + fastStateBuffer + // + ); + + // + // Slow Buffer ... + CopyBuffer( + mHandler, + XRL_SLOW_LINE, + 0, + totalBars, + slowBuffer + // + ); + + // + // Slow State Buffer ... + CopyBuffer( + mHandler, + XRL_SLOW_STATE_LINE, + 0, + totalBars, + slowStateBuffer + // + ); + + // + // Verifier Buffer ... + CopyBuffer( + mHandler, + XRL_VERIFIER_LINE, + 0, + totalBars, + verifierBuffer + // + ); + + // + // Verifier State Buffer ... + CopyBuffer( + mHandler, + XRL_VERIFIER_STATE_LINE, + 0, + totalBars, + verifierStateBuffer + // + ); + } +}; + +// \ No newline at end of file diff --git a/Indicators/x-saherelm.xrl.mq5 b/Indicators/x-saherelm.xrl.mq5 index f8b1f733..91929972 100644 --- a/Indicators/x-saherelm.xrl.mq5 +++ b/Indicators/x-saherelm.xrl.mq5 @@ -30,16 +30,17 @@ // input group "Market"; input group "Fast"; -input int fastLength = 9; // Length -input ENUM_APPLIED_PRICE fastAppliedTo = PRICE_CLOSE; // Applied To -input int slowLength = 18; // Length -input ENUM_APPLIED_PRICE slowAppliedTo = PRICE_CLOSE; // Applied To +input int fastLength = 9; // Length +input ENUM_APPLIED_PRICE fastAppliedTo = PRICE_CLOSE; // Applied To +input group "Slow"; +input int slowLength = 18; // Length +input ENUM_APPLIED_PRICE slowAppliedTo = PRICE_CLOSE; // Applied To // input group "Presentation"; -input bool showFast = true; // Show Fast -input bool showSlow = true; // Show Slow -input bool showVerifier = true; // Show Verifier +input bool showFast = true; // Show Fast +input bool showSlow = true; // Show Slow +input bool showVerifier = true; // Show Verifier // // Buffers ... @@ -48,20 +49,20 @@ input bool showVerifier = true; // Show Verifier #property indicator_chart_window // -#property indicator_buffers 8 +#property indicator_buffers 11 #property indicator_plots 6 // -#define hideColorIDX 0 +#define hideColorIDX 0 #define neuturalColorIDX 1 -#define bullColorIDX 2 -#define bearColorIDX 3 +#define bullColorIDX 2 +#define bearColorIDX 3 // // Fast ... // -#define fastBufferIndex 0 +#define fastBufferIndex 0 #define fastBufferPlotIndex 0 double fastBuffer[]; @@ -80,7 +81,7 @@ double fastBufferColor[]; // Slow ... // -#define slowBufferIndex 2 +#define slowBufferIndex 2 #define slowBufferPlotIndex 1 double slowBuffer[]; @@ -99,7 +100,7 @@ double slowBufferColor[]; // Verifier ... // -#define verifierBufferIndex 4 +#define verifierBufferIndex 4 #define verifierBufferPlotIndex 2 double verifierBuffer[]; @@ -121,6 +122,18 @@ double fastLRBuffer[]; #define slowLRBufferIndex 7 double slowLRBuffer[]; +// +#define fastStateBufferIndex 8 +double fastStateBuffer[]; + +// +#define slowStateBufferIndex 9 +double slowStateBuffer[]; + +// +#define verifierStateBufferIndex 10 +double verifierStateBuffer[]; + // // Variables ... @@ -137,10 +150,12 @@ XLinearRegression verifierCalculator; // // Initialization ... -int OnInit() { +int OnInit() +{ // // Validate Inputs ... - if(!ValidateInputs()) { + if (!ValidateInputs()) + { return INIT_PARAMETERS_INCORRECT; } @@ -166,7 +181,8 @@ int OnInit() { // // DeInitialization ... -void OnDeinit(const int reason) { +void OnDeinit(const int reason) +{ // // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function // REASON_REMOVE 1 Program removed from a chart @@ -183,17 +199,18 @@ void OnDeinit(const int reason) { // // Calculating what we want ... int OnCalculate( - const int rates_total, // Total Bars on Chart ... - const int prev_calculated, // Total Calculated Bars on Charts ... - const datetime &time[], // History of Open Time ... - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - const long &tick_volume[], // History of Tick Volumes on Bar ... - const long &volume[], // History of Trade Volumes ... - const int &spread[] // History of Spread Price ... -) { + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ // int limit = (prev_calculated > 0) ? prev_calculated - 1 : 0; @@ -205,7 +222,7 @@ int OnCalculate( low, close, limit, - rates_total // + rates_total // ); // @@ -216,7 +233,7 @@ int OnCalculate( low, close, limit, - rates_total // + rates_total // ); // @@ -227,7 +244,7 @@ int OnCalculate( low, close, limit, - rates_total // + rates_total // ); // @@ -239,7 +256,8 @@ int OnCalculate( // // Validate Input Args for Initialization ... -bool ValidateInputs() { +bool ValidateInputs() +{ // bool result = false; @@ -254,7 +272,8 @@ bool ValidateInputs() { // // Retrieve all Exists Input Max Length ... // use for Start Of Drawing ... -int ExtractMaxLengthOfInputs() { +int ExtractMaxLengthOfInputs() +{ // int result = 0; @@ -268,13 +287,15 @@ int ExtractMaxLengthOfInputs() { // // Set Indicator Short Name and also we can define Buffers Labels ... -void SetIndicatorName() { +void SetIndicatorName() +{ IndicatorSetString(INDICATOR_SHORTNAME, ShortName); } // // Define Indexes and Styles ... -void DefineBuffers() { +void DefineBuffers() +{ // // Fast ... @@ -326,6 +347,11 @@ void DefineBuffers() { // SetIndexBuffer(fastLRBufferIndex, fastLRBuffer, INDICATOR_CALCULATIONS); SetIndexBuffer(slowLRBufferIndex, slowLRBuffer, INDICATOR_CALCULATIONS); + + // + SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(verifierStateBufferIndex, verifierStateBuffer, INDICATOR_CALCULATIONS); } // @@ -333,21 +359,23 @@ void DefineBuffers() { // void CalculateFast( - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - int limit, - const int rates_total // -) { + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + int limit, + const int rates_total // +) +{ // // Fast ... // // Calculate Fast Intercept and Slope ... - double fastSlope = 0; + double fastSlope = 0; double fastIntercept = 0; - for(int i = limit; i < rates_total && !IsStopped(); i++) { + for (int i = limit; i < rates_total && !IsStopped(); i++) + { // double fastAppliedPrice = iGetPrice(fastAppliedTo, open[i], high[i], low[i], close[i]); @@ -358,25 +386,33 @@ void CalculateFast( fastSlope, fastIntercept, i, - rates_total // + rates_total // ); fastLRBuffer[i] = fastLRValue; } // // Calculate Fast ... - for(int i = 0; i < fastLength && !IsStopped(); i++) { + for (int i = 0; i < fastLength && !IsStopped(); i++) + { // - double fast = fastIntercept + fastSlope * (fastLength - i - 1); + double fast = fastIntercept + fastSlope * (fastLength - i - 1); fastBuffer[rates_total - i - 1] = fast; // double fastColor = - (fastSlope > 0) ? bullColorIDX : (fastSlope < 0) ? bearColorIDX : - neuturalColorIDX; + (fastSlope > 0) + ? bullColorIDX + : (fastSlope < 0) + ? bearColorIDX + : neuturalColorIDX; + double fastState = (fastSlope > 0) + ? 1 + : -1; // fastBufferColor[rates_total - i - 1] = fastColor; + fastStateBuffer[rates_total - i - 1] = fastState; } // @@ -386,21 +422,23 @@ void CalculateFast( // void CalculateSlow( - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - int limit, - const int rates_total // -) { + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + int limit, + const int rates_total // +) +{ // // Slow ... // // Calculate Slow Intercept and Slope ... - double slowSlope = 0; + double slowSlope = 0; double slowIntercept = 0; - for(int i = limit; i < rates_total && !IsStopped(); i++) { + for (int i = limit; i < rates_total && !IsStopped(); i++) + { // double slowAppliedPrice = iGetPrice(slowAppliedTo, open[i], high[i], low[i], close[i]); @@ -411,25 +449,33 @@ void CalculateSlow( slowSlope, slowIntercept, i, - rates_total // + rates_total // ); slowLRBuffer[i] = slowLRValue; } // // Calculate Slow ... - for(int i = 0; i < slowLength && !IsStopped(); i++) { + for (int i = 0; i < slowLength && !IsStopped(); i++) + { // - double slow = slowIntercept + slowSlope * (slowLength - i - 1); + double slow = slowIntercept + slowSlope * (slowLength - i - 1); slowBuffer[rates_total - i - 1] = slow; // double slowColor = - (slowSlope > 0) ? bullColorIDX : (slowSlope < 0) ? bearColorIDX : - neuturalColorIDX; + (slowSlope > 0) + ? bullColorIDX + : (slowSlope < 0) + ? bearColorIDX + : neuturalColorIDX; + double slowState = (slowSlope > 0) + ? 1 + : -1; // slowBufferColor[rates_total - i - 1] = slowColor; + slowStateBuffer[rates_total - i - 1] = slowState; } // @@ -439,16 +485,18 @@ void CalculateSlow( // void CalculateVerifier( - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - int limit, - const int rates_total // -) { + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + int limit, + const int rates_total // +) +{ // // Calculate Verifier ... - for(int i = limit; i < rates_total && !IsStopped(); i++) { + for (int i = limit; i < rates_total && !IsStopped(); i++) + { // double verifierSlope; double verifierIntercept; @@ -463,17 +511,31 @@ void CalculateVerifier( verifierSlope, verifierIntercept, i, - rates_total // + rates_total // ); verifierBuffer[i] = verifier; // double verifierColor = - (i > 0) ? - (verifierBuffer[i] > verifierBuffer[i - 1]) ? bullColorIDX : (verifierBuffer[i] < verifierBuffer[i - 1]) ? bearColorIDX : - verifierBuffer[i - 1] : - neuturalColorIDX; + (i > 0) + ? (verifierBuffer[i] > verifierBuffer[i - 1]) + ? bullColorIDX + : (verifierBuffer[i] < verifierBuffer[i - 1]) + ? bearColorIDX + : verifierBufferColor[i - 1] + : neuturalColorIDX; + double verifierState = + (i > 0) + ? (verifierBuffer[i] > verifierBuffer[i - 1]) + ? 1 + : (verifierBuffer[i] < verifierBuffer[i - 1]) + ? -1 + : verifierStateBuffer[i - 1] + : -1; + + // verifierBufferColor[i] = verifierColor; + verifierStateBuffer[i] = verifierState; } } diff --git a/MQL5.code-workspace b/MQL5.code-workspace index 395aab15..57097327 100644 --- a/MQL5.code-workspace +++ b/MQL5.code-workspace @@ -4,10 +4,5 @@ "path": "." } ], - "settings": { - "C_Cpp.default.includePath": [ - "c:\\Users\\saherelm\\AppData\\Roaming\\MetaQuotes\\Terminal\\FAE4959D5A0334AE230243FCFFFD4053\\MQL5\\Include" - ], - "C_Cpp.clang_format_style": "file:c:\\Users\\saherelm\\.vscode\\extensions\\l-i-v.mql-tools-2.1.0\\files\\.clang-format" - } -} \ No newline at end of file + "settings": {} +}