/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 X121 Indicator // --------------------------------------------- // Name: X121 // Description: Market Analyser // Market Analysor ... // // // 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 // // START Constants ... // // // Indicator Short Name ... #define ShortName "X121" // // Ichimoku Golden Numbers ... enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS { X_ICH_BASE = 9, X_ICH_GOLDEN = 17, X_ICH_CYCLE = 26, X_ICH_PERIOD = 35, X_ICH_STAR = 45, X_ICH_MED = 52, X_ICH_LONG = 63, X_ICH_FULL = 72 }; // // Ichimoku Lines Calculator Mode ... enum ENUM_X_ICHIMOKU_CALCULATION_MODE { // X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close }; // // 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 ... // // // PEAKSANDVALES ... // input group "Peaks and Vales"; // input group "Makret Cycles"; input int shortLength = 9; // Short Length input int mediumLength = 17; // Medium Length input int longLength = 26; // Long Length // input group "Detection Modes"; input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method // // SUPPORTSANDRESISTANCE ... // input group "Support and Resistance"; // input group "Level 1"; input ENUM_X_PERIOD_METHOD level1Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES level1Period = NULL; // Time Period // input group "Level 2"; input ENUM_X_PERIOD_METHOD level2Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES level2Period = NULL; // Time Period // input group "Level 3"; input ENUM_X_PERIOD_METHOD level3Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES level3Period = NULL; // Time Period // input group "Level 4"; input ENUM_X_PERIOD_METHOD level4Method = X_PERIOD_AUTO; // How to Find Period input ENUM_TIMEFRAMES level4Period = NULL; // Time Period // // MA Crosses ... input group "Moving Averages"; // input group "Fast"; input int fastMaLength = 9; // Length input int fastMaShift = 0; // Shift input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Method input ENUM_APPLIED_PRICE fastMaAppliedTo = PRICE_CLOSE; // Applied To // input group "Slow"; input int slowMaLength = 18; // Length input int slowMaShift = 0; // Shift input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Method input ENUM_APPLIED_PRICE slowMaAppliedTo = PRICE_CLOSE; // Applied To // // ICHIMOKU Kinko Hyo ... // input group "Ichimoku Kinko Hyo"; // // TENKANSEN ... input group "Tenkan Sen"; input int tenkanSenLength = 9; // Length input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode // // KIJUNSEN ... input group "Kijun Sen"; input int kijunSenLength = 26; // Length input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode // // SENKOUSPANB ... input group "Senkou Span B"; input int senkouSpanBLength = 52; // Length input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode // // CHIKOUSPAN ... input group "Chikou Span"; input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type // input group "Presentation"; // input group "Peaks and Vales"; input bool showPeaksAndVales = true; // Show Peaks and Vales // input group "Support and Resistance"; input bool showSRLevel1 = true; // Show Level 1 input bool showSRLevel2 = true; // Show Level 2 input bool showSRLevel3 = true; // Show Level 3 input bool showSRLevel4 = true; // Show Level 4 // input group "Moving Averages"; input bool showFastMa = true; // Show Fast input bool showSlowMa = true; // Show Slow // input group "Ichimoku Kinko Hyo"; input bool showTenkanSen = true; // Show Tenkan Sen input bool showKijunSen = true; // Show Kijun Sen input bool showChikouSpan = true; // Show Chikou Span input bool showKumo = true; // Show Kumo // // END Inputs ... // // // START Includes and Imports ... // // // Includes Logging Library ... #include "../Libraries/x-saherelm.log.lib.mq5" // // Includes Draw Library ... #include "../Libraries/x-saherelm.draw.lib.mq5" // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" // // END Includes and Imports ... // // // START Buffers ... // #property indicator_chart_window // #property indicator_buffers 27 #property indicator_plots 18 // // PLOTTED Buffers ... // double rUpBuffer[]; double rUpColorBuffer[]; // #property indicator_label1 "X121 R UP" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrAqua, CLR_NONE #property indicator_style1 STYLE_DOT #property indicator_width1 1 // double rDownBuffer[]; double rDownColorBuffer[]; // #property indicator_label2 "X121 R Down" #property indicator_type2 DRAW_COLOR_LINE #property indicator_color2 clrMagenta, CLR_NONE #property indicator_style2 STYLE_DOT #property indicator_width2 1 // // PEKSANDVALES ... // // PEAKS ... // double peaksBuffer[]; // #property indicator_label3 "X121 PEAKS" #property indicator_type3 DRAW_ARROW #property indicator_color3 clrAqua #property indicator_width3 3 // // VALES ... // double valesBuffer[]; // #property indicator_label4 "X121 VALES" #property indicator_type4 DRAW_ARROW #property indicator_color4 clrMagenta #property indicator_width4 3 // // MA ... // // FAST ... double fastMaBuffer[]; // #property indicator_label5 "X121 MA F" #property indicator_type5 DRAW_LINE #property indicator_color5 clrYellow #property indicator_style5 STYLE_SOLID #property indicator_width5 1 // // SLOW ... double slowMaBuffer[]; // #property indicator_label6 "X121 MA S" #property indicator_type6 DRAW_LINE #property indicator_color6 clrDarkOrange #property indicator_style6 STYLE_SOLID #property indicator_width6 1 // // SUPPORTANDRESISTANCE ... // // LEVEL 1 ... // // UP ... double srLevel1UpBuffer[]; // #property indicator_label7 "X121 L1 Up" #property indicator_type7 DRAW_LINE #property indicator_color7 clrLightGray #property indicator_style7 STYLE_DOT #property indicator_width7 1 // // DOWN ... double srLevel1DownBuffer[]; // #property indicator_label8 "X121 L1 Down" #property indicator_type8 DRAW_LINE #property indicator_color8 clrLightGray #property indicator_style8 STYLE_DOT #property indicator_width8 1 // // LEVEL 2 ... // // UP ... double srLevel2UpBuffer[]; // #property indicator_label9 "X121 L2 Up" #property indicator_type9 DRAW_LINE #property indicator_color9 clrLightGray #property indicator_style9 STYLE_DOT #property indicator_width9 1 // // DOWN ... double srLevel2DownBuffer[]; // #property indicator_label10 "X121 L2 Down" #property indicator_type10 DRAW_LINE #property indicator_color10 clrLightGray #property indicator_style10 STYLE_DOT #property indicator_width10 1 // // LEVEL 3 ... // // UP ... double srLevel3UpBuffer[]; // #property indicator_label11 "X121 L3 Up" #property indicator_type11 DRAW_LINE #property indicator_color11 clrLightGray #property indicator_style11 STYLE_DOT #property indicator_width11 1 // // DOWN ... double srLevel3DownBuffer[]; // #property indicator_label12 "X121 L3 Down" #property indicator_type12 DRAW_LINE #property indicator_color12 clrLightGray #property indicator_style12 STYLE_DOT #property indicator_width12 1 // // LEVEL 4 ... // // UP ... double srLevel4UpBuffer[]; // #property indicator_label13 "X121 L4 Up" #property indicator_type13 DRAW_LINE #property indicator_color13 clrLightGray #property indicator_style13 STYLE_DOT #property indicator_width13 1 // // DOWN ... double srLevel4DownBuffer[]; // #property indicator_label14 "X121 L4 Down" #property indicator_type14 DRAW_LINE #property indicator_color14 clrLightGray #property indicator_style14 STYLE_DOT #property indicator_width14 1 // // ICHIMOKU ... // // TENKANSEN ... // double tenkanSenBuffer[]; // #property indicator_label15 "X121 Tenkan Sen" #property indicator_type15 DRAW_LINE #property indicator_color15 clrBrown #property indicator_style15 STYLE_SOLID #property indicator_width15 1 // // KIJUNSEN ... // double kijunSenBuffer[]; // #property indicator_label16 "X121 Kijun Sen" #property indicator_type16 DRAW_LINE #property indicator_color16 clrDodgerBlue #property indicator_style16 STYLE_SOLID #property indicator_width16 1 // // CHIKOUSPAN ... // double chikouSpanBuffer[]; // #property indicator_label17 "X121 Chikou Span" #property indicator_type17 DRAW_LINE #property indicator_color17 clrDarkGreen #property indicator_style17 STYLE_SOLID #property indicator_width17 1 // // SENKOUSPANA ... double senkouSpanABuffer[]; // // SENKOUSPANB ... double senkouSpanBBuffer[]; // // KUMOCLOUD ... #property indicator_label18 "X121 Kumo" #property indicator_type18 DRAW_FILLING #property indicator_color18 clrAqua, clrMagenta #property indicator_style18 STYLE_SOLID #property indicator_width18 1 // // DATA Buffers ... // double sHHBuffer[]; double sLLBuffer[]; // double mHHBuffer[]; double mLLBuffer[]; // double lHHBuffer[]; double lLLBuffer[]; // // END Buffers ... // // // START Global Definitions: Variables, Properties and etc ... // // int maxLength; // double lastPeak; double lastVale; // ENUM_SERIESMODE mTenkanSenTopMode = NULL; ENUM_SERIESMODE mTenkanSenBottomMode = NULL; // ENUM_SERIESMODE mKijunSenTopMode = NULL; ENUM_SERIESMODE mKijunSenBottomMode = NULL; // ENUM_SERIESMODE mSenkouSpanBTopMode = NULL; ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL; // int currentPeriodSecconds = 0; // int mLevel1Candles; double mSRLastL1Up; double mSRLastL1Down; int mLastLevel1StartBarIndex = 0; datetime mLevel1StartTime = NULL; ENUM_TIMEFRAMES mLevel1Period = NULL; // int mLevel2Candles; double mSRLastL2Up; double mSRLastL2Down; int mLastLevel2StartBarIndex = 0; datetime mLevel2StartTime = NULL; ENUM_TIMEFRAMES mLevel2Period = NULL; // int mLevel3Candles; double mSRLastL3Up; double mSRLastL3Down; int mLastLevel3StartBarIndex = 0; datetime mLevel3StartTime = NULL; ENUM_TIMEFRAMES mLevel3Period = NULL; // int mLevel4Candles; double mSRLastL4Up; double mSRLastL4Down; int mLastLevel4StartBarIndex = 0; datetime mLevel4StartTime = NULL; ENUM_TIMEFRAMES mLevel4Period = NULL; // int fastMaHandler = INVALID_HANDLE; int slowMaHandler = INVALID_HANDLE; // // END Global Definitions: Variables, Properties and etc ... // // // START Event Handlers ... // // // Initialization ... int OnInit() { // // Validate Inputs ... if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // logTag = ShortName; drawPrefix = ShortName; // // 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(); // // MA Initialization ... // // FAST ... fastMaHandler = iMA( _Symbol, _Period, fastMaLength, fastMaShift, fastMaMethod, fastMaAppliedTo); if (fastMaHandler == INVALID_HANDLE) { // string msg = "Error in Initilizing Indicator ..."; LogMessage(msg); // return INIT_FAILED; } // // SLOW ... slowMaHandler = iMA( _Symbol, _Period, slowMaLength, slowMaShift, slowMaMethod, slowMaAppliedTo); if (slowMaHandler == INVALID_HANDLE) { // string msg = "Error in Initilizing Indicator ..."; LogMessage(msg); // return INIT_FAILED; } // if (currentPeriodSecconds == 0) { currentPeriodSecconds = PeriodSeconds(_Period); } // // Finde Level 1 Period ... if (mLevel1Period == NULL) { // if (level1Method == X_PERIOD_AUTO) { mLevel1Period = GetNearestTimeFrame(_Period); } else { mLevel1Period = level1Period; } // int level1PeriodSecconds = PeriodSeconds(mLevel1Period); // mLevel1Candles = level1PeriodSecconds / currentPeriodSecconds; } // // Finde Level 2 Period ... if (mLevel2Period == NULL) { // if (level2Method == X_PERIOD_AUTO) { mLevel2Period = GetMediestTimeFrame(_Period); } else { mLevel2Period = level2Period; } // int level2PeriodSecconds = PeriodSeconds(mLevel2Period); // mLevel2Candles = level2PeriodSecconds / currentPeriodSecconds; } // // Finde Level 3 Period ... if (mLevel3Period == NULL) { // if (level3Method == X_PERIOD_AUTO) { mLevel3Period = GetFarestTimeFrame(_Period); } else { mLevel3Period = level3Period; } // int level3PeriodSecconds = PeriodSeconds(mLevel3Period); // mLevel3Candles = level3PeriodSecconds / currentPeriodSecconds; } // // Finde Level 4 Period ... if (mLevel4Period == NULL) { // if (level4Method == X_PERIOD_AUTO) { mLevel4Period = GetHindmostTimeFrame(_Period); } else { mLevel4Period = level4Period; } // int level4PeriodSecconds = PeriodSeconds(mLevel4Period); // mLevel4Candles = level4PeriodSecconds / currentPeriodSecconds; } // string comment = GenerateComment(); Comment(comment); // // 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 // // Here we can handle De Initialization Reasons ... IndicatorRelease(fastMaHandler); IndicatorRelease(slowMaHandler); // // Clear Comments ... Comment(""); // // Remove All Drawing Objects ... RemoveDraws(drawPrefix); } // // Calculations ... // // 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; // // Check Calculated Bars ... int fastMaCalculatedBars = BarsCalculated(fastMaHandler); int slowMaCalculatedBars = BarsCalculated(slowMaHandler); if (fastMaCalculatedBars < maxLength || slowMaCalculatedBars < maxLength) { return prev_calculated; } // limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; // // Buffers Copy ... int copiedFastMas = CopyBuffer(fastMaHandler, 0, 0, limit, fastMaBuffer); int copiedSlowMas = CopyBuffer(slowMaHandler, 0, 0, limit, slowMaBuffer); if (copiedFastMas <= 0 || copiedSlowMas <= 0) { return prev_calculated; } // // 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 = // // Validate Peaks and Vales ... (shortLength > 2 && mediumLength > shortLength && longLength > mediumLength) // && // // Validate Supports and Resistance ... ( // // Level 1 ... (level1Method == X_PERIOD_AUTO || (level1Method == X_PERIOD_MANUALLY && level1Period != NULL)) // && // // Level 2 ... (level2Method == X_PERIOD_AUTO || (level2Method == X_PERIOD_MANUALLY && level2Period != NULL)) // && // // Level 3 ... (level3Method == X_PERIOD_AUTO || (level3Method == X_PERIOD_MANUALLY && level3Period != NULL)) // && // // Level 4 ... (level4Method == X_PERIOD_AUTO || (level4Method == X_PERIOD_MANUALLY && level4Period != NULL)) // ) // && // // Validate Ma ... (fastMaLength > 2 && slowMaLength > fastMaLength) // && // // Validate Ichimoku Kinko Hyo ... (tenkanSenLength > 2 && kijunSenLength > tenkanSenLength && senkouSpanBLength > kijunSenLength) // ; // return result; } // // Retrieve all Exists Input Max Length ... // use for Start Of Drawing ... int ExtractMaxLengthOfInputs() { // int result = 0; // // Peaks and Vales ... result = MathMax(shortLength, mediumLength); result = MathMax(result, longLength); // // Ma ... result = MathMax(result, fastMaLength); result = MathMax(result, slowMaLength); // // Ichimoku ... result = MathMax(result, tenkanSenLength); result = MathMax(result, kijunSenLength); result = MathMax(result, senkouSpanBLength); // return result; } // // Define Indexes and Styles ... void DefineBuffers() { // // RANGE ... // // UP Buffer ... ArraySetAsSeries(rUpBuffer, true); SetIndexBuffer(0, rUpBuffer, INDICATOR_DATA); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(0, PLOT_SHOW_DATA, false); // // UP Color Buffer ... ArraySetAsSeries(rUpColorBuffer, true); SetIndexBuffer(1, rUpColorBuffer, INDICATOR_COLOR_INDEX); // // DOWN Buffer ... ArraySetAsSeries(rDownBuffer, true); SetIndexBuffer(2, rDownBuffer, INDICATOR_DATA); PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(1, PLOT_SHOW_DATA, false); // // DOWN Color Buffer ... ArraySetAsSeries(rDownColorBuffer, true); SetIndexBuffer(3, rDownColorBuffer, INDICATOR_COLOR_INDEX); // // PEAKS and VALES ... ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; // // PEAKS ... ArraySetAsSeries(peaksBuffer, true); SetIndexBuffer(4, peaksBuffer, INDICATOR_DATA); PlotIndexSetInteger(4, PLOT_ARROW, 225); PlotIndexSetInteger(4, PLOT_ARROW_SHIFT, 20); PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, 0); PlotIndexSetInteger(2, PLOT_SHOW_DATA, false); PlotIndexSetInteger(2, PLOT_DRAW_TYPE, pvDrawType); // // VALES ... ArraySetAsSeries(valesBuffer, true); SetIndexBuffer(5, valesBuffer, INDICATOR_DATA); PlotIndexSetInteger(5, PLOT_ARROW, 225); PlotIndexSetInteger(5, PLOT_ARROW_SHIFT, 20); PlotIndexSetDouble(5, PLOT_EMPTY_VALUE, 0); PlotIndexSetInteger(3, PLOT_SHOW_DATA, false); PlotIndexSetInteger(3, PLOT_DRAW_TYPE, pvDrawType); // // MA ... // // FAST ... ENUM_DRAW_TYPE fastMaDrawType = showFastMa ? DRAW_LINE : DRAW_NONE; ArraySetAsSeries(fastMaBuffer, true); SetIndexBuffer(6, fastMaBuffer, INDICATOR_DATA); PlotIndexSetInteger(6, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(4, PLOT_SHOW_DATA, false); PlotIndexSetInteger(4, PLOT_DRAW_TYPE, fastMaDrawType); // // SLOW ... ENUM_DRAW_TYPE slowMaDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE; ArraySetAsSeries(slowMaBuffer, true); SetIndexBuffer(7, slowMaBuffer, INDICATOR_DATA); PlotIndexSetInteger(7, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(5, PLOT_SHOW_DATA, false); PlotIndexSetInteger(5, PLOT_DRAW_TYPE, slowMaDrawType); // // SUPPORTANDRESISTANCE ... // // LEVEL 1 ... ENUM_DRAW_TYPE srL1DrawType = showSRLevel1 ? DRAW_LINE : DRAW_NONE; // // UP ... ArraySetAsSeries(srLevel1UpBuffer, true); SetIndexBuffer(8, srLevel1UpBuffer, INDICATOR_DATA); PlotIndexSetInteger(8, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(6, PLOT_SHOW_DATA, false); PlotIndexSetInteger(6, PLOT_DRAW_TYPE, srL1DrawType); // // DOWN ... ArraySetAsSeries(srLevel1DownBuffer, true); SetIndexBuffer(9, srLevel1DownBuffer, INDICATOR_DATA); PlotIndexSetInteger(9, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(7, PLOT_SHOW_DATA, false); PlotIndexSetInteger(7, PLOT_DRAW_TYPE, srL1DrawType); // // LEVEL 2 ... ENUM_DRAW_TYPE srL2DrawType = showSRLevel2 ? DRAW_LINE : DRAW_NONE; // // UP ... ArraySetAsSeries(srLevel2UpBuffer, true); SetIndexBuffer(10, srLevel2UpBuffer, INDICATOR_DATA); PlotIndexSetInteger(10, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(8, PLOT_SHOW_DATA, false); PlotIndexSetInteger(8, PLOT_DRAW_TYPE, srL2DrawType); // // DOWN ... ArraySetAsSeries(srLevel2DownBuffer, true); SetIndexBuffer(11, srLevel2DownBuffer, INDICATOR_DATA); PlotIndexSetInteger(11, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(9, PLOT_SHOW_DATA, false); PlotIndexSetInteger(9, PLOT_DRAW_TYPE, srL2DrawType); // // LEVEL 3 ... ENUM_DRAW_TYPE srL3DrawType = showSRLevel3 ? DRAW_LINE : DRAW_NONE; // // UP ... ArraySetAsSeries(srLevel3UpBuffer, true); SetIndexBuffer(12, srLevel3UpBuffer, INDICATOR_DATA); PlotIndexSetInteger(12, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetDouble(12, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(10, PLOT_SHOW_DATA, false); PlotIndexSetInteger(10, PLOT_DRAW_TYPE, srL3DrawType); // // DOWN ... ArraySetAsSeries(srLevel3DownBuffer, true); SetIndexBuffer(13, srLevel3DownBuffer, INDICATOR_DATA); PlotIndexSetInteger(13, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetDouble(13, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(11, PLOT_SHOW_DATA, false); PlotIndexSetInteger(11, PLOT_DRAW_TYPE, srL3DrawType); // // LEVEL 4 ... ENUM_DRAW_TYPE srL4DrawType = showSRLevel4 ? DRAW_LINE : DRAW_NONE; // // UP ... ArraySetAsSeries(srLevel4UpBuffer, true); SetIndexBuffer(14, srLevel4UpBuffer, INDICATOR_DATA); PlotIndexSetInteger(14, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetDouble(14, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(12, PLOT_SHOW_DATA, false); PlotIndexSetInteger(12, PLOT_DRAW_TYPE, srL4DrawType); // // DOWN ... ArraySetAsSeries(srLevel4DownBuffer, true); SetIndexBuffer(15, srLevel4DownBuffer, INDICATOR_DATA); PlotIndexSetInteger(15, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetDouble(15, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(13, PLOT_SHOW_DATA, false); PlotIndexSetInteger(13, PLOT_DRAW_TYPE, srL4DrawType); // // ICHIMOKU ... // // TENKANSEN ... // ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(tenkanSenBuffer, true); SetIndexBuffer(16, tenkanSenBuffer, INDICATOR_DATA); PlotIndexSetInteger(16, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(14, PLOT_SHOW_DATA, false); PlotIndexSetInteger(14, PLOT_DRAW_TYPE, tenkanSenDrawType); // // KIJUNSEN ... // ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(kijunSenBuffer, true); SetIndexBuffer(17, kijunSenBuffer, INDICATOR_DATA); PlotIndexSetInteger(17, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(15, PLOT_SHOW_DATA, false); PlotIndexSetInteger(15, PLOT_DRAW_TYPE, kijunSenDrawType); // // CHIKOUSPAN ... // ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE; // ArraySetAsSeries(chikouSpanBuffer, true); SetIndexBuffer(18, chikouSpanBuffer, INDICATOR_DATA); PlotIndexSetInteger(18, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(16, PLOT_SHIFT, -kijunSenLength); PlotIndexSetInteger(16, PLOT_SHOW_DATA, false); PlotIndexSetInteger(16, PLOT_DRAW_TYPE, chikouSpanDrawType); // // SENKOUSPANA ... ArraySetAsSeries(senkouSpanABuffer, true); SetIndexBuffer(19, senkouSpanABuffer, INDICATOR_DATA); PlotIndexSetInteger(19, PLOT_DRAW_BEGIN, maxLength); // // SENKOUSPANB ... ArraySetAsSeries(senkouSpanBBuffer, true); SetIndexBuffer(20, senkouSpanBBuffer, INDICATOR_DATA); PlotIndexSetInteger(20, PLOT_DRAW_BEGIN, maxLength); // // KUMO ... // ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE; // PlotIndexSetInteger(17, PLOT_SHIFT, kijunSenLength); PlotIndexSetInteger(17, PLOT_DRAW_TYPE, kumoDrawType); // int i = 21; // ArraySetAsSeries(sHHBuffer, true); SetIndexBuffer(i, sHHBuffer, INDICATOR_CALCULATIONS); // i++; // ArraySetAsSeries(sLLBuffer, true); SetIndexBuffer(i, sLLBuffer, INDICATOR_CALCULATIONS); // i++; // ArraySetAsSeries(mHHBuffer, true); SetIndexBuffer(i, mHHBuffer, INDICATOR_CALCULATIONS); // i++; // ArraySetAsSeries(mLLBuffer, true); SetIndexBuffer(i, mLLBuffer, INDICATOR_CALCULATIONS); // i++; // ArraySetAsSeries(lHHBuffer, true); SetIndexBuffer(i, lHHBuffer, INDICATOR_CALCULATIONS); // i++; // ArraySetAsSeries(lLLBuffer, true); SetIndexBuffer(i, lLLBuffer, INDICATOR_CALCULATIONS); } // // Set Indicator Short Name and also we can define Buffers Labels ... void SetIndicatorName() { // string indicatorShortName = ""; StringConcatenate(indicatorShortName, ShortName, ""); // IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName); } // // Calculate Buffers ... void CalculateBuffers( int bar_index // Selected Bar Index ) { // // Calculate ... // double rUpColorIDX = 1; double rDownColorIDX = 1; // // PEAKS and VALES ... // // SHORT ... // // HH Buffer ... int sHHIndex = iHighest( _Symbol, _Period, hhMode, shortLength, bar_index); double sHHValue = GetAppliedPrice( sHHIndex, hhMode); // sHHBuffer[bar_index] = sHHValue; // // LL Buffer ... int sLLIndex = iLowest( _Symbol, _Period, llMode, shortLength, bar_index); double sLLValue = GetAppliedPrice( sLLIndex, llMode); // sLLBuffer[bar_index] = sLLValue; // // MEDIUM ... // // HH Buffer ... int mHHIndex = iHighest( _Symbol, _Period, hhMode, mediumLength, bar_index); double mHHValue = GetAppliedPrice( mHHIndex, hhMode); // mHHBuffer[bar_index] = mHHValue; // // LL Buffer ... int mLLIndex = iLowest( _Symbol, _Period, llMode, mediumLength, bar_index); double mLLValue = GetAppliedPrice( mLLIndex, llMode); // mLLBuffer[bar_index] = mLLValue; // // LONG ... // // HH Buffer ... int lHHIndex = iHighest( _Symbol, _Period, hhMode, longLength, bar_index); double lHHValue = GetAppliedPrice( lHHIndex, hhMode); // lHHBuffer[bar_index] = lHHValue; // // LL Buffer ... int lLLIndex = iLowest( _Symbol, _Period, llMode, longLength, bar_index); double lLLValue = GetAppliedPrice( lLLIndex, llMode); // lLLBuffer[bar_index] = lLLValue; // // RANGE ... // // UP ... double rUpValue = (sHHValue + mHHValue + lHHValue) / 3; rUpBuffer[bar_index] = rUpValue; // // DOWN ... double rDownValue = (sLLValue + mLLValue + lLLValue) / 3; rDownBuffer[bar_index] = rDownValue; // // Detecting Peaks and Vales ... // // PEAKS ... bool isPeak = rUpValue == lHHValue && lHHValue == mHHValue && mHHValue == sHHValue; // if (isPeak && lastPeak != rUpValue) { // if (showPeaksAndVales) { rUpColorIDX = 0; } // lastPeak = rUpValue; peaksBuffer[bar_index] = lastPeak; } else { peaksBuffer[bar_index] = 0; } // // VALES ... bool isVale = rDownValue == lLLValue && lLLValue == mLLValue && mLLValue == sLLValue; if (isVale && lastVale != rDownValue) { // if (showPeaksAndVales) { rDownColorIDX = 0; } // lastVale = rDownValue; valesBuffer[bar_index] = lastVale; } else { valesBuffer[bar_index] = 0; } // // Set Default Colors ... // rUpColorBuffer[bar_index] = rUpColorIDX; rDownColorBuffer[bar_index] = rDownColorIDX; // // SUPPORTANDRESISTANCE ... // datetime barTime = iTime( _Symbol, _Period, bar_index); // // LEVEL 1 ... // // Calculate Start Bar Index ... if (mLastLevel1StartBarIndex == 0) { // datetime level1StartTime = GetPeriodStartTime( _Symbol, mLevel1Period, barTime); // // Check Level 1 Start Time is New or Not ... if (mLevel1StartTime != level1StartTime) { mLevel1StartTime = level1StartTime; } // // Access Level 1 Start Bar Index on Current Chart ... mLastLevel1StartBarIndex = iBarShift( _Symbol, _Period, mLevel1StartTime); // // Calculate level1 Highest Open ... mSRLastL1Up = GetHighestHigh( _Symbol, _Period, MODE_HIGH, mLevel1Candles, mLastLevel1StartBarIndex); // srLevel1UpBuffer[bar_index] = mSRLastL1Up; // // Calculate level1 Lowest Close ... mSRLastL1Down = GetLowestLow( _Symbol, _Period, MODE_LOW, mLevel1Candles, mLastLevel1StartBarIndex); // srLevel1DownBuffer[bar_index] = mSRLastL1Down; } else { // int lDiff = mLastLevel1StartBarIndex - bar_index; if (lDiff == mLevel1Candles) { mLastLevel1StartBarIndex = 0; } // srLevel1UpBuffer[bar_index] = mSRLastL1Up; srLevel1DownBuffer[bar_index] = mSRLastL1Down; } // // LEVEL 2 ... // // Calculate Start Bar Index ... if (mLastLevel2StartBarIndex == 0) { // datetime level2StartTime = GetPeriodStartTime( _Symbol, mLevel2Period, barTime); // // Check Level 2 Start Time is New or Not ... if (mLevel2StartTime != level2StartTime) { mLevel2StartTime = level2StartTime; } // // Access Level 2 Start Bar Index on Current Chart ... mLastLevel2StartBarIndex = iBarShift( _Symbol, _Period, mLevel2StartTime); // // Calculate level2 Highest Open ... mSRLastL2Up = GetHighestHigh( _Symbol, _Period, MODE_HIGH, mLevel2Candles, mLastLevel2StartBarIndex); // srLevel2UpBuffer[bar_index] = mSRLastL2Up; // // Calculate level2 Lowest Close ... mSRLastL2Down = GetLowestLow( _Symbol, _Period, MODE_LOW, mLevel2Candles, mLastLevel2StartBarIndex); // srLevel2DownBuffer[bar_index] = mSRLastL2Down; } else { // int lDiff = mLastLevel2StartBarIndex - bar_index; if (lDiff == mLevel2Candles) { mLastLevel2StartBarIndex = 0; } // srLevel2UpBuffer[bar_index] = mSRLastL2Up; srLevel2DownBuffer[bar_index] = mSRLastL2Down; } // // LEVEL 3 ... // // Calculate Start Bar Index ... if (mLastLevel3StartBarIndex == 0) { // datetime level3StartTime = GetPeriodStartTime( _Symbol, mLevel3Period, barTime); // // Check Level 3 Start Time is New or Not ... if (mLevel3StartTime != level3StartTime) { mLevel3StartTime = level3StartTime; } // // Access Level 3 Start Bar Index on Current Chart ... mLastLevel3StartBarIndex = iBarShift( _Symbol, _Period, mLevel3StartTime); // // Calculate level3 Highest Open ... mSRLastL3Up = GetHighestHigh( _Symbol, _Period, MODE_HIGH, mLevel3Candles, mLastLevel3StartBarIndex); // srLevel3UpBuffer[bar_index] = mSRLastL3Up; // // Calculate level3 Lowest Close ... mSRLastL3Down = GetLowestLow( _Symbol, _Period, MODE_LOW, mLevel3Candles, mLastLevel3StartBarIndex); // srLevel3DownBuffer[bar_index] = mSRLastL3Down; } else { // int lDiff = mLastLevel3StartBarIndex - bar_index; if (lDiff == mLevel3Candles) { mLastLevel3StartBarIndex = 0; } // srLevel3UpBuffer[bar_index] = mSRLastL3Up; srLevel3DownBuffer[bar_index] = mSRLastL3Down; } // // LEVEL 4 ... // // Calculate Start Bar Index ... if (mLastLevel4StartBarIndex == 0) { // datetime level4StartTime = GetPeriodStartTime( _Symbol, mLevel4Period, barTime); // // Check Level 4 Start Time is New or Not ... if (mLevel4StartTime != level4StartTime) { mLevel4StartTime = level4StartTime; } // // Access Level 4 Start Bar Index on Current Chart ... mLastLevel4StartBarIndex = iBarShift( _Symbol, _Period, mLevel4StartTime); // // Calculate level4 Highest Open ... mSRLastL4Up = GetHighestHigh( _Symbol, _Period, MODE_OPEN, mLevel4Candles, mLastLevel4StartBarIndex); // srLevel4UpBuffer[bar_index] = mSRLastL4Up; // // Calculate level4 Lowest Close ... mSRLastL4Down = GetLowestLow( _Symbol, _Period, MODE_LOW, mLevel4Candles, mLastLevel4StartBarIndex); // srLevel4DownBuffer[bar_index] = mSRLastL4Down; } else { // int lDiff = mLastLevel4StartBarIndex - bar_index; if (lDiff == mLevel4Candles) { mLastLevel4StartBarIndex = 0; } // srLevel4UpBuffer[bar_index] = mSRLastL4Up; srLevel4DownBuffer[bar_index] = mSRLastL4Down; } // // ICHIMOKU ... // double topValue; double bottomValue; // // TENKANSEN ... // // Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ... if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL) { // switch (tenkanSenMode) { // case X_XICH_HH_LL_MODE: // mTenkanSenTopMode = MODE_HIGH; mTenkanSenBottomMode = MODE_LOW; break; // case X_XICH_HO_LC_MODE: // mTenkanSenTopMode = MODE_OPEN; mTenkanSenBottomMode = MODE_CLOSE; break; } } // // Calculate Top ... topValue = GetHighestHigh( _Symbol, _Period, mTenkanSenTopMode, tenkanSenLength, bar_index); // // Calculate Bottom ... bottomValue = GetLowestLow( _Symbol, _Period, mTenkanSenBottomMode, tenkanSenLength, bar_index); // double tenkanSenValue = (topValue + bottomValue) / 2; tenkanSenBuffer[bar_index] = tenkanSenValue; // // KIJUNSEN ... // // Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ... if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL) { // switch (kijunSenMode) { // case X_XICH_HH_LL_MODE: // mKijunSenTopMode = MODE_HIGH; mKijunSenBottomMode = MODE_LOW; break; // case X_XICH_HO_LC_MODE: // mKijunSenTopMode = MODE_OPEN; mKijunSenBottomMode = MODE_CLOSE; break; } } // // Calculate Top ... topValue = GetHighestHigh( _Symbol, _Period, mKijunSenTopMode, kijunSenLength, bar_index); // // Calculate Bottom ... bottomValue = GetLowestLow( _Symbol, _Period, mKijunSenBottomMode, kijunSenLength, bar_index); // double kijunSenValue = (topValue + bottomValue) / 2; kijunSenBuffer[bar_index] = kijunSenValue; // // CHIKOUSPAN ... double chikouSpanValue = GetAppliedPrice( bar_index, chikuoSpanAppliedTo); chikouSpanBuffer[bar_index] = chikouSpanValue; // // KUMO ... // // SENKOUSPANA ... double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2; senkouSpanABuffer[bar_index] = senkouSpanAValue; // // SENKOUSPANB ... // // Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ... if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL) { // switch (senkouSpanBMode) { // case X_XICH_HH_LL_MODE: // mSenkouSpanBTopMode = MODE_HIGH; mSenkouSpanBBottomMode = MODE_LOW; break; // case X_XICH_HO_LC_MODE: // mSenkouSpanBTopMode = MODE_OPEN; mSenkouSpanBBottomMode = MODE_CLOSE; break; } } // // Calculate Top ... topValue = GetHighestHigh( _Symbol, _Period, mSenkouSpanBTopMode, senkouSpanBLength, bar_index); // // Calculate Bottom ... bottomValue = GetLowestLow( _Symbol, _Period, mSenkouSpanBBottomMode, senkouSpanBLength, bar_index); // double senkouSpanBValue = (topValue + bottomValue) / 2; senkouSpanBBuffer[bar_index] = senkouSpanBValue; } // // Generate Comment String ... string GenerateComment() { // string result = ""; // result += "L1 P: " + EnumToString(mLevel1Period) + "\n"; // result += "L1 C: " + (string)mLevel1Candles + "\n"; // result += "\n"; // result += "L2 P: " + EnumToString(mLevel2Period) + "\n"; // result += "L2 C: " + (string)mLevel2Candles + "\n"; // result += "\n"; // result += "L3 P: " + EnumToString(mLevel3Period) + "\n"; // result += "L3 C: " + (string)mLevel3Candles + "\n"; // result += "\n"; // result += "L4 P: " + EnumToString(mLevel4Period) + "\n"; // result += "L4 C: " + (string)mLevel4Candles + "\n"; // result += "\n"; // return result; } // // END Functions ... //