/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Indicator // ------------------------------------------------- // Name: X121 XCA // Description: XCA ... // // // 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 XCA Indicator" #property strict // // Definitions ... // #define ShortName "X121 XCA" // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" // // Inputs ... // input group "Market"; // 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 "Fibo Levels"; input ENUM_X_FIBO_LEVELS fiboLevel1 = X_FIBO_LEVEL_236; // Fibo Level 1 input ENUM_X_FIBO_LEVELS fiboLevel2 = X_FIBO_LEVEL_500; // Fibo Level 2 input ENUM_X_FIBO_LEVELS fiboLevel3 = X_FIBO_LEVEL_764; // Fibo Level 3 // input group "Sar Detection"; input double sarStep = 0.02; // Step input double sarMax = 0.2; // Maximum // // KI ... input group "KI"; input int kiLength = 26; // KI Length // // VIDYA ... // Variable Index Dynamic Average ... input group "VIDYA"; input int vidyaCMOLength = 20; // CMO (Candle Momentum) Length input int vidyaEMALength = 14; // EMA Length input ENUM_APPLIED_PRICE vidyaAppliedTo = PRICE_CLOSE; // Applied To // // Manalyser ... input group "Manalyser"; input int manalyserLength = 14; // Length input ENUM_MA_METHOD manalyserMethod = MODE_SMA; // Method // input group "Swing Detection"; input int swingLength = 5; // Length // input group "Support and Resistance"; input int supResSmoothingLength = 7; // Smoothing Length input ENUM_X_MA_METHOD supResSmoothingMode = X_MA_MODE_SMA; // Smoothing Method // // Presentation ... input group "Presentation"; // input int startCalculationForLastBars = 1000; // Calculate Last n Bars // input bool showSar = true; // Show Sar input bool showKI = true; // Show KI input bool showTKI = true; // Show KI Trend input bool showMAH = true; // Show MAH input bool showMAL = true; // Show MAL input bool showMAC = true; // Show MAC input bool showVidya = true; // Show Vidya input bool showTrend = true; // Show Trend input bool showSwings = true; // Show Swings input bool showFiboLevel1 = true; // Show Fibo Level 1 input bool showFiboLevel2 = true; // Show Fibo Level 2 input bool showFiboLevel3 = true; // Show Fibo Level 3 input bool showPeaksAndVales = true; // Show Peaks And Vales input bool showPeakAndValeGolden = true; // Show Peak and Vale Golden input bool showSupportAndResistance = true; // Show Support and Resistance input bool showShortCycle = true; // Show Short Cycle input bool showMediumCycle = true; // Show Medium Cycle input bool showLongCycle = true; // Show Long Cycle input bool showHindCycle = true; // Show Hind Cycle // int sarArrowCode = 159; // Parabolic Sar Arrow Code int peakArrowCode = 159; // Peaks Arrow Code int valeArrowCode = 159; // Vales Arrow Code int swingLowArrowCode = 225; // Swing Low Arrow Code int swingHighArrowCode = 226; // Swing High Arrow Code // // Buffers ... // #define hideColorIDX 0 #define bullishColorIDX 1 #define bearishColorIDX 2 #define neuturalColorIDX 3 // #define bullishState 1 #define neuturalState 0 #define bearishState -1 // #define emptyValue 0.0 // #property indicator_chart_window // #property indicator_buffers 37 #property indicator_plots 27 // // Plot Buffers ... // // SHORT ... // #define sHHBufferIndex 0 double sHHBuffer[]; // #property indicator_label1 "SH" #property indicator_type1 DRAW_LINE #property indicator_color1 clrGray #property indicator_style1 STYLE_DOT #property indicator_width1 1 // #define sLLBufferIndex 1 double sLLBuffer[]; // #property indicator_label2 "SL" #property indicator_type2 DRAW_LINE #property indicator_color2 clrGray #property indicator_style2 STYLE_DOT #property indicator_width2 1 // // MEDIUM ... // #define mHHBufferIndex 2 double mHHBuffer[]; // #property indicator_label3 "MH" #property indicator_type3 DRAW_LINE #property indicator_color3 clrIndigo #property indicator_style3 STYLE_DOT #property indicator_width3 1 // #define mLLBufferIndex 3 double mLLBuffer[]; // #property indicator_label4 "ML" #property indicator_type4 DRAW_LINE #property indicator_color4 clrIndigo #property indicator_style4 STYLE_DOT #property indicator_width4 1 // // LONG ... // #define lHHBufferIndex 4 double lHHBuffer[]; // #property indicator_label5 "LH" #property indicator_type5 DRAW_LINE #property indicator_color5 clrGoldenrod #property indicator_style5 STYLE_DOT #property indicator_width5 1 // #define lLLBufferIndex 5 double lLLBuffer[]; // #property indicator_label6 "LL" #property indicator_type6 DRAW_LINE #property indicator_color6 clrGoldenrod #property indicator_style6 STYLE_DOT #property indicator_width6 1 // // HIND ... // #define hHHBufferIndex 6 double hHHBuffer[]; // #property indicator_label7 "HH" #property indicator_type7 DRAW_LINE #property indicator_color7 clrBrown #property indicator_style7 STYLE_DOT #property indicator_width7 1 // #define hLLBufferIndex 7 double hLLBuffer[]; // #property indicator_label8 "HL" #property indicator_type8 DRAW_LINE #property indicator_color8 clrBrown #property indicator_style8 STYLE_DOT #property indicator_width8 1 // // SUPPORT ... // #define supportBufferIndex 8 double supportBuffer[]; // #property indicator_label9 "SUPPORT" #property indicator_type9 DRAW_LINE #property indicator_color9 clrLime #property indicator_style9 STYLE_SOLID #property indicator_width9 1 // // RESISTANCE ... // #define resistanceBufferIndex 9 double resistanceBuffer[]; // #property indicator_label10 "RESISTANCE" #property indicator_type10 DRAW_LINE #property indicator_color10 clrRed #property indicator_style10 STYLE_SOLID #property indicator_width10 1 // // PEAKS ... // #define peakBufferIndex 10 double peakBuffer[]; // #property indicator_label11 "PEAK" #property indicator_type11 DRAW_ARROW #property indicator_color11 clrMagenta #property indicator_width11 1 // // PEAKS Golden ... // #define peakGoldenBufferIndex 11 double peakGoldenBuffer[]; // #property indicator_label12 "PEAK Golden" #property indicator_type12 DRAW_LINE #property indicator_color12 clrMagenta #property indicator_style2 STYLE_DOT #property indicator_width12 1 // // VALES ... // #define valeBufferIndex 12 double valeBuffer[]; // #property indicator_label13 "VALE" #property indicator_type13 DRAW_ARROW #property indicator_color13 clrAqua #property indicator_width13 1 // // VALE Golden ... // #define valeGoldenBufferIndex 13 double valeGoldenBuffer[]; // #property indicator_label14 "VALES Golden" #property indicator_type14 DRAW_LINE #property indicator_color14 clrAqua #property indicator_style4 STYLE_DOT #property indicator_width14 1 // // FIBO Level 1 // #define fiboLevel1BufferIndex 14 double fiboLevel1Buffer[]; // #property indicator_label15 "Fibo L1" #property indicator_type15 DRAW_LINE #property indicator_color15 clrGold #property indicator_style15 STYLE_DOT #property indicator_width15 1 // // FIBO Level 2 // #define fiboLevel2BufferIndex 15 double fiboLevel2Buffer[]; // #property indicator_label16 "Fibo L2" #property indicator_type16 DRAW_LINE #property indicator_color16 clrYellow #property indicator_style16 STYLE_DASH #property indicator_width16 1 // // FIBO Level 3 // #define fiboLevel3BufferIndex 16 double fiboLevel3Buffer[]; // #property indicator_label17 "Fibo L3" #property indicator_type17 DRAW_LINE #property indicator_color17 clrGold #property indicator_style17 STYLE_DOT #property indicator_width17 1 // // SAR ... // #define sarBufferIndex 17 double sarBuffer[]; // #property indicator_label18 "SAR" #property indicator_type18 DRAW_ARROW #property indicator_color18 clrYellow #property indicator_width18 1 // // TREND ... // #define trendBufferIndex 18 #define trendBufferPlotIndex 18 double trendBuffer[]; // #define trendColorBufferIndex 19 double trendColorBuffer[]; // #property indicator_label19 "TRND" #property indicator_type19 DRAW_COLOR_LINE #property indicator_color19 CLR_NONE, clrAqua, clrMagenta, clrGray #property indicator_style19 STYLE_DASH #property indicator_width19 2 // // KI ... // #define kiBufferIndex 20 #define kiBufferPlotIndex 19 double kiBuffer[]; // #define kiColorBufferIndex 21 double kiColorBuffer[]; // #property indicator_label20 "KI" #property indicator_type20 DRAW_COLOR_LINE #property indicator_color20 CLR_NONE, clrGreen, clrRed, clrGray #property indicator_style20 STYLE_DASHDOTDOT #property indicator_width20 2 // // SWING Low ... // #define swingLowBufferIndex 22 #define swingLowBufferPlotIndex 20 double swingLowBuffer[]; // #property indicator_label21 "SWL" #property indicator_type21 DRAW_ARROW #property indicator_color21 clrGreen #property indicator_width21 1 // // SWING High ... // #define swingHighBufferIndex 23 #define swingHighBufferPlotIndex 21 double swingHighBuffer[]; // #property indicator_label22 "SWH" #property indicator_type22 DRAW_ARROW #property indicator_color22 clrRed #property indicator_width22 1 // // TKI ... // #define tkiBufferIndex 24 #define tkiBufferPlotIndex 22 double tkiBuffer[]; // #define tkiColorBufferIndex 25 double tkiColorBuffer[]; // #property indicator_label23 "TKI" #property indicator_type23 DRAW_COLOR_LINE #property indicator_color23 CLR_NONE, clrGreen, clrRed, clrGray #property indicator_style23 STYLE_DASHDOTDOT #property indicator_width23 2 // // VIDYA ... // #define vidyaBufferIndex 26 #define vidyaBufferPlotIndex 23 double vidyaBuffer[]; // #define vidyaColorBufferIndex 27 double vidyaColorBuffer[]; // #property indicator_label24 "VIDYA" #property indicator_type24 DRAW_COLOR_LINE #property indicator_color24 CLR_NONE, clrAqua, clrMagenta, clrGray #property indicator_style24 STYLE_SOLID #property indicator_width24 1 // // MAH ... // #define mahBufferIndex 28 #define mahBufferPlotIndex 24 double mahBuffer[]; // #property indicator_label25 "MAH" #property indicator_type25 DRAW_LINE #property indicator_color25 clrMagenta #property indicator_style25 STYLE_SOLID #property indicator_width25 1 // // MAL ... // #define malBufferIndex 29 #define malBufferPlotIndex 25 double malBuffer[]; // #property indicator_label26 "MAL" #property indicator_type26 DRAW_LINE #property indicator_color26 clrAqua #property indicator_style26 STYLE_SOLID #property indicator_width26 1 // // MAC ... // #define macBufferIndex 30 #define macBufferPlotIndex 26 double macBuffer[]; // #property indicator_label27 "MAC" #property indicator_type27 DRAW_LINE #property indicator_color27 clrYellow #property indicator_style27 STYLE_SOLID #property indicator_width27 1 // // Data Buffers ... #define mLastBufferIndex 30 // #define trendStateBufferIndex mLastBufferIndex + 1 double trendStateBuffer[]; // #define kiStateBufferIndex mLastBufferIndex + 2 double kiStateBuffer[]; // #define tkiStateBufferIndex mLastBufferIndex + 3 double tkiStateBuffer[]; // #define vidyaStateBufferIndex mLastBufferIndex + 4 double vidyaStateBuffer[]; // #define supBufferIndex mLastBufferIndex + 5 double supBuffer[]; // #define resBufferIndex mLastBufferIndex + 6 double resBuffer[]; // // Variables, Properties and etc ... // // this counts Available Bars ... int limit; // int firstBarIndex; // int maxLength; // // SAR Handler ... int sarHandler = INVALID_HANDLE; // // TREND Handler ... int tkiHandler = INVALID_HANDLE; int vidyaHandler = INVALID_HANDLE; int trendHandler = INVALID_HANDLE; // // Manalyser Handlers ... int mahHandler = INVALID_HANDLE; int malHandler = INVALID_HANDLE; int macHandler = INVALID_HANDLE; // // 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; } // if (!InitMarketCycles()) { return INIT_PARAMETERS_INCORRECT; } // // Initialize Indicator Handlers ... // // SAR ... sarHandler = iSAR( _Symbol, _Period, sarStep, sarMax // ); bool isInited = sarHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; } // // TKI ... tkiHandler = iMA( _Symbol, _Period, kiLength, 0, MODE_SMA, PRICE_MEDIAN // ); isInited = tkiHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; } // // VIDYA ... vidyaHandler = iVIDyA( _Symbol, _Period, vidyaCMOLength, vidyaEMALength, 0, vidyaAppliedTo // ); isInited = vidyaHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; } // // TREND ... trendHandler = iMA( _Symbol, _Period, mHCLength, 0, MODE_SMA, PRICE_CLOSE // ); isInited = trendHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; } // // MANALYSE ... // // MAH ... mahHandler = iMA( _Symbol, _Period, manalyserLength, 0, manalyserMethod, PRICE_HIGH // ); isInited = mahHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; } // // MAL ... malHandler = iMA( _Symbol, _Period, manalyserLength, 0, manalyserMethod, PRICE_LOW // ); isInited = malHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; } // // MAC ... macHandler = iMA( _Symbol, _Period, manalyserLength, 0, manalyserMethod, PRICE_CLOSE // ); isInited = macHandler != INVALID_HANDLE; if (!isInited) { return INIT_FAILED; } // // 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(tkiHandler); IndicatorRelease(vidyaHandler); IndicatorRelease(trendHandler); } /** * 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); // // Validate Calculated Bars ... // // SAR ... int sarCalculatedBars = BarsCalculated(sarHandler); // // TKI ... int tkiCalculatedBars = BarsCalculated(tkiHandler); // // VIDYA ... int vidyaCalculatedBars = BarsCalculated(vidyaHandler); // // TREND ... int trendCalculatedBars = BarsCalculated(trendHandler); // // MANALYSER ... // // MAH ... int mahCalculatedBars = BarsCalculated(mahHandler); // // MAL ... int malCalculatedBars = BarsCalculated(malHandler); // // MAC ... int macCalculatedBars = BarsCalculated(macHandler); // bool isPassedRequiredCalculatedBars = // // SAR ... sarCalculatedBars >= maxLength && // // TKI ... tkiCalculatedBars >= maxLength && // // VIDYA ... vidyaCalculatedBars >= maxLength && // // TREND ... trendCalculatedBars >= maxLength && // // MANALYSER ... // MAH ... mahCalculatedBars >= maxLength && // MAL ... malCalculatedBars >= maxLength && // MAC ... macCalculatedBars >= 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); // // TKI ... int copiedTKIs = CopyBuffer(tkiHandler, 0, 0, limit, tkiBuffer); // // TKI ... int copiedVidyas = CopyBuffer(vidyaHandler, 0, 0, limit, vidyaBuffer); // // TREND ... int copiedTrends = CopyBuffer(trendHandler, MAIN_LINE, 0, limit + 1, trendBuffer); // // MANALYSER ... // // MAH ... int copiedMahs = CopyBuffer(mahHandler, 0, 0, limit, mahBuffer); // // MAL ... int copiedMals = CopyBuffer(malHandler, 0, 0, limit, malBuffer); // // MAC ... int copiedMacs = CopyBuffer(macHandler, 0, 0, limit, macBuffer); // // Validate Copied Items ... bool isPassedRequiredCopiedItems = // // SAR ... copiedSars >= limit && // // TKI ... copiedTKIs >= limit && // // VIDYA ... copiedVidyas >= limit && // // TREND ... copiedTrends >= limit && // // MANALYSER ... // MAH ... copiedMahs >= limit && // MAL ... copiedMals >= limit && // MAC ... copiedMacs >= limit // ; 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 = false; // result = // // SAR ... sarMax > 0 && sarStep > 0 && kiLength > 0 && swingLength > 0 && sarMax > sarStep && vidyaEMALength > 0 && vidyaCMOLength > 0 && manalyserLength > 0 && // // XCA ... (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; // result = MathMax(kiLength, swingLength); result = MathMax(result, vidyaCMOLength); result = MathMax(result, vidyaEMALength); result = MathMax(result, manalyserLength); // return result; } /** * Define Required Buffers ... */ void DefineBuffers() { // // Plot Buffers ... // // SHORT ... // ENUM_DRAW_TYPE sDrawType = showShortCycle ? DRAW_LINE : DRAW_NONE; // // HH ... // ArraySetAsSeries(sHHBuffer, true); SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(sHHBufferIndex, PLOT_SHOW_DATA, showShortCycle); PlotIndexSetInteger(sHHBufferIndex, PLOT_DRAW_TYPE, sDrawType); // PlotIndexSetDouble(sHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // LL ... // ArraySetAsSeries(sLLBuffer, true); SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(sLLBufferIndex, PLOT_SHOW_DATA, showShortCycle); PlotIndexSetInteger(sLLBufferIndex, PLOT_DRAW_TYPE, sDrawType); // PlotIndexSetDouble(sLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // MEDIUM ... // ENUM_DRAW_TYPE mDrawType = showMediumCycle ? DRAW_LINE : DRAW_NONE; // // HH ... // ArraySetAsSeries(mHHBuffer, true); SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(mHHBufferIndex, PLOT_SHOW_DATA, showMediumCycle); PlotIndexSetInteger(mHHBufferIndex, PLOT_DRAW_TYPE, mDrawType); // PlotIndexSetDouble(mHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // LL ... // ArraySetAsSeries(mLLBuffer, true); SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(mLLBufferIndex, PLOT_SHOW_DATA, showMediumCycle); PlotIndexSetInteger(mLLBufferIndex, PLOT_DRAW_TYPE, mDrawType); // PlotIndexSetDouble(mLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // LONG ... // ENUM_DRAW_TYPE lDrawType = showLongCycle ? DRAW_LINE : DRAW_NONE; // // HH ... // ArraySetAsSeries(lHHBuffer, true); SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(lHHBufferIndex, PLOT_SHOW_DATA, showLongCycle); PlotIndexSetInteger(lHHBufferIndex, PLOT_DRAW_TYPE, lDrawType); // PlotIndexSetDouble(lHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // LL ... // ArraySetAsSeries(lLLBuffer, true); SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(lLLBufferIndex, PLOT_SHOW_DATA, showLongCycle); PlotIndexSetInteger(lLLBufferIndex, PLOT_DRAW_TYPE, lDrawType); // PlotIndexSetDouble(lLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // HIND ... // ENUM_DRAW_TYPE hDrawType = showHindCycle ? DRAW_LINE : DRAW_NONE; // // HH ... // ArraySetAsSeries(hHHBuffer, true); SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(hHHBufferIndex, PLOT_SHOW_DATA, showHindCycle); PlotIndexSetInteger(hHHBufferIndex, PLOT_DRAW_TYPE, hDrawType); // PlotIndexSetDouble(hHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // LL ... // ArraySetAsSeries(hLLBuffer, true); SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(hLLBufferIndex, PLOT_SHOW_DATA, showHindCycle); PlotIndexSetInteger(hLLBufferIndex, PLOT_DRAW_TYPE, hDrawType); // PlotIndexSetDouble(hLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // SUPPORT / RESISTANCE ... // ENUM_DRAW_TYPE supResDrawType = showSupportAndResistance ? DRAW_LINE : DRAW_NONE; // // SUPPORT ... // ArraySetAsSeries(supportBuffer, true); SetIndexBuffer(supportBufferIndex, supportBuffer, INDICATOR_DATA); // PlotIndexSetInteger(supportBufferIndex, PLOT_SHOW_DATA, showSupportAndResistance); PlotIndexSetInteger(supportBufferIndex, PLOT_DRAW_TYPE, supResDrawType); // PlotIndexSetDouble(supportBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // RESISTANCE ... // ArraySetAsSeries(resistanceBuffer, true); SetIndexBuffer(resistanceBufferIndex, resistanceBuffer, INDICATOR_DATA); // PlotIndexSetInteger(resistanceBufferIndex, PLOT_SHOW_DATA, showSupportAndResistance); PlotIndexSetInteger(resistanceBufferIndex, PLOT_DRAW_TYPE, supResDrawType); // PlotIndexSetDouble(resistanceBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // PEAK / VALE ... // ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; // // PEAK ... // ArraySetAsSeries(peakBuffer, true); SetIndexBuffer(peakBufferIndex, peakBuffer, INDICATOR_DATA); // PlotIndexSetInteger(peakBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); PlotIndexSetInteger(peakBufferIndex, PLOT_DRAW_TYPE, pvDrawType); // PlotIndexSetDouble(peakBufferIndex, PLOT_EMPTY_VALUE, emptyValue); PlotIndexSetInteger(peakBufferIndex, PLOT_ARROW, peakArrowCode); // // VALE ... // ArraySetAsSeries(valeBuffer, true); SetIndexBuffer(valeBufferIndex, valeBuffer, INDICATOR_DATA); // PlotIndexSetInteger(valeBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); PlotIndexSetInteger(valeBufferIndex, PLOT_DRAW_TYPE, pvDrawType); // PlotIndexSetDouble(valeBufferIndex, PLOT_EMPTY_VALUE, emptyValue); PlotIndexSetInteger(valeBufferIndex, PLOT_ARROW, valeArrowCode); // // PV GOLDEN ... // ENUM_DRAW_TYPE pvGoldenDrawType = showPeakAndValeGolden ? DRAW_LINE : DRAW_NONE; // // PEAK Golden ... // ArraySetAsSeries(peakGoldenBuffer, true); SetIndexBuffer(peakGoldenBufferIndex, peakGoldenBuffer, INDICATOR_DATA); // PlotIndexSetInteger(peakGoldenBufferIndex, PLOT_SHOW_DATA, showPeakAndValeGolden); PlotIndexSetInteger(peakGoldenBufferIndex, PLOT_DRAW_TYPE, pvGoldenDrawType); // PlotIndexSetDouble(peakGoldenBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // VALE Golden ... // ArraySetAsSeries(valeGoldenBuffer, true); SetIndexBuffer(valeGoldenBufferIndex, valeGoldenBuffer, INDICATOR_DATA); // PlotIndexSetInteger(valeGoldenBufferIndex, PLOT_SHOW_DATA, showPeakAndValeGolden); PlotIndexSetInteger(valeGoldenBufferIndex, PLOT_DRAW_TYPE, pvGoldenDrawType); // PlotIndexSetDouble(valeGoldenBufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // FIBO L1 ... // ENUM_DRAW_TYPE fiboL1DrawType = showFiboLevel1 ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(fiboLevel1Buffer, true); SetIndexBuffer(fiboLevel1BufferIndex, fiboLevel1Buffer, INDICATOR_DATA); // PlotIndexSetInteger(fiboLevel1BufferIndex, PLOT_SHOW_DATA, showFiboLevel1); PlotIndexSetInteger(fiboLevel1BufferIndex, PLOT_DRAW_TYPE, fiboL1DrawType); // PlotIndexSetDouble(fiboLevel1BufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // FIBO L2 ... // ENUM_DRAW_TYPE fiboL2DrawType = showFiboLevel2 ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(fiboLevel2Buffer, true); SetIndexBuffer(fiboLevel2BufferIndex, fiboLevel2Buffer, INDICATOR_DATA); // PlotIndexSetInteger(fiboLevel2BufferIndex, PLOT_SHOW_DATA, showFiboLevel2); PlotIndexSetInteger(fiboLevel2BufferIndex, PLOT_DRAW_TYPE, fiboL2DrawType); // PlotIndexSetDouble(fiboLevel2BufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // FIBO L3 ... // ENUM_DRAW_TYPE fiboL3DrawType = showFiboLevel3 ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(fiboLevel3Buffer, true); SetIndexBuffer(fiboLevel3BufferIndex, fiboLevel3Buffer, INDICATOR_DATA); // PlotIndexSetInteger(fiboLevel3BufferIndex, PLOT_SHOW_DATA, showFiboLevel3); PlotIndexSetInteger(fiboLevel3BufferIndex, PLOT_DRAW_TYPE, fiboL3DrawType); // PlotIndexSetDouble(fiboLevel3BufferIndex, PLOT_EMPTY_VALUE, emptyValue); // // 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, emptyValue); PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode); // // TREND ... // ENUM_DRAW_TYPE trendDrawType = showTrend ? DRAW_COLOR_LINE : DRAW_NONE; // ArraySetAsSeries(trendBuffer, true); SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA); // PlotIndexSetInteger(trendBufferPlotIndex, PLOT_SHOW_DATA, showTrend); // PlotIndexSetInteger(trendBufferPlotIndex, PLOT_DRAW_TYPE, trendDrawType); // PlotIndexSetDouble(trendBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); // ArraySetAsSeries(trendColorBuffer, true); SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX); // // KI ... // ENUM_DRAW_TYPE kiDrawType = showKI ? DRAW_COLOR_LINE : DRAW_NONE; // ArraySetAsSeries(kiBuffer, true); SetIndexBuffer(kiBufferIndex, kiBuffer, INDICATOR_DATA); // PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKI); // PlotIndexSetInteger(kiBufferPlotIndex, PLOT_DRAW_TYPE, kiDrawType); // PlotIndexSetDouble(kiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); // ArraySetAsSeries(kiColorBuffer, true); SetIndexBuffer(kiColorBufferIndex, kiColorBuffer, INDICATOR_COLOR_INDEX); // // TKI ... // ENUM_DRAW_TYPE tkiDrawType = showTKI ? DRAW_COLOR_LINE : DRAW_NONE; // ArraySetAsSeries(tkiBuffer, true); SetIndexBuffer(tkiBufferIndex, tkiBuffer, INDICATOR_DATA); // PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_SHOW_DATA, showKI); // PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_DRAW_TYPE, kiDrawType); // PlotIndexSetDouble(tkiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); // ArraySetAsSeries(tkiColorBuffer, true); SetIndexBuffer(tkiColorBufferIndex, tkiColorBuffer, INDICATOR_COLOR_INDEX); // // VIDYA ... // ENUM_DRAW_TYPE vidyaDrawType = showVidya ? DRAW_COLOR_LINE : DRAW_NONE; // ArraySetAsSeries(vidyaBuffer, true); SetIndexBuffer(vidyaBufferIndex, vidyaBuffer, INDICATOR_DATA); // PlotIndexSetInteger(vidyaBufferPlotIndex, PLOT_SHOW_DATA, showKI); // PlotIndexSetInteger(vidyaBufferPlotIndex, PLOT_DRAW_TYPE, vidyaDrawType); // PlotIndexSetDouble(vidyaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); // ArraySetAsSeries(vidyaColorBuffer, true); SetIndexBuffer(vidyaColorBufferIndex, vidyaColorBuffer, INDICATOR_COLOR_INDEX); // // SWINGS ... // ENUM_DRAW_TYPE swingDrawType = showSwings ? DRAW_ARROW : DRAW_NONE; // // SWING Low ... // ArraySetAsSeries(swingLowBuffer, true); SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); // PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_SHOW_DATA, showSwings); PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_DRAW_TYPE, swingDrawType); // PlotIndexSetDouble(swingLowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_ARROW, swingLowArrowCode); // // SWING High ... // ArraySetAsSeries(swingHighBuffer, true); SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); // PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_SHOW_DATA, showSwings); PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_DRAW_TYPE, swingDrawType); // PlotIndexSetDouble(swingHighBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_ARROW, swingHighArrowCode); // // MANALYSER ... // // MAH ... // ENUM_DRAW_TYPE mahDrawType = showMAH ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(mahBuffer, true); SetIndexBuffer(mahBufferIndex, mahBuffer, INDICATOR_DATA); // PlotIndexSetInteger(mahBufferPlotIndex, PLOT_SHOW_DATA, showMAH); PlotIndexSetInteger(mahBufferPlotIndex, PLOT_DRAW_TYPE, mahDrawType); // PlotIndexSetDouble(mahBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); // // MAL ... // ENUM_DRAW_TYPE malDrawType = showMAL ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(malBuffer, true); SetIndexBuffer(malBufferIndex, malBuffer, INDICATOR_DATA); // PlotIndexSetInteger(malBufferPlotIndex, PLOT_SHOW_DATA, showMAL); PlotIndexSetInteger(malBufferPlotIndex, PLOT_DRAW_TYPE, malDrawType); // PlotIndexSetDouble(malBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); // // MAC ... // ENUM_DRAW_TYPE macDrawType = showMAC ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(macBuffer, true); SetIndexBuffer(macBufferIndex, macBuffer, INDICATOR_DATA); // PlotIndexSetInteger(macBufferPlotIndex, PLOT_SHOW_DATA, showMAC); PlotIndexSetInteger(macBufferPlotIndex, PLOT_DRAW_TYPE, mahDrawType); // PlotIndexSetDouble(macBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); // // Data Buffers ... // ArraySetAsSeries(trendStateBuffer, true); SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS); // ArraySetAsSeries(kiStateBuffer, true); SetIndexBuffer(kiStateBufferIndex, kiStateBuffer, INDICATOR_CALCULATIONS); // ArraySetAsSeries(tkiStateBuffer, true); SetIndexBuffer(tkiStateBufferIndex, tkiStateBuffer, INDICATOR_CALCULATIONS); // ArraySetAsSeries(vidyaStateBuffer, true); SetIndexBuffer(vidyaStateBufferIndex, vidyaStateBuffer, INDICATOR_CALCULATIONS); // ArraySetAsSeries(supBuffer, true); SetIndexBuffer(supBufferIndex, supBuffer, INDICATOR_CALCULATIONS); // ArraySetAsSeries(resBuffer, true); SetIndexBuffer(resBufferIndex, resBuffer, INDICATOR_CALCULATIONS); // } /** * Set Indicator Short Name and also we can define Buffers Labels ... */ void SetIndicatorName() { // IndicatorSetInteger(INDICATOR_DIGITS, _Digits); 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; if (barsLimit == 0) { // barsLimit = ratesTotal; firstBarIndex = barsLimit - 1; } else { // firstBarIndex = startCalculationForLastBars; } // // bool canCalculate = true; bool canCalculate = bar_index <= barsLimit; if (canCalculate) { // // Calculate Cycles ... CalculateCycles(bar_index); // // Calculate Support nad Resistance ... CalculateValues( 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) { // // SHORT ... sHHBuffer[barIndex] = emptyValue; sLLBuffer[barIndex] = emptyValue; // // MEDIUM ... mHHBuffer[barIndex] = emptyValue; mLLBuffer[barIndex] = emptyValue; // // LONG ... lHHBuffer[barIndex] = emptyValue; lLLBuffer[barIndex] = emptyValue; // // HIND ... hHHBuffer[barIndex] = emptyValue; hLLBuffer[barIndex] = emptyValue; // // SUPPORT / RESISTANCE ... supBuffer[barIndex] = emptyValue; resBuffer[barIndex] = emptyValue; supportBuffer[barIndex] = emptyValue; resistanceBuffer[barIndex] = emptyValue; // // PEAKS ... peakBuffer[barIndex] = emptyValue; peakGoldenBuffer[barIndex] = emptyValue; // // VALES ... valeBuffer[barIndex] = emptyValue; valeGoldenBuffer[barIndex] = emptyValue; // // SAR ... sarBuffer[barIndex] = emptyValue; // // TREND ... trendBuffer[barIndex] = emptyValue; trendColorBuffer[barIndex] = hideColorIDX; trendStateBuffer[barIndex] = neuturalState; // // KI ... kiBuffer[barIndex] = emptyValue; kiColorBuffer[barIndex] = hideColorIDX; kiStateBuffer[barIndex] = neuturalState; // // TKI ... tkiBuffer[barIndex] = emptyValue; tkiColorBuffer[barIndex] = hideColorIDX; tkiStateBuffer[barIndex] = neuturalState; // // VIDYA ... vidyaBuffer[barIndex] = emptyValue; vidyaColorBuffer[barIndex] = hideColorIDX; vidyaStateBuffer[barIndex] = neuturalState; // // SWINGS ... swingLowBuffer[barIndex] = emptyValue; swingHighBuffer[barIndex] = emptyValue; } /** * 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 Values ... * * @param bar_index: int, Specified Bar Index ... * @param prevCalculated: int, Provides Previous Calculated Bars ... * @param ratesTotal: int, Provides All Availabled Bars ... * @param open: double Collection, Provides Open Prices Time Series ... * @param high: double Collection, Provides High Prices Time Series ... * @param close: double Collection, Provides Close Prices Time Series ... * @param low: double Collection, Provides Low Prices Time Series ... * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... */ void CalculateValues( 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[] // ) { // // Check Prev Bar ... // int lastBarIndex = bar_index + 1; bool isFirstBar = startCalculationForLastBars > 0 ? bar_index == startCalculationForLastBars : bar_index == firstBarIndex; XOHCL iBar; bool isInited = iBar.Init( _Symbol, _Period, bar_index // ); // double iSHH = sHHBuffer[bar_index]; double iSLL = sLLBuffer[bar_index]; // double iMHH = mHHBuffer[bar_index]; double iMLL = mLLBuffer[bar_index]; // double iLHH = lHHBuffer[bar_index]; double iLLL = lLLBuffer[bar_index]; // double iHHH = hHHBuffer[bar_index]; double iHLL = hLLBuffer[bar_index]; // // Calculate BOS ... // // Calculate CHOCH ... // // Calculate Support ... double lastSupport = isFirstBar ? emptyValue : supBuffer[lastBarIndex]; bool isSupport = iSLL == iMLL; double iSupport = isSupport ? iSLL : lastSupport; supBuffer[bar_index] = iSupport; // // Calculate Vale ... double lastVale = isFirstBar ? emptyValue : valeBuffer[lastBarIndex]; bool isVale = isSupport && iMLL == iLLL && iLLL == iHLL; double iVale = isVale ? iMLL : lastVale; valeBuffer[bar_index] = iVale; // // Calculate Resistance ... double lastResistance = isFirstBar ? emptyValue : resBuffer[lastBarIndex]; bool isResistance = iSHH == iMHH; double iResistance = isResistance ? iSHH : lastResistance; resBuffer[bar_index] = iResistance; // // Calculate Peak ... double lastPeak = isFirstBar ? emptyValue : peakBuffer[lastBarIndex]; bool isPeak = isResistance && iMHH == iLHH && iLHH == iHHH; double iPeak = isPeak ? iMHH : lastPeak; peakBuffer[bar_index] = iPeak; // bool canSmooth = supResSmoothingLength > 0 && supResSmoothingMode != X_MA_MODE_NONE; if (!canSmooth) { // supportBuffer[bar_index] = iSupport; resistanceBuffer[bar_index] = iResistance; } else { // // Support ... iMAOnBuffer( ratesTotal, prevCalculated, bar_index, supResSmoothingLength, supBuffer, supportBuffer, supResSmoothingMode // ); // // Resistance ... iMAOnBuffer( ratesTotal, prevCalculated, bar_index, supResSmoothingLength, resBuffer, resistanceBuffer, supResSmoothingMode // ); } // // Calculate Fibo Levels ... // double iFiboUpper = peakBuffer[bar_index]; double iFiboLower = valeBuffer[bar_index]; // double iFiboLevel1 = GetFibonacciLevel( iFiboUpper, iFiboLower, fiboLevel1, X_DIRECTION_BEARISH // ); fiboLevel1Buffer[bar_index] = iFiboLevel1; // double iFiboLevel2 = GetFibonacciLevel( iFiboUpper, iFiboLower, fiboLevel2, X_DIRECTION_BEARISH // ); fiboLevel2Buffer[bar_index] = iFiboLevel2; // double iFiboLevel3 = GetFibonacciLevel( iFiboUpper, iFiboLower, fiboLevel3, X_DIRECTION_BEARISH // ); fiboLevel3Buffer[bar_index] = iFiboLevel3; // // Calculate Trend Color Buffer ... double iClose = close[bar_index]; double iTrend = trendBuffer[bar_index]; // double iTrendState = neuturalState; double iTrendColor = neuturalColorIDX; if (iClose > iTrend) { // iTrendState = bullishState; iTrendColor = !showTrend ? hideColorIDX : bullishColorIDX; } else if (iClose < iTrend) { // iTrendState = bearishState; iTrendColor = !showTrend ? hideColorIDX : bearishColorIDX; } trendStateBuffer[bar_index] = iTrendState; trendColorBuffer[bar_index] = iTrendColor; // // Calculate KI / Color ... double lastKI = isFirstBar ? emptyValue : kiBuffer[lastBarIndex]; double iKI = lastKI; if (isInited) { // double iLLKI = iBar.FindLowest(kiLength, MODE_LOW); double iHHKI = iBar.FindHighest(kiLength, MODE_HIGH); // iKI = (iHHKI + iLLKI) / 2; if (iLLKI == 0 || iHHKI == 0) { iKI = lastKI; } } else { iKI = lastKI; } kiBuffer[bar_index] = iKI; // double iKIState = neuturalState; double iKIColor = neuturalColorIDX; if (iClose > iKI) { // iKIState = bullishState; iKIColor = !showKI ? hideColorIDX : bullishColorIDX; } else if (iClose < iKI) { // iKIState = bearishState; iKIColor = !showKI ? hideColorIDX : bearishColorIDX; } kiStateBuffer[bar_index] = iKIState; kiColorBuffer[bar_index] = iKIColor; // // Calculate PV Gold ... double lastPeakGold = isFirstBar ? emptyValue : peakGoldenBuffer[lastBarIndex]; double lastValeGold = isFirstBar ? emptyValue : valeGoldenBuffer[lastBarIndex]; double iPeakGold = lastPeakGold; double iValeGold = lastValeGold; if (isInited) { // iPeakGold = iBar.FindHighest(mHCLength, MODE_CLOSE); if (iPeakGold == 0) { iPeakGold = lastPeakGold; } // iValeGold = iBar.FindLowest(mHCLength, MODE_CLOSE); if (iValeGold == 0) { iValeGold = lastValeGold; } } else { // iPeakGold = lastPeakGold; iValeGold = lastValeGold; } peakGoldenBuffer[bar_index] = iPeakGold; valeGoldenBuffer[bar_index] = iValeGold; // // Calculate Swings ... // double lastSwingLow = isFirstBar ? emptyValue : swingLowBuffer[lastBarIndex]; double lastSwingHigh = isFirstBar ? emptyValue : swingHighBuffer[lastBarIndex]; // bool isSwingLow = IsSwingLow( high, low, bar_index, swingLength // ); bool isSwingHigh = IsSwingHigh( high, low, bar_index, swingLength // ); bool hasSwing = isSwingLow || isSwingHigh; if (!hasSwing) { // // FillBuffersZero(bar_index); // swingLowBuffer[bar_index] = lastSwingLow; swingHighBuffer[bar_index] = lastSwingHigh; } else { // double iSwingLow = low[bar_index]; double iSwingHigh = high[bar_index]; // if (isSwingLow && !isSwingHigh) { iSwingHigh = lastSwingHigh; } else if (isSwingHigh && !isSwingLow) { iSwingLow = lastSwingLow; } // if (iSwingLow > lastSwingLow && iSwingHigh == lastSwingHigh) { iSwingLow = lastSwingLow; } // if (iSwingHigh < lastSwingHigh && iSwingLow == lastSwingLow) { iSwingHigh = lastSwingHigh; } // swingLowBuffer[bar_index] = iSwingLow; swingHighBuffer[bar_index] = iSwingHigh; } // // TKI State and Color ... // double iTKI = tkiBuffer[bar_index]; // double iTKIState = neuturalState; double iTKIColor = neuturalColorIDX; if (iClose > iTKI) { // iTKIState = bullishState; iTKIColor = !showTKI ? hideColorIDX : bullishColorIDX; } else if (iClose < iTKI) { // iTKIState = bearishState; iTKIColor = !showTKI ? hideColorIDX : bearishColorIDX; } tkiStateBuffer[bar_index] = iTKIState; tkiColorBuffer[bar_index] = iTKIColor; // // VIDYA Color ... // double iVIDYA = vidyaBuffer[bar_index]; // double iVIDYAState = neuturalState; double iVIDYAColor = neuturalColorIDX; if (iClose > iVIDYA) { // iVIDYAState = bullishState; iVIDYAColor = !showVidya ? hideColorIDX : bullishColorIDX; } else if (iClose < iVIDYA) { // iVIDYAState = bearishState; iVIDYAColor = !showVidya ? hideColorIDX : bearishColorIDX; } vidyaStateBuffer[bar_index] = iVIDYAState; vidyaColorBuffer[bar_index] = iVIDYAColor; // // Cleanup Resources ... // iBar.Clean(); } // bool IsSwingLow( const double &high[], const double &low[], int index, int length // ) { // bool result = false; // result = index + 1 + length <= firstBarIndex; if (!result) { return result; } // for (int i = index + 1; i <= index + length; i++) { // result = low[index] < low[i]; if (!result) { break; } } // return result; } // bool IsSwingHigh( const double &high[], const double &low[], int index, int length // ) { // bool result = false; // result = index + 1 + length <= firstBarIndex; if (!result) { return result; } // for (int i = index + 1; i <= index + length; i++) { // result = high[index] > high[i]; if (!result) { break; } } // return result; } //