/////////////////////////////////////////////////////// // // SaherElm IT Center XTest MQL5 Expert Advisor // ------------------------------------------------- // Name: XTestEA // Description: an Exper Advisor which used XTestSetup // to Analyse Market ... // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // //////////////////////////////////////////////////////x // // Global Properties ... #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm XTestEA" #property strict // #define ShortName "XTestEA" // // Imports ... #include "../Libraries/x-saherelm.tools.mq5" #include "../Libraries/x-saherelm.common.lib.mq5" // // Inputs ... long mMagicNumber = 78692110; // Magic Number int mSlippage = 10; // Slippgae // double eaVolume = 0.01; double eaAllowLong = true; double eaAllowShort = true; // XBarTracker eaBarTracker; // // Event Handlers ... // // Initialization ... int OnInit() { // if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // drawPrefix = ShortName; // bool isInited = eaBarTracker.Init( _Symbol, _Period // ); // // Init Succeed ... return INIT_SUCCEEDED; } // // DeInitialization ... 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 // REASON_RECOMPILE 2 Program recompiled // REASON_CHARTCHANGE 3 A symbol or a chart period is changed // REASON_CHARTCLOSE 4 Chart closed // REASON_PARAMETERS 5 Inputs changed by a user // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings // REASON_TEMPLATE 7 Another chart template applied // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value // REASON_CLOSE 9 Terminal closed // // De Initialize XSampleEA Providers ... } // // On Tick Handler ... void OnTick() { // if (!eaBarTracker.CanProcessBar()) { return; } // // Find Doji Patterns ... // FindDoji(); // // Find Hammer Patters ... // FindHammer(); // // Find Shooting Star Pattern ... // FindShootingStar(); // // Find Bullish Engulfing Pattern ... // FindBullishEngulfing(); // // Find Bearish Engulfing Pattern ... // FindBearishEngulfing(); // // Find Morning Star Pattern ... // FindMorningStar(); // // Find Evening Star Pattern ... // FindEveningStar(); // // Find Swing High Pattern ... // FindSwingHigh(); // // Find Swing Low Pattern ... // FindSwingLow(); // // Find Bullish FVG ... // FindBullishFVG(); // // Find Bearish FVG ... // FindBearishFVG(); // // Find Support ... // FindSupport(); // // Find Resistance ... // FindResistance(); // // Find Bullish Trend ... // FindBullishTrend(); // // Find Bearish Trend ... // FindBearishTrend(); // // Find Bullish Order Block ... // FindBullishOrderBlock(); // // Find Bearish Order Block ... // FindBearishOrderBlock(); // // Find Sharp Going Up Price Action ... // FindSharpBullish(); // // Find Sharp Going Down Price Action ... // FindSharpBearish(); // } // // Custom Functions ... // bool ValidateInputs() { // bool result = false; // result = true; // return result; } // // Custom Testing Functions ... // // Find Sharp Going Up Price Action ... void FindSharpBullish() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // if (!cBar.IsSharpBullish()) { return; } // eaBarTracker.Waits(); // Print("Detect Sharp Bullish Price Action ..."); } // // Find Sharp Going Down Price Action ... void FindSharpBearish() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // if (!cBar.IsSharpBearish()) { return; } // eaBarTracker.Waits(); // Print("Detect Sharp Bearish Price Action ..."); } // // Find Doji Pattern ... void FindDoji() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // if (!cBar.IsDoji()) { return; } // eaBarTracker.Waits(); // DrawArrow( ChartID(), "Doji-" + ToString((int)cBar.time), 0, cBar.time, cBar.low, 233, ANCHOR_TOP, clrGray, STYLE_SOLID, 2 // ); // Print("Doji Pattern Detected ..."); } // // Find Hammer Pattern ... void FindHammer() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // if (!cBar.IsHammer()) { return; } // eaBarTracker.Waits(); // DrawArrow( ChartID(), "Hammer-" + ToString((int)cBar.time), 0, cBar.time, cBar.low, 233, ANCHOR_TOP, clrAqua, STYLE_SOLID, 2 // ); // Print("Hammer Pattern Detected ..."); } // // Find Shooting Star Pattern ... void FindShootingStar() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // if (!cBar.IsShootingStar()) { return; } // eaBarTracker.Waits(); // DrawArrow( ChartID(), "ShootingStar-" + ToString((int)cBar.time), 0, cBar.time, cBar.high, 234, ANCHOR_BOTTOM, clrMagenta, STYLE_SOLID, 2 // ); // Print("Shooting Star Pattern Detected ..."); } // // Find Bullish Engulfing Pattern ... void FindBullishEngulfing() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL pBar; isInited = cBar.GetPreviousBar(pBar); if (!isInited) { return; } // if (!cBar.IsBullishEngulfing()) { return; } // eaBarTracker.Waits(); // DrawRectangle( ChartID(), "BullishEngulfing-" + ToString((int)cBar.time), 0, pBar.time, pBar.low, cBar.time, cBar.high, clrAqua, STYLE_SOLID, 1, false // ); // Print("Bullish Engulfing Pattern Detected ..."); } // // Find Bearish Engulfing Pattern ... void FindBearishEngulfing() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL pBar; isInited = cBar.GetPreviousBar(pBar); if (!isInited) { return; } // if (!cBar.IsBearishEngulfing()) { return; } // eaBarTracker.Waits(); // DrawRectangle( ChartID(), "BearishEngulfing-" + ToString((int)cBar.time), 0, pBar.time, pBar.low, cBar.time, cBar.high, clrMagenta, STYLE_SOLID, 1, false // ); // Print("Bearish Engulfing Pattern Detected ..."); } // // Find Morning Star Pattern ... void FindMorningStar() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL pBar; isInited = cBar.GetPreviousBar(pBar); if (!isInited) { return; } // if (!cBar.IsMorningStar()) { return; } // eaBarTracker.Waits(); // DrawArrow( ChartID(), "MorningStar-" + ToString((int)cBar.time), 0, cBar.time, cBar.low, 233, ANCHOR_TOP, clrAqua, STYLE_SOLID, 2 // ); // Print("Morning Star Pattern Detected ..."); } // // Find Evening Star Pattern ... void FindEveningStar() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL pBar; isInited = cBar.GetPreviousBar(pBar); if (!isInited) { return; } // if (!cBar.IsEveningStar()) { return; } // eaBarTracker.Waits(); // DrawArrow( ChartID(), "EveningStar-" + ToString((int)cBar.time), 0, cBar.time, cBar.high, 234, ANCHOR_BOTTOM, clrMagenta, STYLE_SOLID, 2 // ); // Print("Evening Star Pattern Detected ..."); } // // Find Swing High Pattern ... void FindSwingHigh() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL pBar; isInited = cBar.GetPreviousBar(pBar); if (!isInited) { return; } // if (!cBar.IsSwingHigh()) { return; } // eaBarTracker.Waits(); // DrawArrow( ChartID(), "SwingHigh-" + ToString((int)pBar.time), 0, pBar.time, pBar.high, 202, ANCHOR_BOTTOM, clrMagenta, 2 // ); // Print("Swing High Detected ..."); } // // Find Swing Low Pattern ... void FindSwingLow() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL pBar; isInited = cBar.GetPreviousBar(pBar); if (!isInited) { return; } // if (!cBar.IsSwingLow()) { return; } // eaBarTracker.Waits(); // DrawArrow( ChartID(), "SwingLow-" + ToString((int)pBar.time), 0, pBar.time, pBar.low, 200, ANCHOR_TOP, clrAqua, 2 // ); // Print("Swing Low Detected ..."); } // // Find Bullish FVG ... void FindBullishFVG() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // double upper = 0; double lower = 0; bool hasFVG = cBar.HasBullishFVG( upper, lower // ); if (!hasFVG) { return; } // eaBarTracker.Waits(); // datetime time1 = iTime( cBar.symbol, cBar.period, 1 + 2 // ); // DrawRectangle( ChartID(), "BullishFVG-" + ToString((int)cBar.time), 0, time1, lower, cBar.time, upper, clrAqua // ); // Print("Bullish FVG Detected ..."); } // // Find Bearish FVG ... void FindBearishFVG() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // double upper = 0; double lower = 0; bool hasFVG = cBar.HasBearishFVG( upper, lower // ); if (!hasFVG) { return; } // eaBarTracker.Waits(); // datetime time1 = iTime( cBar.symbol, cBar.period, 1 + 2 // ); // DrawRectangle( ChartID(), "BearishFVG-" + ToString((int)cBar.time), 0, time1, upper, cBar.time, lower, clrMagenta // ); // Print("Bearish FVG Detected ..."); } // // Find Support ... void FindSupport() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // datetime at = NULL; double support = 0; bool hasSupport = cBar.HasSupport( support, at // ); if (!hasSupport) { return; } // eaBarTracker.Waits(); // DrawTrendLine( ChartID(), "Support-" + ToString((int)at), 0, at, support, TimeCurrent(), support, clrAqua, STYLE_DOT, 1, false, false, true // ); // Print("Support Detected ..."); } // // Find Resistance ... void FindResistance() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // datetime at = NULL; double resistance = 0; bool hasResistance = cBar.HasResistance( resistance, at // ); if (!hasResistance) { return; } // eaBarTracker.Waits(); // DrawTrendLine( ChartID(), "Resistance-" + ToString((int)at), 0, at, resistance, TimeCurrent(), resistance, clrMagenta, STYLE_DOT, 1, false, false, true // ); // Print("Resistance Detected ..."); } // // Find Bullish Trend ... void FindBullishTrend() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // double hSwings[]; datetime hSwingTimes[]; // double lSwings[]; datetime lSwingTimes[]; // bool isBullishTrend = cBar.HasBullishTrend( hSwings, hSwingTimes, lSwings, lSwingTimes, false // Method 2 ... ); if (!isBullishTrend) { return; } // eaBarTracker.Waits(); // DrawTrendLine( ChartID(), "HSING-BULLTrend-" + ToString((int)hSwingTimes[ArraySize(hSwingTimes) - 1]) + "," + ToString((int)hSwingTimes[0]), 0, hSwingTimes[ArraySize(hSwingTimes) - 1], hSwings[ArraySize(hSwings) - 1], hSwingTimes[0], hSwings[0], clrAqua, STYLE_DOT, 1, false, false, true // ); // DrawTrendLine( ChartID(), "LSING-BULLTrend-" + ToString((int)lSwingTimes[ArraySize(lSwingTimes) - 1]) + "," + ToString((int)lSwingTimes[0]), 0, lSwingTimes[ArraySize(lSwingTimes) - 1], lSwings[ArraySize(lSwings) - 1], lSwingTimes[0], lSwings[0], clrMagenta, STYLE_DOT, 1, false, false, true // ); // // Draw Arrow On Swing Highs ... for (int i = 0; i < ArraySize(hSwings); i++) { // double iPrice = hSwings[i]; datetime iTime = hSwingTimes[i]; // DrawArrow( ChartID(), "HSIGN-BULLTrend-Arrow-" + ToString((int)iTime), 0, iTime, iPrice, 234, ANCHOR_BOTTOM, clrAqua, STYLE_SOLID, 2 // ); } // // Draw Arrow On Swing Highs ... for (int i = 0; i < ArraySize(lSwings); i++) { // double iPrice = lSwings[i]; datetime iTime = lSwingTimes[i]; // DrawArrow( ChartID(), "LSIGN-BULLTrend-Arrow-" + ToString((int)iTime), 0, iTime, iPrice, 233, ANCHOR_TOP, clrMagenta, STYLE_SOLID, 2 // ); } // Print("Bullish Trend Detected ..."); } // // Find Bearish Trend ... void FindBearishTrend() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // double hSwings[]; datetime hSwingTimes[]; // double lSwings[]; datetime lSwingTimes[]; // bool isBearishTrend = cBar.HasBearishTrend( hSwings, hSwingTimes, lSwings, lSwingTimes, false // Method 2 ... ); if (!isBearishTrend) { return; } // eaBarTracker.Waits(); // DrawTrendLine( ChartID(), "HSING-BEARTrend-" + ToString((int)hSwingTimes[ArraySize(hSwingTimes) - 1]) + "," + ToString((int)hSwingTimes[0]), 0, hSwingTimes[ArraySize(hSwingTimes) - 1], hSwings[ArraySize(hSwings) - 1], hSwingTimes[0], hSwings[0], clrAqua, STYLE_DOT, 1, false, false, true // ); // DrawTrendLine( ChartID(), "LSING-BEARTrend-" + ToString((int)lSwingTimes[ArraySize(lSwingTimes) - 1]) + "," + ToString((int)lSwingTimes[0]), 0, lSwingTimes[ArraySize(lSwingTimes) - 1], lSwings[ArraySize(lSwings) - 1], lSwingTimes[0], lSwings[0], clrMagenta, STYLE_DOT, 1, false, false, true // ); // // Draw Arrow On Swing Highs ... for (int i = 0; i < ArraySize(hSwings); i++) { // double iPrice = hSwings[i]; datetime iTime = hSwingTimes[i]; // DrawArrow( ChartID(), "HSIGN-BEARTrend-Arrow-" + ToString((int)iTime), 0, iTime, iPrice, 234, ANCHOR_BOTTOM, clrAqua, STYLE_SOLID, 2 // ); } // // Draw Arrow On Swing Highs ... for (int i = 0; i < ArraySize(lSwings); i++) { // double iPrice = lSwings[i]; datetime iTime = lSwingTimes[i]; // DrawArrow( ChartID(), "LSIGN-BEARTrend-Arrow-" + ToString((int)iTime), 0, iTime, iPrice, 233, ANCHOR_TOP, clrMagenta, STYLE_SOLID, 2 // ); } // Print("Bearish Trend Detected ..."); } // // Find Bullish Order Block ... void FindBullishOrderBlock() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL obBar; bool hasOB = cBar.HasBullishOrderBlock( obBar // ); if (!hasOB) { return; } // eaBarTracker.Waits(); // DrawTrendLine( ChartID(), "BULLOB-H-" + ToString((int) obBar.time), 0, obBar.time, obBar.high, cBar.time, obBar.high, clrAqua, STYLE_SOLID, 2, false, false, true // ); // DrawTrendLine( ChartID(), "BULLOB-L-" + ToString((int) obBar.time), 0, obBar.time, obBar.low, cBar.time, obBar.low, clrAqua, STYLE_SOLID, 2, false, false, true // ); // Print("Detect new Bullish Order Block ..."); } // // Find Bearish Order Block ... void FindBearishOrderBlock() { // XOHCL cBar; bool isInited = cBar.Init( _Symbol, _Period, 1 // ); if (!isInited) { return; } // XOHCL obBar; bool hasOB = cBar.HasBearishOrderBlock( obBar // ); if (!hasOB) { return; } // eaBarTracker.Waits(); // DrawTrendLine( ChartID(), "BEAROB-H-" + ToString((int) obBar.time), 0, obBar.time, obBar.high, cBar.time, obBar.high, clrMagenta, STYLE_SOLID, 2, false, false, true // ); // DrawTrendLine( ChartID(), "BEAROB-L-" + ToString((int) obBar.time), 0, obBar.time, obBar.low, cBar.time, obBar.low, clrMagenta, STYLE_SOLID, 2, false, false, true // ); // Print("Detect new Bearish Order Block ..."); } //