add new indicators ...

This commit is contained in:
2024-06-22 15:42:08 +03:30
parent 154ebda012
commit fbe701f198
33 changed files with 5602 additions and 24 deletions
+333
View File
@@ -0,0 +1,333 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XATSL
// Description: ATR SL ...
//
// 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 XATSL Indicator"
#property strict
//
#define ShortName "XATSL"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Market";
input int length = 14; // Length
input double coeff = 2.0; // Coefficient
//
input group "Presentation";
input bool show = true; // Show
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 7
#property indicator_plots 2
//
#define mainBufferIndex 0
double mainBuffer[];
//
#define mainBufferColorIndex 1
double mainBufferColor[];
//
#define hideColorIDX 0
#define bullColorIDX 1
#define bearColorIDX 2
//
#property indicator_label1 "XATSL"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
#define hlBufferIndex 2
double hlBuffer[];
//
#define wmaBufferIndex 3
double wmaBuffer[];
//
#define tmpBufferIndex 4
double tmpBuffer[];
//
#define diffBufferIndex 5
double diffBuffer[];
//
// Variables ...
int maPeriod;
double k;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
maPeriod = int(length < 1 ? 1 : length);
double n1 = 2.0 * double(maPeriod - 1);
k = 2.0 / (n1 + 1);
//
// 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 ...
)
{
//
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
//
if (rates_total < maPeriod)
{
return 0;
}
//
int limit = rates_total - prev_calculated;
if (limit > 1)
{
//
limit = rates_total - 2;
//
ArrayInitialize(mainBuffer, EMPTY_VALUE);
ArrayInitialize(hlBuffer, 0);
ArrayInitialize(diffBuffer, 0);
ArrayInitialize(wmaBuffer, 0);
ArrayInitialize(tmpBuffer, 0);
}
//
for (int i = limit; i >= 0 && !IsStopped(); i--)
{
//
hlBuffer[i] = high[i] - low[i];
//
double href = 0;
double lref = 0;
//
double sma = MAOnArray(hlBuffer, 0, maPeriod, 0, MODE_SMA, i);
double hiLo = fmin(hlBuffer[i], sma);
//
href = (low[i] <= high[i + 1] ? high[i] - close[i + 1] : (hlBuffer[i] - close[i + 1] + high[i + 1]) / 2);
lref = (high[i] >= low[i + 1] ? close[i + 1] - low[i] : (close[i + 1] - low[i + 1] + hlBuffer[i]) / 2);
//
diffBuffer[i] = fmax(hiLo, fmax(href, lref));
}
//
for (int i = limit; i >= 0 && !IsStopped(); i--)
{
//
if (i == rates_total - 2)
{
wmaBuffer[i] = MAOnArray(diffBuffer, 0, maPeriod, 0, MODE_EMA, i);
}
else
{
wmaBuffer[i] = (diffBuffer[i] - wmaBuffer[i + 1]) * k + wmaBuffer[i + 1];
}
}
//
for (int i = limit; i >= 0 && !IsStopped(); i--)
{
//
double loss = wmaBuffer[i] * coeff;
if (close[i] > tmpBuffer[i + 1] && close[i + 1] > tmpBuffer[i + 1])
{
//
tmpBuffer[i] = fmax(tmpBuffer[i + 1], close[i] - loss);
//
mainBuffer[i] = tmpBuffer[i];
}
else
{
//
if (close[i] < tmpBuffer[i + 1] && close[i + 1] < tmpBuffer[i + 1])
{
//
tmpBuffer[i] = fmin(tmpBuffer[i + 1], close[i] + loss);
//
mainBuffer[i] = tmpBuffer[i];
}
else
{
//
if (close[i] > tmpBuffer[i + 1])
{
//
tmpBuffer[i] = close[i] - loss;
//
mainBuffer[i] = tmpBuffer[i];
}
else
{
//
tmpBuffer[i] = close[i] + loss;
//
mainBuffer[i] = tmpBuffer[i];
}
}
}
//
// Define Color Buffer ...
double clrValue = !show
? hideColorIDX
: mainBuffer[i] > close[i]
? bearColorIDX
: bullColorIDX;
mainBufferColor[i] = clrValue;
}
//
return rates_total;
}
//
// Custom Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result = length >= 2 &&
coeff > 0;
//
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()
{
//
// Main ...
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(mainBuffer, true);
ArraySetAsSeries(mainBufferColor, true);
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
//
ArraySetAsSeries(hlBuffer, true);
SetIndexBuffer(hlBufferIndex, hlBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(wmaBuffer, true);
SetIndexBuffer(wmaBufferIndex, wmaBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(tmpBuffer, true);
SetIndexBuffer(tmpBufferIndex, tmpBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(diffBuffer, true);
SetIndexBuffer(diffBufferIndex, diffBuffer, INDICATOR_CALCULATIONS);
}
//
+222
View File
@@ -0,0 +1,222 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XDMNT
// Description: Dominant ...
//
// 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 XDMNT Indicator"
#property strict
//
#define ShortName "XDMNT"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Presentation";
input bool showBull = true; // Show Bull
input bool showBear = true; // Show Bear
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 2
#property indicator_plots 2
//
#define bullBufferIndex 0
double bullBuffer[];
//
#property indicator_label1 "XDMNT Bull"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrAqua
#property indicator_width1 2
//
#define bearBufferIndex 1
double bearBuffer[];
//
#property indicator_label2 "XDMNT Bear"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta
#property indicator_width2 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 ...
)
{
//
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(time, true);
//
for (int i = 1; i < rates_total - 2; i++)
{
//
// Bullish ...
if (open[i] < close[i] && open[i + 1] < close[i + 1] && open[i] >= close[i + 1] && low[i] < close[i + 1] && high[i + 1] > open[i])
{
//
bullBuffer[i] = low[i + 1];
}
else
{
//
bullBuffer[i] = 0;
}
//
// Bearish ...
if (open[i] > close[i] && open[i + 1] > close[i + 1] && open[i] <= close[i + 1] && high[i] > close[i + 1] && low[i + 1] < open[i])
{
//
bearBuffer[i] = high[i + 1];
}
else
{
//
bearBuffer[i] = 0;
}
}
//
return rates_total;
}
//
// Custom Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result = true;
//
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()
{
//
// Bull ...
ENUM_DRAW_TYPE bullDrawType = showBull ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(bullBuffer, true);
PlotIndexSetInteger(bullBufferIndex, PLOT_ARROW, 225);
PlotIndexSetDouble(bullBufferIndex, PLOT_EMPTY_VALUE, 0);
SetIndexBuffer(bullBufferIndex, bullBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(bullBufferIndex, PLOT_SHOW_DATA, showBull);
PlotIndexSetInteger(bullBufferIndex, PLOT_DRAW_TYPE, bullDrawType);
//
// Bear ...
ENUM_DRAW_TYPE bearDrawType = showBear ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(bearBuffer, true);
PlotIndexSetInteger(bearBufferIndex, PLOT_ARROW, 225);
PlotIndexSetDouble(bearBufferIndex, PLOT_EMPTY_VALUE, 0);
SetIndexBuffer(bearBufferIndex, bearBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(bearBufferIndex, PLOT_SHOW_DATA, showBull);
PlotIndexSetInteger(bearBufferIndex, PLOT_DRAW_TYPE, bearDrawType);
}
//
+368
View File
@@ -0,0 +1,368 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XHTD
// Description: HULL Trend Detector ...
//
// 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 XHTD Indicator"
#property strict
//
#define ShortName "XHTD"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Market";
input int length = 14; // Length
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
input double multiplier = 0.66; // Multiplier
//
input group "Presentation";
input bool show = true; // Show
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 2
#property indicator_plots 2
//
#define mainBufferIndex 0
double mainBuffer[];
//
#define mainBufferColorIndex 1
double mainBufferColor[];
//
#define hideColorIDX 0
#define bullColorIDX 1
#define bearColorIDX 2
//
#property indicator_label1 "XHTD"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
#define upBufferIndex 2
double upBuffer[];
//
#define downBufferIndex 3
double downBuffer[];
//
#define directionBufferIndex 4
double directionBuffer[];
//
// 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 (ArraySize(directionBuffer) != rates_total)
{
//
ArrayResize(upBuffer, rates_total);
ArrayResize(downBuffer, rates_total);
ArrayResize(directionBuffer, rates_total);
}
//
for (int i = (int)MathMax(prev_calculated - 1, 1); i < rates_total; i++)
{
//
double atr = 0;
for (int k = 0; k < length && (i - k - 1) >= 0; k++)
{
atr += MathMax(high[i - k], close[i - k - 1]) - MathMin(low[i - k], close[i - k - 1]);
}
//
atr /= length;
//
double cprice = close[i];
double appliedPrice = getPrice(
appliedTo,
open,
close,
high,
low,
i,
rates_total //
);
double mprice = iHull(
appliedPrice,
length,
i,
rates_total //
);
//
upBuffer[i] = mprice + multiplier * atr;
downBuffer[i] = mprice - multiplier * atr;
//
mainBufferColor[i] = mainBufferColor[i - 1];
directionBuffer[i] = directionBuffer[i - 1];
//
if (cprice > upBuffer[i - 1])
{
directionBuffer[i] = 1;
}
//
if (cprice < downBuffer[i - 1])
{
directionBuffer[i] = -1;
}
//
if (directionBuffer[i] > 0)
{
//
downBuffer[i] = MathMax(downBuffer[i], downBuffer[i - 1]);
//
mainBuffer[i] = downBuffer[i];
}
else
{
//
upBuffer[i] = MathMin(upBuffer[i], upBuffer[i - 1]);
//
mainBuffer[i] = upBuffer[i];
}
//
if (directionBuffer[i] == 1)
{
mainBufferColor[i] = bullColorIDX;
}
//
if (directionBuffer[i] == -1)
{
mainBufferColor[i] = bearColorIDX;
}
}
//
return rates_total;
}
//
// Custom Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result = length >= 2 &&
multiplier > 0;
//
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()
{
//
// Main ...
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
//
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
//
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
//
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
//
SetIndexBuffer(directionBufferIndex, directionBuffer, INDICATOR_CALCULATIONS);
}
//
// Hull Handler ...
double workHull[][2];
double iHull(
double price,
double period,
int r,
int bars,
int instanceNo = 0 //
)
{
//
if (ArrayRange(workHull, 0) != bars)
{
ArrayResize(workHull, bars);
}
//
int HmaPeriod = (int)MathMax(period, 2);
int HalfPeriod = (int)MathFloor(HmaPeriod / 2);
int HullPeriod = (int)MathFloor(MathSqrt(HmaPeriod));
double hma, hmw, weight;
instanceNo *= 2;
//
workHull[r][instanceNo] = price;
//
hmw = HalfPeriod;
hma = hmw * price;
for (int k = 1; k < HalfPeriod && (r - k) >= 0; k++)
{
//
weight = HalfPeriod - k;
hmw += weight;
hma += weight * workHull[r - k][instanceNo];
}
workHull[r][instanceNo + 1] = 2.0 * hma / hmw;
//
hmw = HmaPeriod;
hma = hmw * price;
for (int k = 1; k < period && (r - k) >= 0; k++)
{
//
weight = HmaPeriod - k;
hmw += weight;
hma += weight * workHull[r - k][instanceNo];
}
workHull[r][instanceNo + 1] -= hma / hmw;
//
hmw = HullPeriod;
hma = hmw * workHull[r][instanceNo + 1];
for (int k = 1; k < HullPeriod && (r - k) >= 0; k++)
{
//
weight = HullPeriod - k;
hmw += weight;
hma += weight * workHull[r - k][1 + instanceNo];
}
//
return (hma / hmw);
}
//
double getPrice(ENUM_APPLIED_PRICE price, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars)
{
switch (price)
{
case PRICE_CLOSE: return(close[i]);
case PRICE_OPEN: return(open[i]);
case PRICE_HIGH: return(high[i]);
case PRICE_LOW: return(low[i]);
case PRICE_MEDIAN: return((high[i]+low[i])/2.0);
case PRICE_TYPICAL: return((high[i]+low[i]+close[i])/3.0);
case PRICE_WEIGHTED: return((high[i]+low[i]+close[i]+close[i])/4.0);
//case PRICE_AVERAGE: return((high[i]+low[i]+close[i]+open[i])/4.0);
}
return(0);
}
//
+264
View File
@@ -0,0 +1,264 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XSLN
// Description: HULL Trend Detector ...
//
// 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 XSLN Indicator"
#property strict
//
#define ShortName "XSLN"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Presentation";
input bool show = true; // Show
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 2
#property indicator_plots 2
//
#define mainBufferIndex 0
double mainBuffer[];
//
#define mainBufferColorIndex 1
double mainBufferColor[];
//
#define hideColorIDX 0
#define bullColorIDX 1
#define bearColorIDX 2
//
#property indicator_label1 "XSLN"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// Variables ...
//
double work[][5];
#define hHi 0
#define hLo 1
#define lHi 2
#define lLo 3
#define trend 4
//
// 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 (ArrayRange(work, 0) != rates_total)
{
ArrayResize(work, rates_total);
}
//
for (int i = (int)MathMax(prev_calculated - 1, 0); i < rates_total; i++)
{
//
if (i == 0)
{
//
work[i][hHi] = high[i];
work[i][hLo] = low[i];
work[i][lHi] = high[i];
work[i][lLo] = low[i];
work[i][trend] = -1;
continue;
}
//
work[i][trend] = work[i - 1][trend];
work[i][hHi] = work[i - 1][hHi];
work[i][hLo] = work[i - 1][hLo];
work[i][lHi] = work[i - 1][lHi];
work[i][lLo] = work[i - 1][lLo];
//
if (work[i - 1][trend] == 1)
{
//
work[i][hHi] = MathMax(work[i - 1][hHi], high[i]);
work[i][hLo] = MathMax(work[i - 1][hLo], low[i]);
//
if (high[i] < work[i][hLo])
{
//
work[i][trend] = -1;
work[i][lHi] = high[i];
work[i][lLo] = low[i];
}
}
//
if (work[i - 1][trend] == -1)
{
//
work[i][lHi] = MathMin(work[i - 1][lHi], high[i]);
work[i][lLo] = MathMin(work[i - 1][lLo], low[i]);
//
if (low[i] > work[i][lHi])
{
//
work[i][trend] = 1;
work[i][hHi] = high[i];
work[i][hLo] = low[i];
}
}
//
if (work[i][trend] == 1)
{
mainBuffer[i] = work[i][hLo];
}
else
{
mainBuffer[i] = work[i][lHi];
}
//
mainBufferColor[i] = mainBufferColor[i - 1];
//
if (work[i][trend] == 1)
{
mainBufferColor[i] = bullColorIDX;
}
//
if (work[i][trend] == -1)
{
mainBufferColor[i] = bearColorIDX;
}
}
//
return rates_total;
}
//
// Custom Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result = true;
//
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()
{
//
// Main ...
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
}
//
+67
View File
@@ -0,0 +1,67 @@
//+------------------------------------------------------------------+
//| YMA.mq5 |
//| Yuriy Tokman |
//| http://ytg.com.ua |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link "http://ytg.com.ua"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_width1 2
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDarkViolet
//--- input parameters
input int YMA_Period=21; // Period
//--- indicator buffers
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0,Buffer);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,YMA_Period);
string short_name="YMA";
IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(YMA_Period)+")");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//----
int i,limit;
//--- check for rates
if(rates_total<YMA_Period) return(0);
//--- preliminary calculations
if(prev_calculated==0)limit=YMA_Period;
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
double res =0;
for(int j=i;j>i-YMA_Period && j>0;j--)
{
res += (close[j]+open[j]+high[j]+low[j])/4;
}
Buffer[i]=res/YMA_Period;
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+