/////////////////////////////////////////////////////// // SaherElm IT Center MQL5 Indicator // ------------------------------------------- // Name: X121_XPV // Description: Market 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_XPV Indicator" #property strict // // START Constants ... // // // Indicator Short Name ... #define ShortName "X121_XPV" // // XPERIOD Calculation Method ... // USED For Multiple Time Frames ... enum ENUM_X_PERIOD_METHOD { // X_PERIOD_NOTHING, // X_PERIOD_AUTO, // X_PERIOD_MANUALLY }; // // END Constants ... // // // START Inputs ... // // input group "Makret Cycles"; // input group "Level 1"; input ENUM_X_PERIOD_METHOD l1Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES l1Period = NULL; // Time Period // input group "Level 2"; input ENUM_X_PERIOD_METHOD l2Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES l2Period = NULL; // Time Period // input group "Level 3"; input ENUM_X_PERIOD_METHOD l3Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES l3Period = NULL; // Time Period // input group "Level 4"; input ENUM_X_PERIOD_METHOD l4Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES l4Period = NULL; // Time Period // input double fiboLevel1 = 0.382; // Fibio 1st Level input double fiboLevel2 = 0.5; // Fibio 2st Level input double fiboLevel3 = 0.618; // Fibio 3rd Level // input group "Detection Modes"; input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method // input group "Presentation"; input bool showPeaksAndVales = true; // Show Peaks and Vales input bool showLevels = false; // Show Levels input bool showFibo1Levels = true; // Show Fibo 1st Level input bool showFibo2Levels = true; // Show Fibo 2nd Level input bool showFibo3Levels = true; // Show Fibo 3rd Level // // END Inputs ... // // // START Includes and Imports ... // // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" // // END Includes and Imports ... // // // START Buffers ... // #property indicator_chart_window // #property indicator_buffers 28 #property indicator_plots 28 // // PEKSANDVALES ... // // PEAKS ... // #define peaksBufferIndex 0 double peaksBuffer[]; // #property indicator_label1 "X121_XPV PEAKS" #property indicator_type1 DRAW_ARROW #property indicator_color1 clrAqua #property indicator_width1 1 // // VALES ... // #define valesBufferIndex 1 double valesBuffer[]; // #property indicator_label2 "X121_XPV VALES" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrMagenta #property indicator_width2 1 // #define rBufferIndex 2 double rBuffer[]; // #define rColorBufferIndex 3 double rColorBuffer[]; // #property indicator_label3 "X121_XPV R" #property indicator_type3 DRAW_COLOR_LINE #property indicator_color3 CLR_NONE, clrAqua #property indicator_style3 STYLE_DOT #property indicator_width3 1 // #define sBufferIndex 4 #define sBufferPlotIndex 3 double sBuffer[]; // #define sColorBufferIndex 5 double sColorBuffer[]; // #property indicator_label4 "X121_XPV S" #property indicator_type4 DRAW_COLOR_LINE #property indicator_color4 CLR_NONE, clrMagenta #property indicator_style4 STYLE_DOT #property indicator_width4 1 // // FIBBO Level 1 ... // #define fl1BufferIndex 6 #define fl1BufferPlotIndex 4 double fl1Buffer[]; // #define fl1ColorBufferIndex 7 double fl1ColorBuffer[]; // #property indicator_label5 "X121_XPV FL1" #property indicator_type5 DRAW_COLOR_LINE #property indicator_color5 CLR_NONE, clrGold #property indicator_style5 STYLE_DASHDOTDOT #property indicator_width5 1 // // FIBBO Level 2 ... // #define fl2BufferIndex 8 #define fl2BufferPlotIndex 5 double fl2Buffer[]; // #define fl2ColorBufferIndex 9 double fl2ColorBuffer[]; // #property indicator_label6 "X121_XPV FL2" #property indicator_type6 DRAW_COLOR_LINE #property indicator_color6 CLR_NONE, clrGold #property indicator_style6 STYLE_DASHDOTDOT #property indicator_width6 1 // // FIBBO Level 3 ... // #define fl3BufferIndex 10 #define fl3BufferPlotIndex 6 double fl3Buffer[]; // #define fl3ColorBufferIndex 11 double fl3ColorBuffer[]; // #property indicator_label7 "X121_XPV FL3" #property indicator_type7 DRAW_COLOR_LINE #property indicator_color7 CLR_NONE, clrGold #property indicator_style7 STYLE_DASHDOTDOT #property indicator_width7 1 // // LEVELS ... // #define sHHBufferIndex 12 #define sHHBufferPlotIndex 7 double sHHBuffer[]; // #define sHHColorBufferIndex 13 double sHHColorBuffer[]; // #property indicator_label8 "X121_XPV SHH" #property indicator_type8 DRAW_COLOR_LINE #property indicator_color8 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style8 STYLE_DOT #property indicator_width8 1 #define sLLBufferIndex 14 #define sLLBufferPlotIndex 8 double sLLBuffer[]; // #define sLLColorBufferIndex 15 double sLLColorBuffer[]; // #property indicator_label9 "X121_XPV SLL" #property indicator_type9 DRAW_COLOR_LINE #property indicator_color9 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style9 STYLE_DOT #property indicator_width9 1 // #define mHHBufferIndex 16 #define mHHBufferPlotIndex 9 double mHHBuffer[]; // #define mHHColorBufferIndex 17 double mHHColorBuffer[]; // #property indicator_label10 "X121_XPV MHH" #property indicator_type10 DRAW_COLOR_LINE #property indicator_color10 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style10 STYLE_DOT #property indicator_width10 1 // #define mLLBufferIndex 18 #define mLLBufferPlotIndex 10 double mLLBuffer[]; // #define mLLColorBufferIndex 19 double mLLColorBuffer[]; // #property indicator_label11 "X121_XPV MLL" #property indicator_type11 DRAW_COLOR_LINE #property indicator_color11 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style11 STYLE_DOT #property indicator_width11 1 // #define lHHBufferIndex 20 #define lHHBufferPlotIndex 11 double lHHBuffer[]; // #define lHHColorBufferIndex 21 double lHHColorBuffer[]; // #property indicator_label12 "X121_XPV LHH" #property indicator_type12 DRAW_COLOR_LINE #property indicator_color12 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style12 STYLE_DOT #property indicator_width12 1 // #define lLLBufferIndex 22 #define lLLBufferPlotIndex 12 double lLLBuffer[]; // #define lLLColorBufferIndex 23 double lLLColorBuffer[]; // #property indicator_label13 "X121_XPV LLL" #property indicator_type13 DRAW_COLOR_LINE #property indicator_color13 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style13 STYLE_DOT #property indicator_width13 1 // #define hHHBufferIndex 24 #define hHHBufferPlotIndex 13 double hHHBuffer[]; // #define hHHColorBufferIndex 25 double hHHColorBuffer[]; // #property indicator_label14 "X121_XPV HHH" #property indicator_type14 DRAW_COLOR_LINE #property indicator_color14 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style14 STYLE_DOT #property indicator_width14 1 // #define hLLBufferIndex 26 #define hLLBufferPlotIndex 14 double hLLBuffer[]; // #define hLLColorBufferIndex 27 double hLLColorBuffer[]; // #property indicator_label15 "X121_XPV HLL" #property indicator_type15 DRAW_COLOR_LINE #property indicator_color15 CLR_NONE, clrLightGray, clrAqua, clrMagenta #property indicator_style15 STYLE_DOT #property indicator_width15 1 // // END Buffers ... // // // START Global Definitions: Variables, Properties and etc ... // // int maxLength; // double lastPeak; double lastVale; // double mLastSHH = 0; double mLastSLL = 0; // double mLastMHH = 0; double mLastMLL = 0; // double mLastLHH = 0; double mLastLLL = 0; // double mLastHHH = 0; double mLastHLL = 0; // double mHideColorIDX = 0; // int currentPeriodSecconds = 0; // // CYCLE 1 ... int mL1Candles; int mL1PeriodSecconds = 0; int mLastL1StartBarIndex = 0; datetime mLastL1StartTime = NULL; ENUM_TIMEFRAMES mL1Period = NULL; // // CYCLE 2 ... int mL2Candles; int mL2PeriodSecconds = 0; int mLastL2StartBarIndex = 0; datetime mLastL2StartTime = NULL; ENUM_TIMEFRAMES mL2Period = NULL; // // CYCLE 3 ... int mL3Candles; int mL3PeriodSecconds = 0; int mLastL3StartBarIndex = 0; datetime mLastL3StartTime = NULL; ENUM_TIMEFRAMES mL3Period = NULL; // // CYCLE 4 ... int mL4Candles; int mL4PeriodSecconds = 0; int mLastL4StartBarIndex = 0; datetime mLastL4StartTime = NULL; ENUM_TIMEFRAMES mL4Period = NULL; // // END Global Definitions: Variables, Properties and etc ... // // // START Event Handlers ... // // // Initialization ... int OnInit() { // // Validate Inputs ... if (!ValidateInputs()) { 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(); // // Initial Periods ... InitialCycles(); // // Init Succeed ... return INIT_SUCCEEDED; } // // DeInitialization ... void OnDeinit(const int reason) { // // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function // REASON_REMOVE 1 Program removed from a chart // REASON_RECOMPILE 2 Program recompiled // REASON_CHARTCHANGE 3 A symbol or a chart period is changed // REASON_CHARTCLOSE 4 Chart closed // REASON_PARAMETERS 5 Inputs changed by a user // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings // REASON_TEMPLATE 7 Another chart template applied // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value // REASON_CLOSE 9 Terminal closed // Comment(""); } // // Calculating what we want ... int OnCalculate( // // total Candles on chart ... const int rates_total, // // total calculated Candles on charts ... const int prev_calculated, // // history of Candles Open Time ... const datetime &time[], // // history of Candles Open Price ... const double &open[], // // history of Candles High Price ... const double &high[], // // history of Candles Low Price ... const double &low[], // // history of Candles Close Price ... const double &close[], // // history of Tick Volumes on Candle ... const long &tick_volume[], // // history of Trade Volumes ... const long &volume[], // // history of Candles Spread Price ... 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); // // this counts Available Bars ... int limit; // limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; // // Main Loop ... for (int i = limit - 1; i >= 0 && !IsStopped(); i--) { CalculateBuffers(i); } // return rates_total; } // // END Event Handlers ... // // // START Functions ... // // // Validate Input Args for Initialization ... bool ValidateInputs() { // bool result = true; // return result; } // // Retrieve all Exists Input Max Length ... // use for Start Of Drawing ... int ExtractMaxLengthOfInputs() { // int result = 1; // return result; } // // Initial Multi Time Frame Cycles Periods ... void InitialCycles() { // // Calculate Current Period Secconds ... currentPeriodSecconds = PeriodSeconds(_Period); // // Nearest ... // Calculate Cycle 1 Requirements ... if (mL1Period == NULL) { // if (l1Method == X_PERIOD_AUTO) { mL1Period = GetNearestTimeFrame(_Period); } else { mL1Period = l1Period; } // mL1PeriodSecconds = PeriodSeconds(mL1Period); // mL1Candles = mL1PeriodSecconds / currentPeriodSecconds; } // // Mediest ... // Calculate Cycle 2 Requirements ... if (mL2Period == NULL) { // if (l2Method == X_PERIOD_AUTO) { mL2Period = GetMediestTimeFrame(_Period); } else { mL2Period = l2Period; } // mL2PeriodSecconds = PeriodSeconds(mL2Period); // mL2Candles = mL2PeriodSecconds / currentPeriodSecconds; } // // Farest ... // Calculate Cycle 3 Requirements ... if (mL3Period == NULL) { // if (l3Method == X_PERIOD_AUTO) { mL3Period = GetFarestTimeFrame(_Period); } else { mL3Period = l3Period; } // mL3PeriodSecconds = PeriodSeconds(mL3Period); // mL3Candles = mL3PeriodSecconds / currentPeriodSecconds; } // // HindMost ... // Calculate Cycle 4 Requirements ... if (mL4Period == NULL) { // if (l4Method == X_PERIOD_AUTO) { mL4Period = GetHindmostTimeFrame(_Period); } else { mL4Period = l4Period; } // mL4PeriodSecconds = PeriodSeconds(mL4Period); // mL4Candles = mL4PeriodSecconds / currentPeriodSecconds; } // string comment = GenerateCyclesRepresentation(); Comment(comment); } // // Define Indexes and Styles ... void DefineBuffers() { // // RANGE ... // // PEAKS and VALES ... ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; // // PEAKS ... ArraySetAsSeries(peaksBuffer, true); SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA); PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225); PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); // PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType); // // VALES ... ArraySetAsSeries(valesBuffer, true); SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA); PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225); PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); // PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType); // // SUPPORT and RESISTANCE ... // // // RESISTANCE ... ArraySetAsSeries(rBuffer, true); SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA); PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false); PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength); // // RESISTANCE Color ... ArraySetAsSeries(rColorBuffer, true); SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX); // // SUPPORT ... ArraySetAsSeries(sBuffer, true); SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); PlotIndexSetInteger(sBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false); // // SUPPORT Color ... ArraySetAsSeries(sColorBuffer, true); SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); // // FIBBO Levels ... // // LEVEL 1 ... // // Buffer ... ArraySetAsSeries(fl1Buffer, true); SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA); PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_SHOW_DATA, showFibo1Levels); // // Color ... ArraySetAsSeries(fl1ColorBuffer, true); SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX); // // LEVEL 2 ... // // BULLISH ... ArraySetAsSeries(fl2Buffer, true); SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA); PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_SHOW_DATA, showFibo2Levels); // // BULLISH Color ... ArraySetAsSeries(fl2ColorBuffer, true); SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX); // // LEVEL 3 ... // // BULLISH ... ArraySetAsSeries(fl3Buffer, true); SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA); PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_SHOW_DATA, showFibo3Levels); // // BULLISH Color ... ArraySetAsSeries(fl3ColorBuffer, true); SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX); // // SHORT Buffers ... // // HIGH ... ArraySetAsSeries(sHHBuffer, true); SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(sHHColorBuffer, true); SetIndexBuffer(sHHColorBufferIndex, sHHColorBuffer, INDICATOR_COLOR_INDEX); // // LOW ... ArraySetAsSeries(sLLBuffer, true); SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(sLLColorBuffer, true); SetIndexBuffer(sLLColorBufferIndex, sLLColorBuffer, INDICATOR_COLOR_INDEX); // // MEDIUM Buffer ... // // HIGH ... ArraySetAsSeries(mHHBuffer, true); SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(mHHColorBuffer, true); SetIndexBuffer(mHHColorBufferIndex, mHHColorBuffer, INDICATOR_COLOR_INDEX); // // LOW ... ArraySetAsSeries(mLLBuffer, true); SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(mLLColorBuffer, true); SetIndexBuffer(mLLColorBufferIndex, mLLColorBuffer, INDICATOR_COLOR_INDEX); // // LONG Buffer ... // // HIGH ... ArraySetAsSeries(lHHBuffer, true); SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(lHHColorBuffer, true); SetIndexBuffer(lHHColorBufferIndex, lHHColorBuffer, INDICATOR_COLOR_INDEX); // // LOW ... ArraySetAsSeries(lLLBuffer, true); SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(lLLColorBuffer, true); SetIndexBuffer(lLLColorBufferIndex, lLLColorBuffer, INDICATOR_COLOR_INDEX); // // HIND Buffer ... // // HIGH ... ArraySetAsSeries(hHHBuffer, true); SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA); // PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(hHHColorBuffer, true); SetIndexBuffer(hHHColorBufferIndex, hHHColorBuffer, INDICATOR_COLOR_INDEX); // // LOW ... ArraySetAsSeries(hLLBuffer, true); SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA); // PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); // ArraySetAsSeries(hLLColorBuffer, true); SetIndexBuffer(hLLColorBufferIndex, hLLColorBuffer, INDICATOR_COLOR_INDEX); } // // Set Indicator Short Name and also we can define Buffers Labels ... void SetIndicatorName() { IndicatorSetString(INDICATOR_SHORTNAME, ShortName); } // // Calculate Buffers ... void CalculateBuffers( int bar_index // Selected Bar Index ) { // // Calculate ... // // Calculate Short Cycle ... CalculateShortCycle(bar_index); // // Calculate Medium Cycle ... CalculateMediumCycle(bar_index); // // Calculate Long Cycle ... CalculateLongCycle(bar_index); // // Calculate Hind Cycle ... CalculateHindCycle(bar_index); // // Calculate Peaks and Vales ... CalculatePeaksAndVales(bar_index); // // Calculate Fibonnaci ... CalculateFibonacci(bar_index); } string GenerateCyclesRepresentation() { // string result = ""; // result += "C1: " + ToString(mL1Period) + "\n"; result += "C2: " + ToString(mL2Period) + "\n"; result += "C3: " + ToString(mL3Period) + "\n"; result += "C4: " + ToString(mL4Period); // return result; } // // START Calculation Parts ... // // // Retrieve Cycles Highest High ... double GetCycleHH( int bar_index, // Bar Index ENUM_TIMEFRAMES period // Period ) { // datetime mCycleStartAt = GetPeriodStartTime( _Symbol, period); // int mStartCycleBarIndex = iBarShift( _Symbol, _Period, mCycleStartAt, false); // int mCycleCount = MathAbs(mStartCycleBarIndex - bar_index); if (mCycleCount < 1) { mCycleCount = 1; } // // HIGH ... int hhIndex = iHighest( _Symbol, _Period, hhMode, mCycleCount, bar_index); double result = GetAppliedPrice( hhIndex, hhMode); // return result; } // // Retrieve Cycles Lowest Low ... double GetCycleLL( int bar_index, // Bar Index ENUM_TIMEFRAMES period // Period ) { // datetime mCycleStartAt = GetPeriodStartTime( _Symbol, period); // int mStartCycleBarIndex = iBarShift( _Symbol, _Period, mCycleStartAt, false); // int mCycleCount = MathAbs(mStartCycleBarIndex - bar_index); if (mCycleCount < 1) { mCycleCount = 1; } // // LOW ... int llIndex = iLowest( _Symbol, _Period, llMode, mCycleCount, bar_index); double result = GetAppliedPrice( llIndex, llMode); // return result; } // // Retrieve Cycles Highest High ... double GetCycleHHC( int bar_index, // Bar Index ENUM_TIMEFRAMES period // Period ) { // int mCycleCount = 0; if (period == mL1Period) { mCycleCount = mL1Candles; } else if (period == mL2Period) { mCycleCount = mL2Candles; } else if (period == mL3Period) { mCycleCount = mL3Candles; } else if (period == mL4Period) { mCycleCount = mL4Candles; } // // HIGH ... int hhIndex = iHighest( _Symbol, _Period, hhMode, mCycleCount, bar_index); double result = GetAppliedPrice( hhIndex, hhMode); // return result; } // // Retrieve Cycles Lowest Low ... double GetCycleLLC( int bar_index, // Bar Index ENUM_TIMEFRAMES period // Period ) { // int mCycleCount = 0; if (period == mL1Period) { mCycleCount = mL1Candles; } else if (period == mL2Period) { mCycleCount = mL2Candles; } else if (period == mL3Period) { mCycleCount = mL3Candles; } else if (period == mL4Period) { mCycleCount = mL4Candles; } // // LOW ... int llIndex = iLowest( _Symbol, _Period, llMode, mCycleCount, bar_index); double result = GetAppliedPrice( llIndex, llMode); // return result; } // // SHORT Cycle ... void CalculateShortCycle( int bar_index // Selected Bar Index ) { // ENUM_TIMEFRAMES mPeriod = mL1Period; // double hhValue = GetCycleHHC( bar_index, mPeriod); // double llValue = GetCycleLLC( bar_index, mPeriod); // double lastHH = mLastSHH; double lastLL = mLastSLL; // double mhhColorIDX = mHideColorIDX; if (showLevels) { // if (hhValue == lastHH) { mhhColorIDX = 1; } else if (hhValue > lastHH) { mhhColorIDX = 2; } else if (hhValue < lastHH) { mhhColorIDX = 3; } } else { mhhColorIDX = mHideColorIDX; } // double mllColorIDX = mHideColorIDX; if (showLevels) { // if (llValue == lastLL) { mllColorIDX = 1; } else if (llValue > lastLL) { mllColorIDX = 2; } else if (llValue < lastLL) { mllColorIDX = 3; } } else { mllColorIDX = mHideColorIDX; } // mLastSHH = hhValue; mLastSLL = llValue; // sHHBuffer[bar_index] = hhValue; sLLBuffer[bar_index] = llValue; sHHColorBuffer[bar_index] = mhhColorIDX; sLLColorBuffer[bar_index] = mllColorIDX; } // // MEDIUM Cycle ... void CalculateMediumCycle( int bar_index // Selected Bar Index ) { // ENUM_TIMEFRAMES mPeriod = mL2Period; // double hhValue = GetCycleHHC( bar_index, mPeriod); // double llValue = GetCycleLLC( bar_index, mPeriod); // double lastHH = mLastMHH; double lastLL = mLastMLL; // double mhhColorIDX = mHideColorIDX; if (showLevels) { // if (hhValue == lastHH) { mhhColorIDX = 1; } else if (hhValue > lastHH) { mhhColorIDX = 2; } else if (hhValue < lastHH) { mhhColorIDX = 3; } } else { mhhColorIDX = mHideColorIDX; } // double mllColorIDX = mHideColorIDX; if (showLevels) { // if (llValue == lastLL) { mllColorIDX = 1; } else if (llValue > lastLL) { mllColorIDX = 2; } else if (llValue < lastLL) { mllColorIDX = 3; } } else { mllColorIDX = mHideColorIDX; } // mLastMHH = hhValue; mLastMLL = llValue; // mHHBuffer[bar_index] = hhValue; mLLBuffer[bar_index] = llValue; mHHColorBuffer[bar_index] = mhhColorIDX; mLLColorBuffer[bar_index] = mllColorIDX; } // // LONG Cycle ... void CalculateLongCycle( int bar_index // Selected Bar Index ) { // ENUM_TIMEFRAMES mPeriod = mL3Period; // double hhValue = GetCycleHHC( bar_index, mPeriod); // double llValue = GetCycleLLC( bar_index, mPeriod); // double lastHH = mLastLHH; double lastLL = mLastLLL; // double mhhColorIDX = mHideColorIDX; if (showLevels) { // if (hhValue == lastHH) { mhhColorIDX = 1; } else if (hhValue > lastHH) { mhhColorIDX = 2; } else if (hhValue < lastHH) { mhhColorIDX = 3; } } else { mhhColorIDX = mHideColorIDX; } // double mllColorIDX = mHideColorIDX; if (showLevels) { // if (llValue == lastLL) { mllColorIDX = 1; } else if (llValue > lastLL) { mllColorIDX = 2; } else if (llValue < lastLL) { mllColorIDX = 3; } } else { mllColorIDX = mHideColorIDX; } // mLastLHH = hhValue; mLastLLL = llValue; // lHHBuffer[bar_index] = hhValue; lLLBuffer[bar_index] = llValue; lHHColorBuffer[bar_index] = mhhColorIDX; lLLColorBuffer[bar_index] = mllColorIDX; } // // HIND Cycle ... void CalculateHindCycle( int bar_index // Selected Bar Index ) { // ENUM_TIMEFRAMES mPeriod = mL4Period; // double hhValue = GetCycleHHC( bar_index, mPeriod); // double llValue = GetCycleLLC( bar_index, mPeriod); // double lastHH = mLastHHH; double lastLL = mLastHLL; // double mhhColorIDX = mHideColorIDX; if (showLevels) { // if (hhValue == lastHH) { mhhColorIDX = 1; } else if (hhValue > lastHH) { mhhColorIDX = 2; } else if (hhValue < lastHH) { mhhColorIDX = 3; } } else { mhhColorIDX = mHideColorIDX; } // double mllColorIDX = mHideColorIDX; if (showLevels) { // if (llValue == lastLL) { mllColorIDX = 1; } else if (llValue > lastLL) { mllColorIDX = 2; } else if (llValue < lastLL) { mllColorIDX = 3; } } else { mllColorIDX = mHideColorIDX; } // mLastHHH = hhValue; mLastHLL = llValue; // hHHBuffer[bar_index] = hhValue; hLLBuffer[bar_index] = llValue; hHHColorBuffer[bar_index] = mhhColorIDX; hLLColorBuffer[bar_index] = mllColorIDX; } // // Calculate Peaks and Values ... void CalculatePeaksAndVales( int bar_index // Bar Index ) { // // Retrieve Requirements ... // // Short ... double sHHValue = sHHBuffer[bar_index]; double sLLValue = sLLBuffer[bar_index]; // // Medium ... double mHHValue = mHHBuffer[bar_index]; double mLLValue = mLLBuffer[bar_index]; // // Long ... double lHHValue = lHHBuffer[bar_index]; double lLLValue = lLLBuffer[bar_index]; // // Hind ... double hHHValue = hHHBuffer[bar_index]; double hLLValue = hLLBuffer[bar_index]; // double rColorIDX = mHideColorIDX; double sColorIDX = mHideColorIDX; // // RESISTANCE ... double rValue = (sHHValue + mHHValue + lHHValue + hHHValue) / 4; // // PEAKS ... bool isPeak = rValue == hHHValue && hHHValue == lHHValue && lHHValue == mHHValue && mHHValue == sHHValue; // if (isPeak && lastPeak != rValue) { // rColorIDX = 1; lastPeak = rValue; } // // SUPPORT ... double sValue = (sLLValue + mLLValue + lLLValue + hLLValue) / 4; // // VALES ... bool isVale = sValue == hLLValue && hLLValue == lLLValue && lLLValue == mLLValue && mLLValue == sLLValue; // if (isVale && lastVale != sValue) { // sColorIDX = 1; lastVale = sValue; } // rBuffer[bar_index] = rValue; sBuffer[bar_index] = sValue; peaksBuffer[bar_index] = lastPeak; valesBuffer[bar_index] = lastVale; // if (showPeaksAndVales) { // rColorBuffer[bar_index] = rColorIDX; sColorBuffer[bar_index] = sColorIDX; } else { // rColorBuffer[bar_index] = mHideColorIDX; sColorBuffer[bar_index] = mHideColorIDX; } } // // Calculate Fibonacci Level 1 ... void CalculateFibonacci( int bar_index // Bar Index ) { // // Select Requirements ... double upPrice = peaksBuffer[bar_index]; double downPrice = valesBuffer[bar_index]; // // Level 1 ... double fibLevel1Value = GetFibonacciLevel( upPrice, downPrice, fiboLevel1, 1); // // Level 2 ... double fibLevel2Value = GetFibonacciLevel( upPrice, downPrice, fiboLevel2, 1); // // Level 3 ... double fibLevel3Value = GetFibonacciLevel( upPrice, downPrice, fiboLevel3, 1); // fl1Buffer[bar_index] = fibLevel1Value; fl2Buffer[bar_index] = fibLevel2Value; fl3Buffer[bar_index] = fibLevel3Value; // double fl1ColorIdx = showFibo1Levels ? 1 : mHideColorIDX; double fl2ColorIdx = showFibo2Levels ? 1 : mHideColorIDX; double fl3ColorIdx = showFibo3Levels ? 1 : mHideColorIDX; // fl1ColorBuffer[bar_index] = fl1ColorIdx; fl2ColorBuffer[bar_index] = fl2ColorIdx; fl3ColorBuffer[bar_index] = fl3ColorIdx; } // // END Calculation Parts ... // // // END Functions ... //