From 1482b30d67e1a4062e75c324c68e93650ce4eb10 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 5 Jun 2024 03:51:54 +0330 Subject: [PATCH] last works ... --- .vscode/vscode-kanban.json | 35 + Classes/x-saherelm.x121.xmcycle.class.mq5 | 36 +- Experts/x-sample.ea.mq5 | 2453 ----------------- Experts/x-test.x121ea.mq5 | 63 +- Helpers/x-saherelm.xich.helper.mq5 | 80 +- Libraries/x-saherelm.common.lib.mq5 | 5 +- .../x-saherelm.x110.signaller.class.mq5 | 314 +++ .../x-saherelm.x121.signaller.class.mq5 | 8 +- .../x-saherelm.x786.signaller.class.mq5 | 8 +- 9 files changed, 454 insertions(+), 2548 deletions(-) delete mode 100644 Experts/x-sample.ea.mq5 create mode 100644 Signallers/x-saherelm.x110.signaller.class.mq5 diff --git a/.vscode/vscode-kanban.json b/.vscode/vscode-kanban.json index 857a7aca..3fb44a92 100644 --- a/.vscode/vscode-kanban.json +++ b/.vscode/vscode-kanban.json @@ -44,6 +44,32 @@ } ], "in-progress": [ + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-06-05T00:10:14.895Z", + "details": { + "content": "- [] Check Last Time trade for Provider;\n- [] Open Trade only when it's new or Previous in Profit;\n- [] Open Only 2 trade in each Direction at same time;\n- [] Close All Open Trades at Specific Time;\n- [] Enable/Disable Robot time Daily;\n- [] Close Long age Trades;\n- [] Trail or Risk Free Same In Profit Trades when Open New One;", + "mime": "text/markdown" + }, + "id": "74", + "references": [], + "title": "add support for:" + }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-06-05T00:17:33.324Z", + "description": { + "content": "from Provider classes and trader class.\nput them into XEA ...\nans Signallers ...", + "mime": "text/markdown" + }, + "id": "75", + "references": [], + "title": "Cleanup all allow long, short, minProfit per trade and drawdown factors variables" + }, { "assignedTo": { "name": "Hadi Khazaee Asl" @@ -81,6 +107,15 @@ "id": "72", "references": [], "title": "R&D about Volume Profiling" + }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-06-05T00:18:44.371Z", + "id": "76", + "references": [], + "title": "Enable Comment Score and Summary on each Tick ..." } ], "testing": [ diff --git a/Classes/x-saherelm.x121.xmcycle.class.mq5 b/Classes/x-saherelm.x121.xmcycle.class.mq5 index b9ab30ef..a7b716e6 100644 --- a/Classes/x-saherelm.x121.xmcycle.class.mq5 +++ b/Classes/x-saherelm.x121.xmcycle.class.mq5 @@ -2540,8 +2540,8 @@ public: ENUM_XSIGNAL_PROVIDERS name; // - bool enableLong; - bool enableShort; + bool allowLong; + bool allowShort; // double r2r; @@ -2567,8 +2567,8 @@ public: name = PROVIDER_NONE; // - enableLong = false; - enableShort = false; + allowLong = false; + allowShort = false; // r2r = 0; @@ -2590,10 +2590,10 @@ public: // name != PROVIDER_NONE && r2r > 0 && - (enableLong + (allowLong ? staticVolumeLong > 0 : true) && - (enableShort + (allowShort ? staticVolumeShort > 0 : true) // @@ -2642,8 +2642,8 @@ public: // // Validate Signal Type ... result = isLong - ? enableLong && staticVolumeLong > 0 - : enableShort && staticVolumeShort > 0; + ? allowLong && staticVolumeLong > 0 + : allowShort && staticVolumeShort > 0; if (!result) { return result; @@ -2703,8 +2703,8 @@ public: // // Validate Signal Type ... result = isLong - ? enableLong && staticVolumeLong > 0 - : enableShort && staticVolumeShort > 0; + ? allowLong && staticVolumeLong > 0 + : allowShort && staticVolumeShort > 0; if (!result) { return result; @@ -4434,14 +4434,14 @@ public: conditions.isTenkanSenCrossedUnderKijunSen = isTenkanSenCrossedUnderKijunSen; // - conditions.isSenkouSpanAOverB = isSenkouSpanACrossedOverB; - conditions.isSenkouSpanAUnderB = isSenkouSpanACrossedUnderB; - conditions.isSenkouSpanAOverLast = isSenkouSpanACrossedOverLast; - conditions.isSenkouSpanAUnderLast = isSenkouSpanACrossedUnderLast; - conditions.isFutureSenkouSpanAOverB = isFutureSenkouSpanACrossedOverB; - conditions.isFutureSenkouSpanAUnderB = isFutureSenkouSpanACrossedUnderB; - conditions.isFutureSenkouSpanAOverLast = isFutureSenkouSpanACrossedOverLast; - conditions.isFutureSenkouSpanAUnderLast = isFutureSenkouSpanACrossedUnderLast; + conditions.isSenkouSpanAOverB = isSenkouSpanAOverB; + conditions.isSenkouSpanAUnderB = isSenkouSpanAUnderB; + conditions.isSenkouSpanAOverLast = isSenkouSpanAOverLast; + conditions.isSenkouSpanAUnderLast = isSenkouSpanAUnderLast; + conditions.isFutureSenkouSpanAOverB = isFutureSenkouSpanAOverB; + conditions.isFutureSenkouSpanAUnderB = isFutureSenkouSpanAUnderB; + conditions.isFutureSenkouSpanAOverLast = isFutureSenkouSpanAOverLast; + conditions.isFutureSenkouSpanAUnderLast = isFutureSenkouSpanAUnderLast; // conditions.isSenkouSpanACrossedOverB = isSenkouSpanACrossedOverB; diff --git a/Experts/x-sample.ea.mq5 b/Experts/x-sample.ea.mq5 deleted file mode 100644 index 5090242d..00000000 --- a/Experts/x-sample.ea.mq5 +++ /dev/null @@ -1,2453 +0,0 @@ -/////////////////////////////////////////////////////// -// -// 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.draw.lib.mq5" -#include "../Helpers/x-saherelm.xcc.helper.mq5" -#include "../Helpers/x-saherelm.xct.helper.mq5" -#include "../Classes/x-saherelm.xtrade.class.mq5" -#include "../Libraries/x-saherelm.common.lib.mq5" -#include "../Classes/x-saherelm.xalert.class.mq5" -#include "../Classes/x-saherelm.x121.xmcycle.class.mq5" -#include "../Classes/x-saherelm.x121.xmcycle.class.mq5" - -// -// Inputs ... - -// -input group "Market"; - -// -input group "Short"; -input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // Method -input ENUM_TIMEFRAMES scPeriod = NULL; // Period - -// -input group "Medium"; -input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // Method -input ENUM_TIMEFRAMES mcPeriod = NULL; // Period - -// -input group "Long"; -input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // Method -input ENUM_TIMEFRAMES lcPeriod = NULL; // Period - -// -input group "Hind"; -input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // Method -input ENUM_TIMEFRAMES hcPeriod = NULL; // Period - -// -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; - -// -// Cycles ... - -// -double bullishBuffer[]; -double bearishBuffer[]; -double nBullishBuffer[]; -double nBearishBuffer[]; -double longVFBuffer[]; -double shortVFBuffer[]; - -// -double lastVale = 0; -double lastPeak = 0; -double lastSupport = 0; -double lastResistance = 0; - -// -double xBullishScore = 0; -double xBearishScore = 0; - -// -double normalizeBullishScore = 0; -double normalizeBearishScore = 0; - -// -double xLongVerifications = 0; -double xShortVerifications = 0; -bool isScoreBalanced = false; - -// -double lastBullishPivot = 0; -double lastBearishPivot = 0; - -// -int normalizationLength = 15; - -// -datetime lastTradeOn = NULL; - -// -// 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; - -// -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 - -// -XSCX121Market *cMarket; -XSCX121Market *sMarket; -XSCX121Market *mMarket; -XSCX121Market *lMarket; -XSCX121Market *hMarket; - -// -X121MCycleConditions cConditions; -X121MCycleConditions sConditions; -X121MCycleConditions mConditions; -X121MCycleConditions lConditions; -X121MCycleConditions hConditions; - -// -XSCTrade *mTrader; -XSCAlert *mAlert; - -// -XPivotTracker mPivotTracker; -XSignal mSignals[]; - -// -// 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; - } - - // - if (!InitialTrader()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initial Cycles ... - if (!InitCycles()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - drawPrefix = ShortName; - - // - // 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 ... - - // - delete mAlert; - delete mTrader; - - // - delete cMarket; - delete sMarket; - delete mMarket; - delete lMarket; - delete hMarket; -} - -// -// On Tick Handler ... -void OnTick() -{ - // - if (!xSamplEABarTracker.IsNewBar()) - { - return; - } - - // - // Reading Tick ... - if (!GetTick( - xSampleEASymbol, - xSampleEATick // - )) - { - return; - } - - // - Analyze(); - - // - Manage(); -} - -// -// Custom Functions ... - -// -// Validate Variables nd Inputs ... -bool XSampleEAValidateInputs() -{ - // - bool result = false; - - // - result = - // - xSampleEASlippage > 0 && - xSampleEAMagicNumber > 0 && - IsValid(scMethod, scPeriod) && - IsValid(mcMethod, mcPeriod) && - IsValid(lcMethod, lcPeriod) && - IsValid(hcMethod, hcPeriod) - // - ; - - // - return result; -} - -// -// Tools ... - -// -// Do Market Analyziation ... -void Analyze() -{ - // - GenerateMarketConditions(); - - // - xBullishScore = 0; - xBearishScore = 0; - CalculateScores( - xBullishScore, - xBearishScore // - ); - - // - normalizeBullishScore = 0; - normalizeBearishScore = 0; - CalculateNormalizedScores( - normalizeBullishScore, - normalizeBearishScore // - ); - - // - xLongVerifications = 0; - xShortVerifications = 0; - CalculateVerifications( - xLongVerifications, - xShortVerifications // - ); - - // - // Check Conditions on Pivots ... - HandleSignalDetection(); - - // - // Execute Signals ... - HandleSignalExecution(); - - // - // SUMMARY ... - - // - string strSuumarry = - "[XTEA]" + "\n" + - "---------------------" + "\n" + - ToString(cMarketInputs.cycle.cycle) + ": " + ToString(cMarket.GetPeriod()) + "\n" + - ToString(sMarketInputs.cycle.cycle) + ": " + ToString(sMarket.GetPeriod()) + "\n" + - ToString(mMarketInputs.cycle.cycle) + ": " + ToString(mMarket.GetPeriod()) + "\n" + - ToString(lMarketInputs.cycle.cycle) + ": " + ToString(lMarket.GetPeriod()) + "\n" + - ToString(hMarketInputs.cycle.cycle) + ": " + ToString(hMarket.GetPeriod()) + "\n" + - "---------------------" + "\n" + - "Scores:" + "\n" + - "---------------------" + "\n" + - "Bullish: " + ToString(xBullishScore) + ", " + ToString(normalizeBullishScore) + ", " + ToString(xLongVerifications) + "\n" + - "Bearish: " + ToString(xBearishScore) + ", " + ToString(normalizeBearishScore) + ", " + ToString(xShortVerifications) + "\n" + - ""; - - // - Comment(strSuumarry); - - // -} - -// -void Manage() -{ -} - -// -// Inbitial Classes ... -bool InitialTrader() -{ - // - bool result = true; - - // - mAlert = new XSCAlert(); - mAlert.SetLogAlerts(true); - mAlert.SetPrefix(ShortName); - mAlert.SetEnableAlerts(true); - mAlert.SetPushAlerts(false); - mAlert.SetMailAlerts(false); - mAlert.SetTerminalAlerts(false); - - // - mTrader = new XSCTrade( - xSampleEASlippage, - xSampleEAMagicNumber, - 0, - 0, - 0, - 0 // - ); - - // - return result; -} - -// -// Initial Market Conditions ... -bool InitCycles() -{ - // - bool result = false; - - // - // Define an Input Object and Configure it ... - // then use same Input for Separate Markets ... - - // - string symbol = _Symbol; - ENUM_TIMEFRAMES period = _Period; - - // - // Set Inputs to Default ... - ccInputs.Default(); - ctInputs.Default(); - zgInputs.Default(); - pvInputs.Default(); - hkInputs.Default(); - mcInputs.Default(); - tdInputs.Default(); - mrbInputs.Default(); - ichInputs.Default(); - cheInputs.Default(); - strInputs.Default(); - donInputs.Default(); - oscInputs.Default(); - - // - cMarketInputs.Default(); - sMarketInputs.Default(); - mMarketInputs.Default(); - lMarketInputs.Default(); - hMarketInputs.Default(); - - // - // XHK ... - hkInputs.drawHikenAshi = false; - hkInputs.drawSmoothedHikenAshi = false; - - // - // XMRB ... - mrbInputs.showFastMa = false; - mrbInputs.showSlowMa = false; - mrbInputs.showRibbon = false; - - // - // XMC ... - mcInputs.showFastMa = false; - mcInputs.showSlowMa = false; - mcInputs.showVerifierMa = false; - - // - // XICH ... - ichInputs.showKumo = false; - ichInputs.showKijunSen = false; - ichInputs.showTenkanSen = false; - ichInputs.showChikouSpan = false; - ichInputs.showSenkouSpanA = false; - ichInputs.showSenkouSpanB = false; - ichInputs.showKijunSenPlus = false; - ichInputs.showKijunSenNegative = false; - - // - // XCHE ... - cheInputs.showLongExit1Line = false; - cheInputs.showShortExit1Line = false; - cheInputs.showLongExit2Line = false; - cheInputs.showShortExit2Line = false; - - // - // XPV ... - pvInputs.showPeaksAndVales = false; - pvInputs.showLevels = false; - pvInputs.showConsolidations = false; - pvInputs.showFibo1Levels = false; - pvInputs.showFibo2Levels = false; - pvInputs.showFibo3Levels = false; - pvInputs.showFibo4Levels = false; - pvInputs.showFibo5Levels = false; - - // - // XZG ... - zgInputs.showZigZag = false; - zgInputs.showPeaksAndVales = false; - - // - // XDON ... - donInputs.showOpen = false; - donInputs.showHigh = false; - donInputs.showClose = false; - donInputs.showLow = false; - - // - // XSTR ... - strInputs.showTrends = false; - strInputs.fillTrends = false; - - // - // Current Cycle ... - - // - ConfigureCurrentCycles(); - - // - cMarketInputs.cycle.symbol = symbol; - cMarketInputs.cycle.period = period; - - // - cMarketInputs.pvInputs = pvInputs; - cMarketInputs.zgInputs = zgInputs; - cMarketInputs.tdInputs = tdInputs; - cMarketInputs.mcInputs = mcInputs; - cMarketInputs.hkInputs = hkInputs; - cMarketInputs.mrbInputs = mrbInputs; - cMarketInputs.strInputs = strInputs; - cMarketInputs.oscInputs = oscInputs; - cMarketInputs.cheInputs = cheInputs; - cMarketInputs.ichInputs = ichInputs; - cMarketInputs.donInputs = donInputs; - - // - result = cMarketInputs.Init( - symbol, - period, - X_MARKET_CYCLE_SHORT, - period, - X_PERIOD_MANUALLY, - "HOST", - false // - ); - if (!result) - { - return result; - } - - // - cMarket = new XSCX121Market(); - result = cMarket.Init(cMarketInputs); - if (!result) - { - return result; - } - - // - // Short Cycle ... - - // - ConfigureShortCycles(); - - // - sMarketInputs.cycle.symbol = symbol; - sMarketInputs.cycle.period = period; - - // - sMarketInputs.pvInputs = pvInputs; - sMarketInputs.zgInputs = zgInputs; - sMarketInputs.tdInputs = tdInputs; - sMarketInputs.mcInputs = mcInputs; - sMarketInputs.hkInputs = hkInputs; - sMarketInputs.mrbInputs = mrbInputs; - sMarketInputs.strInputs = strInputs; - sMarketInputs.oscInputs = oscInputs; - sMarketInputs.cheInputs = cheInputs; - sMarketInputs.ichInputs = ichInputs; - sMarketInputs.donInputs = donInputs; - - // - result = sMarketInputs.Init( - symbol, - period, - X_MARKET_CYCLE_SHORT, - scPeriod, - scMethod, - NULL, - false // - ); - if (!result) - { - return result; - } - - // - sMarket = new XSCX121Market(); - result = sMarket.Init(sMarketInputs); - if (!result) - { - return result; - } - - // - // Medium Cycle ... - - // - ConfigureMediumCycles(); - - // - mMarketInputs.cycle.symbol = symbol; - mMarketInputs.cycle.period = period; - - // - mMarketInputs.pvInputs = pvInputs; - mMarketInputs.zgInputs = zgInputs; - mMarketInputs.tdInputs = tdInputs; - mMarketInputs.mcInputs = mcInputs; - mMarketInputs.hkInputs = hkInputs; - mMarketInputs.mrbInputs = mrbInputs; - mMarketInputs.strInputs = strInputs; - mMarketInputs.oscInputs = oscInputs; - mMarketInputs.cheInputs = cheInputs; - mMarketInputs.ichInputs = ichInputs; - mMarketInputs.donInputs = donInputs; - - // - result = mMarketInputs.Init( - symbol, - period, - X_MARKET_CYCLE_MEDIUM, - mcPeriod, - mcMethod, - NULL, - false // - ); - if (!result) - { - return result; - } - - // - mMarket = new XSCX121Market(); - result = mMarket.Init(mMarketInputs); - if (!result) - { - return result; - } - - // - // Long Cycle ... - - // - ConfigureLongCycles(); - - // - lMarketInputs.cycle.symbol = symbol; - lMarketInputs.cycle.period = period; - - // - lMarketInputs.pvInputs = pvInputs; - lMarketInputs.zgInputs = zgInputs; - lMarketInputs.tdInputs = tdInputs; - lMarketInputs.mcInputs = mcInputs; - lMarketInputs.hkInputs = hkInputs; - lMarketInputs.mrbInputs = mrbInputs; - lMarketInputs.strInputs = strInputs; - lMarketInputs.oscInputs = oscInputs; - lMarketInputs.cheInputs = cheInputs; - lMarketInputs.ichInputs = ichInputs; - lMarketInputs.donInputs = donInputs; - - // - result = lMarketInputs.Init( - symbol, - period, - X_MARKET_CYCLE_LONG, - lcPeriod, - lcMethod, - NULL, - false // - ); - if (!result) - { - return result; - } - - // - lMarket = new XSCX121Market(); - result = lMarket.Init(lMarketInputs); - if (!result) - { - return result; - } - - // - // Hind Cycle ... - - // - ConfigureHindCycles(); - - // - hMarketInputs.cycle.symbol = symbol; - hMarketInputs.cycle.period = period; - - // - hMarketInputs.pvInputs = pvInputs; - hMarketInputs.zgInputs = zgInputs; - hMarketInputs.tdInputs = tdInputs; - hMarketInputs.mcInputs = mcInputs; - hMarketInputs.hkInputs = hkInputs; - hMarketInputs.mrbInputs = mrbInputs; - hMarketInputs.strInputs = strInputs; - hMarketInputs.oscInputs = oscInputs; - hMarketInputs.cheInputs = cheInputs; - hMarketInputs.ichInputs = ichInputs; - hMarketInputs.donInputs = donInputs; - - // - result = hMarketInputs.Init( - symbol, - period, - X_MARKET_CYCLE_HIND, - hcPeriod, - hcMethod, - NULL, - false // - ); - if (!result) - { - return result; - } - - // - hMarket = new XSCX121Market(); - result = hMarket.Init(hMarketInputs); - if (!result) - { - return result; - } - - // - return result; -} - -// -// Generate and Update Market Conditions ... -void GenerateMarketConditions() -{ - // - cConditions.Clear(); - cMarket.GetMarketConditions(cConditions); - - // - sConditions.Clear(); - sMarket.GetMarketConditions(sConditions); - - // - mConditions.Clear(); - mMarket.GetMarketConditions(mConditions); - - // - lConditions.Clear(); - lMarket.GetMarketConditions(lConditions); - - // - hConditions.Clear(); - hMarket.GetMarketConditions(hConditions); -} - -// -// Calculate Markets Score Summary ... -void CalculateScores( - double &mBullishScore, - double &mBearishScore // -) -{ - // - // Current Market ... - - // - double cBullScore = 0; - double cBearScore = 0; - double cScoreMultiplier = 1; - - // - cConditions.GenerateScore( - cBullScore, - cBearScore, - cScoreMultiplier // - ); - - // - // Short Market ... - - // - double sBullScore = 0; - double sBearScore = 0; - double sScoreMultiplier = 1.25; - - // - sConditions.GenerateScore( - sBullScore, - sBearScore, - sScoreMultiplier // - ); - - // - // Medium Market ... - - // - double mBullScore = 0; - double mBearScore = 0; - double mScoreMultiplier = 1.5; - - // - mConditions.GenerateScore( - mBullScore, - mBearScore, - mScoreMultiplier // - ); - - // - // Long Market ... - - // - double lBullScore = 0; - double lBearScore = 0; - double lScoreMultiplier = 2; - - // - lConditions.GenerateScore( - lBullScore, - lBearScore, - lScoreMultiplier // - ); - - // - // Hind Market ... - - // - double hBullScore = 0; - double hBearScore = 0; - double hScoreMultiplier = 2.5; - - // - hConditions.GenerateScore( - hBullScore, - hBearScore, - hScoreMultiplier // - ); - - // - mBullishScore = cBullScore + - sBullScore + - mBullScore + - lBullScore + - hBullScore; - - // - mBearishScore = cBearScore + - sBearScore + - mBearScore + - lBearScore + - hBearScore; - - // - Add( - mBullishScore, - bullishBuffer - // - ); - - // - Add( - mBearishScore, - bearishBuffer - // - ); -} - -// -// Calculate Market Normalized Scores ... -void CalculateNormalizedScores( - double &mBullishScore, - double &mBearishScore // -) -{ - // - CalculateNormalization( - mBullishScore, - mBearishScore - // - ); - - Add( - mBullishScore, - nBullishBuffer // - ); - - Add( - mBearishScore, - nBearishBuffer // - ); -} - -// -// Calculate Normalization Value ... -void CalculateNormalization( - double &normalBullish, - double &normalBearish // -) -{ - // - normalBullish = GetNormalizedValueMethod2( - bullishBuffer, - ArraySize(bullishBuffer), - 1, - -1, - 0 // - ); - - // - normalBearish = GetNormalizedValueMethod2( - bearishBuffer, - ArraySize(bearishBuffer), - 1, - -1, - 0 // - ); -} - -// -// Calculate Market Verifications ... -void CalculateVerifications( - double &longVerifications, - double &shortVerifications // -) -{ - // - // Generate Long ans Short Verifiers ... - - // - // XSTR ... - - // - bool isTrendBullish = - // - hConditions.isTrendBullish && - lConditions.isTrendBullish && - mConditions.isTrendBullish && - sConditions.isTrendBullish && - cConditions.isTrendBullish - // - ; - - // - if (isTrendBullish) - { - longVerifications++; - } - - // - bool isTrendBearish = - // - hConditions.isTrendBearish && - lConditions.isTrendBearish && - mConditions.isTrendBearish && - sConditions.isTrendBearish && - cConditions.isTrendBearish - // - ; - - // - if (isTrendBearish) - { - shortVerifications++; - } - - // - // XTD ... - - // - bool isTDBullish = - // - hConditions.isTDBullish && - lConditions.isTDBullish && - mConditions.isTDBullish && - sConditions.isTDBullish && - cConditions.isTDBullish - // - ; - - // - if (isTDBullish) - { - longVerifications++; - } - - // - bool isTDBearish = - // - hConditions.isTDBearish && - lConditions.isTDBearish && - mConditions.isTDBearish && - sConditions.isTDBearish && - cConditions.isTDBearish - // - ; - - // - if (isTDBearish) - { - shortVerifications++; - } - - // - // XCHE ... - - // - bool isCHEBullish = - // - hConditions.isCHEBullish && - lConditions.isCHEBullish && - mConditions.isCHEBullish && - sConditions.isCHEBullish && - cConditions.isCHEBullish - // - ; - - // - if (isCHEBullish) - { - longVerifications++; - } - - // - bool isCHEBearish = - // - hConditions.isCHEBearish && - lConditions.isCHEBearish && - mConditions.isCHEBearish && - sConditions.isCHEBearish && - cConditions.isCHEBearish - // - ; - - // - if (isCHEBearish) - { - shortVerifications++; - } - - // - // XHK ... - - // - bool isHKBullish = - // - (hConditions.isHKBullish && - lConditions.isHKBullish && - mConditions.isHKBullish && - sConditions.isHKBullish && - cConditions.isHKBullish) - // - || - // - (hConditions.isSMHKBullish && - lConditions.isSMHKBullish && - mConditions.isSMHKBullish && - sConditions.isSMHKBullish && - cConditions.isSMHKBullish) - // - ; - - // - if (isHKBullish) - { - longVerifications++; - } - - // - bool isHKBearish = - // - (hConditions.isHKBearish && - lConditions.isHKBearish && - mConditions.isHKBearish && - sConditions.isHKBearish && - cConditions.isHKBearish) - // - || - // - (hConditions.isSMHKBearish && - lConditions.isSMHKBearish && - mConditions.isSMHKBearish && - sConditions.isSMHKBearish && - cConditions.isSMHKBearish) - // - ; - - // - if (isHKBearish) - { - shortVerifications++; - } - - // - // XMC ... - - // - bool isMCBullish = - // - (hConditions.isMCFastOverSlow && - lConditions.isMCFastOverSlow && - mConditions.isMCFastOverSlow && - sConditions.isMCFastOverSlow && - cConditions.isMCFastOverSlow) - // - || - // - (hConditions.isMCFastOverVerifier && - lConditions.isMCFastOverVerifier && - mConditions.isMCFastOverVerifier && - sConditions.isMCFastOverVerifier && - cConditions.isMCFastOverVerifier) - // - ; - - // - if (isMCBullish) - { - longVerifications++; - } - - // - bool isMCBearish = - // - (hConditions.isMCFastUnderSlow && - lConditions.isMCFastUnderSlow && - mConditions.isMCFastUnderSlow && - sConditions.isMCFastUnderSlow && - cConditions.isMCFastUnderSlow) - // - || - // - (hConditions.isMCFastUnderVerifier && - lConditions.isMCFastUnderVerifier && - mConditions.isMCFastUnderVerifier && - sConditions.isMCFastUnderVerifier && - cConditions.isMCFastUnderVerifier) - // - ; - - // - if (isMCBearish) - { - shortVerifications++; - } - - // - // XMRB ... - - // - bool isMRBBullish = - // - (hConditions.isMRBFastOverSlow && - lConditions.isMRBFastOverSlow && - mConditions.isMRBFastOverSlow && - sConditions.isMRBFastOverSlow && - cConditions.isMRBFastOverSlow) - // - || - // - (hConditions.isMRBFastOverVerifier && - lConditions.isMRBFastOverVerifier && - mConditions.isMRBFastOverVerifier && - sConditions.isMRBFastOverVerifier && - cConditions.isMRBFastOverVerifier) - // - || - // - (hConditions.isMRBSlowOverVerifier && - lConditions.isMRBSlowOverVerifier && - mConditions.isMRBSlowOverVerifier && - sConditions.isMRBSlowOverVerifier && - cConditions.isMRBSlowOverVerifier) - // - ; - - // - if (isMRBBullish) - { - longVerifications++; - } - - // - bool isMRBBearish = - // - (hConditions.isMRBFastUnderSlow && - lConditions.isMRBFastUnderSlow && - mConditions.isMRBFastUnderSlow && - sConditions.isMRBFastUnderSlow && - cConditions.isMRBFastUnderSlow) - // - || - // - (hConditions.isMRBFastUnderVerifier && - lConditions.isMRBFastUnderVerifier && - mConditions.isMRBFastUnderVerifier && - sConditions.isMRBFastUnderVerifier && - cConditions.isMRBFastUnderVerifier) - // - || - // - (hConditions.isMRBSlowUnderVerifier && - lConditions.isMRBSlowUnderVerifier && - mConditions.isMRBSlowUnderVerifier && - sConditions.isMRBSlowUnderVerifier && - cConditions.isMRBSlowUnderVerifier) - // - ; - - // - if (isMRBBearish) - { - shortVerifications++; - } - - // - // X786 ... - - // - bool isX786CLong = - // - (cConditions.isSMHKSwitchedToBullish && - (cConditions.isTDBullish && - cConditions.isCHEBullish && - cConditions.isTrendBullish)) - // - || - // - (cConditions.isTDSwitchedToBullish && - (cConditions.isSMHKBullish && - cConditions.isCHEBullish && - cConditions.isTrendBullish)) - // - || - // - (cConditions.isCHESwitchedToBullish && - (cConditions.isTDBullish && - cConditions.isSMHKBullish && - cConditions.isTrendBullish)) - // - || - // - (cConditions.isTrendSwitchedToBullish && - (cConditions.isTDBullish && - cConditions.isCHEBullish && - cConditions.isSMHKBullish)) - // - ; - - // - if (isX786CLong) - { - xLongVerifications++; - } - - // - bool isX786SLong = - // - (sConditions.isSMHKSwitchedToBullish && - (sConditions.isTDBullish && - sConditions.isCHEBullish && - sConditions.isTrendBullish)) - // - || - // - (sConditions.isTDSwitchedToBullish && - (sConditions.isSMHKBullish && - sConditions.isCHEBullish && - sConditions.isTrendBullish)) - // - || - // - (sConditions.isCHESwitchedToBullish && - (sConditions.isTDBullish && - sConditions.isSMHKBullish && - sConditions.isTrendBullish)) - // - || - // - (sConditions.isTrendSwitchedToBullish && - (sConditions.isTDBullish && - sConditions.isCHEBullish && - sConditions.isSMHKBullish)) - // - ; - - // - if (isX786SLong) - { - xLongVerifications++; - } - - // - bool isX786MLong = - // - (mConditions.isSMHKSwitchedToBullish && - (mConditions.isTDBullish && - mConditions.isCHEBullish && - mConditions.isTrendBullish)) - // - || - // - (mConditions.isTDSwitchedToBullish && - (mConditions.isSMHKBullish && - mConditions.isCHEBullish && - mConditions.isTrendBullish)) - // - || - // - (mConditions.isCHESwitchedToBullish && - (mConditions.isTDBullish && - mConditions.isSMHKBullish && - mConditions.isTrendBullish)) - // - || - // - (mConditions.isTrendSwitchedToBullish && - (mConditions.isTDBullish && - mConditions.isCHEBullish && - mConditions.isSMHKBullish)) - // - ; - - // - if (isX786MLong) - { - xLongVerifications++; - } - - // - bool isX786LLong = - // - (lConditions.isSMHKSwitchedToBullish && - (lConditions.isTDBullish && - lConditions.isCHEBullish && - lConditions.isTrendBullish)) - // - || - // - (lConditions.isTDSwitchedToBullish && - (lConditions.isSMHKBullish && - lConditions.isCHEBullish && - lConditions.isTrendBullish)) - // - || - // - (lConditions.isCHESwitchedToBullish && - (lConditions.isTDBullish && - lConditions.isSMHKBullish && - lConditions.isTrendBullish)) - // - || - // - (lConditions.isTrendSwitchedToBullish && - (lConditions.isTDBullish && - lConditions.isCHEBullish && - lConditions.isSMHKBullish)) - // - ; - - // - if (isX786LLong) - { - xLongVerifications++; - } - - // - bool isX786HLong = - // - (hConditions.isSMHKSwitchedToBullish && - (hConditions.isTDBullish && - hConditions.isCHEBullish && - hConditions.isTrendBullish)) - // - || - // - (hConditions.isTDSwitchedToBullish && - (hConditions.isSMHKBullish && - hConditions.isCHEBullish && - hConditions.isTrendBullish)) - // - || - // - (hConditions.isCHESwitchedToBullish && - (hConditions.isTDBullish && - hConditions.isSMHKBullish && - hConditions.isTrendBullish)) - // - || - // - (hConditions.isTrendSwitchedToBullish && - (hConditions.isTDBullish && - hConditions.isCHEBullish && - hConditions.isSMHKBullish)) - // - ; - - // - if (isX786HLong) - { - xLongVerifications++; - } - - // - bool isX786CShort = - // - (cConditions.isSMHKSwitchedToBearish && - (cConditions.isTDBearish && - cConditions.isCHEBearish && - cConditions.isTrendBearish)) - // - || - // - (cConditions.isTDSwitchedToBearish && - (cConditions.isSMHKBearish && - cConditions.isCHEBearish && - cConditions.isTrendBearish)) - // - || - // - (cConditions.isCHESwitchedToBearish && - (cConditions.isTDBearish && - cConditions.isSMHKBearish && - cConditions.isTrendBearish)) - // - || - // - (cConditions.isTrendSwitchedToBearish && - (cConditions.isTDBearish && - cConditions.isCHEBearish && - cConditions.isSMHKBearish)) - // - ; - - // - if (isX786CShort) - { - xShortVerifications++; - } - - // - bool isX786SShort = - // - (sConditions.isSMHKSwitchedToBearish && - (sConditions.isTDBearish && - sConditions.isCHEBearish && - sConditions.isTrendBearish)) - // - || - // - (sConditions.isTDSwitchedToBearish && - (sConditions.isSMHKBearish && - sConditions.isCHEBearish && - sConditions.isTrendBearish)) - // - || - // - (sConditions.isCHESwitchedToBearish && - (sConditions.isTDBearish && - sConditions.isSMHKBearish && - sConditions.isTrendBearish)) - // - || - // - (sConditions.isTrendSwitchedToBearish && - (sConditions.isTDBearish && - sConditions.isCHEBearish && - sConditions.isSMHKBearish)) - // - ; - - // - if (isX786SShort) - { - xShortVerifications++; - } - - // - bool isX786MShort = - // - (mConditions.isSMHKSwitchedToBearish && - (mConditions.isTDBearish && - mConditions.isCHEBearish && - mConditions.isTrendBearish)) - // - || - // - (mConditions.isTDSwitchedToBearish && - (mConditions.isSMHKBearish && - mConditions.isCHEBearish && - mConditions.isTrendBearish)) - // - || - // - (mConditions.isCHESwitchedToBearish && - (mConditions.isTDBearish && - mConditions.isSMHKBearish && - mConditions.isTrendBearish)) - // - || - // - (mConditions.isTrendSwitchedToBearish && - (mConditions.isTDBearish && - mConditions.isCHEBearish && - mConditions.isSMHKBearish)) - // - ; - - // - if (isX786MShort) - { - xShortVerifications++; - } - - // - bool isX786LShort = - // - (lConditions.isSMHKSwitchedToBearish && - (lConditions.isTDBearish && - lConditions.isCHEBearish && - lConditions.isTrendBearish)) - // - || - // - (lConditions.isTDSwitchedToBearish && - (lConditions.isSMHKBearish && - lConditions.isCHEBearish && - lConditions.isTrendBearish)) - // - || - // - (lConditions.isCHESwitchedToBearish && - (lConditions.isTDBearish && - lConditions.isSMHKBearish && - lConditions.isTrendBearish)) - // - || - // - (lConditions.isTrendSwitchedToBearish && - (lConditions.isTDBearish && - lConditions.isCHEBearish && - lConditions.isSMHKBearish)) - // - ; - - // - if (isX786LShort) - { - xShortVerifications++; - } - - // - bool isX786HShort = - // - (hConditions.isSMHKSwitchedToBearish && - (hConditions.isTDBearish && - hConditions.isCHEBearish && - hConditions.isTrendBearish)) - // - || - // - (hConditions.isTDSwitchedToBearish && - (hConditions.isSMHKBearish && - hConditions.isCHEBearish && - hConditions.isTrendBearish)) - // - || - // - (hConditions.isCHESwitchedToBearish && - (hConditions.isTDBearish && - hConditions.isSMHKBearish && - hConditions.isTrendBearish)) - // - || - // - (hConditions.isTrendSwitchedToBearish && - (hConditions.isTDBearish && - hConditions.isCHEBearish && - hConditions.isSMHKBearish)) - // - ; - - // - if (isX786HShort) - { - xShortVerifications++; - } - - // - Add( - xLongVerifications, - longVFBuffer // - ); - - // - Add( - xShortVerifications, - shortVFBuffer // - ); -} - -// -void HandleSignalDetection() -{ - // - // Define Using Variables ... - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - - // - // Define Global Variables ... - double r2r = 1.5; - double tpPrice = 0; - double slPrice = 0; - bool hasLong = false; - bool hasShort = false; - bool hasSignal = false; - - // - double scroeDetectionMultiplier = 2; - double verificationDetectionCount = 4; - - // - if (ArraySize(bullishBuffer) < 3) - { - return; - } - - // - // Set Arrays As Series ... - ArraySetAsSeries(bullishBuffer, true); - ArraySetAsSeries(bearishBuffer, true); - ArraySetAsSeries(longVFBuffer, true); - ArraySetAsSeries(shortVFBuffer, true); - - // - bool isZScoreBullish = bullishBuffer[zIndex] > - bearishBuffer[zIndex] * scroeDetectionMultiplier; - // - bool isCScoreBullish = bullishBuffer[cIndex] > - bearishBuffer[cIndex] * scroeDetectionMultiplier; - // - bool isPScoreBullish = bullishBuffer[pIndex] > - bearishBuffer[pIndex] * scroeDetectionMultiplier; - - // - bool isZScoreBearish = bearishBuffer[zIndex] > - bullishBuffer[zIndex] * scroeDetectionMultiplier; - // - bool isCScoreBearish = bearishBuffer[cIndex] > - bullishBuffer[cIndex] * scroeDetectionMultiplier; - // - bool isPScoreBearish = bearishBuffer[pIndex] > - bullishBuffer[pIndex] * scroeDetectionMultiplier; - - // - bool isZLongVerificationsBullish = longVFBuffer[zIndex] > longVFBuffer[cIndex] && - longVFBuffer[zIndex] > shortVFBuffer[cIndex] && - longVFBuffer[cIndex] >= verificationDetectionCount; - - // - bool isCLongVerificationsBullish = longVFBuffer[cIndex] > longVFBuffer[pIndex] && - longVFBuffer[cIndex] > shortVFBuffer[pIndex] && - longVFBuffer[pIndex] >= verificationDetectionCount; - - // - bool isZShortVerificationsBearish = shortVFBuffer[zIndex] > shortVFBuffer[cIndex] && - shortVFBuffer[zIndex] > longVFBuffer[cIndex] && - shortVFBuffer[cIndex] >= verificationDetectionCount; - - // - bool isCShortVerificationsBearish = shortVFBuffer[cIndex] > shortVFBuffer[pIndex] && - shortVFBuffer[cIndex] > longVFBuffer[pIndex] && - shortVFBuffer[pIndex] >= verificationDetectionCount; - - // - bool lookingLong = - // - isZScoreBullish - // - || - // - (isZLongVerificationsBullish && - !isCLongVerificationsBullish) - // - ; - - // - bool lookingShort = - // - isZScoreBearish - // - || - // - (isZShortVerificationsBearish && - !isCShortVerificationsBearish) - // - ; - - // - if (lookingLong) - { - // - bool cHasX786 = cMarket.HasX786LongConditions(); - bool sHasX786 = sMarket.HasX786LongConditions(); - bool mHasX786 = mMarket.HasX786LongConditions(); - bool lHasX786 = lMarket.HasX786LongConditions(); - bool hHasX786 = hMarket.HasX786LongConditions(); - - // - double cMarketSL = cMarket.don.GetLowerH(cIndex); - double sMarketSL = sMarket.don.GetLowerH(cIndex); - double mMarketSL = mMarket.don.GetLowerH(cIndex); - double lMarketSL = lMarket.don.GetLowerH(cIndex); - double hMarketSL = hMarket.don.GetLowerH(cIndex); - - // - bool condition1 = - // - ((cHasX786 && - sHasX786 && - mHasX786) - // - || - // - (cHasX786 && - mHasX786 && - lHasX786)) - // - ; - - // - bool condition2 = - // - ((sHasX786 && - mHasX786 && - lHasX786) - // - || - // - (sHasX786 && - lHasX786 && - hHasX786)) - // - ; - - // - bool condition3 = - // - ((mHasX786 && - lHasX786 && - hHasX786) - // - || - // - (mHasX786 && - hHasX786 && - sHasX786)) - // - ; - - // - bool condition4 = - // - (lHasX786 && - hHasX786 && - mHasX786) - // - ; - - // - bool condition5 = (isZLongVerificationsBullish && - !isCLongVerificationsBullish); - - // - if (condition1) - { - // - double sls[] = { - cMarketSL, - sMarketSL, - mMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition2) - { - // - double sls[] = { - sMarketSL, - mMarketSL, - lMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition3) - { - // - double sls[] = { - mMarketSL, - lMarketSL, - hMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition4) - { - // - double sls[] = { - lMarketSL, - hMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition5) - { - slPrice = sMarketSL; - } - - // - hasLong = - // - condition1 - // - || - // - condition2 - // - || - // - condition3 - // - || - // - condition4 - // - || - // - condition5 - // - ; - } - else if (lookingShort) - { - // - bool cHasX786 = cMarket.HasX786ShortConditions(); - bool sHasX786 = sMarket.HasX786ShortConditions(); - bool mHasX786 = mMarket.HasX786ShortConditions(); - bool lHasX786 = lMarket.HasX786ShortConditions(); - bool hHasX786 = hMarket.HasX786ShortConditions(); - - // - double cMarketSL = cMarket.don.GetUpperL(cIndex); - double sMarketSL = sMarket.don.GetUpperL(cIndex); - double mMarketSL = mMarket.don.GetUpperL(cIndex); - double lMarketSL = lMarket.don.GetUpperL(cIndex); - double hMarketSL = hMarket.don.GetUpperL(cIndex); - - // - bool condition1 = - // - ((cHasX786 && - sHasX786) - // - || - // - (cHasX786 && - mHasX786)) - // - ; - - // - bool condition2 = - // - ((sHasX786 && - mHasX786) - // - || - // - (sHasX786 && - lHasX786)) - // - ; - - // - bool condition3 = - // - ((mHasX786 && - lHasX786) - // - || - // - (mHasX786 && - hHasX786)) - // - ; - - // - bool condition4 = - // - (lHasX786 && - hHasX786) - // - ; - - // - bool condition5 = (isZShortVerificationsBearish && - !isCShortVerificationsBearish); - - // - if (condition1) - { - // - double sls[] = { - cMarketSL, - sMarketSL, - mMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition2) - { - // - double sls[] = { - sMarketSL, - mMarketSL, - lMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition3) - { - // - double sls[] = { - mMarketSL, - lMarketSL, - hMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition4) - { - // - double sls[] = { - lMarketSL, - hMarketSL // - }; - - // - slPrice = GetAverage(sls); - } - else if (condition5) - { - slPrice = sMarketSL; - } - - // - hasShort = - // - condition1 - // - || - // - condition2 - // - || - // - condition3 - // - || - // - condition4 - // - || - // - condition5 - // - ; - - // // - // XPivot pivot; - // pivot.pivot = pivotPrice; - - // // - // DrawPivot( - // pivot, - // clrOrange // - // ); - } - - // - // Set Arrays As Series ... - ArraySetAsSeries(bullishBuffer, false); - ArraySetAsSeries(bearishBuffer, false); - ArraySetAsSeries(longVFBuffer, false); - ArraySetAsSeries(shortVFBuffer, false); - - // - // Handle Signal Generating ... - hasSignal = hasLong || hasShort; - if (!hasSignal) - { - return; - } - - // - // Generate Signal ... - - // - ENUM_POSITION_TYPE mType = - hasLong - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; - - // - double mEntry = GetEntry( - xSampleEASymbol, - mType // - ); - - // - double mSL = 0; - double mTP = 0; - CalculateTPSL( - mSL, - mTP, - mType, - mEntry, - r2r, - slPrice // - ); - - // - if (mTP == 0 && mSL == 0) - { - Print("Zero"); - } - - // - lastBullishPivot = - hasLong - ? slPrice - : lastBullishPivot; - lastBearishPivot = - hasShort - ? slPrice - : lastBearishPivot; - // - XSignal signal; - bool isPrepared = signal.Prepare( - xSampleEASymbol, - "X92", - xSampleEAPeriod, - mType, - X_ORDER_MODE_MARKET, - mEntry, - 0.01, - mSL, - mTP // - ); - - // - if (isPrepared) - { - // - AddRef( - signal, - mSignals // - ); - } -} - -// -// Execute Signals ... -void HandleSignalExecution() -{ - // - int signalsCount = ArraySize(mSignals); - if (!IsValidSize(signalsCount)) - { - return; - } - - // - XSignal tmp[]; - Copy( - mSignals, - tmp // - ); - - // - for (int i = 0; i < signalsCount; i++) - { - // - XSignal iSignal = tmp[i]; - - // - if (!iSignal.IsValid()) - { - continue; - } - - // - // TODO: - // Validate Signal Execution based on lastTradeOn ... - - // - ENUM_X_SIGNAL_EXECUTION_RESULT state; - bool isExecuted = mTrader.ExecuteSignal( - iSignal, - state // - ); - if (isExecuted) - { - // - // Remove Signal from mSignals ... - - // - bool isRemoved = ArrayRemove( - mSignals, - i, - 1 // - ); - - // - if (isRemoved) - { - // - string message = "Signal Executed Successfully ..."; - - // - mAlert.Alert(message); - - // - long chartID = ChartID(); - - // - iSignal.Draw( - chartID // - ); - - // - // Remove Drawn Pivot ... - RemovePivotDraw(lastPeak); - RemovePivotDraw(lastVale); - RemovePivotDraw(lastSupport); - RemovePivotDraw(lastResistance); - - // - lastPeak = 0; - lastVale = 0; - lastSupport = 0; - lastResistance = 0; - mPivotTracker.Clean(); - - // - // Check Last Trade ON ... - lastTradeOn = - // - TimeCurrent() - // - ; - - // - // Detect All In Profit Positions and Trail their Stops ... - XPosition positions[]; - int positionsCount = mTrader.GetInProfitPositions( - positions, - iSignal.symbol, - iSignal.provider, - iSignal.period, - iSignal.type // - ); - if (IsValidSize(positionsCount)) - { - // - // Trial Stops ... - for (int i = 0; i < positionsCount; i++) - { - // - XPosition iPosition = positions[i]; - if (iPosition.ticket == iSignal.positionId) - { - continue; - } - - // - string comment = "Modify SL ..."; - - // - bool isLong = IsLong(iPosition.type); - double slDiff = PointToPrice(30, iPosition.symbol); - double sl = iSignal.entry + (isLong - ? -1 * slDiff - : slDiff); - sl = MathMin(sl, iPosition.sl); - // XPivot slPivot; - // slPivot.pivot = sl; - // DrawPivot( - // slPivot, - // clrAqua // - // ); - - // - bool isModified = mTrader.Modify( - iPosition.ticket, - sl, - iPosition.tp, - comment // - ); - - // - if (isModified) - { - mAlert.Alert(comment); - } - } - } - } - } - } -} - -// -void HandleDrawPivots() -{ - // - // return; - bool hasChild = mPivotTracker.HasChild(); - if (!hasChild) - { - return; - } - - // - int pivotsCount = mPivotTracker.Count(); - - // - for (int i = 0; i < pivotsCount; i++) - { - // - XPivot iPivot = mPivotTracker.GetPivot(i); - if (!iPivot.IsValid()) - { - continue; - } - - // - DrawPivot(iPivot); - } -} - -// -void RemovePivotDraw(double pivot) -{ - // - if (pivot <= 0) - { - return; - } - - // - long chartID = ChartID(); - - // - string pPrefix = "P_" + - ToString(pivot); - - // - if (!IsDrawExists(pPrefix)) - { - return; - } - - // - RemoveDraw(pPrefix); -} - -// -void DrawPivot( - XPivot &pivot, - color crl = clrLime // -) -{ - // - if (!pivot.IsValid()) - { - return; - } - - // - long chartID = ChartID(); - datetime time1 = iTime( - xSampleEASymbol, - xSampleEAPeriod, - 2 // - ); - datetime time = iTime( - xSampleEASymbol, - xSampleEAPeriod, - 0 // - ); - - // - bool currentPrice = MathMax(xSampleEATick.ask, xSampleEATick.bid); - - // - string pPrefix = "P_" + - ToString(pivot.pivot); - - // - // RemoveDraws(pPrefix); - - // - if (IsDrawExists(pPrefix)) - { - return; - } - - // - DrawTrendLine( - chartID, - pPrefix, - 0, - time1, - pivot.pivot, - time, - pivot.pivot, - crl, - STYLE_SOLID, - 2, - false, - false, - true // - ); -} - -// -void ConfigureCurrentCycles() -{ - - // - // XHK ... - hkInputs.drawHikenAshi = false; - hkInputs.drawSmoothedHikenAshi = false; - - // - // XMRB ... - mrbInputs.showFastMa = false; - mrbInputs.showSlowMa = false; - mrbInputs.showRibbon = false; - - // - // XMC ... - mcInputs.showFastMa = false; - mcInputs.showSlowMa = false; - mcInputs.showVerifierMa = false; - - // - // XICH ... - ichInputs.showKumo = false; - ichInputs.showKijunSen = false; - ichInputs.showTenkanSen = false; - ichInputs.showChikouSpan = false; - ichInputs.showSenkouSpanA = false; - ichInputs.showSenkouSpanB = false; - ichInputs.showKijunSenPlus = false; - ichInputs.showKijunSenNegative = false; - - // - // XCHE ... - cheInputs.showLongExit1Line = true; - cheInputs.showShortExit1Line = true; - cheInputs.showLongExit2Line = true; - cheInputs.showShortExit2Line = true; - - // - // XPV ... - pvInputs.showPeaksAndVales = true; - pvInputs.showLevels = false; - pvInputs.showConsolidations = false; - pvInputs.showFibo1Levels = false; - pvInputs.showFibo2Levels = false; - pvInputs.showFibo3Levels = false; - pvInputs.showFibo4Levels = false; - pvInputs.showFibo5Levels = false; - - // - // XZG ... - zgInputs.showZigZag = false; - zgInputs.showPeaksAndVales = true; - - // - // XDON ... - donInputs.showOpen = false; - donInputs.showHigh = false; - donInputs.showClose = false; - donInputs.showLow = false; - - // - // XSTR ... - strInputs.showTrends = false; - strInputs.fillTrends = false; -} - -// -void ConfigureShortCycles() {} - -// -void ConfigureMediumCycles() {} - -// -void ConfigureLongCycles() {} - -// -void ConfigureHindCycles() {} - -// -// Add Score ... -void AddBullishScroe() -{ - // -} - -// \ No newline at end of file diff --git a/Experts/x-test.x121ea.mq5 b/Experts/x-test.x121ea.mq5 index 8d5e0cb4..2242a4ee 100644 --- a/Experts/x-test.x121ea.mq5 +++ b/Experts/x-test.x121ea.mq5 @@ -24,6 +24,7 @@ // #include "../Classes/x-saherelm.x121.xea.class.mq5" +#include "../Signallers/x-saherelm.x110.signaller.class.mq5" #include "../Signallers/x-saherelm.x121.signaller.class.mq5" #include "../Signallers/x-saherelm.x786.signaller.class.mq5" @@ -234,21 +235,33 @@ bool InitialEA() Clean(iDescriptor.signallers); // - ArrayResize(iDescriptor.signallers, 2); + ArrayResize(iDescriptor.signallers, 3); // // X786 Signaller ... X786Signaller *x786Signaller = new X786Signaller(); x786Signaller.Default(); + x786Signaller.allowLong = false; // x121EAAllowLong; + x786Signaller.allowShort = false; // x121EAAllowShort; // // X121 Signaller ... X121Signaller *x121Signaller = new X121Signaller(); x121Signaller.Default(); + x121Signaller.allowLong = false; // x121EAAllowLong; + x121Signaller.allowShort = false; // x121EAAllowShort; + + // + // X110 Signaller ... + X110Signaller *x110Signaller = new X110Signaller(); + x110Signaller.Default(); + x110Signaller.allowLong = x121EAAllowLong; + x110Signaller.allowShort = x121EAAllowShort; // iDescriptor.signallers[0] = x786Signaller; iDescriptor.signallers[1] = x121Signaller; + iDescriptor.signallers[2] = x110Signaller; // // Set Inputs to Default ... @@ -988,17 +1001,7 @@ void ApplyPreDefineConfigurations(X121ProviderDescriptor &iDescriptor) // bool isX786 = false; bool isX121 = false; - - - // - // XHULL ... - iDescriptor.inputs.hullInputs.showUpZone = false; - iDescriptor.inputs.hullInputs.showDownZone = false; - - // - // XSSLC ... - iDescriptor.inputs.sslcInputs.showUp = false; - iDescriptor.inputs.sslcInputs.showDown = false; + bool isX110 = false; // if (isX786) @@ -1007,22 +1010,38 @@ void ApplyPreDefineConfigurations(X121ProviderDescriptor &iDescriptor) // if (isX121) + { + } + + // + if (isX110) { // - iDescriptor.inputs.mrbInputs.showFastMa = isX121; - iDescriptor.inputs.mrbInputs.showSlowMa = isX121; - iDescriptor.inputs.mrbInputs.showRibbon = isX121; + iDescriptor.inputs.strInputs.showTrends = isX110; // - iDescriptor.inputs.mcInputs.showFastMa = isX121; - iDescriptor.inputs.mcInputs.showSlowMa = isX121; - iDescriptor.inputs.mcInputs.showVerifierMa = isX121; + iDescriptor.inputs.mcInputs.showVerifierMa = isX110; // - iDescriptor.inputs.cheInputs.showLongExit1Line = isX121; - iDescriptor.inputs.cheInputs.showShortExit1Line = isX121; - iDescriptor.inputs.cheInputs.showLongExit2Line = isX121; - iDescriptor.inputs.cheInputs.showShortExit2Line = isX121; + iDescriptor.inputs.ichInputs.showKumo = isX110; + iDescriptor.inputs.ichInputs.showKijunSen = isX110; + iDescriptor.inputs.ichInputs.showTenkanSen = isX110; + iDescriptor.inputs.ichInputs.showSenkouSpanA = isX110; + iDescriptor.inputs.ichInputs.showSenkouSpanB = isX110; + + // + iDescriptor.inputs.cheInputs.showLongExit1Line = isX110; + iDescriptor.inputs.cheInputs.showShortExit1Line = isX110; + iDescriptor.inputs.cheInputs.showLongExit2Line = isX110; + iDescriptor.inputs.cheInputs.showShortExit2Line = isX110; + + // + iDescriptor.inputs.pvInputs.showPeaksAndVales = isX110; + iDescriptor.inputs.pvInputs.showFibo1Levels = isX110; + iDescriptor.inputs.pvInputs.showFibo2Levels = isX110; + iDescriptor.inputs.pvInputs.showFibo3Levels = isX110; + iDescriptor.inputs.pvInputs.showFibo4Levels = isX110; + iDescriptor.inputs.pvInputs.showFibo5Levels = isX110; } } diff --git a/Helpers/x-saherelm.xich.helper.mq5 b/Helpers/x-saherelm.xich.helper.mq5 index 3a1dcf97..bb44a0dc 100644 --- a/Helpers/x-saherelm.xich.helper.mq5 +++ b/Helpers/x-saherelm.xich.helper.mq5 @@ -241,6 +241,8 @@ public: ArraySetAsSeries(chikouSpanBuffer, true); ArraySetAsSeries(senkouSpanABuffer, true); ArraySetAsSeries(senkouSpanBBuffer, true); + ArraySetAsSeries(futureSenkouSpanABuffer, true); + ArraySetAsSeries(futureSenkouSpanBBuffer, true); // mHandler = iCustom( @@ -507,21 +509,6 @@ public: int barIndex // Bar Index ) { - // - barIndex += mInputs.kijunSenLength; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex > ArraySize(senkouSpanABuffer)) - { - barIndex = ArraySize(senkouSpanABuffer) - 1; - } - // Calculate(); @@ -545,7 +532,7 @@ public: // // Copy Items ... return Copy( - start + mInputs.kijunSenLength, + start, count, senkouSpanABuffer, buffer, @@ -580,21 +567,6 @@ public: int barIndex // Bar Index ) { - // - barIndex += mInputs.kijunSenLength; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex > ArraySize(senkouSpanBBuffer)) - { - barIndex = ArraySize(senkouSpanBBuffer) - 1; - } - // Calculate(); @@ -618,7 +590,7 @@ public: // // Copy Items ... return Copy( - start + mInputs.kijunSenLength, + start, count, senkouSpanBBuffer, buffer, @@ -654,10 +626,7 @@ public: ) { // - if (barIndex < 0) - { - barIndex = 0; - } + barIndex -= mInputs.kijunSenLength; // Calculate(); @@ -682,9 +651,9 @@ public: // // Copy Items ... return Copy( - start, + start - mInputs.kijunSenLength, count, - senkouSpanABuffer, + futureSenkouSpanABuffer, buffer, forceClean // @@ -692,7 +661,7 @@ public: } // - // SenkouSpanB ... + // Future SenkouSpanB ... // double GetFutureSenkouSpanB( @@ -700,10 +669,7 @@ public: ) { // - if (barIndex < 0) - { - barIndex = 0; - } + barIndex -= mInputs.kijunSenLength; // Calculate(); @@ -728,9 +694,9 @@ public: // // Copy Items ... return Copy( - start, + start - mInputs.kijunSenLength, count, - senkouSpanBBuffer, + futureSenkouSpanBBuffer, buffer, forceClean // @@ -754,6 +720,8 @@ private: double chikouSpanBuffer[]; double senkouSpanABuffer[]; double senkouSpanBBuffer[]; + double futureSenkouSpanABuffer[]; + double futureSenkouSpanBBuffer[]; // // Tools ... @@ -820,6 +788,28 @@ private: senkouSpanBBuffer // ); + + // + // SenkouSpan A ... + CopyBuffer( + mHandler, + X_ICH_SENKOUSPANA_LINE, + 0 - mInputs.kijunSenLength, + totalBars, + futureSenkouSpanABuffer + // + ); + + // + // SenkouSpan B ... + CopyBuffer( + mHandler, + X_ICH_SENKOUSPANB_LINE, + 0 - mInputs.kijunSenLength, + totalBars, + futureSenkouSpanBBuffer + // + ); } }; diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 198f494c..a78067bd 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -5780,7 +5780,8 @@ int Copy( int count, // Number of Items for read T &source[], // Source Buffer T &dest[], // Dest Buffer - bool forceClean = true // Force To Clean buffer + bool forceClean = true, // Force To Clean buffer + bool forceStart = true // Force To Clean buffer ) { // @@ -5793,7 +5794,7 @@ int Copy( } // - if (start < 0) + if (start < 0 && forceStart) { start = 0; } diff --git a/Signallers/x-saherelm.x110.signaller.class.mq5 b/Signallers/x-saherelm.x110.signaller.class.mq5 new file mode 100644 index 00000000..976272b1 --- /dev/null +++ b/Signallers/x-saherelm.x110.signaller.class.mq5 @@ -0,0 +1,314 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: X110Signaller +// Description: Signalling using X121 rules ... +// +// +// 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 "../Libraries/x-saherelm.xtrade.lib.mq5" +#include "../Classes/x-saherelm.x121.xmcycle.class.mq5" + +// +// Definitions ... + +// +// Class ... +class X110Signaller : public XSignallerDescriptor +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor(s) ... + void X110Signaller() + { + name = X110; + Default(); + } + + // + // Deconstructor ... + void ~X110Signaller() {} + + // + // Override(s) ... + + // + bool HasLongConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) override + { + // + bool result = false; + + // + sl = 0; + tp = 0; + + // + result = allowLong; + if (!result) + { + return result; + } + + // + bool isCloseOverSenkouSpanA = conditions.bars[1].close > conditions.ichSenkouSpanAs[1]; + + // + bool isBaseBullish = isCloseOverSenkouSpanA && + conditions.isSenkouSpanAOverB && + conditions.isSenkouSpanAOverLast; + + // + bool isKijunSenOverSenkouSpanA = conditions.ichKijunSens[1] > conditions.ichSenkouSpanAs[1]; + + // + bool isCloseOverTenkanSen = conditions.bars[1].close > conditions.ichTenkanSens[1]; + + // + bool isPriceCloseCrossedUpTenkanSen = conditions.bars[2].close <= conditions.ichTenkanSens[2] && + conditions.bars[1].close > conditions.ichTenkanSens[1]; + + // + double cKumoUpper = MathMax(conditions.ichSenkouSpanAs[1], conditions.ichSenkouSpanBs[1]); + double pKumoUpper = MathMax(conditions.ichSenkouSpanAs[2], conditions.ichSenkouSpanBs[2]); + + // + double cKumoLower = MathMin(conditions.ichSenkouSpanAs[1], conditions.ichSenkouSpanBs[1]); + double pKumoLower = MathMin(conditions.ichSenkouSpanAs[2], conditions.ichSenkouSpanBs[2]); + + // + bool isTenkanSenOverKumo = conditions.ichTenkanSens[1] > cKumoUpper; + bool isTenkanSenOverKumoPrev = conditions.ichTenkanSens[2] > pKumoUpper; + + // + bool isTenkanSenUnderKumo = conditions.ichTenkanSens[1] < cKumoLower; + bool isTenkanSenUnderKumoPrev = conditions.ichTenkanSens[2] < pKumoLower; + + // + bool isTenkanSenCrossedOverKumo = isTenkanSenOverKumo && + !isTenkanSenOverKumoPrev; + + // + bool isTenkanSenCrossedUnderKumo = isTenkanSenUnderKumo && + !isTenkanSenUnderKumoPrev; + + // + bool condition1 = + isBaseBullish && + isCloseOverTenkanSen && + isKijunSenOverSenkouSpanA && + conditions.isTenkanSenCrossedOverKijunSen; + + // + bool condition2 = + isBaseBullish && + isCloseOverTenkanSen && + isKijunSenOverSenkouSpanA && + conditions.isTenkanSenOverKijunSen && + conditions.isSenkouSpanACrossedOverB; + + // + bool condition3 = + isBaseBullish && + isKijunSenOverSenkouSpanA && + isPriceCloseCrossedUpTenkanSen && + conditions.isTenkanSenOverKijunSen; + + // + bool condition4 = + isCloseOverTenkanSen && + isTenkanSenCrossedOverKumo && + conditions.isTenkanSenOverKijunSen && + conditions.isFutureSenkouSpanAOverB && + conditions.isFutureSenkouSpanAOverLast; + + // + result = + // + condition1 + // + || + // + condition2 + // + || + // + condition3 + // + || + // + condition4 + // + ; + + // + if (result) + { + sl = conditions.ichSenkouSpanBs[1]; + } + + // + return result; + } + + // + bool HasShortConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) override + { + // + bool result = false; + + // + sl = 0; + tp = 0; + + // + result = allowLong; + if (!result) + { + return result; + } + + // + bool isCloseUnderSenkouSpanB = conditions.bars[1].close < conditions.ichSenkouSpanBs[1]; + + // + bool isBaseBearish = isCloseUnderSenkouSpanB && + conditions.isSenkouSpanAUnderB && + conditions.isSenkouSpanAUnderLast; + + // + bool isKijunSenUnderSenkouSpanB = conditions.ichKijunSens[1] < conditions.ichSenkouSpanBs[1]; + + // + bool isCloseUnderTenkanSen = conditions.bars[1].close < conditions.ichTenkanSens[1]; + + // + bool isPriceCloseCrossedDownTenkanSen = conditions.bars[2].close >= conditions.ichTenkanSens[2] && + conditions.bars[1].close < conditions.ichTenkanSens[1]; + + // + double cKumoUpper = MathMax(conditions.ichSenkouSpanAs[1], conditions.ichSenkouSpanBs[1]); + double pKumoUpper = MathMax(conditions.ichSenkouSpanAs[2], conditions.ichSenkouSpanBs[2]); + + // + double cKumoLower = MathMin(conditions.ichSenkouSpanAs[1], conditions.ichSenkouSpanBs[1]); + double pKumoLower = MathMin(conditions.ichSenkouSpanAs[2], conditions.ichSenkouSpanBs[2]); + + // + bool isTenkanSenOverKumo = conditions.ichTenkanSens[1] > cKumoUpper; + bool isTenkanSenOverKumoPrev = conditions.ichTenkanSens[2] > pKumoUpper; + + // + bool isTenkanSenUnderKumo = conditions.ichTenkanSens[1] < cKumoLower; + bool isTenkanSenUnderKumoPrev = conditions.ichTenkanSens[2] < pKumoLower; + + // + bool isTenkanSenCrossedOverKumo = isTenkanSenOverKumo && + !isTenkanSenOverKumoPrev; + + // + bool isTenkanSenCrossedUnderKumo = isTenkanSenUnderKumo && + !isTenkanSenUnderKumoPrev; + + // + bool condition1 = + isBaseBearish && + isCloseUnderTenkanSen && + isKijunSenUnderSenkouSpanB && + conditions.isTenkanSenCrossedUnderKijunSen; + + // + bool condition2 = + isBaseBearish && + isCloseUnderTenkanSen && + isKijunSenUnderSenkouSpanB && + conditions.isTenkanSenUnderKijunSen && + conditions.isSenkouSpanACrossedUnderB; + + // + bool condition3 = + isBaseBearish && + isKijunSenUnderSenkouSpanB && + isPriceCloseCrossedDownTenkanSen && + conditions.isTenkanSenUnderKijunSen; + + // + bool condition4 = + isCloseUnderTenkanSen && + isTenkanSenCrossedUnderKumo && + conditions.isTenkanSenUnderKijunSen && + conditions.isFutureSenkouSpanAUnderB && + conditions.isFutureSenkouSpanAUnderLast; + + // + result = + // + condition1 + // + || + // + condition2 + // + || + // + condition3 + // + || + // + condition4 + // + ; + + // + if (result) + { + sl = conditions.ichSenkouSpanAs[1]; + } + + // + return result; + } + + // + // Tools ... + void Default() + { + // + allowLong = true; + allowShort = true; + + // + r2r = 1; + + // + staticVolumeLong = 0.01; + staticVolumeShort = 0.01; + } +}; \ No newline at end of file diff --git a/Signallers/x-saherelm.x121.signaller.class.mq5 b/Signallers/x-saherelm.x121.signaller.class.mq5 index e6f792f2..d8ac18cb 100644 --- a/Signallers/x-saherelm.x121.signaller.class.mq5 +++ b/Signallers/x-saherelm.x121.signaller.class.mq5 @@ -67,7 +67,7 @@ public: tp = 0; // - result = enableLong; + result = allowLong; if (!result) { return result; @@ -123,7 +123,7 @@ public: tp = 0; // - result = enableShort; + result = allowShort; if (!result) { return result; @@ -175,8 +175,8 @@ public: void Default() { // - enableLong = true; - enableShort = true; + allowLong = true; + allowShort = true; // r2r = 1; diff --git a/Signallers/x-saherelm.x786.signaller.class.mq5 b/Signallers/x-saherelm.x786.signaller.class.mq5 index 057e4f75..9ca8f9fe 100644 --- a/Signallers/x-saherelm.x786.signaller.class.mq5 +++ b/Signallers/x-saherelm.x786.signaller.class.mq5 @@ -68,7 +68,7 @@ public: tp = 0; // - result = enableLong; + result = allowLong; if (!result) { return result; @@ -125,7 +125,7 @@ public: bool result = false; // - result = enableShort; + result = allowShort; if (!result) { return result; @@ -180,8 +180,8 @@ public: void Default() { // - enableLong = true; - enableShort = true; + allowLong = true; + allowShort = true; // r2r = 1;