This commit is contained in:
2024-05-11 05:36:03 +03:30
parent e16ad365c2
commit d2dcdd1a64
71 changed files with 54410 additions and 0 deletions
@@ -0,0 +1,348 @@
//////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XDEMA
// Description: Super Trend Indicator ...
//
//
// 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_XAMA Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "X121_XDEMA"
//
// END Constants ...
//
//
// START Inputs ...
//
//
// Market ...
input group "Market";
input int length = 200; // Length
input int shift = 0; // Shift
//
// Presentation ...
input group "Presentation";
input bool showDema = true; // Show Dema
input bool showEMA = false; // Show EMA
input bool showEMAOfEMA = false; // Show EMA of EMA
//
// END Inputs ...
//
//
// Includes Common Library ...
#include <MovingAverages.mqh>
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 6
#property indicator_plots 6
//
#define demaBufferIndex 0
double demaBuffer[];
//
#define demaColorBufferIndex 1
double demaColorBuffer[];
//
#property indicator_label1 "X121_XDEMA DEMA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrDodgerBlue, CLR_NONE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#define emaBufferIndex 2
double emaBuffer[];
//
#define emaColorBufferIndex 3
double emaColorBuffer[];
//
#property indicator_label2 "X121_XDEMA EMA"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrBlue, CLR_NONE
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
#define emaOfEMABufferIndex 4
double emaOfEMABuffer[];
//
#define emaOfEMAColorBufferIndex 5
double emaOfEMAColorBuffer[];
//
#property indicator_label3 "X121_XDEMA EMA of EMA"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrOrange, CLR_NONE
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
// 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();
//
// 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
}
//
// Do Calculations ...
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//
ArraySetAsSeries(price, true);
//
// check for data ...
if (rates_total < 2 * length - 2)
{
return 0;
}
//
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// calculate EMA ...
ExponentialMAOnBuffer(rates_total, prev_calculated, 0, length, price, emaBuffer);
//
// calculate EMA on EMA array ...
ExponentialMAOnBuffer(rates_total, prev_calculated, length - 1, length, emaBuffer, emaOfEMABuffer);
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// calculate DEMA ...
demaBuffer[i] = 2 * emaBuffer[i] - emaOfEMABuffer[i];
//
double showColorIDX = 0;
double hideColorIDX = 1;
//
demaColorBuffer[i] = hideColorIDX;
emaColorBuffer[i] = hideColorIDX;
emaOfEMAColorBuffer[i] = hideColorIDX;
//
if (showDema)
{
demaColorBuffer[i] = showColorIDX;
}
//
if (showEMA)
{
emaColorBuffer[i] = showColorIDX;
}
//
if (showEMAOfEMA)
{
emaOfEMAColorBuffer[i] = showColorIDX;
}
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
(length > 2 &&
shift >= 0)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Peaks and Vales ...
result = length;
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// DEMA ...
//
// Buffer ...
ArraySetAsSeries(demaBuffer, true);
SetIndexBuffer(demaBufferIndex, demaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(demaBufferIndex, PLOT_SHOW_DATA, showDema);
//
// Color Buffer ...
ArraySetAsSeries(demaColorBuffer, true);
SetIndexBuffer(demaColorBufferIndex, demaColorBuffer, INDICATOR_COLOR_INDEX);
//
// EMA ...
//
// Buffer ...
ArraySetAsSeries(emaBuffer, true);
SetIndexBuffer(emaBufferIndex, emaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(emaBufferIndex, PLOT_SHOW_DATA, showEMA);
//
// Color Buffer ...
ArraySetAsSeries(emaColorBuffer, true);
SetIndexBuffer(emaColorBufferIndex, emaColorBuffer, INDICATOR_COLOR_INDEX);
//
// EMA of EMA ...
//
// Buffer ...
ArraySetAsSeries(emaOfEMABuffer, true);
SetIndexBuffer(emaOfEMABufferIndex, emaOfEMABuffer, INDICATOR_DATA);
PlotIndexSetInteger(emaOfEMABufferIndex, PLOT_SHOW_DATA, showEMAOfEMA);
//
// Color Buffer ...
ArraySetAsSeries(emaOfEMAColorBuffer, true);
SetIndexBuffer(emaOfEMAColorBufferIndex, emaOfEMAColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// END Functions ...
//
@@ -0,0 +1,240 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XDSR
// Description: Dynamic Support and Resistances ...
//
// 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 XDSR Indicator"
#property strict
//
#define ShortName "XDSR"
//
// Includes ...
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
//
// INPUT ...
//
// Short ...
input ENUM_TIMEFRAMES scPeriod = PERIOD_H4; // Short Period
input bool drawSCMidLine = true; // Draw MidLine
//
// Medium ...
input ENUM_TIMEFRAMES mcPeriod = PERIOD_H12; // Mid Period
input bool drawMCMidLine = true; // Draw MidLine
//
// Long ...
input ENUM_TIMEFRAMES lcPeriod = PERIOD_D1; // Long Period
input bool drawLCMidLine = true; // Draw MidLine
//
// Hind ...
input ENUM_TIMEFRAMES hcPeriod = PERIOD_W1; // Hind Period
input bool drawHCMidLine = true; // Draw MidLine
//
// BUFFERS ...
//
#property indicator_chart_window
//
#property indicator_buffers 5
#property indicator_plots 5
//
// Short ...
//
// Open ...
#define scOpenBufferIndex 0;
double scOpenBuffer[];
//
#property indicator_label1 "X121_XDSR SC O"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrCornflowerBlue
#property indicator_width1 1
//
// High ,,,
#define scHighBufferIndex 1;
double scHighBuffer[];
//
#property indicator_label2 "X121_XDSR SC H"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrCornflowerBlue
#property indicator_width2 1
//
// Close ,,,
#define scCloseBufferIndex 2;
double scCloseBuffer[];
//
#property indicator_label3 "X121_XDSR SC C"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrCornflowerBlue
#property indicator_width3 1
//
// Low ,,,
#define scLowBufferIndex 3;
double scLowBuffer[];
//
#property indicator_label4 "X121_XDSR SC L"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrCornflowerBlue
#property indicator_width4 1
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
drawPrefix = ShortName;
//
// 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 < 50)
{
return prev_calculated;
}
//
int start = prev_calculated == 0
? 50
: prev_calculated - 1;
//
// Main Loop ...
for (int barIndex = start; barIndex < rates_total; barIndex++)
{
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result = true;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
@@ -0,0 +1,836 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121_XICH
// Description: Ichimoku Kinko Hyo ...
//
//
// 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_XICH Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_XICH"
//
// 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
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
// 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 bool showTenkanSen = true; // Show Tenkan Sen
input bool showKijunSen = true; // Show Kijun Sen
input bool showKijunSenPlus = false; // Show Kijun Sen +
input bool showKijunSenNegative = false; // Show Kijun Sen -
input bool showChikouSpan = true; // Show Chikou Span
input bool showSenkouSpanA = true; // Show Senkou Span A
input bool showSenkouSpanB = true; // Show Senkou Span B
input bool showKumo = true; // Show Kumo
input bool shiftKumo = true; // Shift Kumo to Future
//
// 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 15
#property indicator_plots 8
//
// PLOTTED Buffers ...
//
// ICHIMOKU ...
//
// TENKANSEN ...
//
#define tenkanSenBufferIndex 0
double tenkanSenBuffer[];
//
#property indicator_label1 "X121_XICH TK"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrBrown
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// KIJUNSEN ...
//
#define kijunSenBufferIndex 1
double kijunSenBuffer[];
//
#property indicator_label2 "X121_XICH KJ"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDodgerBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
#define kijunSenPlusBufferIndex 2
double kijunSenPlusBuffer[];
//
#property indicator_label3 "X121_XICH KJ+"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrMediumTurquoise
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define kijunSenNegativeBufferIndex 3
double kijunSenNegativeBuffer[];
//
#property indicator_label4 "X121_XICH KJ-"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrDarkSeaGreen
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
// CHIKOUSPAN ...
//
#define chikouSpanBufferIndex 4
double chikouSpanBuffer[];
//
#property indicator_label5 "X121_XICH CS"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrDarkGreen
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//
#define senkouABufferIndex 5
double senkouABuffer[];
//
#property indicator_label6 "X121_XICH SSA"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrLightGray
#property indicator_style6 STYLE_DASHDOTDOT
#property indicator_width6 1
//
#define senkouBBufferIndex 6
double senkouBBuffer[];
//
#property indicator_label7 "X121_XICH SSB"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrLightGray
#property indicator_style7 STYLE_DASHDOTDOT
#property indicator_width7 1
//
// KUMO ...
//
// SENKOUSPANA ...
//
#define senkouSpanABufferIndex 7
double senkouSpanABuffer[];
//
// SENKOUSPANB ...
//
#define senkouSpanBBufferIndex 8
double senkouSpanBBuffer[];
//
// KUMOCLOUD ...
//
#define kumoBufferIndex 7
//
#property indicator_label8 "X121_XICH Kumo"
#property indicator_type8 DRAW_FILLING
#property indicator_color8 clrAqua, clrMagenta
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//
// DATA Buffers ...
//
#define dTenkanBufferIndex 9
double dTenkanBuffer[];
//
#define dKijunBufferIndex 10
double dKijunBuffer[];
//
#define dChikouBufferIndex 11
double dChikouBuffer[];
//
#define dSSABufferIndex 12
double dSSABuffer[];
//
#define dSSBBufferIndex 13
double dSSBBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
int mHandler;
//
ENUM_SERIESMODE mTenkanSenTopMode = NULL;
ENUM_SERIESMODE mTenkanSenBottomMode = NULL;
//
ENUM_SERIESMODE mKijunSenTopMode = NULL;
ENUM_SERIESMODE mKijunSenBottomMode = NULL;
//
ENUM_SERIESMODE mSenkouSpanBTopMode = NULL;
ENUM_SERIESMODE mSenkouSpanBBottomMode = 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();
//
// Init Handler ...
mHandler = iIchimoku(
_Symbol,
_Period,
tenkanSenLength,
kijunSenLength,
senkouSpanBLength);
if (mHandler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
// 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
//
IndicatorRelease(mHandler);
}
//
// 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 ichCalculatedBars = BarsCalculated(mHandler);
if (ichCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedTenkans = CopyBuffer(mHandler, TENKANSEN_LINE, 0, limit, dTenkanBuffer);
int copiedKijuns = CopyBuffer(mHandler, KIJUNSEN_LINE, 0, limit, dKijunBuffer);
int copiedChikous = CopyBuffer(mHandler, CHIKOUSPAN_LINE, 0, limit, dChikouBuffer);
int copiedSSAs = CopyBuffer(mHandler, SENKOUSPANA_LINE, 0, limit, dSSABuffer);
int copiedSSBs = CopyBuffer(mHandler, SENKOUSPANB_LINE, 0, limit, dSSBBuffer);
if (
copiedSSAs < 0 ||
copiedSSBs < 0 ||
copiedKijuns < 0 ||
copiedTenkans < 0 ||
copiedChikous < 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 =
//
(tenkanSenLength > 2 &&
kijunSenLength > tenkanSenLength &&
senkouSpanBLength > kijunSenLength)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Ichimoku ...
result = MathMax(result, tenkanSenLength);
result = MathMax(result, kijunSenLength);
result = MathMax(result, senkouSpanBLength);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// ICHIMOKU ...
//
// TENKANSEN ...
//
ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(tenkanSenBuffer, true);
SetIndexBuffer(tenkanSenBufferIndex, tenkanSenBuffer, INDICATOR_DATA);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_SHOW_DATA, showTenkanSen);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_TYPE, tenkanSenDrawType);
//
// KIJUNSEN ...
//
ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(kijunSenBuffer, true);
SetIndexBuffer(kijunSenBufferIndex, kijunSenBuffer, INDICATOR_DATA);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_SHOW_DATA, showKijunSen);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_TYPE, kijunSenDrawType);
//
// KIJUNSEN Plus ...
//
ENUM_DRAW_TYPE kijunSenPlusDrawType = showKijunSenPlus ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(kijunSenPlusBuffer, true);
SetIndexBuffer(kijunSenPlusBufferIndex, kijunSenPlusBuffer, INDICATOR_DATA);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHIFT, kijunSenLength);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_TYPE, kijunSenPlusDrawType);
//
// KIJUNSEN Negative ...
//
ENUM_DRAW_TYPE kijunSenNegativeDrawType = showKijunSenNegative ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(kijunSenNegativeBuffer, true);
SetIndexBuffer(kijunSenNegativeBufferIndex, kijunSenNegativeBuffer, INDICATOR_DATA);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHIFT, -kijunSenLength);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_TYPE, kijunSenNegativeDrawType);
//
// CHIKOUSPAN ...
//
ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(chikouSpanBuffer, true);
SetIndexBuffer(chikouSpanBufferIndex, chikouSpanBuffer, INDICATOR_DATA);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHIFT, -kijunSenLength);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHOW_DATA, showChikouSpan);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_TYPE, chikouSpanDrawType);
//
// SENKOUSPAN A and B ...
int shiftSize = shiftKumo ? kijunSenLength : 0;
//
// SENKOUSPANA ...
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(senkouABuffer, true);
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
//
// SENKOUSPANB ...
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(senkouBBuffer, true);
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
//
// KUMO ...
//
// SENKOUSPANA ...
ArraySetAsSeries(senkouSpanABuffer, true);
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
// SENKOUSPANB ...
ArraySetAsSeries(senkouSpanBBuffer, true);
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
// KUMO ...
//
ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE;
//
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(kumoBufferIndex, PLOT_DRAW_TYPE, kumoDrawType);
//
// DATA Buffers ...
//
// D Tenkan ...
ArraySetAsSeries(dTenkanBuffer, true);
SetIndexBuffer(dTenkanBufferIndex, dTenkanBuffer, INDICATOR_CALCULATIONS);
//
// D Kijun ...
ArraySetAsSeries(dKijunBuffer, true);
SetIndexBuffer(dKijunBufferIndex, dKijunBuffer, INDICATOR_CALCULATIONS);
//
// D Chikou ...
ArraySetAsSeries(dChikouBuffer, true);
SetIndexBuffer(dChikouBufferIndex, dChikouBuffer, INDICATOR_CALCULATIONS);
//
// D SSA ...
ArraySetAsSeries(dSSABuffer, true);
SetIndexBuffer(dSSABufferIndex, dSSABuffer, INDICATOR_CALCULATIONS);
//
// D SSB ...
ArraySetAsSeries(dSSBBuffer, true);
SetIndexBuffer(dSSBBufferIndex, dSSBBuffer, INDICATOR_CALCULATIONS);
}
//
// 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
)
{
//
// 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;
//
kijunSenPlusBuffer[bar_index] = kijunSenValue;
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
//
// CHIKOUSPAN ...
double chikouSpanValue = GetAppliedPrice(
bar_index,
chikuoSpanAppliedTo);
chikouSpanBuffer[bar_index] = chikouSpanValue;
//
// KUMO ...
//
// SENKOUSPANA ...
double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2;
senkouABuffer[bar_index] = senkouSpanAValue;
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;
senkouBBuffer[bar_index] = senkouSpanBValue;
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
}
//
// END Functions ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,775 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XCHNL
// Description: XCHL Channel Indicator ...
//
//
// 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_XCHNL Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "X121_XCHNL"
//
// END Constants ...
//
//
// START Includes and Imports ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// END Includes and Imports ...
//
//
// START XSCHULL Class Definition ...
//
//
// END XSCHULL Class Definition ...
//
//
// START Inputs ...
//
//
input group "Makret Cycles";
input int shortLength = 9; // Short Length
input int mediumLength = 17; // Medium Length
input int longLength = 26; // Long Length
input int hindLength = 35; // Hind Length
//
input group "Trend";
input int numOfShoulder = 10; // Number of Shoulders for Swings
//
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 showTrend = false; // Show Trend
input bool showSRs = false; // Show Support and Resistance
//
// END Inputs ...
//
//
// START Buffers ...
//
//
// PEKSANDVALES ...
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 0
#define sHHBufferIndex 0
#define sLLBufferIndex 1
#define mHHBufferIndex 2
#define mLLBufferIndex 3
#define lHHBufferIndex 4
#define lLLBufferIndex 5
#define hHHBufferIndex 6
#define hLLBufferIndex 7
double sHHBuffer[];
double sLLBuffer[];
double mHHBuffer[];
double mLLBuffer[];
double lHHBuffer[];
double lLLBuffer[];
double hHHBuffer[];
double hLLBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
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();
//
// Make an Instance of Hull Class ...
//
// 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 mPeriod 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
//
RemoveDraws(drawPrefix);
}
//
// 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[])
{
//
// this counts Available Bars ...
int limit;
//
limit = prev_calculated - 1;
if (limit < 0)
{
limit = 0;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
result =
//
// Validate Peaks and Vales ...
(shortLength > 2 &&
mediumLength > shortLength &&
longLength > mediumLength &&
hindLength > longLength)
//
;
//
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);
result = MathMax(result, hindLength);
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ArraySetAsSeries(sHHBuffer, true);
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(sLLBuffer, true);
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(mHHBuffer, true);
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(mLLBuffer, true);
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(lHHBuffer, true);
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(lLLBuffer, true);
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(hHHBuffer, true);
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(hLLBuffer, true);
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// Calculate ...
//
// SHORT ...
//
// HIGH ...
int sHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
shortLength,
bar_index);
double sHHValue = GetAppliedPrice(
sHHIndex,
hhMode);
//
sHHBuffer[bar_index] = sHHValue;
//
// LOW ...
int sLLIndex = iLowest(
_Symbol,
_Period,
llMode,
shortLength,
bar_index);
double sLLValue = GetAppliedPrice(
sLLIndex,
llMode);
//
sLLBuffer[bar_index] = sLLValue;
//
// MEDIUM ...
//
// HIGH ...
int mHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
mediumLength,
bar_index);
double mHHValue = GetAppliedPrice(
mHHIndex,
hhMode);
//
mHHBuffer[bar_index] = mHHValue;
//
// LOW ...
int mLLIndex = iLowest(
_Symbol,
_Period,
llMode,
mediumLength,
bar_index);
double mLLValue = GetAppliedPrice(
mLLIndex,
llMode);
//
mLLBuffer[bar_index] = mLLValue;
//
// LONG ...
//
// HIGH ...
int lHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
longLength,
bar_index);
double lHHValue = GetAppliedPrice(
lHHIndex,
hhMode);
//
lHHBuffer[bar_index] = lHHValue;
//
// LOW ...
int lLLIndex = iLowest(
_Symbol,
_Period,
llMode,
longLength,
bar_index);
double lLLValue = GetAppliedPrice(
lLLIndex,
llMode);
//
lLLBuffer[bar_index] = lLLValue;
//
// HIND ...
//
// HIGH ...
int hHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
hindLength,
bar_index);
double hHHValue = GetAppliedPrice(
hHHIndex,
hhMode);
//
hHHBuffer[bar_index] = hHHValue;
//
// LOW ...
int hLLIndex = iLowest(
_Symbol,
_Period,
llMode,
hindLength,
bar_index);
double hLLValue = GetAppliedPrice(
hLLIndex,
llMode);
//
hLLBuffer[bar_index] = hLLValue;
//
// Find Swings ...
//
// High ...
int hSwing1 = FindSwing(
_Symbol,
_Period,
MODE_HIGH,
numOfShoulder,
bar_index + 1);
int hSwing2 = FindSwing(
_Symbol,
_Period,
MODE_HIGH,
numOfShoulder,
hSwing1 + 1);
//
// High ...
int hSwing3 = FindSwing(
_Symbol,
_Period,
MODE_HIGH,
numOfShoulder,
hSwing2 + 1);
// int hSwing4 = FindSwing(
// _Symbol,
// _Period,
// MODE_HIGH,
// numOfShoulder,
// hSwing3 + 1);
//
// Low ...
int lSwing1 = FindSwing(
_Symbol,
_Period,
MODE_LOW,
numOfShoulder,
bar_index + 1);
int lSwing2 = FindSwing(
_Symbol,
_Period,
MODE_LOW,
numOfShoulder,
lSwing1 + 1);
int lSwing3 = FindSwing(
_Symbol,
_Period,
MODE_LOW,
numOfShoulder,
lSwing2 + 1);
// int lSwing4 = FindSwing(
// _Symbol,
// _Period,
// MODE_LOW,
// numOfShoulder,
// lSwing3 + 1);
//
if (bar_index < 50)
{
//
bool isStrongResistance =
//
hHHBuffer[bar_index + 1] == hHHBuffer[bar_index + 2] &&
hHHBuffer[bar_index + 2] == hHHBuffer[bar_index + 3] &&
//
lHHBuffer[bar_index + 1] == lHHBuffer[bar_index + 2] &&
lHHBuffer[bar_index + 2] == lHHBuffer[bar_index + 3] &&
//
mHHBuffer[bar_index + 1] == mHHBuffer[bar_index + 2] &&
mHHBuffer[bar_index + 2] == mHHBuffer[bar_index + 3] &&
//
sHHBuffer[bar_index + 1] == sHHBuffer[bar_index + 2] &&
sHHBuffer[bar_index + 2] == sHHBuffer[bar_index + 3]
//
;
//
bool isStrongSupport =
//
hLLBuffer[bar_index + 1] == hLLBuffer[bar_index + 2] &&
hLLBuffer[bar_index + 2] == hLLBuffer[bar_index + 3] &&
//
lLLBuffer[bar_index + 1] == lLLBuffer[bar_index + 2] &&
lLLBuffer[bar_index + 2] == lLLBuffer[bar_index + 3] &&
//
mLLBuffer[bar_index + 1] == mLLBuffer[bar_index + 2] &&
mLLBuffer[bar_index + 2] == mLLBuffer[bar_index + 3] &&
//
sLLBuffer[bar_index + 1] == sLLBuffer[bar_index + 2] &&
sLLBuffer[bar_index + 2] == sLLBuffer[bar_index + 3]
//
;
//
if (isStrongResistance && showSRs)
{
//
DrawSupportResistance(
"R",
clrRed,
sHHBuffer[bar_index + 3],
bar_index + 3);
}
//
if (isStrongSupport && showSRs)
{
//
DrawSupportResistance(
"S",
clrGreen,
sLLBuffer[bar_index + 3],
bar_index + 3);
}
}
//
if (showTrend && bar_index < 20)
{
//
DrawSwing(
"High1",
MODE_HIGH,
clrAqua,
hSwing1,
hSwing2);
//
DrawSwing(
"Low1",
MODE_LOW,
clrAqua,
lSwing1,
lSwing2);
//
DrawSwing(
"High2",
MODE_HIGH,
clrMagenta,
hSwing2,
hSwing3);
//
DrawSwing(
"Low2",
MODE_LOW,
clrMagenta,
lSwing2,
lSwing3);
}
}
//
void DrawSwing(
string prefix, // Prefix ...
ENUM_SERIESMODE mode, // Swing Mode ...
color swingColor, // Color ...
int index1, // Index 1 ...
int index2 // Index 2 ...
)
{
//
if (mode != MODE_HIGH && mode != MODE_LOW)
{
return;
}
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
index1);
//
datetime time1 = GetCandleTime(
_Symbol,
_Period,
index1);
//
XOHCL c2 = GetCandle(
_Symbol,
_Period,
index2);
//
datetime time2 = GetCandleTime(
_Symbol,
_Period,
index2);
//
double value1 = -1;
double value2 = -1;
//
switch (mode)
{
//
case MODE_HIGH:
value1 = c1.high;
value2 = c2.high;
break;
//
case MODE_LOW:
value1 = c1.low;
value2 = c2.low;
break;
}
//
if (value1 == -1 || value2 == -1)
{
return;
}
//
long chartId = ChartID();
string tlName = prefix + "_" + "TrendLine";
// //
// if (IsDrawExists(tlName)) {
// RemoveDraw(tlName);
// }
//
DrawTrendLine(
chartId,
tlName,
0,
time2,
value2,
time1,
value1,
swingColor,
STYLE_DOT,
3,
false,
false,
true);
}
//
// Draw Support and Resistance ...
void DrawSupportResistance(
string prefix, // Prefix ...
color lColor, // Color ...
double price, // Support or Resistance price ...
int bar_index // Start Bar Index ...
)
{
//
datetime time1 = GetCandleTime(
_Symbol,
_Period,
bar_index);
//
datetime time2 = GetCandleTime(
_Symbol,
_Period,
bar_index - 1);
//
long chartId = ChartID();
string tlName = prefix + "_" + "TL" + "_" + (string)(NormalizePrice(price, _Symbol));
//
DrawTrendLine(
chartId,
tlName,
0,
time1,
price,
time2,
price,
lColor,
STYLE_DOT,
3,
false,
false,
true);
}
@@ -0,0 +1,365 @@
///////////////////////////////////////////////////////
// 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);
}