/////////////////////////////////////////////////////// // // SaherElm IT Center MQL4 XMA Signal Global Library // --------------------------------------------------- // saherelm useful tools and definitions ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Includes library ... #include "../Libraries/x-saherelm.lib.mq4" // // Includes Indicator library ... #include "../Libraries/x-saherelm.indicator.lib.mq4" // // Includes Models library ... #include "../Libraries/x-saherelm.models.lib.mq4" // // START Global Requirement Functions ... // // // XMA Based Signal Conditions ... struct XMAMMLongSignalConditions { // datetime crossUnderTime; // datetime crossOverTime; }; // static XMAMMLongSignalConditions xmaMMLongConds; // // END Global Requirement Functions ... // // // START Functions ... // // // Check and Fill CC Signal Conditions ... void CheckXMAMMLongSignalConditions( const int bar_index, const int marketLen, // double stp, double mxm, // int scFMult, int scSMult, // int mcFMult, int mcSMult, // int lcFMult, int lcSMult, // const double smoother = 5 ) { // datetime barTime = iTime( _Symbol, _Period, bar_index ); // XState states[]; ArrayResize( states, marketLen ); // int index = 0; for (int i = bar_index; i < marketLen; i++) { // XState state = GetXState( i, marketLen, // stp, mxm, scFMult, scSMult, mcFMult, mcSMult, lcFMult, lcSMult ); // states[index] = state; // index++; } // bool isCrossUnder = states[1].marketMiddleage < states[1].sc.fast && !(states[2].marketMiddleage < states[2].sc.fast) ; // bool isCrossOver = states[1].marketMiddleage > states[1].sc.fast && !(states[2].marketMiddleage > states[2].sc.fast) ; // if ( isCrossUnder && xmaMMLongConds.crossUnderTime == 0 ) { // xmaMMLongConds.crossUnderTime = barTime; return; } // if ( isCrossOver && xmaMMLongConds.crossUnderTime > 0 && xmaMMLongConds.crossOverTime == 0 ) { // xmaMMLongConds.crossOverTime = barTime; return; } } // // Convert XMA Long Signal Conditions to XSignal ... XSignalRequest GenerateXMAMMLongSignal( const int bar_index, // Bar Index ... const int marketLen, // MarketLength for TP and SL ... const double r2r // Risk to Reward ratio ... ) { // XSignalRequest result = {}; // result.hasSignal = false; result.type = X_SIGNAL_NONE; result.provider = X_UNKNOWN_PROVIDER; // if (!ValidateXMAMMLongConditions()) { return result; } // // Price Calculations ... // RefreshRates(); // double entryPrice = SymbolInfoDouble( _Symbol, SYMBOL_ASK ); // double exitPrice = SymbolInfoDouble( _Symbol, SYMBOL_BID ); // double priceGap = MathAbs(entryPrice - exitPrice); // double ll = GetMarketLowestLow( bar_index, marketLen ); // double openPrice = iOpen( _Symbol, _Period, bar_index ); // double closePrice = iClose( _Symbol, _Period, bar_index ); // double risk = MathMin(openPrice, closePrice) - ll; double reward = 300 * _Point; // risk * r2r; // double sl = 0; // entryPrice - (300 * _Point); // ll; double tp = entryPrice + reward; // datetime barTime = iTime( _Symbol, _Period, bar_index ); // result.signal.tp = tp; result.signal.sl = sl; result.signal.symbol = _Symbol; result.signal.type = X_SIGNAL_LONG; result.signal.id = totalSignals + 1; result.signal.entry = entryPrice; result.signal.provider = X_XMA_PROVIDER; result.signal.time = barTime; // result.hasSignal = true; result.type = X_SIGNAL_LONG; result.provider = X_XMA_PROVIDER; // return result; } // // Validate XMA Signal Conditions ... bool ValidateXMAMMLongConditions() { // bool isConditionsFilled = true && xmaMMLongConds.crossOverTime > 0 && xmaMMLongConds.crossUnderTime > 0 ; // bool isBLFilled = false; if (isConditionsFilled) { // int crossOverBarIndex = iBarShift( _Symbol, _Period, xmaMMLongConds.crossOverTime ); // int crossUnderBarIndex = iBarShift( _Symbol, _Period, xmaMMLongConds.crossUnderTime ); // isBLFilled = true // && (crossUnderBarIndex - crossOverBarIndex) > 5 // && xmaMMLongConds.crossOverTime > xmaMMLongConds.crossUnderTime ; } // bool result = isBLFilled && isConditionsFilled ; // // Since maybe Conditions Filled but // Slope is Negative, for Handling Next Signals and // Prevent from infinity loop, here we Clear Signal Conditions ... if ( !result && isConditionsFilled ) { ClearXMAMMLongSignalConditions(); } // return result; } // // Clear Long Signal Conditions for New One ... void ClearXMAMMLongSignalConditions() { // xmaMMLongConds.crossOverTime = 0; xmaMMLongConds.crossUnderTime = 0; } // // Check XMA State for Long Signals ... bool IsReadyForXMAMMLongSignals( const XSignal &signal, const XState &states[], const int marketLen ) { // bool result = false; // result = // true // // && states[0].parabolicSAR < states[0].marketMiddleage // && !( // states[0].parabolicSAR < states[0].mc.fast // && states[0].parabolicSAR < states[0].mc.slow // ) // // && states[0].mc.fast > states[0].mc.slow // // && MathAbs(states[0].mc.fast - states[0].mc.slow) > (150 * _Point) ; // return result; } // // END Functions ... //