/////////////////////////////////////////////////////// // // SaherElm IT Center XSAMPLE MQL5 Expert Advisor // ------------------------------------------------- // Name: XSAMPLE // Description: an Exper Advisor which used RSI and MA // 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 XSAMPLE" #property strict // #define ShortName "XSAMPLE" // #include "../Libraries/x-saherelm.log.lib.mq5" #include "../Libraries/x-saherelm.common.lib.mq5" // #include "../Helpers/x-saherelm.x121.xmc.helper.mq5" #include "../Helpers/x-saherelm.x121.xstr.helper.mq5" #include "../Helpers/x-saherelm.x121.xche.helper.mq5" #include "../Helpers/x-saherelm.x121.xosc.helper.mq5" // #include "../Classes/x-saherelm.xtrade.class.mq5" #include "../Classes/x-saherelm.x121.xmcycle.class.mq5" // // Inputs ... long xSampleEAMagicNumber = 78692110; // Magic Number int xSampleEASlippage = 10; // Slippgae // double xSampleEAVolume = 0.01; // // Vars ... string xSampleEASymbol; ENUM_TIMEFRAMES xSampleEAPeriod; // int maxBuys = 1; int maxSells = 1; int buyCount = 0; int sellCount = 0; // double _tp = 0; double _sl = 0; double _entry = 0; ENUM_POSITION_TYPE _type = NULL; // MqlTick xSampleEATick; // XBarTracker xSamplEABarTracker; // // X121MCycle ... X121MCycleInputs xSampleEA121MCInputs; XSC121Market xSampleEA121MC; // XSCSignalCollector signalCollector; // // Event Handlers ... // // Initialization ... int OnInit() { // if (xSampleEASymbol == NULL || StringLen(xSampleEASymbol) <= 0) { xSampleEASymbol = _Symbol; } // if (xSampleEAPeriod == NULL) { xSampleEAPeriod = _Period; } // // Validate Inputs ... if (!XSampleEAValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // logTag = ShortName; drawPrefix = ShortName; // bool result = xSamplEABarTracker.Init( xSampleEASymbol, xSampleEAPeriod); if (!result) { return INIT_PARAMETERS_INCORRECT; } // // X121Market Cycle ... result = xSampleEA121MCInputs.Init( xSampleEASymbol, xSampleEAPeriod, X_MARKET_CYCLE_SHORT, PERIOD_H1, X_PERIOD_MANUALLY // ); if (!result) { return INIT_PARAMETERS_INCORRECT; } // // after Inputs Initialize Successfully we must prepare Styling for Draw ... ApplyMCDrawStyles(); // result = xSampleEA121MC.Init( xSampleEA121MCInputs // ); if (!result) { return INIT_PARAMETERS_INCORRECT; } // // 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 (!xSamplEABarTracker.IsNewBar()) { return; } // // Reading Tick ... if (!SymbolInfoTick(xSampleEASymbol, xSampleEATick)) { return; } // // Draw Market Cycle Bars On Chart ... int offset = 0; xSampleEA121MC.Draw( ChartID(), 0, offset // ); // // TestXSignalCollector(); } // // Custom Functions ... // // Validate Variables nd Inputs ... bool XSampleEAValidateInputs() { // bool result = false; // result = // xSampleEASlippage > 0 && xSampleEAMagicNumber > 0 // ; // return result; } // // Tools ... // void TestXSignalCollector() { // XSignal signal; bool isPrepared = signal.Prepare( xSampleEASymbol, "XTest", xSampleEAPeriod, POSITION_TYPE_BUY, X_ORDER_MODE_MARKET, GetEntry( xSampleEASymbol, POSITION_TYPE_BUY), 0.01, 0, 0 // ); if (isPrepared) { // bool isAdded = signalCollector .Add(signal); // if (isAdded) { LogMessage("Signal Added Successfully ..."); } } // // Try to Reading Collection ... XSignal collectedSignals[]; int collectedSignalsCount = signalCollector.Collect(collectedSignals); if (collectedSignalsCount > 0) { LogMessage("Number of Loaded Signals: " + ToString(collectedSignalsCount)); } } // void ApplyMCDrawStyles() { // // Here we Apply All Draw Styles on Input of Market Cycle ... xSampleEA121MCInputs.drawCBar = true; xSampleEA121MCInputs.drawPBar = true; xSampleEA121MCInputs.drawLabels = true; xSampleEA121MCInputs.drawCBarMid = true; xSampleEA121MCInputs.drawPBarMid = true; // // Current ... // // MidLine ... xSampleEA121MCInputs.cBarMidDrawSpecs.width = 1; xSampleEA121MCInputs.cBarMidDrawSpecs.style = STYLE_DOT; xSampleEA121MCInputs.cBarMidDrawSpecs.clr = clrSpringGreen; xSampleEA121MCInputs.cBarMidDrawSpecs.Label( xSampleEA121MCInputs.cycle.prefix + "_C MID", xSampleEA121MCInputs.cBarMidDrawSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... xSampleEA121MCInputs.cBarDrawSpecs.Default(); xSampleEA121MCInputs.cBarDrawSpecs.Width(1); xSampleEA121MCInputs.cBarDrawSpecs.Style(STYLE_DOT); // xSampleEA121MCInputs.cBarDrawSpecs.openStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_C O", xSampleEA121MCInputs.cBarDrawSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); xSampleEA121MCInputs.cBarDrawSpecs.highStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_C H", xSampleEA121MCInputs.cBarDrawSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_C C", xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_C L", xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Prev ... // // MidLine ... xSampleEA121MCInputs.pBarMidDrawSpecs.width = 2; xSampleEA121MCInputs.pBarMidDrawSpecs.style = STYLE_SOLID; xSampleEA121MCInputs.pBarMidDrawSpecs.clr = clrLimeGreen; xSampleEA121MCInputs.pBarMidDrawSpecs.Label( xSampleEA121MCInputs.cycle.prefix + "_P MID", xSampleEA121MCInputs.pBarMidDrawSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... xSampleEA121MCInputs.pBarDrawSpecs.Default(); xSampleEA121MCInputs.pBarDrawSpecs.Width(2); // xSampleEA121MCInputs.pBarDrawSpecs.openStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_P O", xSampleEA121MCInputs.pBarDrawSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); xSampleEA121MCInputs.pBarDrawSpecs.highStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_P H", xSampleEA121MCInputs.pBarDrawSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_P C", xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.Label( xSampleEA121MCInputs.cycle.prefix + "_P L", xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); }