/////////////////////////////////////////////////////// // SaherElm IT Center MQL5 Indicator // ------------------------------------------- // Name: XDON // Description: DONCHAIN Channel ... // // 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 XDON Indicator" #property strict // #define ShortName "XDON" // // INPUT ... // input group "Market"; input int length = 52; // Market Length input double offset = 0; // Offset // input group "Presentation"; input bool showOpen = true; // Show Open input bool showHigh = true; // Show High input bool showClose = true; // Show Close input bool showLow = true; // Show Low // // BUFFERS ... // #property indicator_chart_window // #property indicator_buffers 8 #property indicator_plots 8 // #define upperOBufferIndex 0 double upperOBuffer[]; // #property indicator_label1 "XDON OU" #property indicator_type1 DRAW_LINE #property indicator_color1 clrCornflowerBlue #property indicator_width1 2 // #define lowerOBufferIndex 1 double lowerOBuffer[]; // #property indicator_label2 "XDON OL" #property indicator_type2 DRAW_LINE #property indicator_color2 clrCornflowerBlue #property indicator_width2 2 // #define upperCBufferIndex 2 double upperCBuffer[]; // #property indicator_label3 "XDON CU" #property indicator_type3 DRAW_LINE #property indicator_color3 clrCoral #property indicator_width3 2 // #define lowerCBufferIndex 3 double lowerCBuffer[]; // #property indicator_label4 "XDON CL" #property indicator_type4 DRAW_LINE #property indicator_color4 clrCoral #property indicator_width4 2 // #define upperHBufferIndex 4 double upperHBuffer[]; // #property indicator_label5 "XDON HU" #property indicator_type5 DRAW_LINE #property indicator_color5 clrAquamarine #property indicator_width5 2 // #define lowerHBufferIndex 5 double lowerHBuffer[]; // #property indicator_label6 "XDON HL" #property indicator_type6 DRAW_LINE #property indicator_color6 clrAquamarine #property indicator_width6 2 // #define upperLBufferIndex 6 double upperLBuffer[]; // #property indicator_label7 "XDON LU" #property indicator_type7 DRAW_LINE #property indicator_color7 clrDarkOrchid #property indicator_width7 2 // #define lowerLBufferIndex 7 double lowerLBuffer[]; // #property indicator_label8 "XDON LL" #property indicator_type8 DRAW_LINE #property indicator_color8 clrDarkOrchid #property indicator_width8 2 // // EVENT Handlers ... // // Initialization ... int OnInit() { // // Validate Inputs ... if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // // Define Index Buffers ... DefineBuffers(); // // Set Indicator ShortName ... SetIndicatorName(); // // 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 } // // Calculating what we want ... int OnCalculate( const int rates_total, // Total Bars on Chart ... const int prev_calculated, // Total Calculated Bars on Charts ... const datetime &time[], // History of Open Time ... const double &open[], // History of Open Price ... const double &high[], // History of High Price ... const double &low[], // History of Low Price ... const double &close[], // History of Close Price ... const long &tick_volume[], // History of Tick Volumes on Bar ... const long &volume[], // History of Trade Volumes ... const int &spread[] // History of Spread Price ... ) { // if (rates_total < length - 1) { return prev_calculated; } // int start = prev_calculated == 0 ? length : prev_calculated - 1; // // Main Loop ... for (int barIndex = start; barIndex < rates_total; barIndex++) { // // OPEN ... // double upperOValue = open[ArrayMaximum(open, barIndex - length + 1, length)]; double lowerOValue = open[ArrayMinimum(open, barIndex - length + 1, length)]; // double oDelta = MathAbs(upperOValue - lowerOValue); double oOffsetValue = oDelta * (offset) * 0.01; // upperOBuffer[barIndex] = upperOValue - oOffsetValue; lowerOBuffer[barIndex] = lowerOValue + oOffsetValue; // // CLOSE ... // double upperCValue = close[ArrayMaximum(close, barIndex - length + 1, length)]; double lowerCValue = close[ArrayMinimum(close, barIndex - length + 1, length)]; // double cDelta = MathAbs(upperCValue - lowerCValue); double cOffsetValue = cDelta * (offset) * 0.01; // upperCBuffer[barIndex] = upperCValue - cOffsetValue; lowerCBuffer[barIndex] = lowerCValue + cOffsetValue; // // HIGH ... // double upperHValue = high[ArrayMaximum(high, barIndex - length + 1, length)]; double lowerHValue = high[ArrayMinimum(high, barIndex - length + 1, length)]; // double hDelta = MathAbs(upperHValue - lowerHValue); double hOffsetValue = hDelta * (offset) * 0.01; // upperHBuffer[barIndex] = upperHValue - hOffsetValue; lowerHBuffer[barIndex] = lowerHValue + hOffsetValue; // // LOW ... // double upperLValue = low[ArrayMaximum(low, barIndex - length + 1, length)]; double lowerLValue = low[ArrayMinimum(low, barIndex - length + 1, length)]; // double lDelta = MathAbs(upperLValue - lowerLValue); double lOffsetValue = lDelta * (offset) * 0.01; // upperLBuffer[barIndex] = upperLValue - lOffsetValue; lowerLBuffer[barIndex] = lowerLValue + lOffsetValue; } // return rates_total; } // // CUSTOM Functions ... // // Validate Input Args for Initialization ... bool ValidateInputs() { // bool result = false; // result = length >= 7; // return result; } // // Define Indexes and Styles ... void DefineBuffers() { // // Open ... ENUM_DRAW_TYPE openDrawType = showOpen ? DRAW_LINE : DRAW_NONE; // // UPPER ... SetIndexBuffer(upperOBufferIndex, upperOBuffer, INDICATOR_DATA); PlotIndexSetInteger(upperOBufferIndex, PLOT_SHOW_DATA, showOpen); PlotIndexSetDouble(upperOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(upperOBufferIndex, PLOT_DRAW_TYPE, openDrawType); // // LOWER ... SetIndexBuffer(lowerOBufferIndex, lowerOBuffer, INDICATOR_DATA); PlotIndexSetInteger(lowerOBufferIndex, PLOT_SHOW_DATA, showOpen); PlotIndexSetDouble(lowerOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(lowerOBufferIndex, PLOT_DRAW_TYPE, openDrawType); // // Close ... ENUM_DRAW_TYPE closeDrawType = showClose ? DRAW_LINE : DRAW_NONE; // // UPPER ... SetIndexBuffer(upperCBufferIndex, upperCBuffer, INDICATOR_DATA); PlotIndexSetInteger(upperCBufferIndex, PLOT_SHOW_DATA, showClose); PlotIndexSetDouble(upperCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(upperCBufferIndex, PLOT_DRAW_TYPE, closeDrawType); // // LOWER ... SetIndexBuffer(lowerCBufferIndex, lowerCBuffer, INDICATOR_DATA); PlotIndexSetInteger(lowerCBufferIndex, PLOT_SHOW_DATA, showClose); PlotIndexSetDouble(lowerCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(lowerCBufferIndex, PLOT_DRAW_TYPE, closeDrawType); // // High ... ENUM_DRAW_TYPE highDrawType = showHigh ? DRAW_LINE : DRAW_NONE; // // UPPER ... SetIndexBuffer(upperHBufferIndex, upperHBuffer, INDICATOR_DATA); PlotIndexSetInteger(upperHBufferIndex, PLOT_SHOW_DATA, showHigh); PlotIndexSetDouble(upperHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(upperHBufferIndex, PLOT_DRAW_TYPE, highDrawType); // // LOWER ... SetIndexBuffer(lowerHBufferIndex, lowerHBuffer, INDICATOR_DATA); PlotIndexSetInteger(lowerHBufferIndex, PLOT_SHOW_DATA, showHigh); PlotIndexSetDouble(lowerHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(lowerHBufferIndex, PLOT_DRAW_TYPE, highDrawType); // // Low ... ENUM_DRAW_TYPE lowDrawType = showLow ? DRAW_LINE : DRAW_NONE; // // UPPER ... SetIndexBuffer(upperLBufferIndex, upperLBuffer, INDICATOR_DATA); PlotIndexSetInteger(upperLBufferIndex, PLOT_SHOW_DATA, showLow); PlotIndexSetDouble(upperLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(upperLBufferIndex, PLOT_DRAW_TYPE, lowDrawType); // // LOWER ... SetIndexBuffer(lowerLBufferIndex, lowerLBuffer, INDICATOR_DATA); PlotIndexSetInteger(lowerLBufferIndex, PLOT_SHOW_DATA, showLow); PlotIndexSetDouble(lowerLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(lowerLBufferIndex, PLOT_DRAW_TYPE, lowDrawType); } // // Set Indicator Short Name and also we can define Buffers Labels ... void SetIndicatorName() { IndicatorSetString(INDICATOR_SHORTNAME, ShortName); }