Files
xMQL5/MQLTestWorkspace/XBEEA/14030224/Indicators/x-saherelm.xdon.mq5
T
2024-05-13 18:21:02 +03:30

366 lines
8.7 KiB
Plaintext

///////////////////////////////////////////////////////
// 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 int length = 52; // Market Length
input double offset = 0; // Offset
//
// 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(
//
// 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[])
{
//
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 ...
//
// UPPER ...
SetIndexBuffer(upperOBufferIndex, upperOBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperOBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerOBufferIndex, lowerOBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerOBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// Close ...
//
// UPPER ...
SetIndexBuffer(upperCBufferIndex, upperCBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperCBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerCBufferIndex, lowerCBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerCBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// High ...
//
// UPPER ...
SetIndexBuffer(upperHBufferIndex, upperHBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperHBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerHBufferIndex, lowerHBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerHBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// Low ...
//
// UPPER ...
SetIndexBuffer(upperLBufferIndex, upperLBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperLBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerLBufferIndex, lowerLBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerLBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}