/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class Library // -------------------------------------- // Name: XSCXSRBRStrategy // Description: provides all based classes for use ... // // // 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.xstrategy.class.mq5" // string XSRBRStartegyToken = "XSRBR"; // class XSCXSRBRStrategy : public XSCBaseStrategy { // // Public ... public: // // Constructor(s) ... void XSCXSRBRStrategy( // // Base ... string _symbol, // Trading Symbol ENUM_TIMEFRAMES _period, // Trading TimeFrame ENUM_TIMEFRAMES _analyzingPeriod, // Analyzing Timeframe double _volume, // Voluem double _r2r, // Risk/Reward Ratio int _slippage, // Trader Slippage long _magicNumber, // Trader Magic Number bool _allowLong = true, bool _allowShort = true, int _maxAllowedLongs = 0, int _maxAllowedShorts = 0, ENUM_X_SIGNALLING_DIRECTION _signallingDirection = X_SIGNALLING_TREND_DIRECTION // Signalling in Which Direction ) : XSCBaseStrategy(_symbol, _period, _volume, _r2r, _slippage, _magicNumber, _allowLong, _allowShort, _maxAllowedLongs, _maxAllowedShorts // ) { // mAnalyzingPeriod = _analyzingPeriod; mSignallingDirection = _signallingDirection; // SetAlertPrefix(GetTag()); } // // Getter / Setter (s) ... // // Overrides ... // // Customize Strategy Identifier ... string GetTag() override { return XSRBRStartegyToken; } // // Check Conditions For Signal ... bool HasSignal( XSignal &signal // ) override { // bool result = false; // double _threshold = 5; double threshold = GetPoints(mSymbol) * _threshold; // signal.Clean(); // double sl = 0; double tp = 0; double risk = 0; double entry = 0; double reward = 0; double r2r = R2R(); ENUM_POSITION_TYPE type; ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; // // Check Signalling Direction ... result = mSignallingDirection != X_SIGNALLING_NONE; if (!result) { return result; } // // Check Conditions Exists ... result = HasRequirements(); if (!result) { // // Prepare Conditions ... result = PrepareRequirements(); if (!result) { return result; } } // // Implement Signalling Conditions ... XOHCL cBar; result = cBar.Init( mSymbol, mPeriod, 1 // ); // double hh4 = cBar.FindHighest( 4, MODE_HIGH // ); double ll4 = cBar.FindHighest( 4, MODE_LOW // ); // // Check Analyzing Period Contains a Trend or not ... // // Detecting Trend ... bool isInBullishTrend = false; bool isInBearishTrend = false; // isInBullishTrend = bar.HasBullishTrend( highSwingBars, lowSwingBars // ); if (!isInBullishTrend) { // isInBearishTrend = bar.HasBearishTrend( highSwingBars, lowSwingBars // ); } // // Only Looks For Signals if aTrend Detected ... result = isInBullishTrend || isInBearishTrend; if (!result) { return result; } // // Here We have to Decide Trend or Reversal Act ... // // Check Trend Direction Signal ... if (mSignallingDirection == X_SIGNALLING_BOTH_DIRECTIONS || mSignallingDirection == X_SIGNALLING_TREND_DIRECTION) { // if (isInBullishTrend) { // // Find Long Signals ... // since we are in Bullish Trend and // we must do Trend Trading ... // // In Trend Trading we must Waits for : // - Support Rejection; // // Support Rejecting Hppens when Price Go Down of Support area and // Go Up or // Price Recive a Candlestic Pattern ... // // this Moving Up Make us Ready for Reciving a // Candlestick Pattern which Prove us Buyers Pressure ... // - Hammer; // - Morning Star; // - Bullish Engulfing; // XOHCL tmpSWH[]; XOHCL tmpSWL[]; // result = // // Check Price Place ... ( // (ll4 < support.high || (MathAbs(ll4 - support.high) <= threshold)) // && // hh4 > support.high // ) // && // // Check Candlestick Pattern ... ( // cBar.HasBullishTrend( tmpSWH, tmpSWL, true // ) // && // ( // cBar.IsHammer() // || // cBar.IsMorningStar() // || // cBar.IsBullishEngulfing() // ) // ) // ; // if (result) { type = POSITION_TYPE_BUY; } } else if (isInBearishTrend) { // // Find Short Signals ... // since we are in Bearish Trend and // we must do Trend Trading ... // XOHCL tmpSWH[]; XOHCL tmpSWL[]; // result = // // Check Price Place ... ( // (hh4 > resistance.low || (MathAbs(hh4 - resistance.low) <= threshold)) // && // ll4 < resistance.low // ) // && // // Check Candlestick Pattern ... ( // cBar.HasBearishTrend( tmpSWH, tmpSWL, true // ) // && // ( // cBar.IsShootingStar() // || // cBar.IsEveningStar() // || // cBar.IsBearishEngulfing() // ) // ) // ; // if (result) { type = POSITION_TYPE_SELL; } } } // // Check Trend Reversal Direction Signal ... if (!result && (mSignallingDirection == X_SIGNALLING_BOTH_DIRECTIONS || mSignallingDirection == X_SIGNALIING_TREND_REVERSAL_DIRECTION)) { // if (isInBullishTrend) { // // Find Short Signals ... // since we are in Bullish Trend and // we must do Trend Reversal Trading ... // result = // false // ; } else if (isInBearishTrend) { // // Find Long Signals ... // since we are in Bearish Trend and // we must do Trend Reversal Trading ... // result = // false // ; } } // // Make Sure Signal Exists ... if (!result) { return result; } // entry = GetEntry(mSymbol, type); CalculateTPSLBtPrice( sl, tp, type, entry, r2r // ); // result = signal.Prepare( mSymbol, GetTag(), mPeriod, type, mode, entry, mVolume, sl, tp // ); // return result; } // // Protected ... protected: // // Props ... // ENUM_TIMEFRAMES mAnalyzingPeriod; // Analyzing Period ENUM_X_SIGNALLING_DIRECTION mSignallingDirection; // Signalling Direction // XOHCL bar; // // Pivots ... XOHCL support; XOHCL resistance; // XOHCL lowSwingBars[]; XOHCL highSwingBars[]; // // Private ... private: // // // Check Requirements Exists or not ... bool HasRequirements() { // bool result = false; // result = // bar.IsValid() && support.IsValid() && resistance.IsValid() // ; // return result; } // // Prepare Requirements ... bool PrepareRequirements() { // bool result = false; // // Finding Analyzing Bar ... result = bar.Init( mSymbol, mAnalyzingPeriod, 1 // ); if (!result) { return result; } // // Find Support Bar based on Analyzing Bar ... result = bar.HasSupport( support // ); if (!result) { return result; } // // Find Resistance Bar based on Analyzing Bar ... result = bar.HasResistance( resistance // ); // return result; } // // Reset Reqirements ... void ResetRequirements() { // } }; //