/////////////////////////////////////////////////////// // // SaherElm IT Center XBEEA MQL5 Expert Advisor // ------------------------------------------------- // Name: XBEEA // 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 XBEEA" #property strict // // // enum ENUM_X_DSR_BUFFERS // { // // // // Short ... // X_DSR_SC_OPEN_LINE = 0, // X_DSR_SC_HIGH_LINE = 2, // X_DSR_SC_CLOSE_LINE = 3, // X_DSR_SC_LOW_LINE = 5, // // // // Medium ... // X_DSR_MC_OPEN_LINE = 6, // X_DSR_MC_HIGH_LINE = 8, // X_DSR_MC_CLOSE_LINE = 9, // X_DSR_MC_LOW_LINE = 11, // // // // Long ... // X_DSR_LC_OPEN_LINE = 12, // X_DSR_LC_HIGH_LINE = 14, // X_DSR_LC_CLOSE_LINE = 15, // X_DSR_LC_LOW_LINE = 17, // // // // Hind ... // X_DSR_HC_OPEN_LINE = 18, // X_DSR_HC_HIGH_LINE = 20, // X_DSR_HC_CLOSE_LINE = 21, // X_DSR_HC_LOW_LINE = 23, // }; // #define ShortName "XBEEA" // #include "../Libraries/x-saherelm.log.lib.mq5" #include "../Libraries/x-saherelm.draw.lib.mq5" #include "../Libraries/x-saherelm.common.lib.mq5" #include "../Classes/x-saherelm.xtrade.class.mq5" // // Inputs ... // long xBEEAMagicNumber = 78692110; // Magic Number int xBEEASlippage = 10; // Slippgae // input double xBEEAVolume = 0.01; // // Indicator Inputs ... // // Maarket ... input group "Cycles"; // // Short ... input group "Short"; input ENUM_X_PERIOD_METHOD scMode = X_PERIOD_MANUALLY; // Method input ENUM_TIMEFRAMES scPeriod = PERIOD_H4; // Period // // Presentation ... input bool xBEEADrawSCLabel = true; input bool xBEEADrawSCCBar = true; input bool xBEEADrawSCPBar = false; input bool xBEEADrawSCCMid = true; input bool xBEEADrawSCPMid = true; // // Medium ... input group "Medium"; input ENUM_X_PERIOD_METHOD mcMode = X_PERIOD_MANUALLY; // Method input ENUM_TIMEFRAMES mcPeriod = PERIOD_H12; // Mid Period // // Presentation ... input bool xBEEADrawMCLabel = true; input bool xBEEADrawMCCBar = true; input bool xBEEADrawMCPBar = false; input bool xBEEADrawMCCMid = true; input bool xBEEADrawMCPMid = true; // // Long ... input group "Long"; input ENUM_X_PERIOD_METHOD lcMode = X_PERIOD_MANUALLY; // Method input ENUM_TIMEFRAMES lcPeriod = PERIOD_D1; // Long Period // // Presentation ... input bool xBEEADrawLCLabel = true; input bool xBEEADrawLCCBar = true; input bool xBEEADrawLCPBar = false; input bool xBEEADrawLCCMid = true; input bool xBEEADrawLCPMid = true; // // Hind ... input group "Hind"; input ENUM_X_PERIOD_METHOD hcMode = X_PERIOD_MANUALLY; // Method input ENUM_TIMEFRAMES hcPeriod = PERIOD_W1; // Hind Period // // Presentation ... input bool xBEEADrawHCLabel = true; input bool xBEEADrawHCCBar = true; input bool xBEEADrawHCPBar = true; input bool xBEEADrawHCCMid = true; input bool xBEEADrawHCPMid = true; // // Vars ... // string xBEEASymbol; ENUM_TIMEFRAMES xBEEAPeriod; // 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 xBEEATick; XSCTrade *xBEEATrader; // int xZGHandler = INVALID_HANDLE; // int xDSRHandler = INVALID_HANDLE; // // // // Short ... // double scOpenBuffer[]; // double scHighBuffer[]; // double scCloseBuffer[]; // double scLowBuffer[]; // // // // Medium ... // double mcOpenBuffer[]; // double mcHighBuffer[]; // double mcCloseBuffer[]; // double mcLowBuffer[]; // // // // Long ... // double lcOpenBuffer[]; // double lcHighBuffer[]; // double lcCloseBuffer[]; // double lcLowBuffer[]; // // // // Hind ... // double hcOpenBuffer[]; // double hcHighBuffer[]; // double hcCloseBuffer[]; // double hcLowBuffer[]; // // Cycles Definitions ... // XMarketCycle sc; XDrawSpecifications scCMidSpecs; XDrawSpecifications scPMidSpecs; XOHCLDrawSpecification scCBSpecs; XOHCLDrawSpecification scPBSpecs; // XMarketCycle mc; XDrawSpecifications mcCMidSpecs; XDrawSpecifications mcPMidSpecs; XOHCLDrawSpecification mcCBSpecs; XOHCLDrawSpecification mcPBSpecs; // XMarketCycle lc; XDrawSpecifications lcCMidSpecs; XDrawSpecifications lcPMidSpecs; XOHCLDrawSpecification lcCBSpecs; XOHCLDrawSpecification lcPBSpecs; // XMarketCycle hc; XDrawSpecifications hcCMidSpecs; XDrawSpecifications hcPMidSpecs; XOHCLDrawSpecification hcCBSpecs; XOHCLDrawSpecification hcPBSpecs; // // Event Handlers ... // // Initialization ... int OnInit() { // if (xBEEASymbol == NULL || StringLen(xBEEASymbol) <= 0) { xBEEASymbol = _Symbol; } // if (xBEEAPeriod == NULL) { xBEEAPeriod = _Period; } // // Validate Inputs ... if (!XBEEAValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // logTag = ShortName; drawPrefix = ShortName; // // Initialize XTrader ... xBEEATrader = new XSCTrade( xBEEASlippage, xBEEAMagicNumber); // // Init Indicators ... if (!InitIndicators()) { return INIT_PARAMETERS_INCORRECT; } // // Prepare Style Specs ... PrepareStyleSpecs(); // // TesterHideIndicators(true); // // 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 XBEEA Providers ... delete xBEEATrader; // IndicatorRelease(xZGHandler); // IndicatorRelease(xDSRHandler); } // // On Tick Handler ... void OnTick() { // if (!IsNewCandle( xBEEASymbol, xBEEAPeriod)) { return; } // // Reading Tick ... if (!SymbolInfoTick(xBEEASymbol, xBEEATick)) { return; } // // Reading Data From XDSR Indicator ... ReadData(); // // Counting Currently Open Positions ... buyCount = xBEEATrader.CountPositions(xBEEASymbol, POSITION_TYPE_BUY); sellCount = xBEEATrader.CountPositions(xBEEASymbol, POSITION_TYPE_SELL); // if (buyCount < maxBuys) { // // Check For Buy Signals ... } // if (sellCount < maxSells) { // // Check for Sell Signals ... } } // // Custom Functions ... // // Validate Variables nd Inputs ... bool XBEEAValidateInputs() { // bool result = false; // result = // xBEEASlippage > 0 && xBEEAMagicNumber > 0 // && // // Short ... IsValidCycle( scMode, scPeriod) // && // // Medium ... IsValidCycle( mcMode, mcPeriod) // && // // Long ... IsValidCycle( lcMode, lcPeriod) // && // // Hind ... IsValidCycle( hcMode, hcPeriod) // ; // return result; } // // Initial Indicators ... bool InitIndicators() { // bool result = false; // // // // Short ... // ArraySetAsSeries(scOpenBuffer, true); // ArraySetAsSeries(scHighBuffer, true); // ArraySetAsSeries(scCloseBuffer, true); // ArraySetAsSeries(scLowBuffer, true); // // // // Medium ... // ArraySetAsSeries(mcOpenBuffer, true); // ArraySetAsSeries(mcHighBuffer, true); // ArraySetAsSeries(mcCloseBuffer, true); // ArraySetAsSeries(mcLowBuffer, true); // // // // Long ... // ArraySetAsSeries(lcOpenBuffer, true); // ArraySetAsSeries(lcHighBuffer, true); // ArraySetAsSeries(lcCloseBuffer, true); // ArraySetAsSeries(lcLowBuffer, true); // // // // Hind ... // ArraySetAsSeries(hcOpenBuffer, true); // ArraySetAsSeries(hcHighBuffer, true); // ArraySetAsSeries(hcCloseBuffer, true); // ArraySetAsSeries(hcLowBuffer, true); // // // // Initialize XDSR Handler ... // xDSRHandler = iCustom( // xBEEASymbol, // xBEEAPeriod, // "x-saherelm.x121.xdsr", // // // // Inputs ... // // // // Cycles ... // "", // // // // Short ... // "", // scMode, // scPeriod, // // // // Medium ... // "", // mcMode, // mcPeriod, // // // // Long ... // "", // lcMode, // lcPeriod, // // // // Hind ... // "", // hcMode, // hcPeriod // // // ); // result = xDSRHandler != INVALID_HANDLE; // if (!result) // { // return result; // } // // Init XZG Indicator ... xZGHandler = iCustom( xBEEASymbol, xBEEAPeriod, "x-saherelm.x121.xzg", // // Inputs ... // TODO: // add these inputs to TODO ... 12, // Depth ... 5, // Deviation ... 3, // Back Step ... 1 // MODE ENUM_X_ZG_PRICE_MODE (X_ZG_PRICE_HIGH_LOW_MODE) ... // ); result = xZGHandler != INVALID_HANDLE; if (!result) { return result; } // // Here we have to Init XMarketCycles also ... result = InitMarketCycles(); // return result; } // // Initial Market Cycles ... bool InitMarketCycles() { // bool result = false; // // Short ... sc.method = scMode; sc.period = scPeriod; result = sc.Init( xBEEASymbol, xBEEAPeriod, X_MARKET_CYCLE_SHORT // ); if (!result) { return result; } // // Medium ... mc.method = mcMode; mc.period = mcPeriod; result = mc.Init( xBEEASymbol, xBEEAPeriod, X_MARKET_CYCLE_MEDIUM // ); if (!result) { return result; } // // Long ... lc.method = lcMode; lc.period = lcPeriod; result = lc.Init( xBEEASymbol, xBEEAPeriod, X_MARKET_CYCLE_LONG // ); if (!result) { return result; } // // Hind ... hc.method = hcMode; hc.period = hcPeriod; result = hc.Init( xBEEASymbol, xBEEAPeriod, X_MARKET_CYCLE_HIND // ); if (!result) { return result; } // return result; } // // Prepare Style Specs for Drawings ... void PrepareStyleSpecs() { // // Each Cycle has 2 Kind of Specs: // 1- MidLines; // 2- Candles; // // also for each Cycle we have 2 Series of Specs: // 1- For Current Bar; // 2- Prev Bar; // // Short ... // // Current ... // // MidLine ... scCMidSpecs.width = 1; scCMidSpecs.style = STYLE_DOT; scCMidSpecs.clr = clrSpringGreen; scCMidSpecs.Label( sc.prefix + "_C MID", scCMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... scCBSpecs.Default(); scCBSpecs.Width(1); scCBSpecs.Style(STYLE_DOT); // // scCBSpecs.openStyle.clr = clrDarkOliveGreen; // scCBSpecs.closeStyle.clr = clrDarkOrchid; // scCBSpecs.highStyle.clr = clrDarkSeaGreen; // scCBSpecs.lowStyle.clr = clrPink; // scCBSpecs.openStyle.Label( sc.prefix + "_C O", scCBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); scCBSpecs.highStyle.Label( sc.prefix + "_C H", scCBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); scCBSpecs.closeStyle.Label( sc.prefix + "_C C", scCBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); scCBSpecs.lowStyle.Label( sc.prefix + "_C L", scCBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Prev ... // // MidLine ... scPMidSpecs.width = 2; scPMidSpecs.style = STYLE_SOLID; scPMidSpecs.clr = clrLimeGreen; scPMidSpecs.Label( sc.prefix + "_P MID", scPMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... scPBSpecs.Default(); scPBSpecs.Width(2); // // scPBSpecs.openStyle.clr = ; // scPBSpecs.closeStyle.clr = ; // scPBSpecs.highStyle.clr = ; // scPBSpecs.lowStyle.clr = ; // scPBSpecs.openStyle.Label( sc.prefix + "_P O", scPBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); scPBSpecs.highStyle.Label( sc.prefix + "_P H", scPBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); scPBSpecs.closeStyle.Label( sc.prefix + "_P C", scPBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); scPBSpecs.lowStyle.Label( sc.prefix + "_P L", scPBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Medium ... // // Current ... // // MidLine ... mcCMidSpecs.width = 1; mcCMidSpecs.style = STYLE_DOT; mcCMidSpecs.clr = clrSteelBlue; mcCMidSpecs.Label( mc.prefix + "_C MID", mcCMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... mcCBSpecs.Default(); mcCBSpecs.Width(1); mcCBSpecs.Style(STYLE_DOT); // // mcCBSpecs.openStyle.clr = clrDarkOliveGreen; // mcCBSpecs.closeStyle.clr = clrDarkOrchid; // mcCBSpecs.highStyle.clr = clrDarkSeaGreen; // mcCBSpecs.lowStyle.clr = clrPink; // mcCBSpecs.openStyle.Label( mc.prefix + "_C O", mcCBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); mcCBSpecs.highStyle.Label( mc.prefix + "_C H", mcCBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); mcCBSpecs.closeStyle.Label( mc.prefix + "_C C", mcCBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); mcCBSpecs.lowStyle.Label( mc.prefix + "_C L", mcCBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Prev ... // // MidLine ... mcPMidSpecs.width = 2; mcPMidSpecs.style = STYLE_SOLID; mcPMidSpecs.clr = clrRoyalBlue; mcPMidSpecs.Label( mc.prefix + "_P MID", mcPMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... mcPBSpecs.Default(); mcPBSpecs.Width(2); // // mcPBSpecs.openStyle.clr = ; // mcPBSpecs.closeStyle.clr = ; // mcPBSpecs.highStyle.clr = ; // mcPBSpecs.lowStyle.clr = ; // mcPBSpecs.openStyle.Label( mc.prefix + "_P O", mcCBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); mcPBSpecs.highStyle.Label( mc.prefix + "_P H", mcPBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); mcPBSpecs.closeStyle.Label( mc.prefix + "_P C", mcPBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); mcPBSpecs.lowStyle.Label( mc.prefix + "_P L", mcPBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Long ... // // Current ... // // MidLine ... lcCMidSpecs.width = 1; lcCMidSpecs.style = STYLE_DOT; lcCMidSpecs.clr = clrYellow; lcCMidSpecs.Label( lc.prefix + "_C MID", lcCMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... lcCBSpecs.Default(); lcCBSpecs.Width(1); lcCBSpecs.Style(STYLE_DOT); // // lcCBSpecs.openStyle.clr = clrDarkOliveGreen; // lcCBSpecs.closeStyle.clr = clrDarkOrchid; // lcCBSpecs.highStyle.clr = clrDarkSeaGreen; // lcCBSpecs.lowStyle.clr = clrPink; // lcCBSpecs.openStyle.Label( lc.prefix + "_C O", lcCBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); lcCBSpecs.highStyle.Label( lc.prefix + "_C H", lcCBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); lcCBSpecs.closeStyle.Label( lc.prefix + "_C C", lcCBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); lcCBSpecs.lowStyle.Label( lc.prefix + "_C L", lcCBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Prev ... // // MidLine ... lcPMidSpecs.width = 2; lcPMidSpecs.style = STYLE_SOLID; lcPMidSpecs.clr = clrOrange; lcPMidSpecs.Label( lc.prefix + "_P MID", lcPMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... lcPBSpecs.Default(); lcPBSpecs.Width(2); // // lcPBSpecs.openStyle.clr = ; // lcPBSpecs.closeStyle.clr = ; // lcPBSpecs.highStyle.clr = ; // lcPBSpecs.lowStyle.clr = ; // lcPBSpecs.openStyle.Label( lc.prefix + "_P O", lcCBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); lcPBSpecs.highStyle.Label( lc.prefix + "_P H", lcPBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); lcPBSpecs.closeStyle.Label( lc.prefix + "_P C", lcPBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); lcPBSpecs.lowStyle.Label( lc.prefix + "_P L", lcPBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Hind ... // // Current ... // // MidLine ... hcCMidSpecs.width = 1; hcCMidSpecs.style = STYLE_DOT; hcCMidSpecs.clr = clrSandyBrown; hcCMidSpecs.Label( hc.prefix + "_C MID", hcCMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... hcCBSpecs.Default(); hcCBSpecs.Width(1); hcCBSpecs.Style(STYLE_DOT); // // hcCBSpecs.openStyle.clr = clrDarkOliveGreen; // hcCBSpecs.closeStyle.clr = clrDarkOrchid; // hcCBSpecs.highStyle.clr = clrDarkSeaGreen; // hcCBSpecs.lowStyle.clr = clrPink; // hcCBSpecs.openStyle.Label( hc.prefix + "_C O", hcCBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); hcCBSpecs.highStyle.Label( hc.prefix + "_C H", hcCBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); hcCBSpecs.closeStyle.Label( hc.prefix + "_C C", hcCBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); hcCBSpecs.lowStyle.Label( hc.prefix + "_C L", hcCBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // Prev ... // // MidLine ... hcPMidSpecs.width = 2; hcPMidSpecs.style = STYLE_SOLID; hcPMidSpecs.clr = clrSaddleBrown; hcPMidSpecs.Label( hc.prefix + "_P MID", hcPMidSpecs.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); // // XOHCL ... hcPBSpecs.Default(); hcPBSpecs.Width(2); // // hcPBSpecs.openStyle.clr = clrDarkOliveGreen; // hcPBSpecs.closeStyle.clr = clrDarkOrchid; // hcPBSpecs.highStyle.clr = clrDarkSeaGreen; // hcPBSpecs.lowStyle.clr = clrPink; // hcPBSpecs.openStyle.Label( hc.prefix + "_P O", hcPBSpecs.openStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); hcPBSpecs.highStyle.Label( hc.prefix + "_P H", hcPBSpecs.highStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); hcPBSpecs.closeStyle.Label( hc.prefix + "_P C", hcPBSpecs.closeStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); hcPBSpecs.lowStyle.Label( hc.prefix + "_P L", hcPBSpecs.lowStyle.clr, "Arial", 8, ANCHOR_LEFT_UPPER, 90 // ); } // // Reading Data From Indicators ... void ReadData() { // int mLoopBack = 15; // // Short ... // // // // Open ... // CopyBuffer( // xDSRHandler, // X_DSR_SC_OPEN_LINE, // 0, // mLoopBack, // scOpenBuffer // // ); // // // // High ... // CopyBuffer( // xDSRHandler, // X_DSR_SC_HIGH_LINE, // 0, // mLoopBack, // scHighBuffer // // ); // // // // Close ... // CopyBuffer( // xDSRHandler, // X_DSR_SC_CLOSE_LINE, // 0, // mLoopBack, // scCloseBuffer // // ); // // // // Low ... // CopyBuffer( // xDSRHandler, // X_DSR_SC_LOW_LINE, // 0, // mLoopBack, // scLowBuffer // // ); // // // // Medium ... // // // // Open ... // CopyBuffer( // xDSRHandler, // X_DSR_MC_OPEN_LINE, // 0, // mLoopBack, // mcOpenBuffer // // ); // // // // High ... // CopyBuffer( // xDSRHandler, // X_DSR_MC_HIGH_LINE, // 0, // mLoopBack, // mcHighBuffer // // ); // // // // Close ... // CopyBuffer( // xDSRHandler, // X_DSR_MC_CLOSE_LINE, // 0, // mLoopBack, // mcCloseBuffer // // ); // // // // Low ... // CopyBuffer( // xDSRHandler, // X_DSR_MC_LOW_LINE, // 0, // mLoopBack, // mcLowBuffer // // ); // // // // Long ... // // // // Open ... // CopyBuffer( // xDSRHandler, // X_DSR_LC_OPEN_LINE, // 0, // mLoopBack, // lcOpenBuffer // // ); // // // // High ... // CopyBuffer( // xDSRHandler, // X_DSR_LC_HIGH_LINE, // 0, // mLoopBack, // lcHighBuffer // // ); // // // // Close ... // CopyBuffer( // xDSRHandler, // X_DSR_LC_CLOSE_LINE, // 0, // mLoopBack, // lcCloseBuffer // // ); // // // // Low ... // CopyBuffer( // xDSRHandler, // X_DSR_LC_LOW_LINE, // 0, // mLoopBack, // lcLowBuffer // // ); // // // // Hind ... // // // // Open ... // CopyBuffer( // xDSRHandler, // X_DSR_HC_OPEN_LINE, // 0, // mLoopBack, // hcOpenBuffer // // ); // // // // High ... // CopyBuffer( // xDSRHandler, // X_DSR_HC_HIGH_LINE, // 0, // mLoopBack, // hcHighBuffer // // ); // // // // Close ... // CopyBuffer( // xDSRHandler, // X_DSR_HC_CLOSE_LINE, // 0, // mLoopBack, // hcCloseBuffer // // ); // // // // Low ... // CopyBuffer( // xDSRHandler, // X_DSR_HC_LOW_LINE, // 0, // mLoopBack, // hcLowBuffer // // ); // // Update Market Cycles ... UpdateMarketCycles(0); // // Provide all Draws ... XBEEAHandleDraws( // // Short ... xBEEADrawSCLabel, xBEEADrawSCCBar, xBEEADrawSCPBar, xBEEADrawSCCMid, xBEEADrawSCPMid, // // Medium ... xBEEADrawMCLabel, xBEEADrawMCCBar, xBEEADrawMCPBar, xBEEADrawMCCMid, xBEEADrawMCPMid, // // Long ... xBEEADrawLCLabel, xBEEADrawLCCBar, xBEEADrawLCPBar, xBEEADrawLCCMid, xBEEADrawLCPMid, // // Hind ... xBEEADrawHCLabel, xBEEADrawHCCBar, xBEEADrawHCPBar, xBEEADrawHCCMid, xBEEADrawHCPMid // ); } // // Update Market Cycles ... bool UpdateMarketCycles(int barIndex) { // bool result = false; // // Short ... result = sc.Update(barIndex); if (!result) { return result; } // // Medium ... result = mc.Update(barIndex); if (!result) { return result; } // // Long ... result = lc.Update(barIndex); if (!result) { return result; } // // Hind ... result = hc.Update(barIndex); if (!result) { return result; } // return result; } // // Handle All Draws of Experts ... void XBEEAHandleDraws( // // Short ... bool drawSCLabel = true, bool drawSCCBar = true, bool drawSCPBar = true, bool drawSCCMid = true, bool drawSCPMid = true, // // Medium ... bool drawMCLabel = true, bool drawMCCBar = true, bool drawMCPBar = true, bool drawMCCMid = true, bool drawMCPMid = true, // // Long ... bool drawLCLabel = true, bool drawLCCBar = true, bool drawLCPBar = true, bool drawLCCMid = true, bool drawLCPMid = true, // // Hind ... bool drawHCLabel = true, bool drawHCCBar = true, bool drawHCPBar = true, bool drawHCCMid = true, bool drawHCPMid = true // ) { // int offset = 0; // // Short ... // // Cycle ... if (drawSCCBar || drawSCPBar) { // XBEEADrawCycle( sc.cycle, drawSCLabel, !drawSCCBar && drawSCPBar, !drawSCPBar && drawSCCBar, offset // ); // if (drawSCLabel) { // if (drawSCCBar) { offset += 3; } // if (drawSCPBar) { offset += 3; } // if (drawSCCMid) { offset++; } // if (drawSCPMid) { offset++; } } } // // MidLine ... if (drawSCCMid || drawSCPMid) { // XBEEADrawMidLine( sc.cycle, drawSCLabel, !drawSCCMid && drawSCPMid, !drawSCPMid && drawSCCMid, offset // ); // if (drawSCLabel) { // if (drawSCCMid) { offset++; } // if (drawSCPMid) { offset++; } } } // // Medium ... // // Cycle ... if (drawMCCBar || drawMCPBar) { // XBEEADrawCycle( mc.cycle, drawMCLabel, !drawMCCBar && drawMCPBar, !drawMCPBar && drawMCCBar, offset // ); // if (drawMCLabel) { // if (drawMCCBar) { offset += 3; } // if (drawMCPBar) { offset += 3; } // if (drawMCCMid) { offset++; } // if (drawMCPMid) { offset++; } } } // // Mid Line ... if (drawMCCMid || drawMCPMid) { // XBEEADrawMidLine( mc.cycle, drawMCLabel, !drawMCCMid && drawMCPMid, !drawMCPMid && drawMCCMid, offset // ); // if (drawMCLabel) { // if (drawMCCMid) { offset++; } // if (drawMCPMid) { offset++; } } } // // Long ... // // Cycle ... if (drawLCCBar || drawLCPBar) { // XBEEADrawCycle( lc.cycle, drawLCLabel, !drawLCCBar && drawLCPBar, !drawLCPBar && drawLCCBar, offset // ); // if (drawLCLabel) { // if (drawLCCBar) { offset += 3; } // if (drawLCPBar) { offset += 3; } // if (drawLCCMid) { offset++; } // if (drawLCPMid) { offset++; } } } // // MidLine ... if (drawLCCMid || drawLCPMid) { // XBEEADrawMidLine( lc.cycle, drawLCLabel, !drawLCCMid && drawLCPMid, !drawLCPMid && drawLCCMid, offset // ); // if (drawLCLabel) { // if (drawLCCMid) { offset++; } // if (drawLCPMid) { offset++; } } } // // Hind ... // // Cycle ... if (drawHCCBar || drawHCPBar) { // XBEEADrawCycle( hc.cycle, drawHCLabel, !drawHCCBar && drawHCPBar, !drawHCPBar && drawHCCBar, offset // ); // if (drawHCLabel) { // if (drawHCCBar) { offset += 3; } // if (drawHCPBar) { offset += 3; } // if (drawHCCMid) { offset++; } // if (drawHCPMid) { offset++; } } } // // MidLine ... if (drawHCCMid || drawHCPMid) { // XBEEADrawMidLine( hc.cycle, drawHCLabel, !drawHCCMid && drawHCPMid, !drawHCPMid && drawHCCMid, offset // ); } } // // Draw Middle Line of Cycle ... void XBEEADrawCycle( ENUM_X_MARKET_CYCLES cycle, // Specify Which Cycle to Draw ... bool drawLabel = false, // Specify Draw Label of Mid Line or not ... bool drawOnlyPrev = false, // Specify Draw Only Prev Bar of Cycle ... bool drawOnlyCurrent = false, // Specify Draw Only Current Bar of Cycle ... int offset = 0 // Distance used for Labels ... ) { // if (offset < 0) { offset = 0; } // XMarketCycle cycleModel; XOHCLDrawSpecification cycleCBarSpecs; XOHCLDrawSpecification cyclePBarSpecs; // switch (cycle) { // case X_MARKET_CYCLE_SHORT: // cycleModel = sc; cycleCBarSpecs = scCBSpecs; cyclePBarSpecs = scPBSpecs; break; // case X_MARKET_CYCLE_MEDIUM: // cycleModel = mc; cycleCBarSpecs = mcCBSpecs; cyclePBarSpecs = mcPBSpecs; break; // case X_MARKET_CYCLE_LONG: // cycleModel = lc; cycleCBarSpecs = lcCBSpecs; cyclePBarSpecs = lcPBSpecs; break; // case X_MARKET_CYCLE_HIND: // cycleModel = hc; cycleCBarSpecs = hcCBSpecs; cyclePBarSpecs = hcPBSpecs; break; } // string baseTag = ToString(cycle); // XOHCL cBar = cycleModel.GetBar(0); XOHCL pBar = cycleModel.GetBar(1); // datetime fromCDate = cycleModel.GetBarTime(0); datetime fromPDate = cycleModel.GetBarTime(1); // datetime cTime = TimeCurrent(); // // Try to Draw ... // bool canDrawPrev = !drawOnlyCurrent; bool canDrawCurrent = !drawOnlyPrev; // // Set Cycles Color based on Current Candle ... // bool isCBarBullish = cBar.open < cBar.close; // bool isPBarBullish = pBar.open < pBar.close; // color clrTemoBullishColor = cycleCBarSpecs.openStyle.clr; color clrTemoBearishColor = cycleCBarSpecs.closeStyle.clr; // color cBarSelectedColor = isCBarBullish ? clrTemoBullishColor : clrTemoBearishColor; color pBarSelectedColor = isPBarBullish ? clrTemoBullishColor : clrTemoBearishColor; // cycleCBarSpecs.openStyle.clr = cBarSelectedColor; cycleCBarSpecs.openStyle.labelColor = cBarSelectedColor; // cycleCBarSpecs.closeStyle.clr = cBarSelectedColor; cycleCBarSpecs.closeStyle.labelColor = cBarSelectedColor; // cyclePBarSpecs.openStyle.clr = pBarSelectedColor; cyclePBarSpecs.openStyle.labelColor = pBarSelectedColor; // cyclePBarSpecs.closeStyle.clr = pBarSelectedColor; cyclePBarSpecs.closeStyle.labelColor = pBarSelectedColor; // if (canDrawPrev) { offset++; } // // Label ... if (drawLabel) { // if (canDrawPrev) { // // Draw Prev Bar Lables ... // XBEEADrawCycleXOHCLLabel( cycleModel, pBar, cyclePBarSpecs, "P", cTime, offset - 1 // ); // offset += 3; } // if (canDrawCurrent) { // // Draw Current Bar Lables ... // XBEEADrawCycleXOHCLLabel( cycleModel, cBar, cycleCBarSpecs, "C", cTime, offset // ); } } // // Line ... // if (canDrawPrev) { // // Draw Cycle Prev Bar ... XBEEADrawCycleXOHCLContent( cycleModel, pBar, cyclePBarSpecs, "P", fromPDate // ); } // if (canDrawCurrent) { // // Draw Cycle Current Bar ... XBEEADrawCycleXOHCLContent( cycleModel, cBar, cycleCBarSpecs, "C", fromCDate // ); } } // // Draw Middle Line of Cycle ... void XBEEADrawMidLine( ENUM_X_MARKET_CYCLES cycle, // Specify Which Cycle to Draw ... bool drawLabel = false, // Specify Draw Label of Mid Line or not ... bool drawOnlyPrev = false, // Specify Draw Only Prev Bar of Cycle ... bool drawOnlyCurrent = false, // Specify Draw Only Current Bar of Cycle ... int offset = 0 // Distance used for Labels ... ) { // if (offset < 0) { offset = 0; } // XMarketCycle cycleModel; XDrawSpecifications cycleCMidSpecs; XDrawSpecifications cyclePMidSpecs; // switch (cycle) { // case X_MARKET_CYCLE_SHORT: // cycleModel = sc; cycleCMidSpecs = scCMidSpecs; cyclePMidSpecs = scPMidSpecs; break; // case X_MARKET_CYCLE_MEDIUM: // cycleModel = mc; cycleCMidSpecs = mcCMidSpecs; cyclePMidSpecs = mcPMidSpecs; break; // case X_MARKET_CYCLE_LONG: // cycleModel = lc; cycleCMidSpecs = lcCMidSpecs; cyclePMidSpecs = lcPMidSpecs; break; // case X_MARKET_CYCLE_HIND: // cycleModel = hc; cycleCMidSpecs = hcCMidSpecs; cyclePMidSpecs = hcPMidSpecs; break; } // // Calculate Mid Line ... double midLine = (cycleModel.bar.high + cycleModel.bar.low) / 2; // XOHCL cyclePrevBar = cycleModel.GetBar(1); double midLinePrev = (cyclePrevBar.high + cyclePrevBar.low) / 2; // string baseTag = ToString(cycle); // string midCTag = baseTag + "|MID|C|"; string midPTag = baseTag + "|MID|P|"; // string midCLblTag = midCTag + "lbl"; string midPLblTag = midPTag + "lbl"; // datetime fromCDate = cycleModel.GetBarTime(0); datetime fromPDate = cycleModel.GetBarTime(1); // datetime cTime = TimeCurrent(); // // Try to Draw ... // bool canDrawPrev = !drawOnlyCurrent; bool canDrawCurrent = !drawOnlyPrev; // if (canDrawPrev) { offset++; } // // Label ... if (drawLabel) { // if (canDrawPrev) { // // Draw Prev Candle MidLine Lable ... XBEEADrawLabel( cyclePMidSpecs, midPLblTag, cTime, midLinePrev, offset // ); } // if (canDrawCurrent) { // // Draw Current Candle MidLine Label ... XBEEADrawLabel( cycleCMidSpecs, midCLblTag, cTime, midLine, offset - 1 // ); } } // // Line ... // if (canDrawPrev) { // // Draw Prev Candle MidLine ... XBEEADrawTrendLine( cyclePMidSpecs, midPTag, fromPDate, midLinePrev // ); } // if (canDrawCurrent) { // // Draw Current Candle MidLine ... XBEEADrawTrendLine( cycleCMidSpecs, midCTag, fromCDate, midLine // ); } } // // // Custom DRAW(s) ... // // Draw OHCL Labels ... void XBEEADrawCycleXOHCLLabel( XMarketCycle &cycleModel, // Specify Which Cycle to Draw ... XOHCL &bar, // Specify Cycle XOHCL Model to Draw ... XOHCLDrawSpecification &specs, // Specify Cycle XOHCL Draw Specifications ... string baseTag, // Specify a Unique Tag ... datetime time, // Draw Time ... int offset = 0 // ) { // // Open ... string openTag = cycleModel.prefix + "_" + baseTag + "_O_lbl"; XBEEADrawLabel( specs.openStyle, openTag, time, bar.open, offset // ); // // High ... string highTag = cycleModel.prefix + "_" + baseTag + "_H_lbl"; XBEEADrawLabel( specs.highStyle, highTag, time, bar.high, offset + 1 // ); // // Close ... string closeTag = cycleModel.prefix + "_" + baseTag + "_C_lbl"; XBEEADrawLabel( specs.closeStyle, closeTag, time, bar.close, offset + 2 // ); // // Low ... string lowTag = cycleModel.prefix + "_" + baseTag + "_L_lbl"; XBEEADrawLabel( specs.lowStyle, lowTag, time, bar.low, offset + 3 // ); } // // Draw OHCL Content ... void XBEEADrawCycleXOHCLContent( XMarketCycle &cycleModel, // Specify Which Cycle to Draw ... XOHCL &bar, // Specify Cycle XOHCL Model to Draw ... XOHCLDrawSpecification &specs, // Specify Cycle XOHCL Draw Specifications ... string baseTag, // Specify a Unique Tag ... datetime time // Draw Time ... ) { // // Open ... string openTag = cycleModel.prefix + "_" + baseTag + "_O"; XBEEADrawTrendLine( specs.openStyle, openTag, time, bar.open // ); // // High ... string highTag = cycleModel.prefix + "_" + baseTag + "_H"; XBEEADrawTrendLine( specs.highStyle, highTag, time, bar.high // ); // // Close ... string closeTag = cycleModel.prefix + "_" + baseTag + "_C"; XBEEADrawTrendLine( specs.closeStyle, closeTag, time, bar.close // ); // // Low ... string lowTag = cycleModel.prefix + "_" + baseTag + "_L"; XBEEADrawTrendLine( specs.lowStyle, lowTag, time, bar.low // ); } // // Draw Label Using Specifications ... void XBEEADrawLabel( XDrawSpecifications &specs, string tag, datetime time, double price, int offset = 0 // ) { // long chartId = ChartID(); int subWindow = 0; // if (offset < 0) { offset = 0; } // int offsetSeconds = PeriodSeconds(xBEEAPeriod) * offset; // string value = specs.label; // DrawText( chartId, tag, subWindow, time - offsetSeconds, price, specs.label, specs.labelFont, specs.labelFontSize, specs.labelColor, specs.labelAngel, specs.labelAnchor, specs.back, specs.selection, specs.hidden, specs.zOrder // ); } // // Draw TrendLine Using Specifications ... void XBEEADrawTrendLine( XDrawSpecifications &specs, string tag, datetime fromDate, double fromPrice, datetime toDate = NULL, double toPrice = 0 // ) { // long chartId = ChartID(); int subWindow = 0; // if (toPrice <= 0) { toPrice = fromPrice; } // if (toDate == 0 || toDate == NULL) { toDate = TimeCurrent(); } // DrawTrendLine( chartId, tag, subWindow, fromDate, fromPrice, toDate, toPrice, specs.clr, specs.style, specs.width, specs.back, specs.selection, specs.rayRight, specs.hidden, specs.zOrder // ); }