/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class Library // ---------------------------------------------- // Name: XSC121Provider // Description: provides all Base Provider // requirements For X121 ... // // // 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 "../Helpers/x-saherelm.xcc.helper.mq5" #include "../Helpers/x-saherelm.xct.helper.mq5" #include "../Helpers/x-saherelm.xmc.helper.mq5" #include "../Helpers/x-saherelm.xzg.helper.mq5" #include "../Helpers/x-saherelm.xpv.helper.mq5" #include "../Helpers/x-saherelm.xtm.helper.mq5" #include "../Helpers/x-saherelm.xtd.helper.mq5" #include "../Helpers/x-saherelm.xdon.helper.mq5" #include "../Helpers/x-saherelm.xstr.helper.mq5" #include "../Helpers/x-saherelm.xche.helper.mq5" #include "../Helpers/x-saherelm.xosc.helper.mq5" #include "../Helpers/x-saherelm.xama.helper.mq5" #include "../Helpers/x-saherelm.xhull.helper.mq5" #include "../Helpers/x-saherelm.xsslc.helper.mq5" // #include "../Classes/x-saherelm.xprovider.class.mq5" #include "../Classes/x-saherelm.x121.xmcycle.class.mq5" // // Definitions ... // // X121 Provider Inputs ... class X121ProviderInputs : public XSCBase { // // Public ... public: // // Props ... // string symbol; ENUM_TIMEFRAMES period; // // S Market ... ENUM_TIMEFRAMES sMarketPeriod; // Short Market Period ENUM_X_PERIOD_METHOD sMarketMethod; // Short Market Period Method string sMarketPrefix; // Short Market Prefix // // MEDIUM Market ... ENUM_TIMEFRAMES mMarketPeriod; // Medium Market Period ENUM_X_PERIOD_METHOD mMarketMethod; // Medium Market Period Method string mMarketPrefix; // Medium Market Prefix // // LONG Market ... ENUM_TIMEFRAMES lMarketPeriod; // Long Market Period ENUM_X_PERIOD_METHOD lMarketMethod; // Long Market Period Method string lMarketPrefix; // Long Market Prefix // // HIND Market ... ENUM_TIMEFRAMES hMarketPeriod; // Hind Market Period ENUM_X_PERIOD_METHOD hMarketMethod; // Hind Market Period Method string hMarketPrefix; // Hind Market Prefix // // Indicators ... XCCInputs ccInputs; XCTInputs ctInputs; // XZGInputs zgInputs; XPVInputs pvInputs; XHKInputs hkInputs; XMCInputs mcInputs; XTDInputs tdInputs; XMRBInputs mrbInputs; XICHInputs ichInputs; XCHEInputs cheInputs; XSTRInputs strInputs; XDONInputs donInputs; XOSCInputs oscInputs; XHULLInputs hullInputs; XSSLCInputs sslcInputs; // X121MCycleInputs cMarketInputs; // Curent Market Inputs X121MCycleInputs sMarketInputs; // Short Market Inputs X121MCycleInputs mMarketInputs; // Medium Market Inputs X121MCycleInputs lMarketInputs; // Long Market Inputs X121MCycleInputs hMarketInputs; // Hind Market Inputs // // Tools ... // // Initialize Input ... bool Init() { // bool result = false; // // Validate Base Requirements ... result = // IsSpecifiedValid(symbol) && IsSpecifiedValid(period) && IsSpecifiedValid(sMarketMethod, sMarketPeriod) && IsSpecifiedValid(mMarketMethod, mMarketPeriod) && IsSpecifiedValid(lMarketMethod, lMarketPeriod) && IsSpecifiedValid(hMarketMethod, hMarketPeriod) // ; if (!result) { return result; } // if (!zgInputs.IsValid()) { zgInputs.Default(); } if (!pvInputs.IsValid()) { pvInputs.Default(); } if (!mcInputs.IsValid()) { mcInputs.Default(); } if (!hkInputs.IsValid()) { hkInputs.Default(); } if (!mrbInputs.IsValid()) { mrbInputs.Default(); } if (!cheInputs.IsValid()) { cheInputs.Default(); } if (!strInputs.IsValid()) { strInputs.Default(); } if (!donInputs.IsValid()) { donInputs.Default(); } if (!oscInputs.IsValid()) { oscInputs.Default(); } if (!ichInputs.IsValid()) { ichInputs.Default(); } if (!hullInputs.IsValid()) { hullInputs.Default(); } if (!sslcInputs.IsValid()) { sslcInputs.Default(); } if (!tdInputs.IsValid()) { tdInputs.Default(); } // // Initialize Market Inputs ... // // Current ... cMarketInputs.pvInputs = this.pvInputs; cMarketInputs.zgInputs = this.zgInputs; cMarketInputs.tdInputs = this.tdInputs; cMarketInputs.mcInputs = this.mcInputs; cMarketInputs.hkInputs = this.hkInputs; cMarketInputs.mrbInputs = this.mrbInputs; cMarketInputs.strInputs = this.strInputs; cMarketInputs.oscInputs = this.oscInputs; cMarketInputs.cheInputs = this.cheInputs; cMarketInputs.ichInputs = this.ichInputs; cMarketInputs.donInputs = this.donInputs; cMarketInputs.hullInputs = this.hullInputs; cMarketInputs.sslcInputs = this.sslcInputs; result = cMarketInputs.Init( this.symbol, this.period, X_MARKET_CYCLE_SHORT, this.period, X_PERIOD_MANUALLY, "HOST", false // ); if (!result) { return result; } // // Short ... sMarketInputs.pvInputs = this.pvInputs; sMarketInputs.zgInputs = this.zgInputs; sMarketInputs.tdInputs = this.tdInputs; sMarketInputs.mcInputs = this.mcInputs; sMarketInputs.hkInputs = this.hkInputs; sMarketInputs.mrbInputs = this.mrbInputs; sMarketInputs.strInputs = this.strInputs; sMarketInputs.oscInputs = this.oscInputs; sMarketInputs.cheInputs = this.cheInputs; sMarketInputs.ichInputs = this.ichInputs; sMarketInputs.donInputs = this.donInputs; sMarketInputs.hullInputs = this.hullInputs; sMarketInputs.sslcInputs = this.sslcInputs; result = sMarketInputs.Init( this.symbol, this.period, X_MARKET_CYCLE_SHORT, this.sMarketPeriod, this.sMarketMethod, this.sMarketPrefix, false // ); if (!result) { return result; } // // Medium ... mMarketInputs.pvInputs = this.pvInputs; mMarketInputs.zgInputs = this.zgInputs; mMarketInputs.tdInputs = this.tdInputs; mMarketInputs.mcInputs = this.mcInputs; mMarketInputs.hkInputs = this.hkInputs; mMarketInputs.mrbInputs = this.mrbInputs; mMarketInputs.strInputs = this.strInputs; mMarketInputs.oscInputs = this.oscInputs; mMarketInputs.cheInputs = this.cheInputs; mMarketInputs.ichInputs = this.ichInputs; mMarketInputs.donInputs = this.donInputs; mMarketInputs.hullInputs = this.hullInputs; mMarketInputs.sslcInputs = this.sslcInputs; result = mMarketInputs.Init( this.symbol, this.period, X_MARKET_CYCLE_MEDIUM, this.mMarketPeriod, this.mMarketMethod, this.mMarketPrefix, false // ); if (!result) { return result; } // // Long ... lMarketInputs.pvInputs = this.pvInputs; lMarketInputs.zgInputs = this.zgInputs; lMarketInputs.tdInputs = this.tdInputs; lMarketInputs.mcInputs = this.mcInputs; lMarketInputs.hkInputs = this.hkInputs; lMarketInputs.mrbInputs = this.mrbInputs; lMarketInputs.strInputs = this.strInputs; lMarketInputs.oscInputs = this.oscInputs; lMarketInputs.cheInputs = this.cheInputs; lMarketInputs.ichInputs = this.ichInputs; lMarketInputs.donInputs = this.donInputs; lMarketInputs.hullInputs = this.hullInputs; lMarketInputs.sslcInputs = this.sslcInputs; result = lMarketInputs.Init( this.symbol, this.period, X_MARKET_CYCLE_LONG, this.lMarketPeriod, this.lMarketMethod, this.lMarketPrefix, false // ); if (!result) { return result; } // // Hind ... hMarketInputs.pvInputs = this.pvInputs; hMarketInputs.zgInputs = this.zgInputs; hMarketInputs.tdInputs = this.tdInputs; hMarketInputs.mcInputs = this.mcInputs; hMarketInputs.hkInputs = this.hkInputs; hMarketInputs.mrbInputs = this.mrbInputs; hMarketInputs.strInputs = this.strInputs; hMarketInputs.oscInputs = this.oscInputs; hMarketInputs.cheInputs = this.cheInputs; hMarketInputs.ichInputs = this.ichInputs; hMarketInputs.donInputs = this.donInputs; hMarketInputs.hullInputs = this.hullInputs; hMarketInputs.sslcInputs = this.sslcInputs; result = hMarketInputs.Init( this.symbol, this.period, X_MARKET_CYCLE_HIND, this.hMarketPeriod, this.hMarketMethod, this.hMarketPrefix, false // ); if (!result) { return result; } // result = IsValid(); // return result; } // // Validate Input ... bool IsValid() { // bool result = false; // result = // // IsSpecifiedValid(symbol) && IsSpecifiedValid(period) && IsSpecifiedValid(sMarketMethod, sMarketPeriod) && IsSpecifiedValid(mMarketMethod, mMarketPeriod) && IsSpecifiedValid(lMarketMethod, lMarketPeriod) && IsSpecifiedValid(hMarketMethod, hMarketPeriod) && // ccInputs.IsValid() && ctInputs.IsValid() && zgInputs.IsValid() && pvInputs.IsValid() && mcInputs.IsValid() && hkInputs.IsValid() && tdInputs.IsValid() && mrbInputs.IsValid() && cheInputs.IsValid() && strInputs.IsValid() && donInputs.IsValid() && oscInputs.IsValid() && ichInputs.IsValid() && hullInputs.IsValid() && sslcInputs.IsValid() && // cMarketInputs.IsValid() && sMarketInputs.IsValid() && mMarketInputs.IsValid() && lMarketInputs.IsValid() && hMarketInputs.IsValid() // ; // return result; } // // Cleanup ... void Clean() { // symbol = NULL; period = NULL; // sMarketPeriod = NULL; sMarketMethod = X_PERIOD_NOTHING; sMarketPrefix = NULL; // mMarketPeriod = NULL; mMarketMethod = X_PERIOD_NOTHING; mMarketPrefix = NULL; // lMarketPeriod = NULL; lMarketMethod = X_PERIOD_NOTHING; lMarketPrefix = NULL; // hMarketPeriod = NULL; hMarketMethod = X_PERIOD_NOTHING; hMarketPrefix = NULL; // ccInputs.Clean(); ctInputs.Clean(); zgInputs.Clean(); pvInputs.Clean(); mcInputs.Clean(); hkInputs.Clean(); tdInputs.Clean(); mrbInputs.Clean(); cheInputs.Clean(); strInputs.Clean(); donInputs.Clean(); oscInputs.Clean(); ichInputs.Clean(); hullInputs.Clean(); sslcInputs.Clean(); // cMarketInputs.Clean(); sMarketInputs.Clean(); mMarketInputs.Clean(); lMarketInputs.Clean(); hMarketInputs.Clean(); } // // Default ... void Default() { // symbol = NULL; period = NULL; // sMarketPeriod = NULL; sMarketMethod = X_PERIOD_AUTO; sMarketPrefix = NULL; // mMarketPeriod = NULL; mMarketMethod = X_PERIOD_AUTO; mMarketPrefix = NULL; // lMarketPeriod = NULL; lMarketMethod = X_PERIOD_AUTO; lMarketPrefix = NULL; // hMarketPeriod = NULL; hMarketMethod = X_PERIOD_AUTO; hMarketPrefix = NULL; // ccInputs.Default(); ctInputs.Default(); zgInputs.Default(); pvInputs.Default(); mcInputs.Default(); hkInputs.Default(); tdInputs.Default(); mrbInputs.Default(); cheInputs.Default(); strInputs.Default(); donInputs.Default(); oscInputs.Default(); ichInputs.Default(); hullInputs.Default(); sslcInputs.Default(); // cMarketInputs.Default(); sMarketInputs.Default(); mMarketInputs.Default(); lMarketInputs.Default(); hMarketInputs.Default(); } // // Max ... int Max() { // int result = 0; // result = MathMax(ctInputs.Max(), ccInputs.Max()); // result = MathMax(result, ctInputs.Max()); result = MathMax(result, ccInputs.Max()); result = MathMax(result, tdInputs.Max()); result = MathMax(result, zgInputs.Max()); result = MathMax(result, pvInputs.Max()); result = MathMax(result, mcInputs.Max()); result = MathMax(result, hkInputs.Max()); result = MathMax(result, mrbInputs.Max()); result = MathMax(result, cheInputs.Max()); result = MathMax(result, strInputs.Max()); result = MathMax(result, donInputs.Max()); result = MathMax(result, oscInputs.Max()); result = MathMax(result, ichInputs.Max()); result = MathMax(result, hullInputs.Max()); result = MathMax(result, sslcInputs.Max()); // return result; } // // Set Symbol ... bool SetSymbol(string value) { // bool result = false; // result = IsSpecifiedValid(value); if (!result) { return result; } // symbol = value; // cMarketInputs.cycle.symbol = value; sMarketInputs.cycle.symbol = value; mMarketInputs.cycle.symbol = value; lMarketInputs.cycle.symbol = value; hMarketInputs.cycle.symbol = value; // return result; } // // Set Period ... bool SetPeriod(ENUM_TIMEFRAMES value) { // bool result = false; // result = IsSpecifiedValid(value); if (!result) { return result; } // period = value; // cMarketInputs.cycle.period = value; sMarketInputs.cycle.period = value; mMarketInputs.cycle.period = value; lMarketInputs.cycle.period = value; hMarketInputs.cycle.period = value; // return result; } // }; // // X121 Provider Market Conditions ... class X121MarketConditions : public XSCBase { // // Public ... public: // // Props ... string symbol; // Symbol ENUM_TIMEFRAMES period; // Period datetime time; // Time // XOHCL bars[]; // Number of Bars ... // // Market Props ... X121MCycleConditions cMarketConditions; // Current Market Conditions X121MCycleConditions sMarketConditions; // Short Market Conditions X121MCycleConditions mMarketConditions; // Medium Market Conditions X121MCycleConditions lMarketConditions; // Long Market Conditions X121MCycleConditions hMarketConditions; // Hind Market Conditions // // Tools ... // // Cleanup ... void Clear() { // symbol = NULL; period = NULL; // Clean(bars); // ArraySetAsSeries(bars, true); // cMarketConditions.Clear(); sMarketConditions.Clear(); mMarketConditions.Clear(); lMarketConditions.Clear(); hMarketConditions.Clear(); } // void GenerateScore( double &bullishScore, // Bullish Score double &bearishScore, // Bearish Score double cMarketMultiplier = 1, // Current Market Score Multiplier double sMarketMultiplier = 1.25, // Short Market Score Multiplier double mMarketMultiplier = 1.5, // Medium Market Score Multiplier double lMarketMultiplier = 2, // Long Market Score Multiplier double hMarketMultiplier = 2.5 // Hind Market Score Multiplier ) { // double bullScore = 0; double bearScore = 0; // // Current Market ... double cMarketBullScore = 0; double cMarketBearScore = 0; cMarketConditions.GenerateScore( cMarketBullScore, cMarketBearScore, cMarketMultiplier // ); // // Short Market ... double sMarketBullScore = 0; double sMarketBearScore = 0; sMarketConditions.GenerateScore( sMarketBullScore, sMarketBearScore, sMarketMultiplier // ); // // Medium Market ... double mMarketBullScore = 0; double mMarketBearScore = 0; mMarketConditions.GenerateScore( mMarketBullScore, mMarketBearScore, mMarketMultiplier // ); // // Long Market ... double lMarketBullScore = 0; double lMarketBearScore = 0; lMarketConditions.GenerateScore( lMarketBullScore, lMarketBearScore, lMarketMultiplier // ); // // Hind Market ... double hMarketBullScore = 0; double hMarketBearScore = 0; hMarketConditions.GenerateScore( hMarketBullScore, hMarketBearScore, hMarketMultiplier // ); // // Calculate Summary Scores ... // bullishScore = // bullScore + cMarketBullScore + sMarketBullScore + mMarketBullScore + lMarketBullScore + hMarketBullScore // ; // bearishScore = // bearScore + cMarketBearScore + sMarketBearScore + mMarketBearScore + lMarketBearScore + hMarketBearScore // ; } // string GenerateSummary( const bool onlySummary = false, // Only Generate Conditions Summary const bool onlyCyclesSummary = false, // Only Generate Conditions Summary double cMarketMultiplier = 1, // Current Market Score Multiplier double sMarketMultiplier = 1.25, // Short Market Score Multiplier double mMarketMultiplier = 1.5, // Medium Market Score Multiplier double lMarketMultiplier = 2, // Long Market Score Multiplier double hMarketMultiplier = 2.5, // Hind Market Score Multiplier const string separator = "\n", // Separator string provided = NULL, // Additional Info about Type, Provider and Symbol const bool ignoreFalseConditions = true // Ignore False Conditions ) { // string result = NULL; // double bullScore = 0; double bearScore = 0; GenerateScore( bullScore, bearScore, cMarketMultiplier, sMarketMultiplier, mMarketMultiplier, lMarketMultiplier, hMarketMultiplier // ); // string commonStr = // "Commons: " + separator + "-----------------------------" + separator + "Symbol: " + symbol + separator + "Period: " + ToString(period) + separator + "Time: " + ToString(TimeCurrent()) + separator + "-----------" + separator + "Cycles: " + separator + "-----------" + separator + sMarketConditions.GetTitle() + separator + mMarketConditions.GetTitle() + separator + lMarketConditions.GetTitle() + separator + hMarketConditions.GetTitle() + separator + "-----------" + separator + "Scores: " + separator + "-----------" + separator + "Bullish: " + ToString(bullScore) + separator + "Bearish: " + ToString(bearScore) + separator + "-----------------------------" + separator + // // TODO: Add Scores Later ... separator + "" // ; // string cMarketConditionsStr = cMarketConditions.GenerateSummary(onlyCyclesSummary, cMarketMultiplier); string sMarketConditionsStr = sMarketConditions.GenerateSummary(onlyCyclesSummary, sMarketMultiplier); string mMarketConditionsStr = mMarketConditions.GenerateSummary(onlyCyclesSummary, mMarketMultiplier); string lMarketConditionsStr = lMarketConditions.GenerateSummary(onlyCyclesSummary, lMarketMultiplier); string hMarketConditionsStr = hMarketConditions.GenerateSummary(onlyCyclesSummary, hMarketMultiplier); // result = // "[" + GetToken() + "]" + separator + (IsSpecifiedValid(provided) ? provided + separator : "") + "-----------------------------" + separator + commonStr + (!onlySummary ? cMarketConditionsStr + sMarketConditionsStr + mMarketConditionsStr + lMarketConditionsStr + hMarketConditionsStr + "" : "") + "" // ; // return result; } // // Tools ... // string GetToken() { return GetSpecificToken(this); } }; // // Class ... // // X121 Provider Class ... class XSCX121Provider : public XSCBaseProvider { // // Public ... public: // // Props ... // XSCXCCHelper *ccHelper; // Candle Clear XSCXCTHelper *ctHelper; // Candle Timer // XSCX121Market *cMarket; // Current Market XSCX121Market *sMarket; // Short Market XSCX121Market *mMarket; // Medium Market XSCX121Market *lMarket; // Long Market XSCX121Market *hMarket; // Hind Market // // Constructor ... XSCX121Provider( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading Period ) : XSCBaseProvider(symbol, period) { // ccHelper = new XSCXCCHelper(); ctHelper = new XSCXCTHelper(); // // Instantiate X121 Market Cycles Classes ... cMarket = new XSCX121Market(); sMarket = new XSCX121Market(); mMarket = new XSCX121Market(); lMarket = new XSCX121Market(); hMarket = new XSCX121Market(); // mNumberOfItems = 15; } // // Properties Gettr(s) / Setter(s) ... // void SetNumberOfItems(int value) { mNumberOfItems = value; } // int GetNumberOfItems() { return mNumberOfItems; } // // Overrides ... // // DeInit all Requirements ... void DeInit() override { // delete ccHelper; delete ctHelper; // delete cMarket; delete sMarket; delete mMarket; delete lMarket; delete hMarket; } // // Functions ... // // Init all Requirements ... bool Init(X121ProviderInputs &inputs) { // bool result = false; // // Validate ... result = inputs.IsValid(); if (!result) { return result; } // mInputs = inputs; // string mSymbol = GetSymbol(); ENUM_TIMEFRAMES mPeriod = GetPeriod(); // // Init Indicators Helpers ... // // CT ... result = ctHelper .Init( mSymbol, mPeriod, mInputs.ctInputs // ); if (!result) { return result; } // // CC ... result = ccHelper .Init( mSymbol, mPeriod, mInputs.ccInputs // ); if (!result) { return result; } // // Initialize X121 Market Cycles ... // // Current Market ... result = cMarket .Init(mInputs.cMarketInputs); if (!result) { return result; } // // Short Market ... result = sMarket .Init(mInputs.sMarketInputs); if (!result) { return result; } // // Medium Market ... result = mMarket .Init(mInputs.mMarketInputs); if (!result) { return result; } // // Long Market ... result = lMarket .Init(mInputs.lMarketInputs); if (!result) { return result; } // // Hind Market ... result = hMarket .Init(mInputs.hMarketInputs); if (!result) { return result; } // return result; } // string GetTag() { // string result = NULL; // result = // GetToken() + "[" + GetSymbol() + "," + ToString(GetPeriod()) + "]" // ; // return result; } // void GetMarketConditions( X121MarketConditions &mConditions, // Market Conditions Result int barIndex = 0 // Specified Bar Index ) { // mConditions.Clear(); // CalculateConditions(mConditions, barIndex); } // // Tools ... // void Draw() { // string symbol = GetSymbol(); ENUM_TIMEFRAMES period = GetPeriod(); // ulong chID = FindChartID( symbol, period); if (chID < 0) { return; } // int subWindow = 0; // int offset = 0; // cMarket.Draw(chID, subWindow, offset); sMarket.Draw(chID, subWindow, offset); mMarket.Draw(chID, subWindow, offset); lMarket.Draw(chID, subWindow, offset); hMarket.Draw(chID, subWindow, offset); } // // Protected ... protected: // X121ProviderInputs mInputs; // // Private ... private: // // Props ... // int mNumberOfItems; // Number of Buffer Ites Read in Conditions ... // void CalculateConditions( X121MarketConditions &mConditions, // Market Conditions Result int barIndex = 0 // Specified Bar Index ) { // mConditions.Clear(); // if (barIndex < 0) { barIndex = 0; } // if (barIndex >= CountBars()) { barIndex = CountBars() + 2; } // int curr = barIndex + 1; int prev = curr + 1; int mLength = 10; int mFrom = curr + mLength; // mConditions.symbol = GetSymbol(); mConditions.period = GetPeriod(); mConditions.time = iTime( mConditions.symbol, mConditions.period, barIndex // ); // GetBars( mConditions.bars, mConditions.symbol, mConditions.period, barIndex, mNumberOfItems // ); // // X121 Cycles Conditions ... // cMarket.GetMarketConditions( mConditions.cMarketConditions, barIndex, mNumberOfItems // ); // sMarket.GetMarketConditions( mConditions.sMarketConditions, barIndex, mNumberOfItems // ); // mMarket.GetMarketConditions( mConditions.mMarketConditions, barIndex, mNumberOfItems // ); // lMarket.GetMarketConditions( mConditions.lMarketConditions, barIndex, mNumberOfItems // ); // hMarket.GetMarketConditions( mConditions.hMarketConditions, barIndex, mNumberOfItems // ); } // }; // // Tools ... // // Model Provider Descriptor ... struct X121ProviderDescriptor { // string symbol; // Trading Symbol ENUM_TIMEFRAMES period; // Trading Timeframe XSignallerDescriptor *signallers[]; // Allowed Signal Providers // X121ProviderInputs inputs; XSCX121Provider *provider; // XSignal signals[]; X121MarketConditions conditions; // // Tools ... // bool Init() { // bool result = false; // result = this.Init( this.symbol, this.period); // return result; } // bool Init( string mSymbol, // Trading Symbol ENUM_TIMEFRAMES mPeriod // Trading Timeframe ) { // bool result = false; // result = // inputs.IsValid() && IsValid(mSymbol) && IsValid(mPeriod) && IsValidSize(ArraySize(this.signallers)) // ; if (!result) { return result; } // this.symbol = mSymbol; this.period = mPeriod; // // Instantiate Provider ... provider = new XSCX121Provider( this.symbol, this.period // ); // // Now Must to Initialize Provider ... result = provider.Init( this.inputs); // return result; } // // Cleanup ... void Clean() { // Clean(signals); conditions.Clear(); } // // Validate ... bool IsValid(bool validateInputs = true) { // bool result = false; // result = // IsValid(symbol) && IsValid(period) && (validateInputs ? inputs.IsValid() : true) && ArraySize(signallers) > 0 // ; // return result; } // // Check Signal ... int HasSignal(int barIndex = 0) { // int result = 0; // if (!inputs.IsValid()) { return result; } // int signallersCount = ArraySize(this.signallers); if (!IsValidSize(signallersCount)) { return result; } // // Clear Signal and Conditions ... Clean(); // // Check Waits Until New Bar ... if (!this.provider.CanIgnoreProcess()) { return result; } // // Fill Market Conditions ... provider.GetMarketConditions( this.conditions, barIndex // ); // // Retrieve All Scores ... double bullishScore = 0; double bearishScore = 0; this.conditions.GenerateScore( bullishScore, bearishScore // ); // // Generate Conditions Summary and Comment it on Chart ... string conditionsStr = this.conditions.GenerateSummary( true // OnlySummary ); Comment("\n", conditionsStr); // // Verifiers ... int longVerifiers = 0; int shortVerifiers = 0; // double mR2R = 0; double mVolume = 0; double slPrice = 0; double tpPrice = 0; string mProvider = NULL; // // Current Market ... double cLNSL = 0; double cLNTP = 0; double cSHSL = 0; double cSHTP = 0; bool cHasLong = false; bool cHasShort = false; double cBullishScore = 0; double cBearishScore = 0; this.conditions.cMarketConditions.GenerateScore( cBullishScore, cBearishScore // ); // // Short Market ... double sLNSL = 0; double sLNTP = 0; double sSHSL = 0; double sSHTP = 0; bool sHasLong = false; bool sHasShort = false; double sBullishScore = 0; double sBearishScore = 0; this.conditions.sMarketConditions.GenerateScore( sBullishScore, sBearishScore // ); // // Medium Market ... double mLNSL = 0; double mLNTP = 0; double mSHSL = 0; double mSHTP = 0; bool mHasLong = false; bool mHasShort = false; double mBullishScore = 0; double mBearishScore = 0; this.conditions.mMarketConditions.GenerateScore( mBullishScore, mBearishScore // ); // // Long Market ... double lLNSL = 0; double lLNTP = 0; double lSHSL = 0; double lSHTP = 0; bool lHasLong = false; bool lHasShort = false; double lBullishScore = 0; double lBearishScore = 0; this.conditions.lMarketConditions.GenerateScore( lBullishScore, lBearishScore // ); // // Hind Market ... double hLNSL = 0; double hLNTP = 0; double hSHSL = 0; double hSHTP = 0; bool hHasLong = false; bool hHasShort = false; double hBullishScore = 0; double hBearishScore = 0; this.conditions.hMarketConditions.GenerateScore( hBullishScore, hBearishScore // ); // for (int i = 0; i < signallersCount; i++) { // // Check all Markets for Long Conditions ... // // Current Market ... cLNSL = 0; cLNTP = 0; cHasLong = this.signallers[i] .HasLongConditions( this.conditions.cMarketConditions, cLNSL, cLNTP // ); if (cHasLong) { // slPrice = cLNSL; tpPrice = cLNTP; longVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeLong; } // // Short Market ... sLNSL = 0; sLNTP = 0; sHasLong = this.signallers[i] .HasLongConditions( this.conditions.sMarketConditions, sLNSL, sLNTP // ); if (sHasLong) { // slPrice = sLNSL; tpPrice = sLNTP; longVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeLong; } // // Medium Market ... mLNSL = 0; mLNTP = 0; mHasLong = this.signallers[i] .HasLongConditions( this.conditions.mMarketConditions, mLNSL, mLNTP // ); if (mHasLong) { // slPrice = mLNSL; tpPrice = mLNTP; longVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeLong; } // // Long Market ... lLNSL = 0; lLNTP = 0; lHasLong = this.signallers[i] .HasLongConditions( this.conditions.lMarketConditions, lLNSL, lLNTP // ); if (lHasLong) { // slPrice = lLNSL; tpPrice = lLNTP; longVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeLong; } // // Hind Market ... hLNSL = 0; hLNTP = 0; hHasLong = this.signallers[i] .HasLongConditions( this.conditions.hMarketConditions, hLNSL, hLNTP // ); if (hHasLong) { // slPrice = hLNSL; tpPrice = hLNTP; longVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeLong; } // // Check All Markets For Short Signals ... // // Current Market ... cSHSL = 0; cSHTP = 0; cHasShort = this.signallers[i] .HasShortConditions( this.conditions.cMarketConditions, cSHSL, cSHTP // ); if (cHasShort) { // slPrice = cSHSL; tpPrice = cSHTP; shortVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeShort; } // // Short Market ... sSHSL = 0; sSHTP = 0; sHasShort = this.signallers[i] .HasShortConditions( this.conditions.sMarketConditions, sSHSL, sSHTP // ); if (sHasShort) { // slPrice = sSHSL; tpPrice = sSHTP; shortVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeShort; } // // Medium Market ... mSHSL = 0; mSHTP = 0; mHasShort = this.signallers[i] .HasShortConditions( this.conditions.mMarketConditions, mSHSL, mSHTP // ); if (mHasShort) { // slPrice = mSHSL; tpPrice = mSHTP; shortVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeShort; } // // Long Market ... lSHSL = 0; lSHTP = 0; lHasShort = this.signallers[i] .HasShortConditions( this.conditions.lMarketConditions, lSHSL, lSHTP // ); if (lHasShort) { // slPrice = lSHSL; tpPrice = lSHTP; shortVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeShort; } // // Hind Market ... hSHSL = 0; hSHTP = 0; hHasShort = this.signallers[i] .HasShortConditions( this.conditions.hMarketConditions, hSHSL, hSHTP // ); if (hHasShort) { // slPrice = hSHSL; tpPrice = hSHTP; shortVerifiers++; mR2R = this.signallers[i].r2r; mProvider = this.signallers[i].GetName(); mVolume = this.signallers[i].staticVolumeShort; } // bool hasLong = // cHasLong // || // sHasLong // || // mHasLong // || // lHasLong // || // hHasLong // ; // bool hasShort = // cHasShort // || // sHasShort // || // mHasShort // || // lHasShort // || // hHasShort // ; // if (!(hasLong || hasShort)) { continue; } // bool isScorePassed = hasLong ? bullishScore > bearishScore * 2 : bearishScore > bullishScore * 2; // bool hasSignal = // isScorePassed && (hasLong ? longVerifiers > 1 : shortVerifiers > 1) // ; if (!hasSignal) { continue; } // // Try to Normalize SL and TP ... // // For Longs ... if (hasLong) { // // Collect all Verifications SLs ... // double sls[]; double tps[]; // // Current Market ... // if (cLNSL > 0) { // Add( cLNSL, sls // ); } // if (cLNTP > 0) { // Add( cLNTP, tps // ); } // // Short Market ... // if (sLNSL > 0) { // Add( sLNSL, sls // ); } // if (sLNTP > 0) { // Add( sLNTP, tps // ); } // // Medium Market ... // if (mLNSL > 0) { // Add( mLNSL, sls // ); } // if (mLNTP > 0) { // Add( mLNTP, tps // ); } // // Long Market ... // if (lLNSL > 0) { // Add( lLNSL, sls // ); } // if (lLNTP > 0) { // Add( lLNTP, tps // ); } // // Hind Market ... // if (hLNSL > 0) { // Add( hLNSL, sls // ); } // if (hLNTP > 0) { // Add( hLNTP, tps // ); } // // Now Select Minimum SL ... if (IsValidSize(ArraySize(sls))) { slPrice = GetMin(sls); } // // Average TP ... if (IsValidSize(ArraySize(tps))) { tpPrice = GetAverage(tps); } } // // For Shorts ... if (hasShort) { // // Collect all Verifications SLs ... // double sls[]; double tps[]; // // Current Market ... // if (cSHSL > 0) { // Add( cSHSL, sls // ); } // if (cSHTP > 0) { // Add( cSHTP, tps // ); } // // Short Market ... // if (sSHSL > 0) { // Add( sSHSL, sls // ); } // if (sSHTP > 0) { // Add( sSHTP, tps // ); } // // Medium Market ... // if (mSHSL > 0) { // Add( mSHSL, sls // ); } // if (mSHTP > 0) { // Add( mSHTP, tps // ); } // // Long Market ... // if (lSHSL > 0) { // Add( lSHSL, sls // ); } // if (lSHTP > 0) { // Add( lSHTP, tps // ); } // // Hind Market ... // if (hSHSL > 0) { // Add( hSHSL, sls // ); } // if (hSHTP > 0) { // Add( hSHTP, tps // ); } // // Now Select Minimum SL ... if (IsValidSize(ArraySize(sls))) { slPrice = GetMin(sls); } // // Average TP ... if (IsValidSize(ArraySize(tps))) { tpPrice = GetAverage(tps); } } // // Generate Signal ... XSignal iSignal; // ENUM_POSITION_TYPE mType = hasLong ? POSITION_TYPE_BUY : POSITION_TYPE_SELL; // double mEntry = GetEntry( this.symbol, mType // ); // double mTP = 0; double mSL = 0; CalculateTPSL( mSL, mTP, mType, mEntry, mR2R, slPrice, tpPrice // ); if (mSL == 0 && mTP == 0) { Print("Zero TP/SL ..."); } // bool isPrepared = iSignal.Prepare( this.symbol, mProvider, this.period, mType, X_ORDER_MODE_MARKET, mEntry, mVolume, mSL, mTP // ); if (!isPrepared) { iSignal.Clean(); } // if (iSignal.IsValid() && isPrepared && hasSignal) { // AddRef( iSignal, this.signals // ); } } // result = ArraySize(this.signals); // // Set Wait Until New Bar ... if (IsValidSize(result)) { this.provider.SetWaitsUntilNewBar(true); } // return result; } // // Check for Guards ... int HasGuard(XGuard &guards[]) { // int result = 0; // Clean(guards); // int signallersCount = CountSignallers(); if (!IsValidSize(signallersCount)) { return result; } // // Loop through Signallers ... for (int i = 0; i < signallersCount; i++) { // XGuard iGuards[]; int iGuardsCount = this.signallers[i] .HasGuard(iGuards); if (!IsValidSize(iGuardsCount)) { continue; } // Copy( iGuards, guards, false // ); } // result = ArraySize(guards); // return result; } // // Count Signallers ... int CountSignallers() { return ArraySize(signallers); } // // Find Specific Signaller Index ... int FindSignallerIndex(ENUM_XSIGNAL_PROVIDERS name) { // int result = -1; // // Converts Provided Signaller Name to String ... string strName = ToString(name); // result = FindSignallerIndex(strName); // return result; } // // Find Specific Signaller Index ... int FindSignallerIndex(string name) { // int result = -1; // int signallersCount = ArraySize(signallers); if (!IsValid() || !IsValid(name) || !IsValidSize(signallersCount) || name == ToString(PROVIDER_NONE)) { return result; } // for (int i = 0; i < signallersCount; i++) { // if (signallers[i].GetName() == name) { // result = i; break; } } // return result; } }; //