From 6e03d6d9931f08883d2363ae120524d9e5e93335 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 3 Jan 2025 21:46:49 +0330 Subject: [PATCH] remove fibo lines from x121 indicator and also add support for rsi in data buffers ... --- .../BKP/1/x-saherelm.x121.old.helper.mq5 | 5171 +++++++++++++++++ Documents/BKP/1/x-saherelm.x121.old.mq5 | 2321 ++++++++ Experts/x-saherelm.x-121.smc.ea.mq5 | 4 +- Helpers/x-saherelm.x121.helper.mq5 | 697 +-- Indicators/x-saherelm.x121.mq5 | 352 +- X121SMCEA/Experts/x-121.smc.expert.class.mq5 | 109 +- .../Signals/x-121.smc.xtwpv.signal.lib.mq5 | 5 + .../Strategy/x-121.smc.strategy.class.mq5 | 11 +- 8 files changed, 7722 insertions(+), 948 deletions(-) create mode 100644 Documents/BKP/1/x-saherelm.x121.old.helper.mq5 create mode 100644 Documents/BKP/1/x-saherelm.x121.old.mq5 diff --git a/Documents/BKP/1/x-saherelm.x121.old.helper.mq5 b/Documents/BKP/1/x-saherelm.x121.old.helper.mq5 new file mode 100644 index 00000000..cbb3bf10 --- /dev/null +++ b/Documents/BKP/1/x-saherelm.x121.old.helper.mq5 @@ -0,0 +1,5171 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XCX121Helper +// Description: provides all Indicator +// Helper requirements ... +// +// +// 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 "../Classes/x-saherelm.x-helper.class.mq5" + +// +// Definitions ... +enum ENUM_X121_BUFFERS +{ + // + // Main Buffers ... + X121_PEAKS_LINE = 0, + X121_VALES_LINE = 1, + X121_SAR_LINE = 2, + X121_ATR_UPPER_LINE = 3, + X121_ATR_LOWER_LINE = 4, + X121_VWAP_FAST_LINE = 5, + X121_VWAP_MID_LINE = 7, + X121_VWAP_SLOW_LINE = 9, + X121_DON_OPEN_UPPER_LINE = 11, + X121_DON_OPEN_LOWER_LINE = 12, + X121_DON_HIGH_UPPER_LINE = 13, + X121_DON_HIGH_LOWER_LINE = 14, + X121_DON_LOW_UPPER_LINE = 15, + X121_DON_LOW_LOWER_LINE = 16, + X121_DON_CLOSE_UPPER_LINE = 17, + X121_DON_CLOSE_LOWER_LINE = 18, + X121_FIB_LEVEL_1_LINE = 19, + X121_FIB_LEVEL_2_LINE = 20, + X121_FIB_LEVEL_3_LINE = 21, + X121_FIB_LEVEL_4_LINE = 22, + X121_FIB_LEVEL_5_LINE = 23, + // + // Data Buffers ... + // + // XPV Data ... + X121_CURRENT_HH_LINE = 24, + X121_CURRENT_LL_LINE = 25, + X121_SHORT_HH_LINE = 26, + X121_SHORT_LL_LINE = 27, + X121_MEDIUM_HH_LINE = 28, + X121_MEDIUM_LL_LINE = 29, + X121_LONG_HH_LINE = 30, + X121_LONG_LL_LINE = 31, + X121_HIND_HH_LINE = 32, + X121_HIND_LL_LINE = 33, + // + // VWAP Data ... + X121_VWAP_VOLUME_LINE = 34, + X121_VWAP_PRICE_LINE = 35, + X121_VWAP_FAST_STATE_LINE = 36, + X121_VWAP_MID_STATE_LINE = 37, + X121_VWAP_SLOW_STATE_LINE = 38, + // + // ATR ... + X121_ATR_LINE = 39, + X121_ATR_UPPER_RAW_LINE = 40, + X121_ATR_LOWER_RAW_LINE = 41, +}; + +// +enum ENUM_XVWAP_STATES +{ + // + XVWAP_STATE_BULLISH = 1, + XVWAP_STATE_BEARISH = 2, + XVWAP_STATE_NEUTURAL = 3, +}; + +// +// Inputs ... +struct X121Inputs +{ + // + // Props ... + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Boundary Detection ... + ENUM_SERIESMODE hhMode; // Highest High Calculation Method + ENUM_SERIESMODE llMode; // Lowest Low Calculation Method + + // + // Parabolic Sar Detection ... + double sarStep; // Step + double sarMax; // Maximum + + // + // RSI ... + int rsiLength; // RSI Length + double rsiOverSoldLevel; // RSI Over Sold Level + double rsiOverBoughtLevel; // RSI Over Bought Level + + // + // Atr Detection ... + int atrLength; // Length + double atrMultiplier; // Multiplier + ENUM_APPLIED_PRICE atrUpperAppliedTo; // Upper Zone Applied To + ENUM_APPLIED_PRICE atrLowerAppliedTo; // Lower Zone Applied To + ENUM_X_MA_METHOD atrSmoothingMode; // Smoothing Method + + // + // VWap Detection ... + int vwapFastLength; // Fast Length + int vwapMidLength; // Mid Length + int vwapSlowLength; // Slow Length + ENUM_APPLIED_PRICE vwapAppliedTo; // Applied To + + // + // Donchain Detection ... + int donchainLength; // Donchain Length + + // + // Fibonacci ... + double fiboLevel1; // Fibio 1st Level + double fiboLevel2; // Fibio 2st Level + double fiboLevel3; // Fibio 3rd Level + double fiboLevel4; // Fibio 4th Level + double fiboLevel5; // Fibio 5th Level + + // + // Presentation ... + + // + int startCalculationForLastBars; // Calculate Last n Bars + + // + int sarArrowCode; // Parabolic Sar Arrow Code + int peaksArrowCode; // Peaks Arrow Code + int valesArrowCode; // Vales Arrow Code + + // + // Global ... + bool showSar; // Show Parabolic Sar + bool showAtr; // Show Atr + bool showPeaks; // Show Peaks + bool showVales; // Show Vales + bool showVWap; // Show VWap + bool showDonchain; // Show Donchain + + // + // Fibonachi Presentation ... + bool showFibo1Levels; // Show Fibo 1st Level + bool showFibo2Levels; // Show Fibo 2nd Level + bool showFibo3Levels; // Show Fibo 3rd Level + bool showFibo4Levels; // Show Fibo 4th Level + bool showFibo5Levels; // Show Fibo 5th Level + + // + // Atr Presentation ... + bool showAtrUpper; // Show Upper Zone + bool showAtrLower; // Show Lower Zone + + // + // VWap Presentation ... + bool showVWapFast; // Show VWap Fast + bool showVWapMedium; // Show VWap Medium + bool showVWapSlow; // Show VWap Slow + + // + // Donchain Presentation ... + + // + bool showUpper; // Show Upper Band + bool showLower; // Show Lower Band + + // + bool showOpen; // Show Open + bool showHigh; // Show High + bool showClose; // Show Close + bool showLow; // Show Low + + // + // Constructor ... + X121Inputs() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + // Cycles ... + + // + // Short ... + scMethod = X_PERIOD_NOTHING; + scPeriod = NULL; + + // + // Medium ... + mcMethod = X_PERIOD_NOTHING; + mcPeriod = NULL; + + // + // Long ... + lcMethod = X_PERIOD_NOTHING; + lcPeriod = NULL; + + // + // Hind ... + hcMethod = X_PERIOD_NOTHING; + hcPeriod = NULL; + + // + // Boundary Detection ... + hhMode = MODE_HIGH; + llMode = MODE_LOW; + + // + // RSI ... + rsiLength = 0; + rsiOverSoldLevel = 0; + rsiOverBoughtLevel = 0; + + // + // Paraboli Sar Detection ... + sarStep = 0; + sarMax = 0; + + // + // Atr Detection ... + atrLength = 0; // Length + atrMultiplier = 0; // Multiplier + atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To + atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To + atrSmoothingMode = X_MA_MODE_NONE; // Smoothing Method + + // + // VWap Detection ... + vwapFastLength = 0; + vwapMidLength = 0; + vwapSlowLength = 0; + vwapAppliedTo = PRICE_CLOSE; + + // + // Donchain Detection ... + donchainLength = 0; + + // + // Fibonacci ... + fiboLevel1 = 0; + fiboLevel2 = 0; + fiboLevel3 = 0; + fiboLevel4 = 0; + fiboLevel5 = 0; + + // + // Presentation ... + + // + startCalculationForLastBars = 0; + + // + sarArrowCode = 0; + peaksArrowCode = 0; + valesArrowCode = 0; + + // + // Globals ... + showSar = false; + showAtr = false; + showPeaks = false; + showVales = false; + showVWap = false; + showDonchain = false; + + // + // Fibonachi Presentation ... + showFibo1Levels = false; + showFibo2Levels = false; + showFibo3Levels = false; + showFibo4Levels = false; + showFibo5Levels = false; + + // + // Atr Presentation ... + showAtrUpper = false; // Show Upper Zone + showAtrLower = false; // Show Lower Zone + + // + // VWap Presentation ... + showVWapFast = false; + showVWapMedium = false; + showVWapSlow = false; + + // + // Donchain Presentation ... + + // + showUpper = false; + showLower = false; + + // + showOpen = false; + showHigh = false; + showClose = false; + showLow = false; + } + + /** + * Set Default Values ... + */ + void Default() + { + // + // Cycles ... + + // + // Short ... + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + + // + // Medium ... + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + + // + // Long ... + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + + // + // Hind ... + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + // Boundary Detection ... + hhMode = MODE_HIGH; + llMode = MODE_LOW; + + // + // RSI ... + rsiLength = 14; + rsiOverSoldLevel = 30; + rsiOverBoughtLevel = 70; + + // + // Paraboli Sar Detection ... + sarStep = 0.02; + sarMax = 0.2; + + // + // Atr Detection ... + atrLength = 14; // Length + atrMultiplier = 1; // Multiplier + atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To + atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To + atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method + + // + // VWap Detection ... + vwapFastLength = 20; + vwapMidLength = 40; + vwapSlowLength = 60; + vwapAppliedTo = PRICE_CLOSE; + + // + // Donchain Detection ... + donchainLength = 40; + + // + // Fibonacci ... + fiboLevel1 = 0.236; + fiboLevel2 = 0.382; + fiboLevel3 = 0.5; + fiboLevel4 = 0.618; + fiboLevel5 = 0.764; + + // + // Presentation ... + + // + startCalculationForLastBars = 1500; + + // + sarArrowCode = 159; + peaksArrowCode = 159; + valesArrowCode = 159; + + // + // Globals ... + showSar = true; + showAtr = true; + showPeaks = true; + showVales = true; + showVWap = true; + showDonchain = true; + + // + // Fibonachi Presentation ... + showFibo1Levels = false; + showFibo2Levels = false; + showFibo3Levels = true; + showFibo4Levels = false; + showFibo5Levels = false; + + // + // Atr Presentation ... + showAtrUpper = true; // Show Upper Zone + showAtrLower = true; // Show Lower Zone + + // + // VWap Presentation ... + showVWapFast = true; + showVWapMedium = true; + showVWapSlow = true; + + // + // Donchain Presentation ... + + // + showUpper = true; + showLower = true; + + // + showOpen = true; + showHigh = false; + showClose = true; + showLow = false; + } + + /** + * Validate ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = + // + // RSI ... + rsiLength > 0 && + rsiOverSoldLevel > 0 && + rsiOverBoughtLevel > 0 && + rsiOverSoldLevel < rsiOverBoughtLevel && + // PSAR ... + sarMax > 0 && + sarStep > 0 && + sarMax > sarStep && + // + // ATR ... + atrLength > 0 && + atrMultiplier > 0 && + // + // XDON ... + donchainLength > 0 && + // + // VWAP ... + vwapFastLength > 2 && + vwapMidLength > vwapFastLength && + vwapSlowLength > vwapMidLength && + // + // XPV ... + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + /** + * Extract Max Input Length ... + * + * @return ( int ) + */ + int Max() + { + // + int result = 0; + + // + // VWAP ... + result = MathMax(result, vwapFastLength); + result = MathMax(result, vwapFastLength); + result = MathMax(result, vwapMidLength); + + // + // ATR ... + result = MathMax(result, atrLength); + result = MathMax(result, rsiLength); + + // + return result; + } +}; + +// +// Conditions ... +struct X121Conditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double peaksBuffer[]; + double valesBuffer[]; + double sarBuffer[]; + double atrUpperBuffer[]; + double atrLowerBuffer[]; + double vwapFastBuffer[]; + double vwapMidBuffer[]; + double vwapSlowBuffer[]; + double donOpenUpperBuffer[]; + double donOpenLowerBuffer[]; + double donCloseUpperBuffer[]; + double donCloseLowerBuffer[]; + double donHighUpperBuffer[]; + double donHighLowerBuffer[]; + double donLowUpperBuffer[]; + double donLowLowerBuffer[]; + double fl1Buffer[]; + double fl2Buffer[]; + double fl3Buffer[]; + double fl4Buffer[]; + double fl5Buffer[]; + double cHHBuffer[]; + double cLLBuffer[]; + double sHHBuffer[]; + double sLLBuffer[]; + double mHHBuffer[]; + double mLLBuffer[]; + double lHHBuffer[]; + double lLLBuffer[]; + double hHHBuffer[]; + double hLLBuffer[]; + double atrBuffer[]; + double atrUpperRawBuffer[]; + double atrLowerRawBuffer[]; + double vwapVolumeBuffer[]; + double vwapPriceBuffer[]; + double vwapFastStateBuffer[]; + double vwapMidStateBuffer[]; + double vwapSlowStateBuffer[]; + double rsiBuffer[]; + + // + // Conditions ... + + // + // XRSI ... + + // + bool isRSIOverBought; + bool isRSICrossedOverOverBought; + bool isRSICrossedUnderOverBought; + + // + bool isRSIOverSold; + bool isRSICrossedUnderOverSold; + bool isRSICrossedOverOverSold; + + // + // XSAR ... + + // + bool isSarBullish; + bool isSarBearish; + + // + bool isSarSwitchedToBullish; + bool isSarSwitchedToBearish; + + // + // XPV ... + + // + bool isNewPeak; + bool isNewPeakOverLast; + bool isNewPeakUnderLast; + + // + bool isNewVale; + bool isNewValeOverLast; + bool isNewValeUnderLast; + + // + // XVWAP ... + + // + bool isVWapFastBullish; + bool isVWapFastBearish; + bool isVWapFastNeutural; + + // + bool isVWapMidBullish; + bool isVWapMidBearish; + bool isVWapMidNeutural; + + // + bool isVWapSlowBullish; + bool isVWapSlowBearish; + bool isVWapSlowNeutural; + + // + bool isVWapFastOverMid; + bool isVWapMidOverSlow; + + // + bool isVWapFastUnderMid; + bool isVWapMidUnderSlow; + + // + bool isVWapBullishState; + bool isVWapBearishState; + bool isVWapNeuturalState; + + // + bool isVWapBullishOrdered; + bool isVWapBearishOrdered; + + // + bool isVWapSwitchedToBullishOrdered; + bool isVWapSwitchedToBearishOrdered; + + // + bool isVWapSwitchedToBullishState; + bool isVWapSwitchedToBearishState; + bool isVWapSwitchedToNeuturalState; + + // + // XDON ... + + // + // bool isCloseLower + + // + // XFIBONACCI ... + + // + bool isOerFib1; + bool isOerFib2; + bool isOerFib3; + bool isOerFib4; + bool isOerFib5; + + // + bool isUnderFib1; + bool isUnderFib2; + bool isUnderFib3; + bool isUnderFib4; + bool isUnderFib5; + + // + bool isCloseOerFib1; + bool isCloseOerFib2; + bool isCloseOerFib3; + bool isCloseOerFib4; + bool isCloseOerFib5; + + // + bool isCloseUnderFib1; + bool isCloseUnderFib2; + bool isCloseUnderFib3; + bool isCloseUnderFib4; + bool isCloseUnderFib5; + + // + // Constructor ... + X121Conditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + // Commons ... + symbol = NULL; + period = NULL; + time = NULL; + + // + // Buffers ... + + // + Clean(peaksBuffer); + Clean(valesBuffer); + Clean(sarBuffer); + Clean(atrUpperBuffer); + Clean(atrLowerBuffer); + Clean(vwapFastBuffer); + Clean(vwapMidBuffer); + Clean(vwapSlowBuffer); + Clean(donOpenUpperBuffer); + Clean(donOpenLowerBuffer); + Clean(donCloseUpperBuffer); + Clean(donCloseLowerBuffer); + Clean(donHighUpperBuffer); + Clean(donHighLowerBuffer); + Clean(donLowUpperBuffer); + Clean(donLowLowerBuffer); + Clean(fl1Buffer); + Clean(fl2Buffer); + Clean(fl3Buffer); + Clean(fl4Buffer); + Clean(fl5Buffer); + Clean(cHHBuffer); + Clean(cLLBuffer); + Clean(sHHBuffer); + Clean(sLLBuffer); + Clean(mHHBuffer); + Clean(mLLBuffer); + Clean(lHHBuffer); + Clean(lLLBuffer); + Clean(hHHBuffer); + Clean(hLLBuffer); + Clean(atrBuffer); + Clean(atrUpperRawBuffer); + Clean(atrLowerRawBuffer); + Clean(vwapVolumeBuffer); + Clean(vwapPriceBuffer); + Clean(vwapFastStateBuffer); + Clean(vwapMidStateBuffer); + Clean(vwapSlowStateBuffer); + Clean(rsiBuffer); + + // + ArraySetAsSeries(peaksBuffer, true); + ArraySetAsSeries(valesBuffer, true); + ArraySetAsSeries(sarBuffer, true); + ArraySetAsSeries(atrUpperBuffer, true); + ArraySetAsSeries(atrLowerBuffer, true); + ArraySetAsSeries(vwapFastBuffer, true); + ArraySetAsSeries(vwapMidBuffer, true); + ArraySetAsSeries(vwapSlowBuffer, true); + ArraySetAsSeries(donOpenUpperBuffer, true); + ArraySetAsSeries(donOpenLowerBuffer, true); + ArraySetAsSeries(donCloseUpperBuffer, true); + ArraySetAsSeries(donCloseLowerBuffer, true); + ArraySetAsSeries(donHighUpperBuffer, true); + ArraySetAsSeries(donHighLowerBuffer, true); + ArraySetAsSeries(donLowUpperBuffer, true); + ArraySetAsSeries(donLowLowerBuffer, true); + ArraySetAsSeries(fl1Buffer, true); + ArraySetAsSeries(fl2Buffer, true); + ArraySetAsSeries(fl3Buffer, true); + ArraySetAsSeries(fl4Buffer, true); + ArraySetAsSeries(fl5Buffer, true); + ArraySetAsSeries(cHHBuffer, true); + ArraySetAsSeries(cLLBuffer, true); + ArraySetAsSeries(sHHBuffer, true); + ArraySetAsSeries(sLLBuffer, true); + ArraySetAsSeries(mHHBuffer, true); + ArraySetAsSeries(mLLBuffer, true); + ArraySetAsSeries(lHHBuffer, true); + ArraySetAsSeries(lLLBuffer, true); + ArraySetAsSeries(hHHBuffer, true); + ArraySetAsSeries(hLLBuffer, true); + ArraySetAsSeries(atrBuffer, true); + ArraySetAsSeries(atrUpperRawBuffer, true); + ArraySetAsSeries(atrLowerRawBuffer, true); + ArraySetAsSeries(vwapVolumeBuffer, true); + ArraySetAsSeries(vwapPriceBuffer, true); + ArraySetAsSeries(vwapFastStateBuffer, true); + ArraySetAsSeries(vwapMidStateBuffer, true); + ArraySetAsSeries(vwapSlowStateBuffer, true); + ArraySetAsSeries(rsiBuffer, true); + + // + // Conditions ... + + // + // XRSI ... + + // + isRSIOverBought = false; + isRSICrossedUnderOverBought = false; + isRSICrossedOverOverBought = false; + + // + isRSIOverSold = false; + isRSICrossedOverOverSold = false; + isRSICrossedUnderOverSold = false; + + // + // XSAR ... + + // + isSarBullish = false; + isSarBearish = false; + + // + isSarSwitchedToBullish = false; + isSarSwitchedToBearish = false; + + // + // XPV ... + + // + isNewPeak = false; + isNewPeakOverLast = false; + isNewPeakUnderLast = false; + + // + isNewVale = false; + isNewValeOverLast = false; + isNewValeUnderLast = false; + + // + // XVWAP ... + + // + isVWapFastBullish = false; + isVWapFastBearish = false; + isVWapFastNeutural = false; + + // + isVWapMidBullish = false; + isVWapMidBearish = false; + isVWapMidNeutural = false; + + // + isVWapSlowBullish = false; + isVWapSlowBearish = false; + isVWapSlowNeutural = false; + + // + isVWapFastOverMid = false; + isVWapMidOverSlow = false; + + // + isVWapFastUnderMid = false; + isVWapMidUnderSlow = false; + + // + isVWapBullishState = false; + isVWapBearishState = false; + isVWapNeuturalState = false; + + // + isVWapBullishOrdered = false; + isVWapBearishOrdered = false; + + // + isVWapSwitchedToBullishOrdered = false; + isVWapSwitchedToBearishOrdered = false; + + // + isVWapSwitchedToBullishState = false; + isVWapSwitchedToBearishState = false; + isVWapSwitchedToNeuturalState = false; + + // + // XDON ... + + // + // XFIBONACCI ... + + // + isOerFib1 = false; + isOerFib2 = false; + isOerFib3 = false; + isOerFib4 = false; + isOerFib5 = false; + + // + isUnderFib1 = false; + isUnderFib2 = false; + isUnderFib3 = false; + isUnderFib4 = false; + isUnderFib5 = false; + + // + isCloseOerFib1 = false; + isCloseOerFib2 = false; + isCloseOerFib3 = false; + isCloseOerFib4 = false; + isCloseOerFib5 = false; + + // + isCloseUnderFib1 = false; + isCloseUnderFib2 = false; + isCloseUnderFib3 = false; + isCloseUnderFib4 = false; + isCloseUnderFib5 = false; + } + + /** + * Generate Conditions Scores ... + * + * @param bullishScore: Double, Directional Scores Reference ... + * @param bearishScore: Double, Directional Scores Reference ... + */ + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // TODO: Implement if Required ... + } + + /** + * Generate Summary String for Represent Conditions State ... + * + * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... + * @param onlyConditions: Boolean, Just Generate Only Conditions ... + * @param includeScores: Boolean, Attach Scores Representations on Result ... + * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... + * @param separator: String, Separate Lines ... + * + * @return ( string ) + */ + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + // TODO: Implement this if required ... + string conditionsStr = + // + // XSAR ... + ToString("isSarBullish", isSarBullish, ignoreFalseConditions, separator) + + ToString("isSarBearish", isSarBearish, ignoreFalseConditions, separator) + + ToString("isSarSwitchedToBullish", isSarSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSarSwitchedToBearish", isSarSwitchedToBearish, ignoreFalseConditions, separator) + + // + // XPV ... + ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) + + ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) + + ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) + + ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) + + ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + + ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + + // + // XVWAP ... + ToString("isVWapFastBullish", isVWapFastBullish, ignoreFalseConditions, separator) + + ToString("isVWapFastBearish", isVWapFastBearish, ignoreFalseConditions, separator) + + ToString("isVWapFastNeutural", isVWapFastNeutural, ignoreFalseConditions, separator) + + ToString("isVWapMidBullish", isVWapMidBullish, ignoreFalseConditions, separator) + + ToString("isVWapMidBearish", isVWapMidBearish, ignoreFalseConditions, separator) + + ToString("isVWapMidNeutural", isVWapMidNeutural, ignoreFalseConditions, separator) + + ToString("isVWapSlowBullish", isVWapSlowBullish, ignoreFalseConditions, separator) + + ToString("isVWapSlowBearish", isVWapSlowBearish, ignoreFalseConditions, separator) + + ToString("isVWapSlowNeutural", isVWapSlowNeutural, ignoreFalseConditions, separator) + + ToString("isVWapFastOverMid", isVWapFastOverMid, ignoreFalseConditions, separator) + + ToString("isVWapMidOverSlow", isVWapMidOverSlow, ignoreFalseConditions, separator) + + ToString("isVWapFastUnderMid", isVWapFastUnderMid, ignoreFalseConditions, separator) + + ToString("isVWapMidUnderSlow", isVWapMidUnderSlow, ignoreFalseConditions, separator) + + ToString("isVWapBullishState", isVWapBullishState, ignoreFalseConditions, separator) + + ToString("isVWapBearishState", isVWapBearishState, ignoreFalseConditions, separator) + + ToString("isVWapNeuturalState", isVWapNeuturalState, ignoreFalseConditions, separator) + + ToString("isVWapBullishOrdered", isVWapBullishOrdered, ignoreFalseConditions, separator) + + ToString("isVWapBearishOrdered", isVWapBearishOrdered, ignoreFalseConditions, separator) + + ToString("isVWapSwitchedToBullishOrdered", isVWapSwitchedToBullishOrdered, ignoreFalseConditions, separator) + + ToString("isVWapSwitchedToBearishOrdered", isVWapSwitchedToBearishOrdered, ignoreFalseConditions, separator) + + ToString("isVWapSwitchedToBullishState", isVWapSwitchedToBullishState, ignoreFalseConditions, separator) + + ToString("isVWapSwitchedToBearishState", isVWapSwitchedToBearishState, ignoreFalseConditions, separator) + + ToString("isVWapSwitchedToNeuturalState", isVWapSwitchedToNeuturalState, ignoreFalseConditions, separator) + + // + // XFIBONACCI ... + ToString("isOerFib1", isOerFib1, ignoreFalseConditions, separator) + + ToString("isOerFib2", isOerFib2, ignoreFalseConditions, separator) + + ToString("isOerFib3", isOerFib3, ignoreFalseConditions, separator) + + ToString("isOerFib4", isOerFib4, ignoreFalseConditions, separator) + + ToString("isOerFib5", isOerFib5, ignoreFalseConditions, separator) + + ToString("isUnderFib1", isUnderFib1, ignoreFalseConditions, separator) + + ToString("isUnderFib2", isUnderFib2, ignoreFalseConditions, separator) + + ToString("isUnderFib3", isUnderFib3, ignoreFalseConditions, separator) + + ToString("isUnderFib4", isUnderFib4, ignoreFalseConditions, separator) + + ToString("isUnderFib5", isUnderFib5, ignoreFalseConditions, separator) + + ToString("isCloseOerFib1", isCloseOerFib1, ignoreFalseConditions, separator) + + ToString("isCloseOerFib2", isCloseOerFib2, ignoreFalseConditions, separator) + + ToString("isCloseOerFib3", isCloseOerFib3, ignoreFalseConditions, separator) + + ToString("isCloseOerFib4", isCloseOerFib4, ignoreFalseConditions, separator) + + ToString("isCloseOerFib5", isCloseOerFib5, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib1", isCloseUnderFib1, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib2", isCloseUnderFib2, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib3", isCloseUnderFib3, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib4", isCloseUnderFib4, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib5", isCloseUnderFib5, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + /** + * Retrieve nique Tag Identifier ... + * + * @return ( string ) + */ + string GetTag() + { + return GetTypeName(this); + } + + // +}; + +// +// Implementation ... + +class XCX121Helper : public XCBaseHelper +{ + // + public: + // + + // + // Constructors ... + XCX121Helper() + : XCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XCX121Helper() + { + IndicatorRelease(mRSIHandler); + } + + // + // Tools ... + + /** + * Initialize Indicator Helper ... + * + * @param symbol: String, Symbol ... + * @param period: ENUM_TIMEFRAMES member, Period ... + * @param inputs: X121Inputs instance, Indicator Inputs ... + * + * @return ( bool ) + */ + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + X121Inputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + // Validate Inputs ... + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + // Setting Arrays As Series ... + ArraySetAsSeries(peaksBuffer, true); + ArraySetAsSeries(valesBuffer, true); + ArraySetAsSeries(sarBuffer, true); + ArraySetAsSeries(atrUpperBuffer, true); + ArraySetAsSeries(atrLowerBuffer, true); + ArraySetAsSeries(vwapFastBuffer, true); + ArraySetAsSeries(vwapMidBuffer, true); + ArraySetAsSeries(vwapSlowBuffer, true); + ArraySetAsSeries(donOpenUpperBuffer, true); + ArraySetAsSeries(donOpenLowerBuffer, true); + ArraySetAsSeries(donCloseUpperBuffer, true); + ArraySetAsSeries(donCloseLowerBuffer, true); + ArraySetAsSeries(donHighUpperBuffer, true); + ArraySetAsSeries(donHighLowerBuffer, true); + ArraySetAsSeries(donLowUpperBuffer, true); + ArraySetAsSeries(donLowLowerBuffer, true); + ArraySetAsSeries(fl1Buffer, true); + ArraySetAsSeries(fl2Buffer, true); + ArraySetAsSeries(fl3Buffer, true); + ArraySetAsSeries(fl4Buffer, true); + ArraySetAsSeries(fl5Buffer, true); + ArraySetAsSeries(cHHBuffer, true); + ArraySetAsSeries(cLLBuffer, true); + ArraySetAsSeries(sHHBuffer, true); + ArraySetAsSeries(sLLBuffer, true); + ArraySetAsSeries(mHHBuffer, true); + ArraySetAsSeries(mLLBuffer, true); + ArraySetAsSeries(lHHBuffer, true); + ArraySetAsSeries(lLLBuffer, true); + ArraySetAsSeries(hHHBuffer, true); + ArraySetAsSeries(hLLBuffer, true); + ArraySetAsSeries(atrBuffer, true); + ArraySetAsSeries(atrUpperRawBuffer, true); + ArraySetAsSeries(atrLowerRawBuffer, true); + ArraySetAsSeries(vwapVolumeBuffer, true); + ArraySetAsSeries(vwapPriceBuffer, true); + ArraySetAsSeries(vwapFastStateBuffer, true); + ArraySetAsSeries(vwapMidStateBuffer, true); + ArraySetAsSeries(vwapSlowStateBuffer, true); + ArraySetAsSeries(rsiBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.x121", + // + // Inputs ... + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Boundary Detection ... + "", + mInputs.hhMode, + mInputs.llMode, + // + // Parabolic Sar Detection ... + "", + mInputs.sarStep, + mInputs.sarMax, + // + // Atr Detection ... + "", + mInputs.atrLength, + mInputs.atrMultiplier, + mInputs.atrUpperAppliedTo, + mInputs.atrLowerAppliedTo, + mInputs.atrSmoothingMode, + // + // VWap Detection ... + "", + mInputs.vwapFastLength, + mInputs.vwapMidLength, + mInputs.vwapSlowLength, + mInputs.vwapAppliedTo, + // + // Donchain Detection ... + "", + mInputs.donchainLength, + // + // Presentation ... + "", + mInputs.startCalculationForLastBars, + // + // Commons ... + mInputs.showSar, + mInputs.showAtr, + mInputs.showPeaks, + mInputs.showVales, + mInputs.showVWap, + mInputs.showDonchain, + // + // Fibonachi Presentation ... + "", + mInputs.showFibo1Levels, + mInputs.showFibo2Levels, + mInputs.showFibo3Levels, + mInputs.showFibo4Levels, + mInputs.showFibo5Levels, + // + // Atr Presentation ... + "", + mInputs.showAtrUpper, + mInputs.showAtrLower, + // + // VWap Presentation ... + "", + mInputs.showVWapFast, + mInputs.showVWapMedium, + mInputs.showVWapSlow, + // + // Donchain Presentation ... + "", + mInputs.showUpper, + mInputs.showLower, + mInputs.showOpen, + mInputs.showHigh, + mInputs.showClose, + mInputs.showLow + // + // Non Important Inpust ... + // + // Fibonacci ... + // "", + // mInputs.fiboLevel1, + // mInputs.fiboLevel2, + // mInputs.fiboLevel3, + // mInputs.fiboLevel4, + // mInputs.fiboLevel5, + // // + // mInputs.sarArrowCode, + // mInputs.peaksArrowCode, + // mInputs.valesArrowCode + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + mRSIHandler = iRSI( + symbol, + period, + mInputs.rsiLength, + PRICE_CLOSE // + ); + result = mRSIHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Retrieve Current Indicator Configs ... + * + * @return ( Inputs ) + */ + X121Inputs GetInputs() + { + return mInputs; + } + + /** + * Set New Indicator Inputs ... + * + * @param inputs: X121Inputs instance, Indicator Inputs ... + * + * @return ( bool ) + */ + bool SetInputs( + X121Inputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Implement Value Getters ... + + // + // XRSI ... + + // + double GetRSI( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(rsiBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return rsiBuffer[barIndex]; + } + + // + int CopyRSI( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + rsiBuffer, + buffer, + forceClean + // + ); + } + + // + // SAR ... + + // + double GetSar( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sarBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sarBuffer[barIndex]; + } + + // + int CopySar( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sarBuffer, + buffer, + forceClean + // + ); + } + + // + // ATR ... + + // + // Common ... + + // + double GetAtr( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(atrBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return atrBuffer[barIndex]; + } + + // + int CopyAtr( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + atrBuffer, + buffer, + forceClean + // + ); + } + + // + double GetAtrUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(atrUpperBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return atrUpperBuffer[barIndex]; + } + + // + int CopyAtrUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + atrUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetAtrUpperRaw( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(atrUpperRawBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return atrUpperRawBuffer[barIndex]; + } + + // + int CopyAtrUpperRaw( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + atrUpperRawBuffer, + buffer, + forceClean + // + ); + } + + // + double GetAtrLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(atrLowerBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return atrLowerBuffer[barIndex]; + } + + // + int CopyAtrLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + atrLowerBuffer, + buffer, + forceClean + // + ); + } + + // + double GetAtrLowerRaw( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(atrLowerRawBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return atrLowerRawBuffer[barIndex]; + } + + // + int CopyAtrLowerRaw( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + atrLowerRawBuffer, + buffer, + forceClean + // + ); + } + + // + // PV ... + + // + // PEAKS ... + + // + double GetPeak( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(peaksBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return peaksBuffer[barIndex]; + } + + // + int CopyPeak( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + peaksBuffer, + buffer, + forceClean + // + ); + } + + // + // VALES ... + + // + double GetVale( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(valesBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return valesBuffer[barIndex]; + } + + // + int CopyVale( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + valesBuffer, + buffer, + forceClean + // + ); + } + + // + // + // + + // + double GetHigherPeak( + double peak, // Peak Source + int barIndex = 0, // Bar Index + int loopback = 576 // Max Allowed Loopback + ) + { + // + double result = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + if (peak <= 0) + { + return result; + } + + // + double iValue = 0; + int index = barIndex; + bool canContinue = true; + while (canContinue) + { + // + iValue = GetPeak(index); + if (iValue > peak) + { + // + result = iValue; + break; + } + + // + canContinue = index < barIndex + loopback; + index++; + } + + // + return result; + } + + // + double GetLowerPeak( + double peak, // Peak Source + int barIndex = 0, // Bar Index + int loopback = 576 // Max Allowed Loopback + ) + { + // + double result = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + if (peak <= 0) + { + return result; + } + + // + double iValue = 0; + int index = barIndex; + bool canContinue = true; + while (canContinue) + { + // + iValue = GetPeak(index); + if (iValue < peak) + { + // + result = iValue; + break; + } + + // + canContinue = index < barIndex + loopback; + index++; + } + + // + return result; + } + + // + double GetHigherVale( + double vale, // Vale Source + int barIndex = 0, // Bar Index + int loopback = 576 // Max Allowed Loopback + ) + { + // + double result = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + if (vale <= 0) + { + return result; + } + + // + double iValue = 0; + int index = barIndex; + bool canContinue = true; + while (canContinue) + { + // + iValue = GetVale(index); + if (iValue > vale) + { + // + result = iValue; + break; + } + + // + canContinue = index > barIndex + loopback; + index++; + } + + // + return result; + } + + // + double GetLowerVale( + double vale, // Vale Source + int barIndex = 0, // Bar Index + int loopback = 576 // Max Allowed Loopback + ) + { + // + double result = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + if (vale <= 0) + { + return result; + } + + // + double iValue = 0; + int index = barIndex; + bool canContinue = true; + while (canContinue) + { + // + iValue = GetVale(index); + if (iValue < vale) + { + // + result = iValue; + break; + } + + // + canContinue = index > barIndex + loopback; + index++; + } + + // + return result; + } + + // + // + // + + // + double GetLowestPeak( + int barIndex, + int &index, + double &vale, + int loopback = 576 // + ) + { + // + double result = 0; + + // + index = -1; + vale = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + Calculate(); + + // + for (int i = 0; i < barIndex + loopback; i++) + { + // + double iPeak = GetPeak(i); + if (iPeak == 0) + { + break; + } + + // + if (iPeak > 0 && (result == 0 || + result >= iPeak)) + { + // + index = i; + result = iPeak; + vale = GetVale(index); + } + } + + // + return result; + } + + // + double GetHighestPeak( + int barIndex, + int &index, + double &vale, + int loopback = 576 // + ) + { + // + double result = 0; + + // + index = -1; + vale = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + Calculate(); + + // + for (int i = 0; i < barIndex + loopback; i++) + { + // + double iPeak = GetPeak(i); + if (iPeak == 0) + { + break; + } + + // + if (iPeak > 0 && (result == 0 || + result <= iPeak)) + { + // + index = i; + result = iPeak; + vale = GetVale(index); + } + } + + // + return result; + } + + // + double GetLowestVale( + int barIndex, + int &index, + double &peak, + int loopback = 576 // + ) + { + // + double result = 0; + + // + index = -1; + peak = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + Calculate(); + + // + for (int i = 0; i < barIndex + loopback; i++) + { + // + double iPeak = GetVale(i); + if (iPeak == 0) + { + break; + } + + // + if (iPeak > 0 && (result == 0 || + result >= iPeak)) + { + // + index = i; + result = iPeak; + peak = GetPeak(index); + } + } + + // + return result; + } + + // + double GetHighestVale( + int barIndex, + int &index, + double &peak, + int loopback = 576 // + ) + { + // + double result = 0; + + // + index = -1; + peak = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 576) + { + loopback = 576; + } + + // + Calculate(); + + // + for (int i = 0; i < barIndex + loopback; i++) + { + // + double iPeak = GetVale(i); + if (iPeak == 0) + { + break; + } + + // + if (iPeak > 0 && (result == 0 || + result <= iPeak)) + { + // + index = i; + result = iPeak; + peak = GetPeak(index); + } + } + + // + return result; + } + + // + // CURRENT ... + + // + // HH ... + + // + double GetCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cHHBuffer[barIndex]; + } + + // + int CopyCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cLLBuffer[barIndex]; + } + + // + int CopyCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cLLBuffer, + buffer, + forceClean + // + ); + } + + // + // SHORT ... + + // + // HH ... + + // + double GetSHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sHHBuffer[barIndex]; + } + + // + int CopySHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetSLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sLLBuffer[barIndex]; + } + + // + int CopySLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sLLBuffer, + buffer, + forceClean + // + ); + } + + // + // MEDIUM ... + + // + // HH ... + + // + double GetMHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mHHBuffer[barIndex]; + } + + // + int CopyMHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetMLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mLLBuffer[barIndex]; + } + + // + int CopyMLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mLLBuffer, + buffer, + forceClean + // + ); + } + + // + // LONG ... + + // + // HH ... + + // + double GetLHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lHHBuffer[barIndex]; + } + + // + int CopyLHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetLLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lLLBuffer[barIndex]; + } + + // + int CopyLLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lLLBuffer, + buffer, + forceClean + // + ); + } + + // + // HIND ... + + // + // HH ... + + // + double GetHHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hHHBuffer[barIndex]; + } + + // + int CopyHHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetHLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hLLBuffer[barIndex]; + } + + // + int CopyHLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hLLBuffer, + buffer, + forceClean + // + ); + } + + // + // VWAP ... + + // + // FAST ... + + // + double GetVWapFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapFastBuffer[barIndex]; + } + + // + int CopyVWapFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapFastBuffer, + buffer, + forceClean + // + ); + } + + // + // STATE FAST ... + + // + double GetVWapFastState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapFastStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapFastStateBuffer[barIndex]; + } + + // + int CopyVWapFastState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapFastStateBuffer, + buffer, + forceClean + // + ); + } + + // + // MID ... + + // + double GetVWapMid( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapMidBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapMidBuffer[barIndex]; + } + + // + int CopyVWapMid( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapMidBuffer, + buffer, + forceClean + // + ); + } + + // + // STATE MID ... + + // + double GetVWapMidState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapMidStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapMidStateBuffer[barIndex]; + } + + // + int CopyVWapMidState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapMidStateBuffer, + buffer, + forceClean + // + ); + } + + // + // SLOW ... + + // + double GetVWapSlowBuffer( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapSlowBuffer[barIndex]; + } + + // + int CopyVWapSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // STATE SLOW ... + + // + double GetVWapSlowState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapSlowStateBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapSlowStateBuffer[barIndex]; + } + + // + int CopyVWapSlowState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapSlowStateBuffer, + buffer, + forceClean + // + ); + } + + // + // VOLUME ... + + // + double GetVWapVolume( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapVolumeBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapVolumeBuffer[barIndex]; + } + + // + int CopyVWapVolume( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + // PRICE ... + + // + double GetVWapPrice( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(vwapPriceBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return vwapPriceBuffer[barIndex]; + } + + // + int CopyVWapPrice( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + vwapPriceBuffer, + buffer, + forceClean + // + ); + } + + // + // Converts to State ... + ENUM_XVWAP_STATES ToVWAPState(double value) + { + // + ENUM_XVWAP_STATES result = + value == 1 + ? XVWAP_STATE_BULLISH + : value == 2 + ? XVWAP_STATE_BEARISH + : XVWAP_STATE_NEUTURAL; + + // + return result; + } + + // + bool IsVWAPBullish(double value) + { + // + bool result = false; + + // + result = ToVWAPState(value) == XVWAP_STATE_BULLISH; + + // + return result; + } + + // + bool IsVWAPBearish(double value) + { + // + bool result = false; + + // + result = ToVWAPState(value) == XVWAP_STATE_BEARISH; + + // + return result; + } + + // + bool IsVWAPNeutural(double value) + { + // + bool result = false; + + // + result = ToVWAPState(value) == XVWAP_STATE_NEUTURAL; + + // + return result; + } + + // + // XDON ... + + // + // OPEN ... + + // + // UPPER ... + + // + double GetDonOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donOpenUpperBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donOpenUpperBuffer[barIndex]; + } + + // + int CopyDonOpenUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + // LOWER ... + + // + double GetDonOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donOpenLowerBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donOpenLowerBuffer[barIndex]; + } + + // + int CopyDonOpenLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // CLOSE ... + + // + // UPPER ... + + // + double GetDonCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donCloseUpperBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donCloseUpperBuffer[barIndex]; + } + + // + int CopyDonCloseUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + // LOWER ... + + // + double GetDonCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donCloseLowerBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donCloseLowerBuffer[barIndex]; + } + + // + int CopyDonCloseLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // HIGH ... + + // + // UPPER ... + + // + double GetDonHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donHighUpperBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donHighUpperBuffer[barIndex]; + } + + // + int CopyDonHighUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + // LOWER ... + + // + double GetDonHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donHighLowerBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donHighLowerBuffer[barIndex]; + } + + // + int CopyDonHighLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // LOW ... + + // + // UPPER ... + + // + double GetDonLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donLowUpperBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donLowUpperBuffer[barIndex]; + } + + // + int CopyDonLowUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + // LOWER ... + + // + double GetDonLoweLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(donLowLowerBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return donLowLowerBuffer[barIndex]; + } + + // + int CopyDonLoweLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + donLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // FIBONACCHI ... + + // + // LEVEL 1 ... + + // + double GetFiboLevel1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fl1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fl1Buffer[barIndex]; + } + + // + int CopyFiboLevel1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // FiboLevel To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fl1Buffer, + buffer, + forceClean + // + ); + } + + // + // LEVEL 2 ... + + // + double GetFiboLevel2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fl2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fl2Buffer[barIndex]; + } + + // + int CopyFiboLevel2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // FiboLevel To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fl2Buffer, + buffer, + forceClean + // + ); + } + + // + // LEVEL 3 ... + + // + double GetFiboLevel3( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fl3Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fl3Buffer[barIndex]; + } + + // + int CopyFiboLevel3( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // FiboLevel To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fl3Buffer, + buffer, + forceClean + // + ); + } + + // + // LEVEL 4 ... + + // + double GetFiboLevel4( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fl4Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fl4Buffer[barIndex]; + } + + // + int CopyFiboLevel4( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // FiboLevel To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fl4Buffer, + buffer, + forceClean + // + ); + } + + // + // LEVEL 5 ... + + // + double GetFiboLevel5( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fl5Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fl5Buffer[barIndex]; + } + + // + int CopyFiboLevel5( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // FiboLevel To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fl5Buffer, + buffer, + forceClean + // + ); + } + + // + // Conditions Generation ... + + bool GetConditions( + X121Conditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + XOHCL zBar; + result = zBar.Init( + mSymbol, + mPeriod, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Buffers ... + + // + CopyRSI( + zIndex, + loopback, + conditions.rsiBuffer // + ); + + // + CopySar( + zIndex, + loopback, + conditions.sarBuffer // + ); + + // + CopyAtr( + zIndex, + loopback, + conditions.atrBuffer // + ); + + // + CopyAtrUpper( + zIndex, + loopback, + conditions.atrUpperBuffer // + ); + + // + CopyAtrUpperRaw( + zIndex, + loopback, + conditions.atrUpperRawBuffer // + ); + + // + CopyAtrLower( + zIndex, + loopback, + conditions.atrLowerBuffer // + ); + + // + CopyAtrLowerRaw( + zIndex, + loopback, + conditions.atrLowerRawBuffer // + ); + + // + CopyPeak( + zIndex, + loopback, + conditions.peaksBuffer // + ); + + // + CopyVale( + zIndex, + loopback, + conditions.valesBuffer // + ); + + // + CopyCHH( + zIndex, + loopback, + conditions.cHHBuffer // + ); + + // + CopyCLL( + zIndex, + loopback, + conditions.cLLBuffer // + ); + + // + CopySHH( + zIndex, + loopback, + conditions.sHHBuffer // + ); + + // + CopySLL( + zIndex, + loopback, + conditions.sLLBuffer // + ); + + // + CopyMHH( + zIndex, + loopback, + conditions.mHHBuffer // + ); + + // + CopyMLL( + zIndex, + loopback, + conditions.mLLBuffer // + ); + + // + CopyLHH( + zIndex, + loopback, + conditions.lHHBuffer // + ); + + // + CopyLLL( + zIndex, + loopback, + conditions.lLLBuffer // + ); + + // + CopyHHH( + zIndex, + loopback, + conditions.hHHBuffer // + ); + + // + CopyHLL( + zIndex, + loopback, + conditions.hLLBuffer // + ); + + // + CopyVWapFast( + zIndex, + loopback, + conditions.vwapFastBuffer // + ); + + // + CopyVWapFastState( + zIndex, + loopback, + conditions.vwapFastStateBuffer // + ); + + // + CopyVWapMid( + zIndex, + loopback, + conditions.vwapMidBuffer // + ); + + // + CopyVWapMidState( + zIndex, + loopback, + conditions.vwapMidStateBuffer // + ); + + // + CopyVWapSlow( + zIndex, + loopback, + conditions.vwapSlowBuffer // + ); + + // + CopyVWapSlowState( + zIndex, + loopback, + conditions.vwapSlowStateBuffer // + ); + + // + CopyVWapVolume( + zIndex, + loopback, + conditions.vwapVolumeBuffer // + ); + + // + CopyVWapPrice( + zIndex, + loopback, + conditions.vwapPriceBuffer // + ); + + // + CopyDonOpenUpper( + zIndex, + loopback, + conditions.donOpenUpperBuffer // + ); + + // + CopyDonOpenLower( + zIndex, + loopback, + conditions.donOpenLowerBuffer // + ); + + // + CopyDonCloseUpper( + zIndex, + loopback, + conditions.donCloseUpperBuffer // + ); + + // + CopyDonCloseLower( + zIndex, + loopback, + conditions.donCloseLowerBuffer // + ); + + // + CopyDonHighUpper( + zIndex, + loopback, + conditions.donHighUpperBuffer // + ); + + // + CopyDonHighLower( + zIndex, + loopback, + conditions.donHighLowerBuffer // + ); + + // + CopyDonLowUpper( + zIndex, + loopback, + conditions.donLowUpperBuffer // + ); + + // + CopyDonLoweLower( + zIndex, + loopback, + conditions.donLowLowerBuffer // + ); + + // + CopyFiboLevel1( + zIndex, + loopback, + conditions.fl1Buffer // + ); + + // + CopyFiboLevel2( + zIndex, + loopback, + conditions.fl2Buffer // + ); + + // + CopyFiboLevel3( + zIndex, + loopback, + conditions.fl3Buffer // + ); + + // + CopyFiboLevel4( + zIndex, + loopback, + conditions.fl4Buffer // + ); + + // + CopyFiboLevel5( + zIndex, + loopback, + conditions.fl5Buffer // + ); + + // + // Conditions ... + + // + int cIDX = 1; + int pIDX = cIDX + 1; + + // + // XRSI ... + + // + bool isRSIOverBought = conditions.rsiBuffer[cIDX] > mInputs.rsiOverBoughtLevel; + bool isRSIOverBoughtPrev = conditions.rsiBuffer[pIDX] > mInputs.rsiOverBoughtLevel; + + // + bool isRSICrossedOverOverBought = isRSIOverBought && + !isRSIOverBoughtPrev; + bool isRSICrossedUnderOverBought = !isRSIOverBought && + isRSIOverBoughtPrev; + + // + bool isRSIOverSold = conditions.rsiBuffer[cIDX] < mInputs.rsiOverSoldLevel; + bool isRSIOverSoldPrev = conditions.rsiBuffer[pIDX] < mInputs.rsiOverSoldLevel; + + // + bool isRSICrossedUnderOverSold = isRSIOverSold && + !isRSIOverSoldPrev; + bool isRSICrossedOverOverSold = !isRSIOverSold && + isRSIOverSoldPrev; + + // + // XSAR ... + + // + bool isSarBullish = conditions.sarBuffer[cIDX] < cBar.low; + bool isSarBullishPrev = conditions.sarBuffer[pIDX] < pBar.low; + + // + bool isSarBearish = conditions.sarBuffer[cIDX] > cBar.high; + bool isSarBearishPrev = conditions.sarBuffer[pIDX] > pBar.high; + + // + bool isSarSwitchedToBullish = isSarBullish && + !isSarBullishPrev; + bool isSarSwitchedToBearish = isSarBearish && + !isSarBearishPrev; + + // + // XPV ... + + // + bool isNewPeak = conditions.peaksBuffer[cIDX] != conditions.peaksBuffer[pIDX]; + bool isNewPeakOverLast = isNewPeak && + conditions.peaksBuffer[cIDX] > conditions.peaksBuffer[pIDX]; + bool isNewPeakUnderLast = isNewPeak && + conditions.peaksBuffer[cIDX] < conditions.peaksBuffer[pIDX]; + + // + bool isNewVale = conditions.valesBuffer[cIDX] != conditions.valesBuffer[pIDX]; + bool isNewValeOverLast = isNewVale && + conditions.valesBuffer[cIDX] > conditions.valesBuffer[pIDX]; + bool isNewValeUnderLast = isNewVale && + conditions.valesBuffer[cIDX] < conditions.valesBuffer[pIDX]; + + // + // XVWAP ... + + // + bool isVWapFastBullish = IsVWAPBullish(conditions.vwapFastStateBuffer[cIDX]); + bool isVWapFastBullishPrev = IsVWAPBullish(conditions.vwapFastStateBuffer[pIDX]); + + // + bool isVWapFastBearish = IsVWAPBearish(conditions.vwapFastStateBuffer[cIDX]); + bool isVWapFastBearishPrev = IsVWAPBearish(conditions.vwapFastStateBuffer[pIDX]); + + // + bool isVWapFastNeutural = IsVWAPNeutural(conditions.vwapFastStateBuffer[cIDX]); + bool isVWapFastNeuturalPrev = IsVWAPNeutural(conditions.vwapFastStateBuffer[pIDX]); + + // + bool isVWapMidBullish = IsVWAPBullish(conditions.vwapMidStateBuffer[cIDX]); + bool isVWapMidBullishPrev = IsVWAPBullish(conditions.vwapMidStateBuffer[pIDX]); + + // + bool isVWapMidBearish = IsVWAPBearish(conditions.vwapMidStateBuffer[cIDX]); + bool isVWapMidBearishPrev = IsVWAPBearish(conditions.vwapMidStateBuffer[pIDX]); + + // + bool isVWapMidNeutural = IsVWAPNeutural(conditions.vwapMidStateBuffer[cIDX]); + bool isVWapMidNeuturalPrev = IsVWAPNeutural(conditions.vwapMidStateBuffer[pIDX]); + + // + bool isVWapSlowBullish = IsVWAPBullish(conditions.vwapSlowStateBuffer[cIDX]); + bool isVWapSlowBullishPrev = IsVWAPBullish(conditions.vwapSlowStateBuffer[pIDX]); + + // + bool isVWapSlowBearish = IsVWAPBearish(conditions.vwapSlowStateBuffer[cIDX]); + bool isVWapSlowBearishPrev = IsVWAPBearish(conditions.vwapSlowStateBuffer[pIDX]); + + // + bool isVWapSlowNeutural = IsVWAPNeutural(conditions.vwapSlowStateBuffer[cIDX]); + bool isVWapSlowNeuturalPrev = IsVWAPNeutural(conditions.vwapSlowStateBuffer[pIDX]); + + // + bool isVWapFastOverMid = conditions.vwapFastBuffer[cIDX] > conditions.vwapMidBuffer[cIDX]; + bool isVWapFastOverMidPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapMidBuffer[pIDX]; + + // + bool isVWapMidOverSlow = conditions.vwapMidBuffer[cIDX] > conditions.vwapSlowBuffer[cIDX]; + bool isVWapMidOverSlowPrev = conditions.vwapMidBuffer[pIDX] > conditions.vwapSlowBuffer[pIDX]; + + // + bool isVWapFastUnderMid = conditions.vwapFastBuffer[cIDX] < conditions.vwapMidBuffer[cIDX]; + bool isVWapFastUnderMidPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapMidBuffer[pIDX]; + + // + bool isVWapMidUnderSlow = conditions.vwapMidBuffer[cIDX] < conditions.vwapSlowBuffer[cIDX]; + bool isVWapMidUnderSlowPrev = conditions.vwapMidBuffer[pIDX] < conditions.vwapSlowBuffer[pIDX]; + + // + bool isVWapBullishState = isVWapFastBullish && + isVWapMidBullish && + isVWapSlowBullish; + bool isVWapBullishStatePrev = isVWapFastBullishPrev && + isVWapMidBullishPrev && + isVWapSlowBullishPrev; + + // + bool isVWapBearishState = isVWapFastBearish && + isVWapMidBearish && + isVWapSlowBearish; + bool isVWapBearishStatePrev = isVWapFastBearishPrev && + isVWapMidBearishPrev && + isVWapSlowBearishPrev; + + // + bool isVWapNeuturalState = isVWapFastNeutural && + isVWapMidNeutural && + isVWapSlowNeutural; + bool isVWapNeuturalStatePrev = isVWapFastNeuturalPrev && + isVWapMidNeuturalPrev && + isVWapSlowNeuturalPrev; + + // + bool isVWapBullishOrdered = isVWapFastOverMid && + isVWapMidOverSlow; + bool isVWapBullishOrderedPrev = isVWapFastOverMidPrev && + isVWapMidOverSlowPrev; + + // + bool isVWapBearishOrdered = isVWapFastUnderMid && + isVWapMidUnderSlow; + bool isVWapBearishOrderedPrev = isVWapFastUnderMidPrev && + isVWapMidUnderSlowPrev; + + // + bool isVWapSwitchedToBullishOrdered = isVWapBullishOrdered && + !isVWapBullishOrderedPrev; + bool isVWapSwitchedToBearishOrdered = isVWapBearishOrdered && + !isVWapBearishOrderedPrev; + + // + bool isVWapSwitchedToBullishState = isVWapBullishState && + !isVWapBullishStatePrev; + bool isVWapSwitchedToBearishState = isVWapBearishState && + !isVWapBearishStatePrev; + bool isVWapSwitchedToNeuturalState = isVWapNeuturalState && + !isVWapNeuturalStatePrev; + + // + // XDON ... + + // + // XFIBONACCI ... + + // + bool isOerFib1 = cBar.low > conditions.fl1Buffer[cIDX]; + bool isOerFib2 = cBar.low > conditions.fl2Buffer[cIDX]; + bool isOerFib3 = cBar.low > conditions.fl3Buffer[cIDX]; + bool isOerFib4 = cBar.low > conditions.fl4Buffer[cIDX]; + bool isOerFib5 = cBar.low > conditions.fl5Buffer[cIDX]; + + // + bool isUnderFib1 = cBar.high < conditions.fl1Buffer[cIDX]; + bool isUnderFib2 = cBar.high < conditions.fl2Buffer[cIDX]; + bool isUnderFib3 = cBar.high < conditions.fl3Buffer[cIDX]; + bool isUnderFib4 = cBar.high < conditions.fl4Buffer[cIDX]; + bool isUnderFib5 = cBar.high < conditions.fl5Buffer[cIDX]; + + // + bool isCloseOerFib1 = cBar.close > conditions.fl1Buffer[cIDX]; + bool isCloseOerFib2 = cBar.close > conditions.fl2Buffer[cIDX]; + bool isCloseOerFib3 = cBar.close > conditions.fl3Buffer[cIDX]; + bool isCloseOerFib4 = cBar.close > conditions.fl4Buffer[cIDX]; + bool isCloseOerFib5 = cBar.close > conditions.fl5Buffer[cIDX]; + + // + bool isCloseUnderFib1 = cBar.close < conditions.fl1Buffer[cIDX]; + bool isCloseUnderFib2 = cBar.close < conditions.fl2Buffer[cIDX]; + bool isCloseUnderFib3 = cBar.close < conditions.fl3Buffer[cIDX]; + bool isCloseUnderFib4 = cBar.close < conditions.fl4Buffer[cIDX]; + bool isCloseUnderFib5 = cBar.close < conditions.fl5Buffer[cIDX]; + + // + + // + // Set ... + conditions.isRSIOverBought = isRSIOverBought; + conditions.isRSICrossedOverOverBought = isRSICrossedOverOverBought; + conditions.isRSICrossedUnderOverBought = isRSICrossedUnderOverBought; + conditions.isRSIOverSold = isRSIOverSold; + conditions.isRSICrossedUnderOverSold = isRSICrossedUnderOverSold; + conditions.isRSICrossedOverOverSold = isRSICrossedOverOverSold; + conditions.isSarBullish = isSarBullish; + conditions.isSarBearish = isSarBearish; + conditions.isSarSwitchedToBullish = isSarSwitchedToBullish; + conditions.isSarSwitchedToBearish = isSarSwitchedToBearish; + conditions.isNewPeak = isNewPeak; + conditions.isNewPeakOverLast = isNewPeakOverLast; + conditions.isNewPeakUnderLast = isNewPeakUnderLast; + conditions.isNewVale = isNewVale; + conditions.isNewValeOverLast = isNewValeOverLast; + conditions.isNewValeUnderLast = isNewValeUnderLast; + conditions.isVWapFastBullish = isVWapFastBullish; + conditions.isVWapFastBearish = isVWapFastBearish; + conditions.isVWapFastNeutural = isVWapFastNeutural; + conditions.isVWapMidBullish = isVWapMidBullish; + conditions.isVWapMidBearish = isVWapMidBearish; + conditions.isVWapMidNeutural = isVWapMidNeutural; + conditions.isVWapSlowBullish = isVWapSlowBullish; + conditions.isVWapSlowBearish = isVWapSlowBearish; + conditions.isVWapSlowNeutural = isVWapSlowNeutural; + conditions.isVWapFastOverMid = isVWapFastOverMid; + conditions.isVWapMidOverSlow = isVWapMidOverSlow; + conditions.isVWapFastUnderMid = isVWapFastUnderMid; + conditions.isVWapMidUnderSlow = isVWapMidUnderSlow; + conditions.isVWapBullishState = isVWapBullishState; + conditions.isVWapBearishState = isVWapBearishState; + conditions.isVWapNeuturalState = isVWapNeuturalState; + conditions.isVWapBullishOrdered = isVWapBullishOrdered; + conditions.isVWapBearishOrdered = isVWapBearishOrdered; + conditions.isVWapSwitchedToBullishOrdered = isVWapSwitchedToBullishOrdered; + conditions.isVWapSwitchedToBearishOrdered = isVWapSwitchedToBearishOrdered; + conditions.isVWapSwitchedToBullishState = isVWapSwitchedToBullishState; + conditions.isVWapSwitchedToBearishState = isVWapSwitchedToBearishState; + conditions.isVWapSwitchedToNeuturalState = isVWapSwitchedToNeuturalState; + conditions.isOerFib1 = isOerFib1; + conditions.isOerFib2 = isOerFib2; + conditions.isOerFib3 = isOerFib3; + conditions.isOerFib4 = isOerFib4; + conditions.isOerFib5 = isOerFib5; + conditions.isUnderFib1 = isUnderFib1; + conditions.isUnderFib2 = isUnderFib2; + conditions.isUnderFib3 = isUnderFib3; + conditions.isUnderFib4 = isUnderFib4; + conditions.isUnderFib5 = isUnderFib5; + conditions.isCloseOerFib1 = isCloseOerFib1; + conditions.isCloseOerFib2 = isCloseOerFib2; + conditions.isCloseOerFib3 = isCloseOerFib3; + conditions.isCloseOerFib4 = isCloseOerFib4; + conditions.isCloseOerFib5 = isCloseOerFib5; + conditions.isCloseUnderFib1 = isCloseUnderFib1; + conditions.isCloseUnderFib2 = isCloseUnderFib2; + conditions.isCloseUnderFib3 = isCloseUnderFib3; + conditions.isCloseUnderFib4 = isCloseUnderFib4; + conditions.isCloseUnderFib5 = isCloseUnderFib5; + + // + return result; + } + + // + protected: + // + + // + private: + // + // Props ... + X121Inputs mInputs; // Inputs ... + + // + // Buffers ... + + // + int mRSIHandler; // RSI Handler ... + + // + // Buffers ... + double peaksBuffer[]; + double valesBuffer[]; + double sarBuffer[]; + double atrUpperBuffer[]; + double atrLowerBuffer[]; + double vwapFastBuffer[]; + double vwapMidBuffer[]; + double vwapSlowBuffer[]; + double donOpenUpperBuffer[]; + double donOpenLowerBuffer[]; + double donCloseUpperBuffer[]; + double donCloseLowerBuffer[]; + double donHighUpperBuffer[]; + double donHighLowerBuffer[]; + double donLowUpperBuffer[]; + double donLowLowerBuffer[]; + double fl1Buffer[]; + double fl2Buffer[]; + double fl3Buffer[]; + double fl4Buffer[]; + double fl5Buffer[]; + double cHHBuffer[]; + double cLLBuffer[]; + double sHHBuffer[]; + double sLLBuffer[]; + double mHHBuffer[]; + double mLLBuffer[]; + double lHHBuffer[]; + double lLLBuffer[]; + double hHHBuffer[]; + double hLLBuffer[]; + double atrBuffer[]; + double atrUpperRawBuffer[]; + double atrLowerRawBuffer[]; + double vwapVolumeBuffer[]; + double vwapPriceBuffer[]; + double vwapFastStateBuffer[]; + double vwapMidStateBuffer[]; + double vwapSlowStateBuffer[]; + double rsiBuffer[]; + + // + // Tools ... + + /** + * Calculate Buffers ... + */ + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Buffers ... + + // + // RSI ... + CopyBuffer( + mRSIHandler, + 0, + 0, + totalBars, + rsiBuffer + // + ); + + // + // XSAR ... + CopyBuffer( + mHandler, + X121_SAR_LINE, + 0, + totalBars, + sarBuffer + // + ); + + // + // ATR ... + + // + CopyBuffer( + mHandler, + X121_ATR_UPPER_LINE, + 0, + totalBars, + atrUpperBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_ATR_LOWER_LINE, + 0, + totalBars, + atrLowerBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_ATR_LINE, + 0, + totalBars, + atrBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_ATR_UPPER_RAW_LINE, + 0, + totalBars, + atrUpperRawBuffer + // + ); + + // + CopyBuffer( + mHandler, + X121_ATR_LOWER_RAW_LINE, + 0, + totalBars, + atrLowerRawBuffer + // + ); + + // + // XPV ... + + // + // PEAKS ... + CopyBuffer( + mHandler, + X121_PEAKS_LINE, + 0, + totalBars, + peaksBuffer + // + ); + + // + // VALES ... + CopyBuffer( + mHandler, + X121_VALES_LINE, + 0, + totalBars, + valesBuffer + // + ); + + // + // CURRENT ... + + // + // HH ... + CopyBuffer( + mHandler, + X121_CURRENT_HH_LINE, + 0, + totalBars, + cHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + X121_CURRENT_LL_LINE, + 0, + totalBars, + cLLBuffer + // + ); + + // + // SHORT ... + + // + // HH ... + CopyBuffer( + mHandler, + X121_SHORT_HH_LINE, + 0, + totalBars, + sHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + X121_SHORT_LL_LINE, + 0, + totalBars, + sLLBuffer + // + ); + + // + // MEDIUM ... + + // + // HH ... + CopyBuffer( + mHandler, + X121_MEDIUM_HH_LINE, + 0, + totalBars, + mHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + X121_MEDIUM_LL_LINE, + 0, + totalBars, + mLLBuffer + // + ); + + // + // LONG ... + + // + // HH ... + CopyBuffer( + mHandler, + X121_LONG_HH_LINE, + 0, + totalBars, + lHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + X121_LONG_LL_LINE, + 0, + totalBars, + lLLBuffer + // + ); + + // + // HIND ... + + // + // HH ... + CopyBuffer( + mHandler, + X121_HIND_HH_LINE, + 0, + totalBars, + hHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + X121_HIND_LL_LINE, + 0, + totalBars, + hLLBuffer + // + ); + + // + // XVWAP ... + + // + // FAST ... + CopyBuffer( + mHandler, + X121_VWAP_FAST_LINE, + 0, + totalBars, + vwapFastBuffer + // + ); + + // + // FAST STATE ... + CopyBuffer( + mHandler, + X121_VWAP_FAST_STATE_LINE, + 0, + totalBars, + vwapFastStateBuffer + // + ); + + // + // MID ... + CopyBuffer( + mHandler, + X121_VWAP_MID_LINE, + 0, + totalBars, + vwapMidBuffer + // + ); + + // + // MID STATE ... + CopyBuffer( + mHandler, + X121_VWAP_MID_STATE_LINE, + 0, + totalBars, + vwapMidStateBuffer + // + ); + + // + // SLOW ... + CopyBuffer( + mHandler, + X121_VWAP_SLOW_LINE, + 0, + totalBars, + vwapSlowBuffer + // + ); + + // + // SLOW STATE ... + CopyBuffer( + mHandler, + X121_VWAP_SLOW_STATE_LINE, + 0, + totalBars, + vwapSlowStateBuffer + // + ); + + // + // VOLUME ... + CopyBuffer( + mHandler, + X121_VWAP_VOLUME_LINE, + 0, + totalBars, + vwapVolumeBuffer + // + ); + + // + // PRICE ... + CopyBuffer( + mHandler, + X121_VWAP_PRICE_LINE, + 0, + totalBars, + vwapPriceBuffer + // + ); + + // + // FIBONACCI ... + + // + // LEVEL 1 ... + CopyBuffer( + mHandler, + X121_FIB_LEVEL_1_LINE, + 0, + totalBars, + fl1Buffer + // + ); + + // + // LEVEL 2 ... + CopyBuffer( + mHandler, + X121_FIB_LEVEL_2_LINE, + 0, + totalBars, + fl2Buffer + // + ); + + // + // LEVEL 3 ... + CopyBuffer( + mHandler, + X121_FIB_LEVEL_3_LINE, + 0, + totalBars, + fl3Buffer + // + ); + + // + // LEVEL 4 ... + CopyBuffer( + mHandler, + X121_FIB_LEVEL_4_LINE, + 0, + totalBars, + fl4Buffer + // + ); + + // + // LEVEL 5 ... + CopyBuffer( + mHandler, + X121_FIB_LEVEL_5_LINE, + 0, + totalBars, + fl5Buffer + // + ); + + // + // XDON ... + + // + // OPEN ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_OPEN_UPPER_LINE, + 0, + totalBars, + donOpenUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_OPEN_LOWER_LINE, + 0, + totalBars, + donOpenLowerBuffer + // + ); + + // + // CLOSE ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_CLOSE_UPPER_LINE, + 0, + totalBars, + donCloseUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_CLOSE_LOWER_LINE, + 0, + totalBars, + donCloseLowerBuffer + // + ); + + // + // HIGH ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_HIGH_UPPER_LINE, + 0, + totalBars, + donHighUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_HIGH_LOWER_LINE, + 0, + totalBars, + donHighLowerBuffer + // + ); + + // + // LOW ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_LOW_UPPER_LINE, + 0, + totalBars, + donLowUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_LOW_LOWER_LINE, + 0, + totalBars, + donLowLowerBuffer + // + ); + } +}; + +// \ No newline at end of file diff --git a/Documents/BKP/1/x-saherelm.x121.old.mq5 b/Documents/BKP/1/x-saherelm.x121.old.mq5 new file mode 100644 index 00000000..241e0133 --- /dev/null +++ b/Documents/BKP/1/x-saherelm.x121.old.mq5 @@ -0,0 +1,2321 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: X121 +// Description: Peaks and Vales ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm X121 Indicator" +#property strict + +// +// Definitions ... + +// +#define ShortName "X121" + +// +// Includes Common Library ... +#include "../Classes/x-saherelm.x-poi.class.mq5" +#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Makret Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Boundary Detection"; +input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method +input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method + +// +input group "Parabolic Sar Detection"; +input double sarStep = 0.02; // Step +input double sarMax = 0.2; // Maximum + +// +input group "Atr Detection"; +input int atrLength = 14; // Length +input double atrMultiplier = 1; // Multiplier +input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To +input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To +input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method + +// +input group "VWap Detection"; +input int vwapFastLength = 20; // Fast Length +input int vwapMidLength = 40; // Mid Length +input int vwapSlowLength = 60; // Slow Length +input ENUM_APPLIED_PRICE vwapAppliedTo = PRICE_CLOSE; // Applied To + +// +input group "Donchain Detection"; +input int donchainLength = 40; // Donchain Length + +// +input group "Presentation"; + +// +input int startCalculationForLastBars = 1000; // Calculate Last n Bars + +// +input bool showSar = true; // Show Parabolic Sar +input bool showAtr = true; // Show Atr +input bool showPeaks = true; // Show Peaks +input bool showVales = true; // Show Vales +input bool showVWap = true; // Show VWap +input bool showDonchain = true; // Show Donchain + +// +input group "Fibonachi Presentation"; +input bool showFibo1Levels = false; // Show Fibo 1st Level +input bool showFibo2Levels = false; // Show Fibo 2nd Level +input bool showFibo3Levels = false; // Show Fibo 3rd Level +input bool showFibo4Levels = false; // Show Fibo 4th Level +input bool showFibo5Levels = false; // Show Fibo 5th Level + +// +input group "Atr Presentation"; +input bool showAtrUpper = true; // Show Upper Zone +input bool showAtrLower = true; // Show Lower Zone + +// +input group "VWap Presentation"; +input bool showVWapFast = true; // Show VWap Fast +input bool showVWapMedium = true; // Show VWap Medium +input bool showVWapSlow = true; // Show VWap Slow + +// +input group "Donchain Presentation"; +input bool showUpper = true; // Show Upper Band +input bool showLower = true; // Show Lower Band +input bool showOpen = true; // Show Open +input bool showHigh = false; // Show High +input bool showClose = true; // Show Close +input bool showLow = false; // Show Low + +// +// Non Important Inputs ... + +// +input group "Fibonacci"; +input double fiboLevel1 = 0.236; // Fibio 1st Level +input double fiboLevel2 = 0.382; // Fibio 2st Level +input double fiboLevel3 = 0.5; // Fibio 3rd Level +input double fiboLevel4 = 0.618; // Fibio 4th Level +input double fiboLevel5 = 0.764; // Fibio 5th Level + +// +input int sarArrowCode = 159; // Parabolic Sar Arrow Code +input int peaksArrowCode = 159; // Peaks Arrow Code +input int valesArrowCode = 159; // Vales Arrow Code + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 +#define neuturalColorIDX 3 + +// +#property indicator_chart_window + +// +#property indicator_buffers 42 +#property indicator_plots 21 + +// +// PEAKS ... + +// +#define peaksBufferIndex 0 +double peaksBuffer[]; + +// +#property indicator_label1 "X121 PEAKS" +#property indicator_type1 DRAW_ARROW +#property indicator_color1 clrAqua +#property indicator_width1 1 + +// +// VALES ... + +// +#define valesBufferIndex 1 +double valesBuffer[]; + +// +#property indicator_label2 "X121 VALES" +#property indicator_type2 DRAW_ARROW +#property indicator_color2 clrMagenta +#property indicator_width2 1 + +// +// SAR ... + +// +#define sarBufferIndex 2 +double sarBuffer[]; + +// +#property indicator_label3 "X121 SAR" +#property indicator_type3 DRAW_ARROW +#property indicator_color3 clrYellow +#property indicator_width3 1 + +// +// ATR ... + +// +// Upper ... + +// +#define atrUpperBufferIndex 3 +double atrUpperBuffer[]; + +#property indicator_label4 "X121 ATRU" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrYellow +#property indicator_style4 STYLE_DOT +#property indicator_width4 2 + +// +// Lower ... + +// +#define atrLowerBufferIndex 4 +double atrLowerBuffer[]; + +#property indicator_label5 "X121 ATRL" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrYellow +#property indicator_style5 STYLE_DOT +#property indicator_width5 2 + +// +// VWAP ... + +// +// FAST ... +#define vwapFastBufferIndex 5 +double vwapFastBuffer[]; + +#define vwapFastColorBufferIndex 6 +double vwapFastColorBuffer[]; + +// +#define vwapFastPlotBufferIndex 5 +#property indicator_label6 "X121 VWF" +#property indicator_type6 DRAW_COLOR_LINE +#property indicator_color6 CLR_NONE, clrAqua, clrMagenta, clrGray +#property indicator_style6 STYLE_SOLID +#property indicator_width6 2 + +// +// MID ... +#define vwapMidBufferIndex 7 +double vwapMidBuffer[]; + +#define vwapMidColorBufferIndex 8 +double vwapMidColorBuffer[]; + +// +#define vwapMidPlotBufferIndex 6 +#property indicator_label7 "X121 VWM" +#property indicator_type7 DRAW_COLOR_LINE +#property indicator_color7 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style7 STYLE_SOLID +#property indicator_width7 2 + +// +// SLOW ... +#define vwapSlowBufferIndex 9 +double vwapSlowBuffer[]; + +#define vwapSlowColorBufferIndex 10 +double vwapSlowColorBuffer[]; + +// +#define vwapSlowPlotBufferIndex 7 +#property indicator_label8 "X121 VWS" +#property indicator_type8 DRAW_COLOR_LINE +#property indicator_color8 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray +#property indicator_style8 STYLE_SOLID +#property indicator_width8 2 + +// +// XDON ... + +// +// Open ... + +// +#define donOpenUpperBufferIndex 11 +double donOpenUpperBuffer[]; + +// +#define donOpenUpperPlotBufferIndex 8 +#property indicator_label9 "X121 O U" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrCornflowerBlue +#property indicator_width9 1 + +// +#define donOpenLowerBufferIndex 12 +double donOpenLowerBuffer[]; + +// +#define donOpenLowerPlotBufferIndex 9 +#property indicator_label10 "X121 O L" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrCornflowerBlue +#property indicator_width10 1 + +// +// High ... + +// +#define donHighUpperBufferIndex 13 +double donHighUpperBuffer[]; + +// +#define donHighUpperPlotBufferIndex 10 +#property indicator_label11 "X121 H U" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAquamarine +#property indicator_width11 1 + +// +#define donHighLowerBufferIndex 14 +double donHighLowerBuffer[]; + +// +#define donHighLowerPlotBufferIndex 11 +#property indicator_label12 "X121 H L" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrAquamarine +#property indicator_width12 1 + +// +// Low ... + +// +#define donLowUpperBufferIndex 15 +double donLowUpperBuffer[]; + +// +#define donLowUpperPlotBufferIndex 12 +#property indicator_label13 "X121 L U" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkOrchid +#property indicator_width13 1 + +// +#define donLowLowerBufferIndex 16 +double donLowLowerBuffer[]; + +// +#define donLowLowerPlotBufferIndex 13 +#property indicator_label14 "X121 L L" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrDarkOrchid +#property indicator_width14 1 + +// +// Close ... + +// +#define donCloseUpperBufferIndex 17 +double donCloseUpperBuffer[]; + +// +#define donCloseUpperPlotBufferIndex 14 +#property indicator_label15 "X121 C U" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrCoral +#property indicator_width15 1 + +// +#define donCloseLowerBufferIndex 18 +double donCloseLowerBuffer[]; + +// +#define donCloseLowerPlotBufferIndex 15 +#property indicator_label16 "X121 C L" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrCoral +#property indicator_width16 1 + +// +// FIBONACCI ... + +// +// FIBBO Level 1 ... + +// +#define fl1BufferIndex 19 +double fl1Buffer[]; + +// +#define fl1PlotBufferIndex 16 +#property indicator_label17 "X121 FL1" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrGold +#property indicator_style17 STYLE_DASHDOTDOT +#property indicator_width17 1 + +// +// FIBBO Level 2 ... + +// +#define fl2BufferIndex 20 +double fl2Buffer[]; + +// +#define fl2PlotBufferIndex 17 +#property indicator_label18 "X121 FL2" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrGold +#property indicator_style18 STYLE_DASHDOTDOT +#property indicator_width18 1 + +// +// FIBBO Level 3 ... + +// +#define fl3BufferIndex 21 +double fl3Buffer[]; + +// +#define fl3PlotBufferIndex 18 +#property indicator_label19 "X121 FL3" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrGold +#property indicator_style19 STYLE_DASHDOTDOT +#property indicator_width19 1 + +// +// FIBBO Level 4 ... + +// +#define fl4BufferIndex 22 +double fl4Buffer[]; + +// +#define fl4PlotBufferIndex 19 +#property indicator_label20 "X121 FL4" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrGold +#property indicator_style20 STYLE_DASHDOTDOT +#property indicator_width20 1 + +// +// FIBBO Level 5 ... + +// +#define fl5BufferIndex 23 +double fl5Buffer[]; + +// +#define fl5PlotBufferIndex 20 +#property indicator_label21 "X121 FL5" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrGold +#property indicator_style21 STYLE_DASHDOTDOT +#property indicator_width21 1 + +// +// Data Buffers ... + +// +int mLastBufferIndex = 23; + +// +// CURRENT ... + +// +#define cHHBufferIndex mLastBufferIndex + 1 +double cHHBuffer[]; + +// +#define cLLBufferIndex mLastBufferIndex + 2 +double cLLBuffer[]; + +// +// SHORT ... + +// +#define sHHBufferIndex mLastBufferIndex + 3 +double sHHBuffer[]; + +// +#define sLLBufferIndex mLastBufferIndex + 4 +double sLLBuffer[]; + +// +// MEDIUM ... + +// +#define mHHBufferIndex mLastBufferIndex + 5 +double mHHBuffer[]; + +// +#define mLLBufferIndex mLastBufferIndex + 6 +double mLLBuffer[]; + +// +// LONG ... + +// +#define lHHBufferIndex mLastBufferIndex + 7 +double lHHBuffer[]; + +// +#define lLLBufferIndex mLastBufferIndex + 8 +double lLLBuffer[]; + +// +// HIND ... + +// +#define hHHBufferIndex mLastBufferIndex + 9 +double hHHBuffer[]; + +// +#define hLLBufferIndex mLastBufferIndex + 10 +double hLLBuffer[]; + +// +// VOLUME ... +#define vwapVolumeBufferIndex mLastBufferIndex + 11 +double vwapVolumeBuffer[]; + +// +// Price ... +#define vwapPriceBufferIndex mLastBufferIndex + 12 +double vwapPriceBuffer[]; + +// +// Fast State ... +#define vwapFastStateBufferIndex mLastBufferIndex + 13 +double vwapFastStateBuffer[]; + +// +// Mid State ... +#define vwapMidStateBufferIndex mLastBufferIndex + 14 +double vwapMidStateBuffer[]; + +// +// Slow State ... +#define vwapSlowStateBufferIndex mLastBufferIndex + 15 +double vwapSlowStateBuffer[]; + +// +// ATR ... + +#define atrBufferIndex mLastBufferIndex + 16 +double atrBuffer[]; + +#define atrUpperRawBufferIndex mLastBufferIndex + 17 +double atrUpperRawBuffer[]; + +#define atrLowerRawBufferIndex mLastBufferIndex + 18 +double atrLowerRawBuffer[]; + +// +// Variables, Properties and etc ... + +// +// this counts Available Bars ... +int limit; + +// +int maxLength; + +// +// SAR Handler ... +int sarHandler = INVALID_HANDLE; + +// +// ATR Handler ... +int atrHandler = INVALID_HANDLE; + +// +double mHideColorIDX = 0; + +// +// XMarketCycle sc; +int mSCLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// XMarketCycle mc; +int mMCLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// XMarketCycle lc; +int mLCLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// XMarketCycle hc; +int mHCLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +/** + * Initialize Indicator ... + * + * @return ( int ) + */ +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Initialize Indicator Handlers ... + + // + // SAR ... + sarHandler = iSAR( + _Symbol, + _Period, + sarStep, + sarMax // + ); + bool isInited = sarHandler != INVALID_HANDLE; + if (!isInited) + { + return INIT_FAILED; + } + + // + // ATR ... + atrHandler = iATR( + _Symbol, + _Period, + atrLength // + ); + isInited = atrHandler != INVALID_HANDLE; + if (!isInited) + { + return INIT_FAILED; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +/** + * De Initialize Indicator ... + * + * @param reason: Integer, De Initialization Reason ... + */ +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 + + // + IndicatorRelease(sarHandler); + IndicatorRelease(atrHandler); +} + +/** + * Calculate Bars ... + * + * @param rates_total: Integer, Total Bars on Chart ... + * @param prev_calculated: Integer, Total Calculated Bars on Charts ... + * @param time: DateTime Array, History of Open Time ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param low: Double Array, History of Low Prices ... + * @param close: Double Array, History of Close Prices ... + * @param tick_volume: Long, History of Tick Volumes on Bar ... + * @param volume: Long, History of Trade Volumes ... + * @param spread: Double, History of Spread Price ... + * + * @return ( int ) + */ +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] // +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // Fill All Buffers by Zero ... + if (prev_calculated == 0) + { + // + ArrayInitialize(peaksBuffer, 0); + ArrayInitialize(valesBuffer, 0); + ArrayInitialize(sarBuffer, 0); + } + + // + // Validate Calculated Bars ... + + // + // SAR ... + int sarCalculatedBars = BarsCalculated(sarHandler); + + // + // ATR ... + int atrCalculatedBars = BarsCalculated(atrHandler); + + // + bool isPassedRequiredCalculatedBars = + // + // SAR ... + sarCalculatedBars >= maxLength && + // + // ATR... + sarCalculatedBars >= maxLength + // + ; + if (!isPassedRequiredCalculatedBars) + { + return prev_calculated; + } + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Buffers Copy ... + + // + // SAR ... + int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); + + // + // ATR ... + int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // + // SAR ... + copiedSars > 0 && + copiedAtrs > 0 + // + ; + if (!isPassedRequiredCopiedItems) + { + return prev_calculated; + } + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +/** + * Validate Input Args for Initialization ... + * + * @return ( bool ) + */ +bool ValidateInputs() +{ + // + bool result = + // + // PSAR ... + sarMax > 0 && + sarStep > 0 && + sarMax > sarStep && + // + // ATR ... + atrLength > 0 && + atrMultiplier > 0 && + // + // XDON ... + donchainLength > 0 && + // + // VWAP ... + vwapFastLength > 2 && + vwapMidLength > vwapFastLength && + vwapSlowLength > vwapMidLength && + // + // XPV ... + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +/** + * Extract Max Length of Inputs ... + * + * @return ( int ) + */ +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // XPV ... + result = MathMax(mSCLength, mMCLength); + result = MathMax(result, mLCLength); + result = MathMax(result, mHCLength); + + // + // XVWAP ... + result = MathMax(result, vwapFastLength); + result = MathMax(result, vwapMidLength); + result = MathMax(result, vwapSlowLength); + + // + // ATR ... + result = MathMax(result, atrLength); + + // + return result; +} + +/** + * Define Required Buffers ... + */ +void DefineBuffers() +{ + // + // PEAKS ... + + // + ENUM_DRAW_TYPE peaksDrawType = showPeaks ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(peaksBuffer, true); + SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaks); + PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, peaksDrawType); + + // + PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, peaksArrowCode); + + // + // VALES ... + + // + ENUM_DRAW_TYPE valesDrawType = showVales ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(valesBuffer, true); + SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showVales); + PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, valesDrawType); + + // + PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, valesArrowCode); + + // + // SAR ... + + // + ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(sarBuffer, true); + SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, showSar); + PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType); + + // + PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode); + + // + // ATR ... + + // + // UPPER ... + bool canShowAtrUpper = showAtr && showAtrUpper; + ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(atrUpperBuffer, true); + SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper); + PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType); + + // + // LOWER ... + bool canShowAtrLower = showAtr && showAtrLower; + ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(atrLowerBuffer, true); + SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower); + PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType); + + // + // XVWAP ... + + // + // Fast ... + ArraySetAsSeries(vwapFastBuffer, true); + ArraySetAsSeries(vwapFastColorBuffer, true); + SetIndexBuffer(vwapFastBufferIndex, vwapFastBuffer, INDICATOR_DATA); + SetIndexBuffer(vwapFastColorBufferIndex, vwapFastColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Mid ... + ArraySetAsSeries(vwapMidBuffer, true); + ArraySetAsSeries(vwapMidColorBuffer, true); + SetIndexBuffer(vwapMidBufferIndex, vwapMidBuffer, INDICATOR_DATA); + SetIndexBuffer(vwapMidColorBufferIndex, vwapMidColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Slow ... + ArraySetAsSeries(vwapSlowBuffer, true); + ArraySetAsSeries(vwapSlowColorBuffer, true); + SetIndexBuffer(vwapSlowBufferIndex, vwapSlowBuffer, INDICATOR_DATA); + SetIndexBuffer(vwapSlowColorBufferIndex, vwapSlowColorBuffer, INDICATOR_COLOR_INDEX); + + // + // XDON ... + + // + // Open ... + + // + // UPPER ... + bool canShowCOpenUpper = showDonchain && showUpper && showOpen; + ENUM_DRAW_TYPE donOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donOpenUpperBuffer, true); + SetIndexBuffer(donOpenUpperBufferIndex, donOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donOpenUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper); + PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_DRAW_TYPE, donOpenUpperDrawType); + + // + // LOWER ... + bool canShowCOpenLower = showDonchain && showLower && showOpen; + ENUM_DRAW_TYPE donOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donOpenLowerBuffer, true); + SetIndexBuffer(donOpenLowerBufferIndex, donOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donOpenLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower); + PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_DRAW_TYPE, donOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowCCloseUpper = showDonchain && showUpper && showClose; + ENUM_DRAW_TYPE donCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donCloseUpperBuffer, true); + SetIndexBuffer(donCloseUpperBufferIndex, donCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donCloseUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper); + PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_DRAW_TYPE, donCloseUpperDrawType); + + // + // LOWER ... + bool canShowCCloseLower = showDonchain && showLower && showClose; + ENUM_DRAW_TYPE donCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donCloseLowerBuffer, true); + SetIndexBuffer(donCloseLowerBufferIndex, donCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donCloseLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower); + PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_DRAW_TYPE, donCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowCHighUpper = showDonchain && showUpper && showHigh; + ENUM_DRAW_TYPE donHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donHighUpperBuffer, true); + SetIndexBuffer(donHighUpperBufferIndex, donHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donHighUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper); + PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_DRAW_TYPE, donHighUpperDrawType); + + // + // LOWER ... + bool canShowCHighLower = showDonchain && showLower && showHigh; + ENUM_DRAW_TYPE donHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donHighLowerBuffer, true); + SetIndexBuffer(donHighLowerBufferIndex, donHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donHighLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighLower); + PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_DRAW_TYPE, donHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowCLowUpper = showDonchain && showUpper && showLow; + ENUM_DRAW_TYPE donLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donLowUpperBuffer, true); + SetIndexBuffer(donLowUpperBufferIndex, donLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donLowUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper); + PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_DRAW_TYPE, donLowUpperDrawType); + + // + // LOWER ... + bool canShowCLowLower = showDonchain && showLower && showLow; + ENUM_DRAW_TYPE donLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(donLowLowerBuffer, true); + SetIndexBuffer(donLowLowerBufferIndex, donLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(donLowLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); + PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType); + + // + // FIBONNACI ... + + // + // LEVEL 1 ... + bool canShowFl1 = showFibo1Levels; + ENUM_DRAW_TYPE fl1DrawType = canShowFl1 ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(fl1Buffer, true); + SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA); + PlotIndexSetDouble(fl1PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(fl1PlotBufferIndex, PLOT_SHOW_DATA, canShowFl1); + PlotIndexSetInteger(fl1PlotBufferIndex, PLOT_DRAW_TYPE, fl1DrawType); + + // + // LEVEL 2 ... + bool canShowFl2 = showFibo2Levels; + ENUM_DRAW_TYPE fl2DrawType = canShowFl2 ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(fl2Buffer, true); + SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA); + PlotIndexSetDouble(fl2PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(fl2PlotBufferIndex, PLOT_SHOW_DATA, canShowFl2); + PlotIndexSetInteger(fl2PlotBufferIndex, PLOT_DRAW_TYPE, fl2DrawType); + + // + // LEVEL 3 ... + bool canShowFl3 = showFibo3Levels; + ENUM_DRAW_TYPE fl3DrawType = canShowFl3 ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(fl3Buffer, true); + SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA); + PlotIndexSetDouble(fl3PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(fl3PlotBufferIndex, PLOT_SHOW_DATA, canShowFl3); + PlotIndexSetInteger(fl3PlotBufferIndex, PLOT_DRAW_TYPE, fl3DrawType); + + // + // LEVEL 4 ... + bool canShowFl4 = showFibo4Levels; + ENUM_DRAW_TYPE fl4DrawType = canShowFl4 ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(fl4Buffer, true); + SetIndexBuffer(fl4BufferIndex, fl4Buffer, INDICATOR_DATA); + PlotIndexSetDouble(fl4PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(fl4PlotBufferIndex, PLOT_SHOW_DATA, canShowFl4); + PlotIndexSetInteger(fl4PlotBufferIndex, PLOT_DRAW_TYPE, fl4DrawType); + + // + // LEVEL 5 ... + bool canShowFl5 = showFibo5Levels; + ENUM_DRAW_TYPE fl5DrawType = canShowFl5 ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(fl5Buffer, true); + SetIndexBuffer(fl5BufferIndex, fl5Buffer, INDICATOR_DATA); + PlotIndexSetDouble(fl5PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(fl5PlotBufferIndex, PLOT_SHOW_DATA, canShowFl5); + PlotIndexSetInteger(fl5PlotBufferIndex, PLOT_DRAW_TYPE, fl5DrawType); + + // + // Data Buffers ... + + // + // CURRENT ... + + // + ArraySetAsSeries(cHHBuffer, true); + SetIndexBuffer(cHHBufferIndex, cHHBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(cLLBuffer, true); + SetIndexBuffer(cLLBufferIndex, cLLBuffer, INDICATOR_CALCULATIONS); + + // + // SHORT ... + + // + ArraySetAsSeries(sHHBuffer, true); + SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(sLLBuffer, true); + SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS); + + // + // MEDIUM ... + + // + ArraySetAsSeries(mHHBuffer, true); + SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(mLLBuffer, true); + SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS); + + // + // LONG ... + + // + ArraySetAsSeries(lHHBuffer, true); + SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(lLLBuffer, true); + SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS); + + // + // HIND ... + + // + ArraySetAsSeries(hHHBuffer, true); + SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(hLLBuffer, true); + SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS); + + // + // XVWAP ... + + // + // Volumes ... + ArraySetAsSeries(vwapVolumeBuffer, true); + SetIndexBuffer(vwapVolumeBufferIndex, vwapVolumeBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + ArraySetAsSeries(vwapPriceBuffer, true); + SetIndexBuffer(vwapPriceBufferIndex, vwapPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Fast State ... + ArraySetAsSeries(vwapFastStateBuffer, true); + SetIndexBuffer(vwapFastStateBufferIndex, vwapFastStateBuffer, INDICATOR_CALCULATIONS); + + // + // Mid State ... + ArraySetAsSeries(vwapMidStateBuffer, true); + SetIndexBuffer(vwapMidStateBufferIndex, vwapMidStateBuffer, INDICATOR_CALCULATIONS); + + // + // Slow State ... + ArraySetAsSeries(vwapSlowStateBuffer, true); + SetIndexBuffer(vwapSlowStateBufferIndex, vwapSlowStateBuffer, INDICATOR_CALCULATIONS); + + // + // ATR ... + + // + ArraySetAsSeries(atrBuffer, true); + SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(atrUpperRawBuffer, true); + SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(atrLowerRawBuffer, true); + SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS); +} + +/** + * Set Indicator Short Name and also we can define Buffers Labels ... + */ +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +/** + * Calculate Custom Buffers ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int barsLimit = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : 0; + // + // bool canCalculate = true; + bool canCalculate = + barsLimit == 0 || + bar_index <= barsLimit; + if (canCalculate) + { + // + // Calculate Cycles ... + CalculateCycles(bar_index); + + // + // Calculate Peaks and Vales ... + CalculatePeaksAndVales(bar_index); + + // + CalculateDonchains( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + CalculateAtrZones( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low // + ); + + // + CalculateFibonacci( + bar_index // + ); + + // + // Calculate Required VWAP Data Buffers ... + if (ratesTotal - bar_index <= maxLength) + { + // + CalculateVWAPDataBuffers( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + // Prevent Moving Forward ... + } + else + { + // + CalculateVWAPDataBuffers( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + CalculateVWAPS( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + } + } + else + { + FillBuffersZero(bar_index); + } +} + +// +// Custom ... + +/** + * Initial Market Cycles ... + * + * @return ( bool ) + */ +bool InitMarketCycles() +{ + // + bool result = false; + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + if (IsValid(mSCPeriod)) + { + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + if (IsValid(mMCPeriod)) + { + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + if (IsValid(mLCPeriod)) + { + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + if (IsValid(mHCPeriod)) + { + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + } + + // + result = mSCLength > 0 && + mMCLength > mSCLength && + mLCLength > mMCLength && + mHCLength > mLCLength; + + // + return result; +} + +/** + * Fill All Bufers to Zero Vlue for Specified Bar Index ... + * + * @param barIndex: Integer ... + */ +void FillBuffersZero(int barIndex) +{ + // + // CURRENT ... + cHHBuffer[barIndex] = 0; + cLLBuffer[barIndex] = 0; + + // + // SHORT ... + sHHBuffer[barIndex] = 0; + sLLBuffer[barIndex] = 0; + + // + // MEDIUM ... + mHHBuffer[barIndex] = 0; + mLLBuffer[barIndex] = 0; + + // + // LONG ... + lHHBuffer[barIndex] = 0; + lLLBuffer[barIndex] = 0; + + // + // HIND ... + hHHBuffer[barIndex] = 0; + hLLBuffer[barIndex] = 0; + + // + // PEAKS ... + peaksBuffer[barIndex] = 0; + + // + // VALES ... + valesBuffer[barIndex] = 0; + + // + // SARS ... + sarBuffer[barIndex] = 0; + + // + // ATRS ... + atrBuffer[barIndex] = 0; + atrUpperBuffer[barIndex] = 0; + atrUpperRawBuffer[barIndex] = 0; + atrUpperBuffer[barIndex] = 0; + atrLowerRawBuffer[barIndex] = 0; + + // + // VWAP ... + + // + vwapFastBuffer[barIndex] = 0; + vwapMidBuffer[barIndex] = 0; + vwapSlowBuffer[barIndex] = 0; + vwapVolumeBuffer[barIndex] = 0; + vwapPriceBuffer[barIndex] = 0; + + // + vwapFastColorBuffer[barIndex] = hideColorIDX; + vwapMidColorBuffer[barIndex] = hideColorIDX; + vwapSlowColorBuffer[barIndex] = hideColorIDX; + vwapFastStateBuffer[barIndex] = hideColorIDX; + vwapMidStateBuffer[barIndex] = hideColorIDX; + vwapSlowStateBuffer[barIndex] = hideColorIDX; + + // + donOpenUpperBuffer[barIndex] = 0; + donOpenLowerBuffer[barIndex] = 0; + donCloseUpperBuffer[barIndex] = 0; + donCloseLowerBuffer[barIndex] = 0; + donHighUpperBuffer[barIndex] = 0; + donHighLowerBuffer[barIndex] = 0; + donLowUpperBuffer[barIndex] = 0; + donLowLowerBuffer[barIndex] = 0; + + // + fl1Buffer[barIndex] = 0; + fl2Buffer[barIndex] = 0; + fl3Buffer[barIndex] = 0; + fl4Buffer[barIndex] = 0; + fl5Buffer[barIndex] = 0; +} + +/** + * Calculate Specified Market Cycle Info ... + * + * @param barIndex: Integer, Bar Index ... + * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... + * @param hhBuffer: Highest High Buffer Reference ... + * @param llBuffer: Lowest Low Buffer Reference ... + */ +void CalculateCycle( + int barIndex, + ENUM_X_MARKET_CYCLES cycle, + double &hhBuffer[], + double &llBuffer[] // +) +{ + // + XOHCL bar; + bool isBarInited = bar.Init( + _Symbol, + _Period, + barIndex + // + ); + if (!isBarInited) + { + return; + } + + // + int mLength = 0; + switch (cycle) + { + // + case X_MARKET_CYCLE_SHORT: + mLength = mSCLength; + break; + + // + case X_MARKET_CYCLE_MEDIUM: + mLength = mMCLength; + break; + + // + case X_MARKET_CYCLE_LONG: + mLength = mLCLength; + break; + + // + case X_MARKET_CYCLE_HIND: + mLength = mHCLength; + break; + } + + // + if (mLength == 0) + { + return; + } + + // + // Find Highest High ... + double hhValue = bar.FindHighest( + mLength, + hhMode + // + ); + hhBuffer[barIndex] = hhValue; + + // + // Find Lowest Low ... + double llValue = bar.FindLowest( + mLength, + llMode + // + ); + llBuffer[barIndex] = llValue; +} + +/** + * Claculate Cycles ... + * + * @param barIndex: Integer, Bar Index ... + */ +void CalculateCycles(int barIndex) +{ + // + // SHORT ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_SHORT, + sHHBuffer, + sLLBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_MEDIUM, + mHHBuffer, + mLLBuffer // + ); + + // + // LONG ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_LONG, + lHHBuffer, + lLLBuffer // + ); + + // + // HIND ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_HIND, + hHHBuffer, + hLLBuffer // + ); +} + +/** + * Calculate Peaks and Vales ... + * + * @param barIndex: Integer, Bar Index ... + */ +void CalculatePeaksAndVales(int barIndex) +{ + // + int lastIndex = barIndex + 1; + int barsCount = iBars(_Symbol, _Period); + + // + // PEAKS ... + double lastPeak = + lastIndex < barsCount + ? peaksBuffer[lastIndex] + : 0; + + // + double isHH = sHHBuffer[barIndex]; + double imHH = mHHBuffer[barIndex]; + double ilHH = lHHBuffer[barIndex]; + double ihHH = hHHBuffer[barIndex]; + + // + double iHHs[4] = { + isHH, + imHH, + ilHH, + ihHH // + }; + double rValue = GetAverage(iHHs); + bool isPeak = rValue == isHH && + isHH == imHH && + imHH == ilHH && + ilHH == ihHH; + double iPeak = + isPeak + ? rValue + : lastPeak; + peaksBuffer[barIndex] = iPeak; + + // + // VALES ... + double lastVale = + lastIndex < barsCount + ? valesBuffer[lastIndex] + : 0; + + // + double isLL = sLLBuffer[barIndex]; + double imLL = mLLBuffer[barIndex]; + double ilLL = lLLBuffer[barIndex]; + double ihLL = hLLBuffer[barIndex]; + + // + double iLLs[4] = { + isLL, + imLL, + ilLL, + ihLL // + }; + double sValue = GetAverage(iLLs); + bool isVale = sValue == isLL && + isLL == imLL && + imLL == ilLL && + ilLL == ihLL; + double iVale = + isVale + ? sValue + : lastVale; + valesBuffer[barIndex] = iVale; +} + +/** + * Calculate VWAP Value for Specified Bar ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + * @param _length: Integer, Specified VWAP Length ... + * @param _show: Boolean, Specified Show Buffer or not ... + * @param _buffer: Double Array Reference, Points to Buffer ... + * @param _colorBuffer: Double Array Reference, Points to Color Buffer ... + * @param _stateBuffer: Double Array Reference, Points to State Buffer ... + */ +void CalculateVWAP( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, // Calculation Length + bool _show, + double &_buffer[], + double &_colorBuffer[], + double &_stateBuffer[] // +) +{ + // + double vSum = 0; + double pSum = 0; + double mSum = 0; + for (int x = 0; x < _length; x++) + { + // + pSum += vwapPriceBuffer[x + bar_index]; + vSum += vwapVolumeBuffer[x + bar_index]; + mSum += vwapPriceBuffer[x + bar_index] * vwapVolumeBuffer[x + bar_index]; + } + + // + double iValue = mSum / vSum; + iValue = NormalizeDouble(iValue, _Digits); + + // + _buffer[bar_index] = iValue; + + // + bool isBullish = low[bar_index] > iValue; + bool isBearish = high[bar_index] < iValue; + + // + double iColor = + isBullish + ? bullishColorIDX + : isBearish + ? bearishColorIDX + : neuturalColorIDX; + + // + _colorBuffer[bar_index] = hideColorIDX; + _stateBuffer[bar_index] = iColor; + if (showVWap && _show) + { + _colorBuffer[bar_index] = iColor; + } +} + +/** + * Calculate Donchain ... + * + * @param bar_index: Integer, Bar Index ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + * @param _length: Integer, Donchain Length ... + * @param _ouBuffer: Double Array Reference ... + * @param _olBuffer: Double Array Reference ... + * @param _huBuffer: Double Array Reference ... + * @param _hlBuffer: Double Array Reference ... + * @param _luBuffer: Double Array Reference ... + * @param _llBuffer: Double Array Reference ... + * @param _cuBuffer: Double Array Reference ... + * @param _clBuffer: Double Array Reference ... + */ +void CalculateDonchain( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, + // + double &_ouBuffer[], + double &_olBuffer[], + double &_huBuffer[], + double &_hlBuffer[], + double &_luBuffer[], + double &_llBuffer[], + double &_cuBuffer[], + double &_clBuffer[] // +) +{ + // + double iUpper = 0; + double iLower = 0; + + // + // OPEN ... + + // + int from = bar_index; + + // + iUpper = open[ArrayMaximum(open, from, _length)]; + iLower = open[ArrayMinimum(open, from, _length)]; + + // + _ouBuffer[bar_index] = iUpper; + _olBuffer[bar_index] = iLower; + + // + // HIGH ... + + // + iUpper = high[ArrayMaximum(high, from, _length)]; + iLower = high[ArrayMinimum(high, from, _length)]; + + // + _huBuffer[bar_index] = iUpper; + _hlBuffer[bar_index] = iLower; + + // + // LOW ... + + // + iUpper = low[ArrayMaximum(low, from, _length)]; + iLower = low[ArrayMinimum(low, from, _length)]; + + // + _luBuffer[bar_index] = iUpper; + _llBuffer[bar_index] = iLower; + + // + // CLOSE ... + + // + iUpper = close[ArrayMaximum(close, from, _length)]; + iLower = close[ArrayMinimum(close, from, _length)]; + + // + _cuBuffer[bar_index] = iUpper; + _clBuffer[bar_index] = iLower; +} + +/** + * Calculate VWAP Required Data Buffers ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateVWAPDataBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + double price = GetAppliedPrice( + vwapAppliedTo, + open, + high, + low, + close, + bar_index // + ); + vwapPriceBuffer[bar_index] = price; + vwapVolumeBuffer[bar_index] = (double)tickVolume[bar_index]; +} + +/** + * Calculate Different VWaps ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateVWAPS( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // Fast ... + CalculateVWAP( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + vwapFastLength, + showVWapFast, + vwapFastBuffer, + vwapFastColorBuffer, + vwapFastStateBuffer // + ); + + // + // Mid ... + CalculateVWAP( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + vwapMidLength, + showVWapMedium, + vwapMidBuffer, + vwapMidColorBuffer, + vwapMidStateBuffer // + ); + + // + // Fast ... + CalculateVWAP( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + vwapSlowLength, + showVWapSlow, + vwapSlowBuffer, + vwapSlowColorBuffer, + vwapSlowStateBuffer // + ); +} + +/** + * Calculate Different VWaps ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateDonchains( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + CalculateDonchain( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + donchainLength, + // + donOpenUpperBuffer, + donOpenLowerBuffer, + donHighUpperBuffer, + donHighLowerBuffer, + donLowUpperBuffer, + donLowLowerBuffer, + donCloseUpperBuffer, + donCloseLowerBuffer // + ); +} + +/** + * Calculate Different VWaps ... + * + * @param bar_index: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + */ +void CalculateAtrZones( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + // Select ATr Value ... + double atrValue = atrBuffer[bar_index]; + double appliedAtrMultiplierValue = atrValue * atrMultiplier; + + // + // Select Upper Price ... + double upperPrice = GetAppliedPrice( + atrUpperAppliedTo, + open, + high, + low, + close, + bar_index // + ); + + // + // Select Lower Price ... + double lowerPrice = GetAppliedPrice( + atrLowerAppliedTo, + open, + high, + low, + close, + bar_index // + ); + + // + // Calculate Raw Atrs ... + + // + // Upper ... + double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue; + atrUpperRawBuffer[bar_index] = atrUpperRawValue; + + // + // Lower ... + double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue; + atrLowerRawBuffer[bar_index] = atrLowerRawValue; + + // + bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE; + if (canSmooth) + { + // + // Upper ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + bar_index, + atrLength, + atrUpperRawBuffer, + atrUpperBuffer, + atrSmoothingMode // + ); + + // + // Lower ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + bar_index, + atrLength, + atrLowerRawBuffer, + atrLowerBuffer, + atrSmoothingMode // + ); + } + else + { + // + // Use Raw Values ... + atrUpperBuffer[bar_index] = atrUpperRawValue; + atrLowerBuffer[bar_index] = atrLowerRawValue; + } +} + +/** + * Calculate Fibonacci Levels ... + * + * @param bar_index: Integer, current Bar Index ... + */ +void CalculateFibonacci( + int bar_index // +) +{ + // + double fiboUpper = 0; + double fiboLower = 0; + + // + fiboUpper = peaksBuffer[bar_index]; + fiboLower = valesBuffer[bar_index]; + + // + // Level 1 ... + bool canCalculateFiboLevel1 = fiboLevel1 > 0; + if (canCalculateFiboLevel1) + { + // + double iFib = GetFibonacciLevel( + fiboUpper, + fiboLower, + fiboLevel1, + 1 // + ); + + // + fl1Buffer[bar_index] = iFib; + } + + // + // Level 2 ... + bool canCalculateFiboLevel2 = fiboLevel2 > 0; + if (canCalculateFiboLevel2) + { + // + double iFib = GetFibonacciLevel( + fiboUpper, + fiboLower, + fiboLevel2, + 1 // + ); + + // + fl2Buffer[bar_index] = iFib; + } + + // + // Level 3 ... + bool canCalculateFiboLevel3 = fiboLevel3 > 0; + if (canCalculateFiboLevel3) + { + // + double iFib = GetFibonacciLevel( + fiboUpper, + fiboLower, + fiboLevel3, + 1 // + ); + + // + fl3Buffer[bar_index] = iFib; + } + + // + // Level 4 ... + bool canCalculateFiboLevel4 = fiboLevel4 > 0; + if (canCalculateFiboLevel4) + { + // + double iFib = GetFibonacciLevel( + fiboUpper, + fiboLower, + fiboLevel4, + 1 // + ); + + // + fl4Buffer[bar_index] = iFib; + } + + // + // Level 5 ... + bool canCalculateFiboLevel5 = fiboLevel5 > 0; + if (canCalculateFiboLevel5) + { + // + double iFib = GetFibonacciLevel( + fiboUpper, + fiboLower, + fiboLevel5, + 1 // + ); + + // + fl5Buffer[bar_index] = iFib; + } + + // +} + +// \ No newline at end of file diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index a8177bdc..4358f1c5 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -46,11 +46,12 @@ input string eaSymbols = "EURUSDb,GBPUSDb,USDJPYb,USDCHFb"; // Trading Symbols input group "Signalling"; input bool eaAllowLong = true; // Allow Long Signals input bool eaAllowShort = true; // Allow Short Signals +input bool eaAllowTrade = true; // Allow Open Trade On Signals input int eaMaxAllowedLongs = 5; // Max Allowed Long Signals input int eaMaxAllowedShorts = 5; // Max Allowed Short Signals input bool eaUseMaxAllowedSignalsPerSymbol = true; // Use Max Allowed Signal Types Per Symbol input double eaLastPositionProfitForAcceptNextInPoint = 30; // Last Position Profit In Points for Accept new Signal -input int eaDelaysBetweenTwoSignalsInBar = 100; // Delay between two Signals in Bars +input int eaDelaysBetweenTwoSignalsInBar = 100; // Delay between two Signals in Bars input double eaMaxAllowedSpread = 25; // Max Allowed Spread for Signalling input int eaMinRequiredVerificationForSpreadPass = 20; // Minimum Spread Verification for Signalling @@ -152,6 +153,7 @@ int OnInit() // Signalling ... eaExpert.AllowLong(eaAllowLong); eaExpert.AllowShort(eaAllowShort); + eaExpert.AllowTrade(eaAllowTrade); eaExpert.MaxAllowedLongs(eaMaxAllowedLongs); eaExpert.MaxAllowedShorts(eaMaxAllowedShorts); eaExpert.UseMaxAllowedSignalsPerSymbol(eaUseMaxAllowedSignalsPerSymbol); diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index cbb3bf10..44017e7e 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -46,37 +46,35 @@ enum ENUM_X121_BUFFERS X121_DON_LOW_LOWER_LINE = 16, X121_DON_CLOSE_UPPER_LINE = 17, X121_DON_CLOSE_LOWER_LINE = 18, - X121_FIB_LEVEL_1_LINE = 19, - X121_FIB_LEVEL_2_LINE = 20, - X121_FIB_LEVEL_3_LINE = 21, - X121_FIB_LEVEL_4_LINE = 22, - X121_FIB_LEVEL_5_LINE = 23, // // Data Buffers ... // // XPV Data ... - X121_CURRENT_HH_LINE = 24, - X121_CURRENT_LL_LINE = 25, - X121_SHORT_HH_LINE = 26, - X121_SHORT_LL_LINE = 27, - X121_MEDIUM_HH_LINE = 28, - X121_MEDIUM_LL_LINE = 29, - X121_LONG_HH_LINE = 30, - X121_LONG_LL_LINE = 31, - X121_HIND_HH_LINE = 32, - X121_HIND_LL_LINE = 33, + X121_CURRENT_HH_LINE = 19, + X121_CURRENT_LL_LINE = 20, + X121_SHORT_HH_LINE = 21, + X121_SHORT_LL_LINE = 22, + X121_MEDIUM_HH_LINE = 23, + X121_MEDIUM_LL_LINE = 24, + X121_LONG_HH_LINE = 25, + X121_LONG_LL_LINE = 26, + X121_HIND_HH_LINE = 27, + X121_HIND_LL_LINE = 28, // // VWAP Data ... - X121_VWAP_VOLUME_LINE = 34, - X121_VWAP_PRICE_LINE = 35, - X121_VWAP_FAST_STATE_LINE = 36, - X121_VWAP_MID_STATE_LINE = 37, - X121_VWAP_SLOW_STATE_LINE = 38, + X121_VWAP_VOLUME_LINE = 29, + X121_VWAP_PRICE_LINE = 30, + X121_VWAP_FAST_STATE_LINE = 31, + X121_VWAP_MID_STATE_LINE = 32, + X121_VWAP_SLOW_STATE_LINE = 33, // // ATR ... - X121_ATR_LINE = 39, - X121_ATR_UPPER_RAW_LINE = 40, - X121_ATR_LOWER_RAW_LINE = 41, + X121_ATR_LINE = 34, + X121_ATR_UPPER_RAW_LINE = 35, + X121_ATR_LOWER_RAW_LINE = 36, + // + // RSI ... + X121_RSI_LINE = 37 }; // @@ -130,9 +128,10 @@ struct X121Inputs // // RSI ... - int rsiLength; // RSI Length - double rsiOverSoldLevel; // RSI Over Sold Level - double rsiOverBoughtLevel; // RSI Over Bought Level + int rsiLength; // Length + double rsiOverSoldLevel; // Over Sold Level + double rsiOverBoughtLevel; // Over Bought Level + ENUM_APPLIED_PRICE rsiAppliedTo; // Applied To // // Atr Detection ... @@ -153,14 +152,6 @@ struct X121Inputs // Donchain Detection ... int donchainLength; // Donchain Length - // - // Fibonacci ... - double fiboLevel1; // Fibio 1st Level - double fiboLevel2; // Fibio 2st Level - double fiboLevel3; // Fibio 3rd Level - double fiboLevel4; // Fibio 4th Level - double fiboLevel5; // Fibio 5th Level - // // Presentation ... @@ -181,14 +172,6 @@ struct X121Inputs bool showVWap; // Show VWap bool showDonchain; // Show Donchain - // - // Fibonachi Presentation ... - bool showFibo1Levels; // Show Fibo 1st Level - bool showFibo2Levels; // Show Fibo 2nd Level - bool showFibo3Levels; // Show Fibo 3rd Level - bool showFibo4Levels; // Show Fibo 4th Level - bool showFibo5Levels; // Show Fibo 5th Level - // // Atr Presentation ... bool showAtrUpper; // Show Upper Zone @@ -261,6 +244,7 @@ struct X121Inputs rsiLength = 0; rsiOverSoldLevel = 0; rsiOverBoughtLevel = 0; + rsiAppliedTo = PRICE_CLOSE; // // Paraboli Sar Detection ... @@ -286,14 +270,6 @@ struct X121Inputs // Donchain Detection ... donchainLength = 0; - // - // Fibonacci ... - fiboLevel1 = 0; - fiboLevel2 = 0; - fiboLevel3 = 0; - fiboLevel4 = 0; - fiboLevel5 = 0; - // // Presentation ... @@ -314,14 +290,6 @@ struct X121Inputs showVWap = false; showDonchain = false; - // - // Fibonachi Presentation ... - showFibo1Levels = false; - showFibo2Levels = false; - showFibo3Levels = false; - showFibo4Levels = false; - showFibo5Levels = false; - // // Atr Presentation ... showAtrUpper = false; // Show Upper Zone @@ -385,6 +353,7 @@ struct X121Inputs rsiLength = 14; rsiOverSoldLevel = 30; rsiOverBoughtLevel = 70; + rsiAppliedTo = PRICE_CLOSE; // // Paraboli Sar Detection ... @@ -410,14 +379,6 @@ struct X121Inputs // Donchain Detection ... donchainLength = 40; - // - // Fibonacci ... - fiboLevel1 = 0.236; - fiboLevel2 = 0.382; - fiboLevel3 = 0.5; - fiboLevel4 = 0.618; - fiboLevel5 = 0.764; - // // Presentation ... @@ -438,14 +399,6 @@ struct X121Inputs showVWap = true; showDonchain = true; - // - // Fibonachi Presentation ... - showFibo1Levels = false; - showFibo2Levels = false; - showFibo3Levels = true; - showFibo4Levels = false; - showFibo5Levels = false; - // // Atr Presentation ... showAtrUpper = true; // Show Upper Zone @@ -572,11 +525,6 @@ struct X121Conditions double donHighLowerBuffer[]; double donLowUpperBuffer[]; double donLowLowerBuffer[]; - double fl1Buffer[]; - double fl2Buffer[]; - double fl3Buffer[]; - double fl4Buffer[]; - double fl5Buffer[]; double cHHBuffer[]; double cLLBuffer[]; double sHHBuffer[]; @@ -687,37 +635,6 @@ struct X121Conditions // // bool isCloseLower - // - // XFIBONACCI ... - - // - bool isOerFib1; - bool isOerFib2; - bool isOerFib3; - bool isOerFib4; - bool isOerFib5; - - // - bool isUnderFib1; - bool isUnderFib2; - bool isUnderFib3; - bool isUnderFib4; - bool isUnderFib5; - - // - bool isCloseOerFib1; - bool isCloseOerFib2; - bool isCloseOerFib3; - bool isCloseOerFib4; - bool isCloseOerFib5; - - // - bool isCloseUnderFib1; - bool isCloseUnderFib2; - bool isCloseUnderFib3; - bool isCloseUnderFib4; - bool isCloseUnderFib5; - // // Constructor ... X121Conditions() @@ -759,11 +676,6 @@ struct X121Conditions Clean(donHighLowerBuffer); Clean(donLowUpperBuffer); Clean(donLowLowerBuffer); - Clean(fl1Buffer); - Clean(fl2Buffer); - Clean(fl3Buffer); - Clean(fl4Buffer); - Clean(fl5Buffer); Clean(cHHBuffer); Clean(cLLBuffer); Clean(sHHBuffer); @@ -801,11 +713,6 @@ struct X121Conditions ArraySetAsSeries(donHighLowerBuffer, true); ArraySetAsSeries(donLowUpperBuffer, true); ArraySetAsSeries(donLowLowerBuffer, true); - ArraySetAsSeries(fl1Buffer, true); - ArraySetAsSeries(fl2Buffer, true); - ArraySetAsSeries(fl3Buffer, true); - ArraySetAsSeries(fl4Buffer, true); - ArraySetAsSeries(fl5Buffer, true); ArraySetAsSeries(cHHBuffer, true); ArraySetAsSeries(cLLBuffer, true); ArraySetAsSeries(sHHBuffer, true); @@ -912,37 +819,6 @@ struct X121Conditions // // XDON ... - - // - // XFIBONACCI ... - - // - isOerFib1 = false; - isOerFib2 = false; - isOerFib3 = false; - isOerFib4 = false; - isOerFib5 = false; - - // - isUnderFib1 = false; - isUnderFib2 = false; - isUnderFib3 = false; - isUnderFib4 = false; - isUnderFib5 = false; - - // - isCloseOerFib1 = false; - isCloseOerFib2 = false; - isCloseOerFib3 = false; - isCloseOerFib4 = false; - isCloseOerFib5 = false; - - // - isCloseUnderFib1 = false; - isCloseUnderFib2 = false; - isCloseUnderFib3 = false; - isCloseUnderFib4 = false; - isCloseUnderFib5 = false; } /** @@ -1030,6 +906,14 @@ struct X121Conditions ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + // + // RSI ... + ToString("isRSIOverBought", isRSIOverBought, ignoreFalseConditions, separator) + + ToString("isRSICrossedOverOverBought", isRSICrossedOverOverBought, ignoreFalseConditions, separator) + + ToString("isRSICrossedUnderOverBought", isRSICrossedUnderOverBought, ignoreFalseConditions, separator) + + ToString("isRSIOverSold", isRSIOverSold, ignoreFalseConditions, separator) + + ToString("isRSICrossedUnderOverSold", isRSICrossedUnderOverSold, ignoreFalseConditions, separator) + + ToString("isRSICrossedOverOverSold", isRSICrossedOverOverSold, ignoreFalseConditions, separator) + + // // XVWAP ... ToString("isVWapFastBullish", isVWapFastBullish, ignoreFalseConditions, separator) + ToString("isVWapFastBearish", isVWapFastBearish, ignoreFalseConditions, separator) + @@ -1055,28 +939,6 @@ struct X121Conditions ToString("isVWapSwitchedToBearishState", isVWapSwitchedToBearishState, ignoreFalseConditions, separator) + ToString("isVWapSwitchedToNeuturalState", isVWapSwitchedToNeuturalState, ignoreFalseConditions, separator) + // - // XFIBONACCI ... - ToString("isOerFib1", isOerFib1, ignoreFalseConditions, separator) + - ToString("isOerFib2", isOerFib2, ignoreFalseConditions, separator) + - ToString("isOerFib3", isOerFib3, ignoreFalseConditions, separator) + - ToString("isOerFib4", isOerFib4, ignoreFalseConditions, separator) + - ToString("isOerFib5", isOerFib5, ignoreFalseConditions, separator) + - ToString("isUnderFib1", isUnderFib1, ignoreFalseConditions, separator) + - ToString("isUnderFib2", isUnderFib2, ignoreFalseConditions, separator) + - ToString("isUnderFib3", isUnderFib3, ignoreFalseConditions, separator) + - ToString("isUnderFib4", isUnderFib4, ignoreFalseConditions, separator) + - ToString("isUnderFib5", isUnderFib5, ignoreFalseConditions, separator) + - ToString("isCloseOerFib1", isCloseOerFib1, ignoreFalseConditions, separator) + - ToString("isCloseOerFib2", isCloseOerFib2, ignoreFalseConditions, separator) + - ToString("isCloseOerFib3", isCloseOerFib3, ignoreFalseConditions, separator) + - ToString("isCloseOerFib4", isCloseOerFib4, ignoreFalseConditions, separator) + - ToString("isCloseOerFib5", isCloseOerFib5, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib1", isCloseUnderFib1, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib2", isCloseUnderFib2, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib3", isCloseUnderFib3, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib4", isCloseUnderFib4, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib5", isCloseUnderFib5, ignoreFalseConditions, separator) + - // "" // ; @@ -1136,7 +998,6 @@ class XCX121Helper : public XCBaseHelper // Deconstructor ... ~XCX121Helper() { - IndicatorRelease(mRSIHandler); } // @@ -1193,11 +1054,6 @@ class XCX121Helper : public XCBaseHelper ArraySetAsSeries(donHighLowerBuffer, true); ArraySetAsSeries(donLowUpperBuffer, true); ArraySetAsSeries(donLowLowerBuffer, true); - ArraySetAsSeries(fl1Buffer, true); - ArraySetAsSeries(fl2Buffer, true); - ArraySetAsSeries(fl3Buffer, true); - ArraySetAsSeries(fl4Buffer, true); - ArraySetAsSeries(fl5Buffer, true); ArraySetAsSeries(cHHBuffer, true); ArraySetAsSeries(cLLBuffer, true); ArraySetAsSeries(sHHBuffer, true); @@ -1254,6 +1110,11 @@ class XCX121Helper : public XCBaseHelper mInputs.hhMode, mInputs.llMode, // + // Rsi Detection ... + "", + mInputs.rsiLength, + mInputs.rsiAppliedTo, + // // Parabolic Sar Detection ... "", mInputs.sarStep, @@ -1281,6 +1142,9 @@ class XCX121Helper : public XCBaseHelper // Presentation ... "", mInputs.startCalculationForLastBars, + mInputs.sarArrowCode, + mInputs.peaksArrowCode, + mInputs.valesArrowCode, // // Commons ... mInputs.showSar, @@ -1290,14 +1154,6 @@ class XCX121Helper : public XCBaseHelper mInputs.showVWap, mInputs.showDonchain, // - // Fibonachi Presentation ... - "", - mInputs.showFibo1Levels, - mInputs.showFibo2Levels, - mInputs.showFibo3Levels, - mInputs.showFibo4Levels, - mInputs.showFibo5Levels, - // // Atr Presentation ... "", mInputs.showAtrUpper, @@ -1318,20 +1174,6 @@ class XCX121Helper : public XCBaseHelper mInputs.showClose, mInputs.showLow // - // Non Important Inpust ... - // - // Fibonacci ... - // "", - // mInputs.fiboLevel1, - // mInputs.fiboLevel2, - // mInputs.fiboLevel3, - // mInputs.fiboLevel4, - // mInputs.fiboLevel5, - // // - // mInputs.sarArrowCode, - // mInputs.peaksArrowCode, - // mInputs.valesArrowCode - // ); result = mHandler != INVALID_HANDLE; if (!result) @@ -1339,19 +1181,6 @@ class XCX121Helper : public XCBaseHelper return result; } - // - mRSIHandler = iRSI( - symbol, - period, - mInputs.rsiLength, - PRICE_CLOSE // - ); - result = mRSIHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - // return result; } @@ -1857,8 +1686,8 @@ class XCX121Helper : public XCBaseHelper // double GetHigherPeak( - double peak, // Peak Source - int barIndex = 0, // Bar Index + double peak, // Peak Source + int barIndex = 0, // Bar Index int loopback = 576 // Max Allowed Loopback ) { @@ -1909,8 +1738,8 @@ class XCX121Helper : public XCBaseHelper // double GetLowerPeak( - double peak, // Peak Source - int barIndex = 0, // Bar Index + double peak, // Peak Source + int barIndex = 0, // Bar Index int loopback = 576 // Max Allowed Loopback ) { @@ -1961,8 +1790,8 @@ class XCX121Helper : public XCBaseHelper // double GetHigherVale( - double vale, // Vale Source - int barIndex = 0, // Bar Index + double vale, // Vale Source + int barIndex = 0, // Bar Index int loopback = 576 // Max Allowed Loopback ) { @@ -2013,8 +1842,8 @@ class XCX121Helper : public XCBaseHelper // double GetLowerVale( - double vale, // Vale Source - int barIndex = 0, // Bar Index + double vale, // Vale Source + int barIndex = 0, // Bar Index int loopback = 576 // Max Allowed Loopback ) { @@ -3727,269 +3556,6 @@ class XCX121Helper : public XCBaseHelper ); } - // - // FIBONACCHI ... - - // - // LEVEL 1 ... - - // - double GetFiboLevel1( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl1Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl1Buffer[barIndex]; - } - - // - int CopyFiboLevel1( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl1Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 2 ... - - // - double GetFiboLevel2( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl2Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl2Buffer[barIndex]; - } - - // - int CopyFiboLevel2( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl2Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 3 ... - - // - double GetFiboLevel3( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl3Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl3Buffer[barIndex]; - } - - // - int CopyFiboLevel3( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl3Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 4 ... - - // - double GetFiboLevel4( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl4Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl4Buffer[barIndex]; - } - - // - int CopyFiboLevel4( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl4Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 5 ... - - // - double GetFiboLevel5( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl5Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl5Buffer[barIndex]; - } - - // - int CopyFiboLevel5( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl5Buffer, - buffer, - forceClean - // - ); - } - // // Conditions Generation ... @@ -4306,41 +3872,6 @@ class XCX121Helper : public XCBaseHelper conditions.donLowLowerBuffer // ); - // - CopyFiboLevel1( - zIndex, - loopback, - conditions.fl1Buffer // - ); - - // - CopyFiboLevel2( - zIndex, - loopback, - conditions.fl2Buffer // - ); - - // - CopyFiboLevel3( - zIndex, - loopback, - conditions.fl3Buffer // - ); - - // - CopyFiboLevel4( - zIndex, - loopback, - conditions.fl4Buffer // - ); - - // - CopyFiboLevel5( - zIndex, - loopback, - conditions.fl5Buffer // - ); - // // Conditions ... @@ -4513,39 +4044,6 @@ class XCX121Helper : public XCBaseHelper // // XDON ... - // - // XFIBONACCI ... - - // - bool isOerFib1 = cBar.low > conditions.fl1Buffer[cIDX]; - bool isOerFib2 = cBar.low > conditions.fl2Buffer[cIDX]; - bool isOerFib3 = cBar.low > conditions.fl3Buffer[cIDX]; - bool isOerFib4 = cBar.low > conditions.fl4Buffer[cIDX]; - bool isOerFib5 = cBar.low > conditions.fl5Buffer[cIDX]; - - // - bool isUnderFib1 = cBar.high < conditions.fl1Buffer[cIDX]; - bool isUnderFib2 = cBar.high < conditions.fl2Buffer[cIDX]; - bool isUnderFib3 = cBar.high < conditions.fl3Buffer[cIDX]; - bool isUnderFib4 = cBar.high < conditions.fl4Buffer[cIDX]; - bool isUnderFib5 = cBar.high < conditions.fl5Buffer[cIDX]; - - // - bool isCloseOerFib1 = cBar.close > conditions.fl1Buffer[cIDX]; - bool isCloseOerFib2 = cBar.close > conditions.fl2Buffer[cIDX]; - bool isCloseOerFib3 = cBar.close > conditions.fl3Buffer[cIDX]; - bool isCloseOerFib4 = cBar.close > conditions.fl4Buffer[cIDX]; - bool isCloseOerFib5 = cBar.close > conditions.fl5Buffer[cIDX]; - - // - bool isCloseUnderFib1 = cBar.close < conditions.fl1Buffer[cIDX]; - bool isCloseUnderFib2 = cBar.close < conditions.fl2Buffer[cIDX]; - bool isCloseUnderFib3 = cBar.close < conditions.fl3Buffer[cIDX]; - bool isCloseUnderFib4 = cBar.close < conditions.fl4Buffer[cIDX]; - bool isCloseUnderFib5 = cBar.close < conditions.fl5Buffer[cIDX]; - - // - // // Set ... conditions.isRSIOverBought = isRSIOverBought; @@ -4587,26 +4085,6 @@ class XCX121Helper : public XCBaseHelper conditions.isVWapSwitchedToBullishState = isVWapSwitchedToBullishState; conditions.isVWapSwitchedToBearishState = isVWapSwitchedToBearishState; conditions.isVWapSwitchedToNeuturalState = isVWapSwitchedToNeuturalState; - conditions.isOerFib1 = isOerFib1; - conditions.isOerFib2 = isOerFib2; - conditions.isOerFib3 = isOerFib3; - conditions.isOerFib4 = isOerFib4; - conditions.isOerFib5 = isOerFib5; - conditions.isUnderFib1 = isUnderFib1; - conditions.isUnderFib2 = isUnderFib2; - conditions.isUnderFib3 = isUnderFib3; - conditions.isUnderFib4 = isUnderFib4; - conditions.isUnderFib5 = isUnderFib5; - conditions.isCloseOerFib1 = isCloseOerFib1; - conditions.isCloseOerFib2 = isCloseOerFib2; - conditions.isCloseOerFib3 = isCloseOerFib3; - conditions.isCloseOerFib4 = isCloseOerFib4; - conditions.isCloseOerFib5 = isCloseOerFib5; - conditions.isCloseUnderFib1 = isCloseUnderFib1; - conditions.isCloseUnderFib2 = isCloseUnderFib2; - conditions.isCloseUnderFib3 = isCloseUnderFib3; - conditions.isCloseUnderFib4 = isCloseUnderFib4; - conditions.isCloseUnderFib5 = isCloseUnderFib5; // return result; @@ -4622,12 +4100,6 @@ class XCX121Helper : public XCBaseHelper // Props ... X121Inputs mInputs; // Inputs ... - // - // Buffers ... - - // - int mRSIHandler; // RSI Handler ... - // // Buffers ... double peaksBuffer[]; @@ -4646,11 +4118,6 @@ class XCX121Helper : public XCBaseHelper double donHighLowerBuffer[]; double donLowUpperBuffer[]; double donLowLowerBuffer[]; - double fl1Buffer[]; - double fl2Buffer[]; - double fl3Buffer[]; - double fl4Buffer[]; - double fl5Buffer[]; double cHHBuffer[]; double cLLBuffer[]; double sHHBuffer[]; @@ -4692,8 +4159,8 @@ class XCX121Helper : public XCBaseHelper // // RSI ... CopyBuffer( - mRSIHandler, - 0, + mHandler, + X121_RSI_LINE, 0, totalBars, rsiBuffer @@ -5005,64 +4472,6 @@ class XCX121Helper : public XCBaseHelper // ); - // - // FIBONACCI ... - - // - // LEVEL 1 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_1_LINE, - 0, - totalBars, - fl1Buffer - // - ); - - // - // LEVEL 2 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_2_LINE, - 0, - totalBars, - fl2Buffer - // - ); - - // - // LEVEL 3 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_3_LINE, - 0, - totalBars, - fl3Buffer - // - ); - - // - // LEVEL 4 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_4_LINE, - 0, - totalBars, - fl4Buffer - // - ); - - // - // LEVEL 5 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_5_LINE, - 0, - totalBars, - fl5Buffer - // - ); - // // XDON ... diff --git a/Indicators/x-saherelm.x121.mq5 b/Indicators/x-saherelm.x121.mq5 index 241e0133..363462b3 100644 --- a/Indicators/x-saherelm.x121.mq5 +++ b/Indicators/x-saherelm.x121.mq5 @@ -62,6 +62,11 @@ input group "Boundary Detection"; input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method +// +input group "Rsi Detection"; +input int rsiLength = 14; // Length +input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To + // input group "Parabolic Sar Detection"; input double sarStep = 0.02; // Step @@ -92,6 +97,11 @@ input group "Presentation"; // input int startCalculationForLastBars = 1000; // Calculate Last n Bars +// +input int sarArrowCode = 159; // Parabolic Sar Arrow Code +input int peaksArrowCode = 159; // Peaks Arrow Code +input int valesArrowCode = 159; // Vales Arrow Code + // input bool showSar = true; // Show Parabolic Sar input bool showAtr = true; // Show Atr @@ -100,14 +110,6 @@ input bool showVales = true; // Show Vales input bool showVWap = true; // Show VWap input bool showDonchain = true; // Show Donchain -// -input group "Fibonachi Presentation"; -input bool showFibo1Levels = false; // Show Fibo 1st Level -input bool showFibo2Levels = false; // Show Fibo 2nd Level -input bool showFibo3Levels = false; // Show Fibo 3rd Level -input bool showFibo4Levels = false; // Show Fibo 4th Level -input bool showFibo5Levels = false; // Show Fibo 5th Level - // input group "Atr Presentation"; input bool showAtrUpper = true; // Show Upper Zone @@ -128,22 +130,6 @@ input bool showHigh = false; // Show High input bool showClose = true; // Show Close input bool showLow = false; // Show Low -// -// Non Important Inputs ... - -// -input group "Fibonacci"; -input double fiboLevel1 = 0.236; // Fibio 1st Level -input double fiboLevel2 = 0.382; // Fibio 2st Level -input double fiboLevel3 = 0.5; // Fibio 3rd Level -input double fiboLevel4 = 0.618; // Fibio 4th Level -input double fiboLevel5 = 0.764; // Fibio 5th Level - -// -input int sarArrowCode = 159; // Parabolic Sar Arrow Code -input int peaksArrowCode = 159; // Peaks Arrow Code -input int valesArrowCode = 159; // Vales Arrow Code - // // Buffers ... @@ -157,8 +143,8 @@ input int valesArrowCode = 159; // Vales Arrow Code #property indicator_chart_window // -#property indicator_buffers 42 -#property indicator_plots 21 +#property indicator_buffers 38 +#property indicator_plots 16 // // PEAKS ... @@ -382,89 +368,11 @@ double donCloseLowerBuffer[]; #property indicator_color16 clrCoral #property indicator_width16 1 -// -// FIBONACCI ... - -// -// FIBBO Level 1 ... - -// -#define fl1BufferIndex 19 -double fl1Buffer[]; - -// -#define fl1PlotBufferIndex 16 -#property indicator_label17 "X121 FL1" -#property indicator_type17 DRAW_LINE -#property indicator_color17 clrGold -#property indicator_style17 STYLE_DASHDOTDOT -#property indicator_width17 1 - -// -// FIBBO Level 2 ... - -// -#define fl2BufferIndex 20 -double fl2Buffer[]; - -// -#define fl2PlotBufferIndex 17 -#property indicator_label18 "X121 FL2" -#property indicator_type18 DRAW_LINE -#property indicator_color18 clrGold -#property indicator_style18 STYLE_DASHDOTDOT -#property indicator_width18 1 - -// -// FIBBO Level 3 ... - -// -#define fl3BufferIndex 21 -double fl3Buffer[]; - -// -#define fl3PlotBufferIndex 18 -#property indicator_label19 "X121 FL3" -#property indicator_type19 DRAW_LINE -#property indicator_color19 clrGold -#property indicator_style19 STYLE_DASHDOTDOT -#property indicator_width19 1 - -// -// FIBBO Level 4 ... - -// -#define fl4BufferIndex 22 -double fl4Buffer[]; - -// -#define fl4PlotBufferIndex 19 -#property indicator_label20 "X121 FL4" -#property indicator_type20 DRAW_LINE -#property indicator_color20 clrGold -#property indicator_style20 STYLE_DASHDOTDOT -#property indicator_width20 1 - -// -// FIBBO Level 5 ... - -// -#define fl5BufferIndex 23 -double fl5Buffer[]; - -// -#define fl5PlotBufferIndex 20 -#property indicator_label21 "X121 FL5" -#property indicator_type21 DRAW_LINE -#property indicator_color21 clrGold -#property indicator_style21 STYLE_DASHDOTDOT -#property indicator_width21 1 - // // Data Buffers ... // -int mLastBufferIndex = 23; +int mLastBufferIndex = 18; // // CURRENT ... @@ -522,7 +430,7 @@ double hHHBuffer[]; double hLLBuffer[]; // -// VOLUME ... +// VWAP ... #define vwapVolumeBufferIndex mLastBufferIndex + 11 double vwapVolumeBuffer[]; @@ -558,6 +466,11 @@ double atrUpperRawBuffer[]; #define atrLowerRawBufferIndex mLastBufferIndex + 18 double atrLowerRawBuffer[]; +// +// RSI ... +#define rsiBufferIndex mLastBufferIndex + 19 +double rsiBuffer[]; + // // Variables, Properties and etc ... @@ -568,6 +481,10 @@ int limit; // int maxLength; +// +// RSI Handler ... +int rsiHandler = INVALID_HANDLE; + // // SAR Handler ... int sarHandler = INVALID_HANDLE; @@ -619,6 +536,20 @@ int OnInit() // // Initialize Indicator Handlers ... + // + // RSI ... + rsiHandler = iRSI( + _Symbol, + _Period, + rsiLength, + rsiAppliedTo // + ); + bool isInited = rsiHandler != INVALID_HANDLE; + if (!isInited) + { + return INIT_FAILED; + } + // // SAR ... sarHandler = iSAR( @@ -627,7 +558,7 @@ int OnInit() sarStep, sarMax // ); - bool isInited = sarHandler != INVALID_HANDLE; + isInited = sarHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; @@ -692,6 +623,7 @@ void OnDeinit(const int reason) // REASON_CLOSE 9 Terminal closed // + IndicatorRelease(rsiHandler); IndicatorRelease(sarHandler); IndicatorRelease(atrHandler); } @@ -749,6 +681,10 @@ int OnCalculate( // // Validate Calculated Bars ... + // + // RSI ... + int rsiCalculatedBars = BarsCalculated(rsiHandler); + // // SAR ... int sarCalculatedBars = BarsCalculated(sarHandler); @@ -759,11 +695,14 @@ int OnCalculate( // bool isPassedRequiredCalculatedBars = + // + // RSI ... + rsiCalculatedBars >= maxLength && // // SAR ... sarCalculatedBars >= maxLength && // - // ATR... + // ATR ... sarCalculatedBars >= maxLength // ; @@ -778,6 +717,10 @@ int OnCalculate( // // Buffers Copy ... + // + // RSI ... + int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer); + // // SAR ... int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); @@ -791,8 +734,13 @@ int OnCalculate( bool isPassedRequiredCopiedItems = // // + // RSI ... + copiedRsis > 0 && + // // SAR ... copiedSars > 0 && + // + // ATR ... copiedAtrs > 0 // ; @@ -835,6 +783,9 @@ bool ValidateInputs() { // bool result = + // + // RSI ... + rsiLength > 0 && // // PSAR ... sarMax > 0 && @@ -891,6 +842,10 @@ int ExtractMaxLengthOfInputs() // ATR ... result = MathMax(result, atrLength); + // + // RSI ... + result = MathMax(result, rsiLength); + // return result; } @@ -1096,59 +1051,6 @@ void DefineBuffers() PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType); - // - // FIBONNACI ... - - // - // LEVEL 1 ... - bool canShowFl1 = showFibo1Levels; - ENUM_DRAW_TYPE fl1DrawType = canShowFl1 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl1Buffer, true); - SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl1PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl1PlotBufferIndex, PLOT_SHOW_DATA, canShowFl1); - PlotIndexSetInteger(fl1PlotBufferIndex, PLOT_DRAW_TYPE, fl1DrawType); - - // - // LEVEL 2 ... - bool canShowFl2 = showFibo2Levels; - ENUM_DRAW_TYPE fl2DrawType = canShowFl2 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl2Buffer, true); - SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl2PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl2PlotBufferIndex, PLOT_SHOW_DATA, canShowFl2); - PlotIndexSetInteger(fl2PlotBufferIndex, PLOT_DRAW_TYPE, fl2DrawType); - - // - // LEVEL 3 ... - bool canShowFl3 = showFibo3Levels; - ENUM_DRAW_TYPE fl3DrawType = canShowFl3 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl3Buffer, true); - SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl3PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl3PlotBufferIndex, PLOT_SHOW_DATA, canShowFl3); - PlotIndexSetInteger(fl3PlotBufferIndex, PLOT_DRAW_TYPE, fl3DrawType); - - // - // LEVEL 4 ... - bool canShowFl4 = showFibo4Levels; - ENUM_DRAW_TYPE fl4DrawType = canShowFl4 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl4Buffer, true); - SetIndexBuffer(fl4BufferIndex, fl4Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl4PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl4PlotBufferIndex, PLOT_SHOW_DATA, canShowFl4); - PlotIndexSetInteger(fl4PlotBufferIndex, PLOT_DRAW_TYPE, fl4DrawType); - - // - // LEVEL 5 ... - bool canShowFl5 = showFibo5Levels; - ENUM_DRAW_TYPE fl5DrawType = canShowFl5 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl5Buffer, true); - SetIndexBuffer(fl5BufferIndex, fl5Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl5PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl5PlotBufferIndex, PLOT_SHOW_DATA, canShowFl5); - PlotIndexSetInteger(fl5PlotBufferIndex, PLOT_DRAW_TYPE, fl5DrawType); - // // Data Buffers ... @@ -1249,6 +1151,13 @@ void DefineBuffers() // ArraySetAsSeries(atrLowerRawBuffer, true); SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS); + + // + // RSI ... + + // + ArraySetAsSeries(rsiBuffer, true); + SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS); } /** @@ -1324,11 +1233,6 @@ void CalculateBuffers( low // ); - // - CalculateFibonacci( - bar_index // - ); - // // Calculate Required VWAP Data Buffers ... if (ratesTotal - bar_index <= maxLength) @@ -1539,6 +1443,10 @@ void FillBuffersZero(int barIndex) // SARS ... sarBuffer[barIndex] = 0; + // + // RSIS ... + rsiBuffer[barIndex] = 0; + // // ATRS ... atrBuffer[barIndex] = 0; @@ -1574,13 +1482,6 @@ void FillBuffersZero(int barIndex) donHighLowerBuffer[barIndex] = 0; donLowUpperBuffer[barIndex] = 0; donLowLowerBuffer[barIndex] = 0; - - // - fl1Buffer[barIndex] = 0; - fl2Buffer[barIndex] = 0; - fl3Buffer[barIndex] = 0; - fl4Buffer[barIndex] = 0; - fl5Buffer[barIndex] = 0; } /** @@ -2213,109 +2114,4 @@ void CalculateAtrZones( } } -/** - * Calculate Fibonacci Levels ... - * - * @param bar_index: Integer, current Bar Index ... - */ -void CalculateFibonacci( - int bar_index // -) -{ - // - double fiboUpper = 0; - double fiboLower = 0; - - // - fiboUpper = peaksBuffer[bar_index]; - fiboLower = valesBuffer[bar_index]; - - // - // Level 1 ... - bool canCalculateFiboLevel1 = fiboLevel1 > 0; - if (canCalculateFiboLevel1) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel1, - 1 // - ); - - // - fl1Buffer[bar_index] = iFib; - } - - // - // Level 2 ... - bool canCalculateFiboLevel2 = fiboLevel2 > 0; - if (canCalculateFiboLevel2) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel2, - 1 // - ); - - // - fl2Buffer[bar_index] = iFib; - } - - // - // Level 3 ... - bool canCalculateFiboLevel3 = fiboLevel3 > 0; - if (canCalculateFiboLevel3) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel3, - 1 // - ); - - // - fl3Buffer[bar_index] = iFib; - } - - // - // Level 4 ... - bool canCalculateFiboLevel4 = fiboLevel4 > 0; - if (canCalculateFiboLevel4) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel4, - 1 // - ); - - // - fl4Buffer[bar_index] = iFib; - } - - // - // Level 5 ... - bool canCalculateFiboLevel5 = fiboLevel5 > 0; - if (canCalculateFiboLevel5) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel5, - 1 // - ); - - // - fl5Buffer[bar_index] = iFib; - } - - // -} - // \ No newline at end of file diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index 27c444d8..aa9f2aaa 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -165,6 +165,28 @@ class XC121SMCExpert : public XCBaseExpert ReConfigure(); } + /** + * Get Allow Open Trade On Signals State ... + * + * @return ( bool ) + */ + bool AllowTrade() + { + return mAllowTrade; + } + + /** + * Set Allow Open Trade On Signals State ... + * + * @param value: Boolean ... + */ + void AllowTrade(bool value) + { + // + mAllowTrade = value; + ReConfigure(); + } + /** * Get Use Max Allowed Signal Types Per Symbol State ... * @@ -806,14 +828,63 @@ class XC121SMCExpert : public XCBaseExpert datetime currentTime = TimeCurrent(); // - // Execute Signal Using Trade Handler ... - ENUM_X_SIGNAL_EXECUTION_RESULT state; - bool isExecuted = mTradeHandler.ExecuteSignal( - signal, - conditions, - state, - false // ignore Policies ... - ); + // Chack Allow Trades ... + bool allowTrade = AllowTrade(); + if (allowTrade) + { + // + // Execute Signal Using Trade Handler ... + ENUM_X_SIGNAL_EXECUTION_RESULT state; + bool isExecuted = mTradeHandler.ExecuteSignal( + signal, + conditions, + state, + false // ignore Policies ... + ); + } + else + { + // + // Only Alert Signals ... + string msg = (IsLong(signal.type) + ? "Long" + : "Short") + + " Signal Recieved: (" + + signal.provider + "," + + signal.symbol + "," + + ToString(signal.period) + + ") ..."; + + // + Alert(msg); + + // + // Draw Signals and Conditions ... + if (eaDrawer != NULL) + { + // + XCBaseObject *objects[]; + XCSignalObject *signalObject; + bool isCreated = eaDrawer.DrawSignal( + signal, + signalObject // + ); + DrawX121SMCStrategyConditions( + conditions, + objects, + eaDrawer, + true, // draw Market Structure ... + true, // Draw Price Zones ... + true // Draw Decision Zones ... + ); + + // + Add( + (XCBaseObject *)signalObject, + objects // + ); + } + } } // @@ -1034,7 +1105,7 @@ class XC121SMCExpert : public XCBaseExpert // // Parsers ... XSymbolParser _symbolParser; - XCPOIDrawer *poiDrawer = NULL; + eaDrawer = NULL; // // Single Symbol ... @@ -1052,11 +1123,11 @@ class XC121SMCExpert : public XCBaseExpert ); // - if (poiDrawer == NULL) + if (eaDrawer == NULL) { // - poiDrawer = iX121SMCStrategy - .GetDrawer(); + eaDrawer = iX121SMCStrategy + .GetDrawer(); } // @@ -1125,11 +1196,11 @@ class XC121SMCExpert : public XCBaseExpert ); // - if (poiDrawer == NULL) + if (eaDrawer == NULL) { // - poiDrawer = iX121SMCStrategy - .GetDrawer(); + eaDrawer = iX121SMCStrategy + .GetDrawer(); } // @@ -1144,9 +1215,9 @@ class XC121SMCExpert : public XCBaseExpert } // - if (poiDrawer != NULL) + if (eaDrawer != NULL) { - mTradeHandler.SetDrawer(poiDrawer); + mTradeHandler.SetDrawer(eaDrawer); } // @@ -1574,6 +1645,7 @@ class XC121SMCExpert : public XCBaseExpert // Signalling Props ... bool mAllowLong; // Allow Long Signals ... bool mAllowShort; // Allow Short Signals ... + bool mAllowTrade; // Allow Open Trade On Signals ... int mMaxAllowedLongs; // Max Allowed Long Signals ... int mMaxAllowedShorts; // Max Allowed Short Signals ... bool mUseMaxAllowedSignalsPerSymbol; // Use Max Allowed Signal Types Per Symbol ... @@ -1602,6 +1674,9 @@ class XC121SMCExpert : public XCBaseExpert double mHedgingMinVolumeStep; // Minimum Volume Step for Hedging ... double mHedgeingMinRequiredProfitPerVolumeStep; // Minimum Required Profit Per Volume Step for Hedging ... + // + XCPOIDrawer *eaDrawer; // EA Drawer ... + // double CalculateAdditionalVolumeMultiplier(XSignal &signal) { diff --git a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 index 0bff4b7c..c271853b 100644 --- a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 @@ -1226,6 +1226,11 @@ bool DetectX121SMCXTWPVSiganlTrigger( } // + // Ignore Target ... + target = 0; + + // + // Filling Conditions Props ... conditions.sl = sl; conditions.target = target; conditions.triggerTime = cTime; diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index ced2eb0a..dfaefe02 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -623,23 +623,18 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy x121Inputs.hcMethod = hcMethod; x121Inputs.hcPeriod = hcPeriod; - // - x121Inputs.showFibo2Levels = false; - x121Inputs.showFibo3Levels = false; - x121Inputs.showFibo4Levels = false; - // x121Inputs.showSar = true; x121Inputs.showPeaks = true; x121Inputs.showVales = true; - x121Inputs.showVWap = false; + x121Inputs.showVWap = true; x121Inputs.showDonchain = true; // x121Inputs.showOpen = false; - x121Inputs.showHigh = true; + x121Inputs.showHigh = false; x121Inputs.showClose = true; - x121Inputs.showLow = true; + x121Inputs.showLow = false; // // Initialize Cycle Helpers ...