/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class Library // ---------------------------------------------- // Name: XSCBaseInd // Description: provides Indicator implementation // 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.xind.class.mq5" // // XSCMid Indicator Buffers ... enum ENUM_XSCMID_BUFFERS { XSCMID_MAIN_LINE = 0, // Main Buffer ... XSCMID_STATE_LINE = 1, // State Buffer ... }; // // XSCMid Indicator Inputs ... struct XSCMidInputs { // // Props ... // int length; // Market Length ... // // Constructor ... XSCMidInputs() { Clean(); } // // Tools ... // // Initial Inputs ... bool Init( int mLength // Market Length ) { // bool result = false; // result = // mLength >= 2 // ; if (!result) { return result; } // this.length = mLength; // result = IsValid(); // return result; } // // Cleanup ... void Clean() { // this.length = 0; } // // Default ... void Default() { // this.length = 2; } // // Validate ... bool IsValid() { // bool result = false; // result = // length > 1 // ; // return result; } // // Retrieve Max Length ... int Max() { // int result = 0; // result = MathMax(this.length, this.length); // return result; } }; // // a Simple Indicator ... class XSCMid : public XSCBaseInd { // // Public ... public: // // Props ... // // Constructor(s) ... void XSCMid( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading TimeFrame ) : XSCBaseInd(symbol, period) { // string token = GetTag(); // SetAlertPrefix(token); } // // Deconstructor ... void ~XSCMid() {} // // Initialize Indicator ... bool Init( XSCMidInputs &inputs // Indicator Inputs ... ) { // bool result = false; // result = inputs.IsValid(); if (!result) { return result; } // // Set Inputs ... this.mInputs = inputs; // // Validate Indicator State ... result = this.IsValid(); if (!result) { return result; } // // Register Required Buffers ... XBuffer main; result = main.Init( "XSCMid" // ); if (!result) { return result; } // result = SetBuffer(main); if (!result) { return result; } // // Calculate First Time ... Calculate(); // return result; } // // Property Getter(s) / Setter(s) ... // XSCMidInputs GetInputs() { return mInputs; } // bool SetInputs( XSCMidInputs &inputs // Indicator Inputs ) { return Init(inputs); } // // Override(s) ... // // Get Tag ... string GetTag() override { // string result = NULL; // result = GetToken(); // return result; } // // Get Token ... string GetToken() override { // string result = NULL; // result = GetSpecificToken(this); // return result; } // // Validate Inputs ... bool IsValidInputs() override { return mInputs.IsValid(); } // // Calculate Buffers ... void Calculate() override { // int max = mInputs.Max(); int limit = CountLimit(); int totalBars = CountBars(); int prevCalculated = GetCalculatedBars(); // // Prepare Buffers Index ... int mainIDX = GetBufferIndex("XSCMid"); // int start = 0; // // // if (prevCalculated == 0) // { // // // if (max > 0) // { // for (int i = 0; i < max; i++) // { // // // for (int j = 0; j < CountBuffers(); j++) // { // mBuffers[j].Add(0); // } // } // } // } // // Loop through Bars ... for (int i = start; i < limit && !IsStopped(); i++) { // // XOHCL iBar; // iBar.Init( // mSymbol, // mPeriod, // i // // ); // double iValue = iClose(mSymbol, mPeriod, i); // Print("BarIndex: " + ToString(i), ", iValue: ", iValue); // int count = mBuffers[mainIDX].Count(); if (count > 0 && i == count - 1) { mBuffers[mainIDX].Set(i, iValue); } else { mBuffers[mainIDX].Add(iValue); } } // for (int i = totalBars - 1; i >= start && !IsStopped(); i--) // { // // // XOHCL iBar; // iBar.Init( // mSymbol, // mPeriod, // i // // ); // // // double iValue = iBar.close; // // // // Print("BarIndex: " + ToString(i), ", iValue: ", iValue); // // // if (i > ArraySize(mBuffers[mainIDX].values) - 1) // { // ArrayResize(mBuffers[mainIDX].values, i + 1); // } // // // mBuffers[mainIDX].values[i] = iValue; // } // // Prevent Double Calculation Same Bars ... mCalculatedBars = totalBars; } // // De Initialize Class ... void DeInit(int reason) { } // // Tools ... // // Reading Values ... // // Protected ... protected: // // Private ... private: // // Props ... // // Inputs ... XSCMidInputs mInputs; };