add MQL5Test Workspace Content as BKP Solution ...

This commit is contained in:
2024-04-22 07:42:50 +03:30
parent ec0a03203e
commit f7fd579a9d
197 changed files with 80113 additions and 0 deletions
@@ -0,0 +1,367 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XAMA Indicator
// ---------------------------------------------
// Name: XAMA
// Description: Trend Magic 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 XAMA Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XAMA"
//
// XAMA Indicator States ...
enum ENUM_X_XAMA_STATES
{
X_XAMA_BULLISH = 1,
X_XAMA_BEARISH = -1,
X_XAMA_NEUTURAL = 0,
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Makret";
input int length = 52; // Period
input int fastEMA = 2; // Fast EMA Period
input int slowEMA = 30; // Slow EMA Period
input int maShift = 0; // Shift
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
//
input group "Presentation";
input bool showLine = true; // Show Line
//
// END Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 1
//
// maBuffer ...
#define maBufferIndex 0
#define maColorBufferIndex 1
#define stateBufferIndex 2
double maBuffer[];
double maColorBuffer[];
double stateBuffer[];
#property indicator_label1 "XAMA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLime, clrGray, clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
int maHandler = 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;
//
// Initializing MA Handler ...
maHandler = iAMA(
_Symbol,
_Period,
length,
fastEMA,
slowEMA,
maShift,
appliedTo);
if (maHandler == INVALID_HANDLE)
{
//
string message = "Error Initializing Ma Handler ...";
LogMessage(message);
//
return INIT_FAILED;
}
//
// 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
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(maHandler);
}
//
// 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;
//
// 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 ...
int maxLength = MathMax(fastEMA, slowEMA);
maxLength = MathMax(maxLength, length);
//
// Check Calculated Bars ...
int maCalculatedBars = BarsCalculated(maHandler);
if (maCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
if (copiedMas <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Do Buffers Calculation ...
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (length >= 2)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
//
string maBufferLabel = "XAMA " + "(" + (string)length + ")";
//
// Ma Buffer ...
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
//
// Ma Color Buffer ...
ArraySetAsSeries(maColorBuffer, true);
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
//
// State Buffer ...
ArraySetAsSeries(stateBuffer, true);
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", "(", length, ")");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(int bar_index)
{
//
// Requirements ...
XOHCL candle = GetCandle(bar_index);
//
double maValue = maBuffer[bar_index];
//
double lineColorIndex =
maValue < candle.low ? 0 : maValue > candle.high ? 2
: 1;
//
// Define State Value ...
// lineColorIndex == 0 => Bullish => 1;
// lineColorIndex == 1 => Neutural => 0;
// lineColorIndex == 2 => Bearish => -1;
double stateValue =
lineColorIndex == 0 ? X_XAMA_BULLISH : lineColorIndex == 2 ? X_XAMA_BEARISH
: X_XAMA_NEUTURAL;
//
// Set Ma Buffer Color Index ...
maColorBuffer[bar_index] = lineColorIndex;
//
// Set State Buffer Value ...
stateBuffer[bar_index] = stateValue;
}
//
// END Functions ...
//
@@ -0,0 +1,765 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_ATRSL ATR Indicator
// ---------------------------------------------------
// Name: X121_ATRSL
// Description: ATR StopLoss Finer
// 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_ATRSL Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_ATRSL"
//
// Available Smoothing Methods ...
enum X_XATRSL_SMOOTHING_METHOD
{
X_ATRSL_SMOOTHING_RMA = 0, // RMA
X_ATRSL_SMOOTHING_SMA = 1, // SMA
X_ATRSL_SMOOTHING_EMA = 2, // EMA
X_ATRSL_SMOOTHING_WMA = 3, // WMA
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 14; // Length
input double step = 0.02; // Increment Step
input double maximum = 0.2; // Maximum
input ENUM_APPLIED_PRICE highAppliedTo = PRICE_HIGH; // High Line Applied To
input ENUM_APPLIED_PRICE lowAppliedTo = PRICE_LOW; // Low Line Applied To
//
input group "Presentation";
input bool showHigh = true; // Show High
input bool showLow = true; // Show Low
input bool showSar = true; // Show PSar
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.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 9
#property indicator_plots 3
//
// PLOTTED Buffers ...
//
// HIGH ...
#define highBufferIndex 0
double highBuffer[];
//
#property indicator_label1 "X121_ATRSL H"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLightGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// LOW ...
#define lowBufferIndex 1
double lowBuffer[];
//
#property indicator_label2 "X121_ATRSL L"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrLightGray
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// SAR ...
#define sarBufferIndex 2
double sarBuffer[];
//
#property indicator_label3 "X121_ATRSL SAR"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrGold
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// DATA Buffers ...
//
// RMA ...
#define rmaBufferIndex 3
double rmaBuffer[];
//
// WMA ...
#define wmaBufferIndex 4
double wmaBuffer[];
//
// WMA CALCULATIONS ...
//
// MA 1 ...
#define ma1BufferIndex 5
double ma1Buffer[];
//
// MA P ...
#define maPBufferIndex 6
double maPBuffer[];
//
// EMA P ...
#define emaPBufferIndex 7
double emaPBuffer[];
//
// ATR ...
#define atrBufferIndex 8
double atrBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
double smoothFactor;
//
// WMA ...
int ma1Handler = INVALID_HANDLE;
int maPHandler = INVALID_HANDLE;
ENUM_APPLIED_PRICE wmaAppliedTo = PRICE_CLOSE;
//
// EMA ...
int emaPHandler = INVALID_HANDLE;
//
// ATR ...
int atrHandler = INVALID_HANDLE;
//
// SAR ...
int sarHandler = 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;
//
// 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();
//
// Calculate RMA and WMA Smooth Factoir ...
smoothFactor = 1.0 / length;
//
// Define Index Buffers ...
DefineBuffers();
//
// Initialize Handlers ...
if (!InitialHandlers())
{
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
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(sarHandler);
IndicatorRelease(atrHandler);
IndicatorRelease(ma1Handler);
IndicatorRelease(maPHandler);
IndicatorRelease(emaPHandler);
}
//
// 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 sarCalculatedBars = BarsCalculated(sarHandler);
int atrCalculatedBars = BarsCalculated(atrHandler);
int ma1CalculatedBars = BarsCalculated(ma1Handler);
int maPCalculatedBars = BarsCalculated(maPHandler);
int emaPCalculatedBars = BarsCalculated(emaPHandler);
if (sarCalculatedBars < maxLength ||
atrCalculatedBars < maxLength ||
ma1CalculatedBars < maxLength ||
maPCalculatedBars < maxLength ||
emaPCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
int copiedMa1s = CopyBuffer(ma1Handler, 0, 0, limit, ma1Buffer);
int copiedMaPs = CopyBuffer(maPHandler, 0, 0, limit, maPBuffer);
int copiedEMaPs = CopyBuffer(emaPHandler, 0, 0, limit, emaPBuffer);
if (copiedSars <= 0 ||
copiedAtrs <= 0 ||
copiedMa1s <= 0 ||
copiedMaPs <= 0 ||
copiedEMaPs <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Determines First Calculation ...
bool isFirstBar = ((limit == rates_total) &&
i == rates_total - 1);
//
CalculateBuffers(
i,
isFirstBar,
limit,
rates_total,
prev_calculated,
open,
high,
low,
close
//
);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
// Validate Inputs ...
(length > 2 &&
step > 0 &&
maximum > step)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Max ...
result = MathMax(result, length);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// HIGH ...
ENUM_DRAW_TYPE highDrawType = showHigh ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(highBuffer, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
PlotIndexSetDouble(highBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(highBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(highBufferIndex, PLOT_DRAW_TYPE, highDrawType);
//
// LOW ...
ENUM_DRAW_TYPE lowDrawType = showLow ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(lowBuffer, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
PlotIndexSetDouble(lowBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(lowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(lowBufferIndex, PLOT_DRAW_TYPE, lowDrawType);
//
// SAR ...
ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(sarBuffer, true);
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA);
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType);
//
// DATA Buffers ...
//
// RMA ...
ArraySetAsSeries(rmaBuffer, true);
SetIndexBuffer(rmaBufferIndex, rmaBuffer, INDICATOR_CALCULATIONS);
//
// MA 1 ...
ArraySetAsSeries(ma1Buffer, true);
SetIndexBuffer(ma1BufferIndex, ma1Buffer, INDICATOR_CALCULATIONS);
//
// MA P ...
ArraySetAsSeries(maPBuffer, true);
SetIndexBuffer(maPBufferIndex, maPBuffer, INDICATOR_CALCULATIONS);
//
// WMA ...
ArraySetAsSeries(wmaBuffer, true);
SetIndexBuffer(wmaBufferIndex, wmaBuffer, INDICATOR_DATA);
//
// ATR ...
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
}
//
// Initialize WMA Required Handlers ...
bool InitialHandlers()
{
//
bool result = false;
//
// MA 1 ...
ma1Handler = iMA(
_Symbol,
_Period,
1, // Lenght of MA 1 ...
0,
MODE_SMA,
wmaAppliedTo);
//
// MA P ...
maPHandler = iMA(
_Symbol,
_Period,
length,
0,
MODE_SMA,
wmaAppliedTo);
//
// EMA P ...
emaPHandler = iMA(
_Symbol,
_Period,
length,
0,
MODE_EMA,
wmaAppliedTo);
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
length);
//
// SAR ...
sarHandler = iSAR(
_Symbol,
_Period,
step,
maximum);
//
result =
//
sarHandler != INVALID_HANDLE &&
atrHandler != INVALID_HANDLE &&
ma1Handler != INVALID_HANDLE &&
maPHandler != INVALID_HANDLE &&
emaPHandler != INVALID_HANDLE
//
;
//
// Log Error Message if Initialization Failed ...
if (!result)
{
LogMessage("Error in Initializing Indicator ...");
}
//
return result;
}
//
// 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
bool isFirstBar, // Determines First Bar
const int limit, // Limit Of Calculations
const int ratesTotal, // Total Rates
const int prevCalculated, // Prev Calculated Bars
const double &open[], // Open Price Series
const double &high[], // High Price Series
const double &low[], // Low Price Series
const double &close[] // Close Price Series
)
{
//
// RMA Calculation ...
//
double closeValue = close[bar_index];
double prevRMAValue = isFirstBar
? closeValue
: rmaBuffer[bar_index + 1];
//
double rmaValue = (closeValue * smoothFactor) + prevRMAValue * (1.0 - smoothFactor);
//
rmaBuffer[bar_index] = rmaValue;
//
// WMA Calculations ...
//
double maPValue = maPBuffer[bar_index];
double ma1Value = ma1Buffer[bar_index];
//
double wmaValue;
if (isFirstBar)
{
wmaValue = maPValue;
}
else
{
wmaValue = (ma1Value - wmaBuffer[bar_index + 1]) * smoothFactor + wmaBuffer[bar_index + 1];
}
//
wmaBuffer[bar_index] = wmaValue;
//
// CALCULATE Buffers ...
//
double atrValue = atrBuffer[bar_index];
double highSourcePrice = GetSourcePrice(
bar_index,
highAppliedTo,
open,
high,
low,
close);
double lowSourcePrice = GetSourcePrice(
bar_index,
lowAppliedTo,
open,
high,
low,
close);
//
// Retrieve SMoothing Value ...
// double smoothingValue = GetSmoothedValue(bar_index);
//
double smoothedATR = atrValue;
//
// HIGH ...
double highValue = highSourcePrice + smoothedATR;
highBuffer[bar_index] = highValue;
//
// LOW ...
double lowValue = lowSourcePrice - smoothedATR;
lowBuffer[bar_index] = lowValue;
}
//
// Retrieve Smoothed Value based on User Choice ...
double GetSmoothedValue(
int bar_index // Bar Index
)
{
//
double result = EMPTY_VALUE;
//
// switch (smoothingMethod)
// {
// //
// // RMA ...
// case X_ATRSL_SMOOTHING_RMA:
// result = rmaBuffer[bar_index];
// break;
// //
// // WMA ...
// case X_ATRSL_SMOOTHING_WMA:
// result = wmaBuffer[bar_index];
// break;
// //
// // EMA ...
// case X_ATRSL_SMOOTHING_EMA:
// result = emaPBuffer[bar_index];
// break;
// //
// // SMA ...
// case X_ATRSL_SMOOTHING_SMA:
// result = maPBuffer[bar_index];
// break;
// //
// default:
// result = maPBuffer[bar_index];
// break;
// }
//
return result;
}
//
// Retrive Which Price Selected By User as Source ...
double GetSourcePrice(
int bar_index, // BarIndex
ENUM_APPLIED_PRICE appliedPrice, // Selected Price Source
const double &open[], // Open Price Series
const double &high[], // High Price Series
const double &low[], // Low Price Series
const double &close[] // Close Price Series
)
{
//
double result = EMPTY_VALUE;
//
switch (appliedPrice)
{
//
// OPEN ...
case PRICE_OPEN:
result = open[bar_index];
break;
//
// HIGH ...
case PRICE_HIGH:
result = high[bar_index];
break;
//
// LOW ...
case PRICE_LOW:
result = low[bar_index];
break;
//
// CLOSE ...
default:
case PRICE_CLOSE:
result = close[bar_index];
break;
}
//
return result;
}
//
// END Functions ...
//
@@ -0,0 +1,481 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_CC Candle Styles
// ---------------------------------------------------
// Name: X121_CC
// Description: Candle Styles ...
// 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_CC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_CC"
//
// Holds an SnapShot of Charts Configuration ...
struct XChartStyle
{
//
// chart's ID ...
long chartId;
//
// chart's mode ...
ENUM_CHART_MODE mode;
//
// show bid line ...
bool showBidLine;
//
// show ask line ...
bool showAskLine;
//
// show grids on chart ...
bool showGrid;
//
// show volumes ...
bool showVolumes;
//
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
bool showTradeLevels;
//
// chart autoscroll ...
bool autoScroll;
//
// chart quick navigation state ...
bool quickNavigation;
//
// chart's foreground color ...
color foreGroundColor;
//
// chart's background color ...
color backGroundColor;
//
// Up Color ...
color upColor;
//
// Down Color ...
color downColor;
//
// Bullish color ...
color bullishColor;
//
// Bearish color ...
color bearishColor;
//
// grid color ...
color gridColor;
//
// bid line color ...
color bidLineColor;
//
// ask line color ...
color askLineColor;
//
// line mode and doji candlestick color ...
color lineColor;
//
// Color of stop order levels (Stop Loss and Take Profit) ...
color stopColor;
//
// volumes color ...
color volumesColor;
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Chart Style";
input color mUpColor = clrLime; // Up Color
input color mDownColor = clrRed; // Down Color
input color mLineColor = clrLime; // Line mode and Doji candlestick Color
input color mBearishColor = clrRed; // Bullish Color
input color mBullishColor = clrLime; // Bearish Color
input color mVolumesColor = clrGreen; // Volumes Color
//
input group "Presentation";
input bool showCandles = false; // Show Candles
//
// 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 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
XChartStyle chartStyle;
XChartStyle clearStyle;
bool hasChartConfig = false;
//
// 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();
//
// Apply Chart Style ...
ApplyCustomChartStyle();
//
// 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
//
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;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// 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 = true;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
}
//
// 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
)
{
}
//
// Apply Custom Chart Style ...
void ApplyCustomChartStyle()
{
//
// Read Prev Applied Chart Style ans Store it ...
if (!hasChartConfig)
{
//
// Read Current Chart Config and Store it ...
ReadChartStyle();
//
// After Reading Current Chart Style ...
// we have to Save Configs and Change Styles ...
clearStyle = chartStyle;
//
clearStyle.upColor = CLR_NONE;
clearStyle.downColor = CLR_NONE;
clearStyle.lineColor = CLR_NONE;
clearStyle.volumesColor = CLR_NONE;
clearStyle.bullishColor = CLR_NONE;
clearStyle.bearishColor = CLR_NONE;
}
//
// Decide to Show or not Candles based on User Input ...
if (showCandles)
{
SetChartStyle(chartStyle);
}
else
{
SetChartStyle(clearStyle);
}
}
//
// Read Previous Chart Style ...
void ReadChartStyle()
{
//
if (hasChartConfig)
{
return;
}
//
// Retrieve Current Chart ID ...
long chartId = ChartID();
chartStyle.chartId = chartId;
//
// Retrieve Chart Mode ...
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
//
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
//
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
//
chartStyle.upColor = mUpColor;
chartStyle.downColor = mDownColor;
chartStyle.lineColor = mLineColor;
chartStyle.bearishColor = mBearishColor;
chartStyle.bullishColor = mBullishColor;
chartStyle.volumesColor = mVolumesColor;
}
//
// Set Chart Style ...
void SetChartStyle(
XChartStyle &mChartStyle // Chart Style to Apply
)
{
//
ApplyChartStyle(
mChartStyle.chartId,
mChartStyle.mode,
mChartStyle.showBidLine,
mChartStyle.showAskLine,
mChartStyle.showGrid,
mChartStyle.showVolumes,
mChartStyle.showTradeLevels,
mChartStyle.autoScroll,
mChartStyle.quickNavigation,
mChartStyle.foreGroundColor,
mChartStyle.backGroundColor,
mChartStyle.upColor,
mChartStyle.downColor,
mChartStyle.bullishColor,
mChartStyle.bearishColor,
mChartStyle.gridColor,
mChartStyle.bidLineColor,
mChartStyle.askLineColor,
mChartStyle.lineColor,
mChartStyle.stopColor,
mChartStyle.volumesColor);
}
//
// END Functions ...
//
@@ -0,0 +1,629 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCHE Indicator
// ---------------------------------------------
// Name: XCHE
// Description: Hull 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 XHull Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "XCHE"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 35; // Length
input int loopback = 26; // Loopback
input double multiplier1 = 3.0; // 1st Multiplier
input double multiplier2 = 3.5; // 2nd Multiplier
//
input group "Calculation";
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
//
input group "Presentation";
input bool showLongExit1Line = true; // Show 1st Long Exit
input bool showShortExit1Line = true; // Show 1st Short Exit
input bool showLongExit2Line = true; // Show 2st Long Exit
input bool showShortExit2Line = true; // Show 2st Short Exit
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.models.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 8
#property indicator_plots 8
//
// Long Exit 1 ...
#define longExit1BufferIndex 0
double longExit1Buffer[];
//
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_DOT
//
// Short Exit 1 ...
#define shortExit1BufferIndex 1
double shortExit1Buffer[];
//
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color2 clrRed
//
// Long Exit 2 ...
#define longExit2BufferIndex 2
double longExit2Buffer[];
//
#property indicator_type3 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color3 clrAqua
//
// Short Exit 2 ...
#define shortExit2BufferIndex 3
double shortExit2Buffer[];
//
#property indicator_type4 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color4 clrMagenta
//
// START Arrows ...
//
// Long Exit 1 Start ...
#define longExit1StartBufferIndex 4
double longExit1StartBuffer[];
//
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrLime
//
// Short Exit 1 Start ...
#define shortExit1StartBufferIndex 5
double shortExit1StartBuffer[];
//
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrRed
//
// Long Exit 2 Start ...
#define longExit2StartBufferIndex 6
double longExit2StartBuffer[];
//
#property indicator_type7 DRAW_ARROW
#property indicator_color7 clrAqua
//
// Short Exit 2 Start ...
#define shortExit2StartBufferIndex 7
double shortExit2StartBuffer[];
//
#property indicator_type8 DRAW_ARROW
#property indicator_color8 clrMagenta
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
// Working Array ...
double work[][6];
#define hi1Idx 0
#define lo1Idx 1
#define hi2Idx 2
#define lo2Idx 3
#define trend1Idx 4
#define trend2Idx 5
//
// 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 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
}
//
// 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[])
{
//
if (Bars(_Symbol, _Period) < rates_total)
{
return (prev_calculated);
}
//
if (ArrayRange(work, 0) != rates_total)
{
ArrayResize(work, rates_total);
}
//
// 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,
prev_calculated,
rates_total,
//
open,
high,
low,
close);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
result =
length >= 9 &&
loopback >= 0;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(length, loopback);
//
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()
{
//
uint arrowCode = 159;
//
// LEVEL 1 ...
//
// Long Exit 1 ...
//
// Draw Type ...
ENUM_DRAW_TYPE longExit1DrawType = showLongExit1Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE longExit1StartDrawType = showLongExit1Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(longExit1BufferIndex, longExit1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit1BufferIndex, PLOT_SHOW_DATA, showLongExit1Line);
PlotIndexSetInteger(longExit1BufferIndex, PLOT_DRAW_TYPE, longExit1DrawType);
//
// Start Buffer ...
SetIndexBuffer(longExit1StartBufferIndex, longExit1StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_DRAW_TYPE, longExit1StartDrawType);
//
// Short Exit 1 ...
//
// Draw Type ...
ENUM_DRAW_TYPE shortExit1DrawType = showShortExit1Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE shortExit1StartDrawType = showShortExit1Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(shortExit1BufferIndex, shortExit1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_SHOW_DATA, showShortExit1Line);
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_DRAW_TYPE, shortExit1DrawType);
//
// Start Buffer ...
SetIndexBuffer(shortExit1StartBufferIndex, shortExit1StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_DRAW_TYPE, shortExit1StartDrawType);
//
// LEVEL 2 ...
//
// Long Exit 2 ...
//
// Draw Type ...
ENUM_DRAW_TYPE longExit2DrawType = showLongExit2Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE longExit2StartDrawType = showLongExit2Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(longExit2BufferIndex, longExit2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit2BufferIndex, PLOT_SHOW_DATA, showLongExit2Line);
PlotIndexSetInteger(longExit2BufferIndex, PLOT_DRAW_TYPE, longExit2DrawType);
//
// Start Buffer ...
SetIndexBuffer(longExit2StartBufferIndex, longExit2StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_DRAW_TYPE, longExit2StartDrawType);
//
// Short Exit 2 ...
//
// Draw Type ...
ENUM_DRAW_TYPE shortExit2DrawType = showShortExit2Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE shortExit2StartDrawType = showShortExit2Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(shortExit2BufferIndex, shortExit2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_SHOW_DATA, showShortExit2Line);
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_DRAW_TYPE, shortExit2DrawType);
//
// Start Buffer ...
SetIndexBuffer(shortExit2StartBufferIndex, shortExit2StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_DRAW_TYPE, shortExit2StartDrawType);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
int prevCalculated, // Previous Calculated
int ratesTotal, // Total Rates
const double &open[], // Rates Open ...
const double &high[], // Rates High ...
const double &low[], // Rates Low ...
const double &close[] // Rates Close ...
)
{
//
// Cleanup Buffers ...
longExit1Buffer[bar_index] = longExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index] = shortExit1StartBuffer[bar_index] = EMPTY_VALUE;
longExit2Buffer[bar_index] = longExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index] = shortExit2StartBuffer[bar_index] = EMPTY_VALUE;
//
int start = MathMax(bar_index - loopback, 0);
//
// Calculate ATR Value ...
double atrValue = 0;
for (int k = 1; k <= length && (bar_index - k - 1) >= 0; k++)
{
//
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
}
atrValue /= (double)length;
//
// Retrieve Highest High and Lowest Lows ...
double loopbackMax = high[ArrayMaximum(high, start, loopback)];
double loopbackMin = low[ArrayMinimum(low, start, loopback)];
//
// Fill Multi Dimesional Working Array ...
work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue;
work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue;
work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue;
work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue;
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
//
if (bar_index > 0)
{
//
// Calculate Trends ...
if (close[bar_index] > work[bar_index - 1][lo1Idx])
{
work[bar_index][trend1Idx] = 1;
}
//
if (close[bar_index] < work[bar_index - 1][hi1Idx])
{
work[bar_index][trend1Idx] = -1;
}
//
if (close[bar_index] > work[bar_index - 1][lo2Idx])
{
work[bar_index][trend2Idx] = 1;
}
//
if (close[bar_index] < work[bar_index - 1][hi2Idx])
{
work[bar_index][trend2Idx] = -1;
}
//
// Calculate Exit Values ...
//
// Exit 1 ...
//
// Long ...
if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1)
{
//
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
{
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
}
//
longExit1Buffer[bar_index] = work[bar_index][hi1Idx];
//
if (longExit1Buffer[bar_index - 1] == EMPTY_VALUE)
{
longExit1StartBuffer[bar_index] = longExit1Buffer[bar_index];
}
}
//
// Short ...
if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1)
{
//
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
{
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
}
//
shortExit1Buffer[bar_index] = work[bar_index][lo1Idx];
//
if (shortExit1Buffer[bar_index - 1] == EMPTY_VALUE)
{
shortExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index];
}
}
//
// Exit 2 ...
//
// Long ...
if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1)
{
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
{
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
}
//
longExit2Buffer[bar_index] = work[bar_index][hi2Idx];
//
if (longExit2Buffer[bar_index - 1] == EMPTY_VALUE)
{
longExit2StartBuffer[bar_index] = longExit2Buffer[bar_index];
}
}
//
// Short ...
if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1)
{
//
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
{
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
}
//
shortExit2Buffer[bar_index] = work[bar_index][lo2Idx];
//
if (shortExit2Buffer[bar_index - 1] == EMPTY_VALUE)
{
shortExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index];
}
}
}
}
//
// END Functions ...
//
@@ -0,0 +1,214 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCTimer Indicator
// ---------------------------------------------
// Name: XCTimer
// Description: Trend Magic 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 XCTimer Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XCTimer"
//
// END Constants ...
//
//
// START Inputs ...
//
input color clr = clrYellow;
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER;
//
// END Inputs ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
CreateIndicatorObject();
//
// 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
//
// Delete Object ...
ObjectDelete(0, ShortName);
}
//
// 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[])
{
//
ArraySetAsSeries(time, true);
//
int m = int(time[0] + PeriodSeconds() - TimeCurrent());
int s = m % 60;
m = (m - s) / 60;
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp = "", _m = "", _s = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
if (m < 10)
_m = "0";
if (s < 10)
_s = "0";
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in " + _m + IntegerToString(m) + ":" + _s + IntegerToString(s);
//
ObjectSetInteger(0, ShortName, OBJPROP_COLOR, clr);
ObjectSetString(0, ShortName, OBJPROP_TEXT, objText);
ObjectSetInteger(0, ShortName, OBJPROP_FONTSIZE, 10);
ObjectSetString(0, ShortName, OBJPROP_FONT, "Courier");
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
void CreateIndicatorObject()
{
//
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
switch (corner)
{
case CORNER_LEFT_UPPER:
Anchor = ANCHOR_LEFT_UPPER;
break;
case CORNER_RIGHT_UPPER:
Anchor = ANCHOR_RIGHT_UPPER;
break;
case CORNER_LEFT_LOWER:
Anchor = ANCHOR_LEFT_LOWER;
break;
case CORNER_RIGHT_LOWER:
Anchor = ANCHOR_RIGHT_LOWER;
break;
}
//
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
}
//
// END Functions ...
//
@@ -0,0 +1,500 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_HK HikenAshi Candles
// ---------------------------------------------------
// Name: X121_HK
// Description: Hiken Ashi ...
// 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_HK Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_HK"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Presentation";
input bool drawCandles = true; // Draw Hiken Ashi Candle
input bool drawCandleLines = false; // Show HikenAshi Lines
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.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 13
#property indicator_plots 5
//
// PLOTTED Buffers ...
//
// Open ...
#define openBufferIndex 0
double openBuffer[];
//
// High ...
#define highBufferIndex 1
double highBuffer[];
//
// Low ...
#define lowBufferIndex 2
double lowBuffer[];
//
// Close ...
#define closeBufferIndex 3
double closeBuffer[];
//
// Candle Color ...
#define candleColorBufferIndex 4
double candleColorBuffer[];
//
#define candlesBufferIndex 0
//
#property indicator_label1 "X121_HK Open;X121_HK High;X121_HK Low;X121_HK Close"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrAqua, clrMagenta, CLR_NONE
//
#define openHKBufferIndex 5
#define openHKColorBufferIndex 6
double openHKBuffer[];
double openHKColorBuffer[];
//
#define openHKBufferPlotIndex 1
#property indicator_label2 "X121_HK O"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrAqua, clrMagenta, clrLightGray
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
#define highHKBufferIndex 7
#define highHKColorBufferIndex 8
double highHKBuffer[];
double highHKColorBuffer[];
//
#define highHKBufferPlotIndex 2
#property indicator_label3 "X121_HK H"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrAqua, clrMagenta, clrLightGray
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define lowHKBufferIndex 9
#define lowHKColorBufferIndex 10
double lowHKBuffer[];
double lowHKColorBuffer[];
//
#define lowHKBufferPlotIndex 3
#property indicator_label4 "X121_HK L"
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_color4 clrAqua, clrMagenta, clrLightGray
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
#define closeHKBufferIndex 11
#define closeHKColorBufferIndex 12
double closeHKBuffer[];
double closeHKColorBuffer[];
//
#define closeHKBufferPlotIndex 4
#property indicator_label5 "X121_HK C"
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_color5 clrAqua, clrMagenta, clrLightGray
#property indicator_style5 STYLE_DOT
#property indicator_width5 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;
}
//
logTag = 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();
//
// 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
}
//
// 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;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i, prev_calculated, rates_total, open, high, close, low);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Candles Color ...
ArraySetAsSeries(candleColorBuffer, true);
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
//
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(candleColorBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openBuffer, true);
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, false);
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highBuffer, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
//
// Close ...
ArraySetAsSeries(closeBuffer, true);
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, false);
//
// Low ...
ArraySetAsSeries(lowBuffer, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
//
// Open HK ...
ENUM_DRAW_TYPE openDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(openHKBuffer, true);
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_DRAW_TYPE, openDrawType);
//
ArraySetAsSeries(openHKColorBuffer, true);
SetIndexBuffer(openHKColorBufferIndex, openHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// High HK ...
ENUM_DRAW_TYPE highDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(highHKBuffer, true);
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_DRAW_TYPE, highDrawType);
//
ArraySetAsSeries(highHKColorBuffer, true);
SetIndexBuffer(highHKColorBufferIndex, highHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// Low HK ...
ENUM_DRAW_TYPE lowDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(lowHKBuffer, true);
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_DRAW_TYPE, lowDrawType);
//
ArraySetAsSeries(lowHKColorBuffer, true);
SetIndexBuffer(lowHKColorBufferIndex, lowHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// Close HK ...
ENUM_DRAW_TYPE closeDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(closeHKBuffer, true);
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_DRAW_TYPE, closeDrawType);
//
ArraySetAsSeries(closeHKColorBuffer, true);
SetIndexBuffer(closeHKColorBufferIndex, closeHKColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// 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
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[])
{
//
double mPrevHKOpenValue;
double mPrevHKCloseValue;
//
if (ArraySize(open) <= bar_index + 1)
{
//
mPrevHKOpenValue = 0;
mPrevHKCloseValue = 0;
}
else
{
//
mPrevHKOpenValue = openBuffer[bar_index + 1];
mPrevHKCloseValue = closeBuffer[bar_index + 1];
}
//
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
//
openBuffer[bar_index] = mHKOpenValue;
highBuffer[bar_index] = mHKHighValue;
lowBuffer[bar_index] = mHKLowValue;
closeBuffer[bar_index] = mHKCloseValue;
//
double candleColorValue =
mHKOpenValue < mHKCloseValue ? 0 : 1;
//
candleColorBuffer[bar_index] = drawCandles ? candleColorValue : 2;
//
openHKBuffer[bar_index] = mHKOpenValue;
openHKColorBuffer[bar_index] = candleColorValue;
//
highHKBuffer[bar_index] = mHKHighValue;
highHKColorBuffer[bar_index] = candleColorValue;
//
lowHKBuffer[bar_index] = mHKLowValue;
lowHKColorBuffer[bar_index] = candleColorValue;
//
closeHKBuffer[bar_index] = mHKCloseValue;
closeHKColorBuffer[bar_index] = candleColorValue;
}
//
// END Functions ...
//
@@ -0,0 +1,587 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XHULL Indicator
// ---------------------------------------------
// Name: XHULL
// Description: Hull 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 XHull Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "XHULL"
//
// END Constants ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.models.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START XSCHULL Class Definition ...
//
//
// a Class For Hull Calculations ...
class XSCHull
{
//
public:
//
// Constructor ...
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
{
//
// These are a way above to assign Private variables at Construct time ...
}
//
// Deconstructor ...
~XSCHull()
{
ArrayFree(mData);
}
//
// Initial Hull ...
bool Init(
int mPeriod,
double mDivisor)
{
//
bool result = false;
//
mFullPeriod = (int)(mPeriod > 1 ? mPeriod : 1);
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (mDivisor > 1 ? mDivisor : 1) : 1);
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
//
mArraySize = -1;
mWeight1 = mWeight2 = mWeight3 = 1;
//
result = true;
//
return result;
}
//
// CalCulate Specific Value ...
double Calculate(
double value,
int i,
int bars)
{
//
double result = 0;
//
if (mArraySize < bars)
{
//
mArraySize = ArrayResize(mData, bars + 500);
if (mArraySize < bars)
return result;
}
//
mData[i].value = value;
if (i > mFullPeriod)
{
//
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
}
else
{
//
mData[i].wsum1 = mData[i].wsum2 =
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
{
//
if (w1 > 0)
{
//
mData[i].wsum1 += mData[i - k].value * w1;
mData[i].lsum1 += mData[i - k].value;
mWeight1 += w1;
}
//
mData[i].wsum2 += mData[i - k].value * w2;
mData[i].lsum2 += mData[i - k].value;
mWeight2 += w2;
}
}
//
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
//
if (i > mSqrtPeriod)
{
//
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
}
else
{
//
mData[i].wsum3 =
mData[i].lsum3 = mWeight3 = 0;
//
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
{
//
mData[i].wsum3 += mData[i - k].value3 * w3;
mData[i].lsum3 += mData[i - k].value3;
mWeight3 += w3;
}
}
//
result = mData[i].wsum3 / mWeight3;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
int mFullPeriod;
int mHalfPeriod;
int mSqrtPeriod;
int mArraySize;
double mWeight1;
double mWeight2;
double mWeight3;
//
XHullData mData[];
};
//
// END XSCHULL Class Definition ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 72; // Length
input double divisor = 2.0; // Divisor (Speed)
//
input group "Calculation";
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
//
input group "Presentation";
input bool showUpZone = true; // Show Up Zone
input bool showDownZone = true; // Show Down Zone
//
// END Inputs ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 4
#property indicator_plots 4
//
// UP Zone ...
//
#define upZoneBufferIndex 0
#define upZoneColorBufferIndex 1
//
double upZoneBuffer[];
double upZoneColorBuffer[];
//
#property indicator_label1 "XHULL Up"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLightGray, clrAqua, clrMagenta
#property indicator_width1 1
//
// DOWN Zone ...
//
#define downZoneBufferIndex 2
#define downZoneColorBufferIndex 3
//
double downZoneBuffer[];
double downZoneColorBuffer[];
//
#property indicator_label2 "XHULL Down"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrLightGray, clrAqua, clrMagenta
#property indicator_width2 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
XSCHull *mUpZHull;
XSCHull *mDownZHull;
//
// 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();
//
// Make an Instance of Hull Class ...
//
mUpZHull = new XSCHull();
mUpZHull.Init(
length,
divisor);
//
mDownZHull = new XSCHull();
mDownZHull.Init(
length,
divisor);
//
// 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
//
delete mUpZHull;
delete mDownZHull;
}
//
// 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[])
{
//
// 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++)
{
//
double upPrice = getPrice(
upAppliedTo,
open, high, low, close, i);
//
double downPrice = getPrice(
downAppliedTo,
open, high, low, close, i);
//
CalculateBuffers(
i,
rates_total,
upPrice,
downPrice);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
result =
length >= 9 &&
divisor >= 0.5;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
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()
{
//
// UP Zone ...
//
// Draw Type ...
ENUM_DRAW_TYPE upZoneDrawType = showUpZone ? DRAW_COLOR_LINE : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(upZoneBufferIndex, upZoneBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upZoneBufferIndex, PLOT_SHOW_DATA, showUpZone);
PlotIndexSetInteger(upZoneBufferIndex, PLOT_DRAW_TYPE, upZoneDrawType);
//
// Color Buffer ...
SetIndexBuffer(upZoneColorBufferIndex, upZoneColorBuffer, INDICATOR_COLOR_INDEX);
//
// DOWN Zone ...
//
// Draw Type ...
ENUM_DRAW_TYPE downZoneDrawType = showDownZone ? DRAW_COLOR_LINE : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(downZoneBufferIndex, downZoneBuffer, INDICATOR_DATA);
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_SHOW_DATA, showDownZone);
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_DRAW_TYPE, downZoneDrawType);
//
// Color Buffer ...
SetIndexBuffer(downZoneColorBufferIndex, downZoneColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
int ratesTotal, // Total Rates
double upPrice, // Up Price ...
double downPrice // Down Price ...
)
{
//
double upValue = mUpZHull.Calculate(
upPrice,
bar_index,
ratesTotal);
upZoneBuffer[bar_index] = upValue;
double upColorIDX = (bar_index > 0)
? (upZoneBuffer[bar_index] > upZoneBuffer[bar_index - 1])
? 1
: (upZoneBuffer[bar_index] < upZoneBuffer[bar_index - 1])
? 2
: upZoneColorBuffer[bar_index - 1]
: 0;
upZoneColorBuffer[bar_index] = upColorIDX;
//
double downValue = mDownZHull.Calculate(
downPrice,
bar_index,
ratesTotal);
downZoneBuffer[bar_index] = downValue;
double downColorIDX = (bar_index > 0)
? (downZoneBuffer[bar_index] > downZoneBuffer[bar_index - 1])
? 1
: (downZoneBuffer[bar_index] < downZoneBuffer[bar_index - 1])
? 2
: downZoneColorBuffer[bar_index - 1]
: 0;
downZoneColorBuffer[bar_index] = downColorIDX;
}
//
// END Functions ...
//
template <typename T>
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
{
switch (tprice)
{
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);
}
return (0);
}
@@ -0,0 +1,895 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_ICH Ichimoku
// -------------------------------------------------
// Name: X121_ICH
// Description:
// 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_ICH Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_ICH"
//
// 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 Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// 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 Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 8
//
// PLOTTED Buffers ...
//
// ICHIMOKU ...
//
// TENKANSEN ...
//
#define tenkanSenBufferIndex 0
double tenkanSenBuffer[];
//
#property indicator_label1 "X121_ICH Tenkan Sen"
#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_ICH Kijun Sen"
#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_ICH Kijun Sen +"
#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_ICH Kijun Sen -"
#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_ICH Chikou Span"
#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_ICH Senkou Span A"
#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_ICH Senkou Span B"
#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_ICH Kumo"
#property indicator_type8 DRAW_FILLING
#property indicator_color8 clrAqua, clrMagenta
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
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;
}
//
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();
//
// 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
//
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;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// 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 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;
//
// 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);
}
//
// 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
)
{
//
// 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;
//
return;
if (ArraySize(senkouABuffer) > bar_index + kijunSenLength + 1)
{
//
// Detect Koumo Switch ...
bool isKumoSwitchBullish =
//
senkouABuffer[bar_index + kijunSenLength] > senkouBBuffer[bar_index + kijunSenLength] &&
senkouABuffer[bar_index + kijunSenLength + 1] <= senkouBBuffer[bar_index + kijunSenLength + 1]
//
;
//
// Detect Koumo Switch ...
bool isKumoSwitchBearish =
//
senkouABuffer[bar_index + kijunSenLength] < senkouBBuffer[bar_index + kijunSenLength] &&
senkouABuffer[bar_index + kijunSenLength + 1] >= senkouBBuffer[bar_index + kijunSenLength + 1]
//
;
//
datetime time = iTime(
_Symbol,
_Period,
bar_index);
//
long chartID = ChartID();
//
if (isKumoSwitchBullish)
{
//
string vlName = "Kumo_Switch_Bullish_NOW" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrAqua,
STYLE_DASHDOT);
}
//
if (isKumoSwitchBearish)
{
//
string vlName = "Kumo_Switch_Bearish_NOW" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrMagenta,
STYLE_DASHDOT);
}
}
//
return;
if (ArraySize(senkouABuffer) > bar_index + 1)
{
//
// Detect Koumo Switch ...
bool isKumoSwitchBullish =
//
senkouABuffer[bar_index] > senkouBBuffer[bar_index] &&
senkouABuffer[bar_index + 1] <= senkouBBuffer[bar_index + 1]
//
;
//
// Detect Koumo Switch ...
bool isKumoSwitchBearish =
//
senkouABuffer[bar_index] < senkouBBuffer[bar_index] &&
senkouABuffer[bar_index + 1] >= senkouBBuffer[bar_index + 1]
//
;
//
datetime time = iTime(
_Symbol,
_Period,
bar_index);
//
long chartID = ChartID();
//
if (isKumoSwitchBullish)
{
//
string vlName = "Kumo_Switch_Bullish_FUTURE" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrAqua,
STYLE_DASHDOT);
}
//
if (isKumoSwitchBearish)
{
//
string vlName = "Kumo_Switch_Bearish_FUTURE" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrMagenta,
STYLE_DASHDOT);
}
}
}
//
// END Functions ...
//
@@ -0,0 +1,469 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_MC MA Cross Indicator
// ---------------------------------------------------
// Name: X121_MC
// Description: Moving Average Crosses
// 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_MC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_MC"
//
// END Constants ...
//
//
// START Inputs ...
//
//
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
//
input group "Verifier";
input int verifierMaLength = 50; // Length
input int verifierMaShift = 0; // Shift
input ENUM_MA_METHOD verifierMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE verifierMaAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Presentation";
input bool showFastMa = true; // Show Fast
input bool showSlowMa = true; // Show Slow
input bool showVerifierMa = true; // Show Verifier
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.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 3
#property indicator_plots 3
//
// PLOTTED Buffers ...
//
// MA ...
//
// FAST ...
#define fastMaBufferIndex 0
double fastMaBuffer[];
//
#property indicator_label1 "X121_MC MA F"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// SLOW ...
#define slowMaBufferIndex 1
double slowMaBuffer[];
//
#property indicator_label2 "X121_MC MA S"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDarkOrange
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// VERIFIER ...
#define verifierMaBufferIndex 2
double verifierMaBuffer[];
//
#property indicator_label3 "X121_MC MA V"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrDarkBlue
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int fastMaHandler = INVALID_HANDLE;
int slowMaHandler = INVALID_HANDLE;
int verifierMaHandler = 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;
//
// 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;
}
//
// VERIFIER ...
verifierMaHandler = iMA(
_Symbol,
_Period,
verifierMaLength,
verifierMaShift,
verifierMaMethod,
verifierMaAppliedTo);
if (verifierMaHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
return INIT_FAILED;
}
//
// 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);
IndicatorRelease(verifierMaHandler);
}
//
// 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);
int verifierMaCalculatedBars = BarsCalculated(verifierMaHandler);
if (fastMaCalculatedBars < maxLength ||
slowMaCalculatedBars < maxLength ||
verifierMaCalculatedBars < 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);
int copiedVerifierMas = CopyBuffer(verifierMaHandler, 0, 0, limit, verifierMaBuffer);
if (copiedFastMas <= 0 ||
copiedSlowMas <= 0 ||
copiedVerifierMas <= 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 Ma ...
(fastMaLength > 2 &&
slowMaLength > fastMaLength &&
verifierMaLength > slowMaLength)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Ma ...
result = MathMax(result, fastMaLength);
result = MathMax(result, slowMaLength);
result = MathMax(result, verifierMaLength);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// MA ...
//
// FAST ...
ENUM_DRAW_TYPE fastMaDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(fastMaBuffer, true);
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastMaDrawType);
//
// SLOW ...
ENUM_DRAW_TYPE slowMaDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(slowMaBuffer, true);
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowMaDrawType);
//
// VERIFIER ...
ENUM_DRAW_TYPE verifierMaDrawType = showVerifierMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(verifierMaBuffer, true);
SetIndexBuffer(verifierMaBufferIndex, verifierMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_TYPE, verifierMaDrawType);
}
//
// 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
)
{
}
//
// END Functions ...
//
@@ -0,0 +1,802 @@
/////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_MRB MA Ribbon Indicator
// -----------------------------------------------------
// Name: X121_MRB
// Description: Moving Average Ribbon
// 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_MRB Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_MRB"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Ribbon 1";
input int fast1Length = 3; // Fast
input int slow1Length = 5; // Slow
//
input group "Ribbon 2";
input int fast2Length = 8; // Fast
input int slow2Length = 13; // Slow
//
input group "Ribbon 3";
input int fast3Length = 21; // Fast
input int slow3Length = 34; // Slow
//
input group "Ribbon 4";
input int fast4Length = 55; // Fast
input int slow4Length = 89; // Slow
//
input group "Ribbon 5";
input int fast5Length = 144; // Fast
input int slow5Length = 233; // Slow
//
input group "Calculation Mode";
input ENUM_MA_METHOD ribbonMode = MODE_EMA; // Calculation Mode
input ENUM_APPLIED_PRICE ribbonAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Presentation";
input bool showFastMa = true; // Show Fast
input bool showSlowMa = true; // Show Slow
input bool showRibbon = false; // Show Ribbon
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.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 12
#property indicator_plots 12
//
// PLOTTED Buffers ...
//
// MA ...
//
// FAST ...
#define fastMaBufferIndex 0
double fastMaBuffer[];
//
#property indicator_label1 "X121_MRB F"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// SLOW ...
#define slowMaBufferIndex 1
double slowMaBuffer[];
//
#property indicator_label2 "X121_MRB S"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// DATA Buffers ...
//
// FAST ...
//
#define fast1BufferIndex 2
double fast1Buffer[];
//
#property indicator_label3 "X121_MRB 1 F"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrAquamarine
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define fast2BufferIndex 3
double fast2Buffer[];
//
#property indicator_label4 "X121_MRB 2 F"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrAquamarine
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
#define fast3BufferIndex 4
double fast3Buffer[];
//
#property indicator_label5 "X121_MRB 3 F"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrAquamarine
#property indicator_style5 STYLE_DOT
#property indicator_width5 1
//
#define fast4BufferIndex 5
double fast4Buffer[];
//
#property indicator_label6 "X121_MRB 4 F"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrAquamarine
#property indicator_style6 STYLE_DOT
#property indicator_width6 1
//
#define fast5BufferIndex 6
double fast5Buffer[];
//
#property indicator_label7 "X121_MRB 5 F"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrAquamarine
#property indicator_style7 STYLE_DOT
#property indicator_width7 1
//
// SLOW ...
//
#define slow1BufferIndex 7
double slow1Buffer[];
//
#property indicator_label8 "X121_MRB 1 S"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrPlum
#property indicator_style8 STYLE_DOT
#property indicator_width8 1
//
#define slow2BufferIndex 8
double slow2Buffer[];
//
#property indicator_label9 "X121_MRB 2 S"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrPlum
#property indicator_style9 STYLE_DOT
#property indicator_width9 1
//
#define slow3BufferIndex 9
double slow3Buffer[];
//
#property indicator_label10 "X121_MRB 3 S"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrPlum
#property indicator_style10 STYLE_DOT
#property indicator_width10 1
//
#define slow4BufferIndex 10
double slow4Buffer[];
//
#property indicator_label11 "X121_MRB 4 S"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrPlum
#property indicator_style11 STYLE_DOT
#property indicator_width11 1
//
#define slow5BufferIndex 11
double slow5Buffer[];
//
#property indicator_label12 "X121_MRB 5 S"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrPlum
#property indicator_style12 STYLE_DOT
#property indicator_width12 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int fast1MaHandler = INVALID_HANDLE;
int fast2MaHandler = INVALID_HANDLE;
int fast3MaHandler = INVALID_HANDLE;
int fast4MaHandler = INVALID_HANDLE;
int fast5MaHandler = INVALID_HANDLE;
//
int slow1MaHandler = INVALID_HANDLE;
int slow2MaHandler = INVALID_HANDLE;
int slow3MaHandler = INVALID_HANDLE;
int slow4MaHandler = INVALID_HANDLE;
int slow5MaHandler = 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;
//
// 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();
//
// Initialize MAs ...
if (!InitializeMas())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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(fast1MaHandler);
IndicatorRelease(fast2MaHandler);
IndicatorRelease(fast3MaHandler);
IndicatorRelease(fast4MaHandler);
IndicatorRelease(fast5MaHandler);
//
IndicatorRelease(slow1MaHandler);
IndicatorRelease(slow2MaHandler);
IndicatorRelease(slow3MaHandler);
IndicatorRelease(slow4MaHandler);
IndicatorRelease(slow5MaHandler);
}
//
// 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 fast1MaCalculatedBars = BarsCalculated(fast1MaHandler);
int fast2MaCalculatedBars = BarsCalculated(fast2MaHandler);
int fast3MaCalculatedBars = BarsCalculated(fast3MaHandler);
int fast4MaCalculatedBars = BarsCalculated(fast4MaHandler);
int fast5MaCalculatedBars = BarsCalculated(fast5MaHandler);
//
int slow1MaCalculatedBars = BarsCalculated(slow1MaHandler);
int slow2MaCalculatedBars = BarsCalculated(slow2MaHandler);
int slow3MaCalculatedBars = BarsCalculated(slow3MaHandler);
int slow4MaCalculatedBars = BarsCalculated(slow4MaHandler);
int slow5MaCalculatedBars = BarsCalculated(slow5MaHandler);
if (
fast1MaCalculatedBars < maxLength ||
fast2MaCalculatedBars < maxLength ||
fast3MaCalculatedBars < maxLength ||
fast4MaCalculatedBars < maxLength ||
fast5MaCalculatedBars < maxLength ||
slow1MaCalculatedBars < maxLength ||
slow2MaCalculatedBars < maxLength ||
slow3MaCalculatedBars < maxLength ||
slow4MaCalculatedBars < maxLength ||
slow5MaCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
int copiedFast1Mas = CopyBuffer(fast1MaHandler, 0, 0, limit, fast1Buffer);
int copiedFast2Mas = CopyBuffer(fast2MaHandler, 0, 0, limit, fast2Buffer);
int copiedFast3Mas = CopyBuffer(fast3MaHandler, 0, 0, limit, fast3Buffer);
int copiedFast4Mas = CopyBuffer(fast4MaHandler, 0, 0, limit, fast4Buffer);
int copiedFast5Mas = CopyBuffer(fast5MaHandler, 0, 0, limit, fast5Buffer);
//
int copiedSlow1Mas = CopyBuffer(slow1MaHandler, 0, 0, limit, slow1Buffer);
int copiedSlow2Mas = CopyBuffer(slow2MaHandler, 0, 0, limit, slow2Buffer);
int copiedSlow3Mas = CopyBuffer(slow3MaHandler, 0, 0, limit, slow3Buffer);
int copiedSlow4Mas = CopyBuffer(slow4MaHandler, 0, 0, limit, slow4Buffer);
int copiedSlow5Mas = CopyBuffer(slow5MaHandler, 0, 0, limit, slow5Buffer);
if (
copiedFast1Mas <= 0 ||
copiedFast2Mas <= 0 ||
copiedFast3Mas <= 0 ||
copiedFast4Mas <= 0 ||
copiedFast5Mas <= 0 ||
copiedSlow1Mas <= 0 ||
copiedSlow2Mas <= 0 ||
copiedSlow3Mas <= 0 ||
copiedSlow4Mas <= 0 ||
copiedSlow5Mas <= 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 Ma ...
(fast1Length > 2 &&
fast2Length > fast1Length &&
fast3Length > fast2Length &&
fast4Length > fast3Length &&
fast5Length > fast4Length &&
slow1Length > fast1Length &&
slow2Length > fast2Length &&
slow3Length > fast3Length &&
slow4Length > fast4Length &&
slow5Length > fast5Length &&
slow2Length > slow1Length &&
slow3Length > slow2Length &&
slow4Length > slow3Length &&
slow5Length > slow4Length
//
)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Ma ...
//
result = MathMax(fast1Length, fast2Length);
result = MathMax(result, fast3Length);
result = MathMax(result, fast4Length);
result = MathMax(result, fast5Length);
//
result = MathMax(result, slow1Length);
result = MathMax(result, slow2Length);
result = MathMax(result, slow3Length);
result = MathMax(result, slow4Length);
result = MathMax(result, slow5Length);
//
return result;
}
//
// Initialize Ma Handlers ...
bool InitializeMas()
{
//
bool result = false;
//
fast1MaHandler = iMA(
_Symbol,
_Period,
fast1Length,
0,
ribbonMode,
ribbonAppliedTo);
fast2MaHandler = iMA(
_Symbol,
_Period,
fast2Length,
0,
ribbonMode,
ribbonAppliedTo);
fast3MaHandler = iMA(
_Symbol,
_Period,
fast3Length,
0,
ribbonMode,
ribbonAppliedTo);
fast4MaHandler = iMA(
_Symbol,
_Period,
fast4Length,
0,
ribbonMode,
ribbonAppliedTo);
fast5MaHandler = iMA(
_Symbol,
_Period,
fast5Length,
0,
ribbonMode,
ribbonAppliedTo);
//
slow1MaHandler = iMA(
_Symbol,
_Period,
slow1Length,
0,
ribbonMode,
ribbonAppliedTo);
slow2MaHandler = iMA(
_Symbol,
_Period,
slow2Length,
0,
ribbonMode,
ribbonAppliedTo);
slow3MaHandler = iMA(
_Symbol,
_Period,
slow3Length,
0,
ribbonMode,
ribbonAppliedTo);
slow4MaHandler = iMA(
_Symbol,
_Period,
slow4Length,
0,
ribbonMode,
ribbonAppliedTo);
slow5MaHandler = iMA(
_Symbol,
_Period,
slow5Length,
0,
ribbonMode,
ribbonAppliedTo);
//
result =
fast1MaHandler != INVALID_HANDLE &&
fast2MaHandler != INVALID_HANDLE &&
fast3MaHandler != INVALID_HANDLE &&
fast4MaHandler != INVALID_HANDLE &&
fast5MaHandler != INVALID_HANDLE &&
slow1MaHandler != INVALID_HANDLE &&
slow2MaHandler != INVALID_HANDLE &&
slow3MaHandler != INVALID_HANDLE &&
slow4MaHandler != INVALID_HANDLE &&
slow5MaHandler != INVALID_HANDLE;
//
if (!result)
{
//
string message = "Error Initializing Handlers ...";
LogMessage(message);
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// FAST ...
ENUM_DRAW_TYPE fastDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(fastMaBuffer, true);
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
//
// SLOW ...
ENUM_DRAW_TYPE slowDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(slowMaBuffer, true);
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
//
// DATA ...
ENUM_DRAW_TYPE ribbonDrawType = showRibbon ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(fast1Buffer, true);
SetIndexBuffer(fast1BufferIndex, fast1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast1BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast2Buffer, true);
SetIndexBuffer(fast2BufferIndex, fast2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast2BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast3Buffer, true);
SetIndexBuffer(fast3BufferIndex, fast3Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast3BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast4Buffer, true);
SetIndexBuffer(fast4BufferIndex, fast4Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast4BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast5Buffer, true);
SetIndexBuffer(fast5BufferIndex, fast5Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast5BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow1Buffer, true);
SetIndexBuffer(slow1BufferIndex, slow1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow1BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow2Buffer, true);
SetIndexBuffer(slow2BufferIndex, slow2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow2BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow3Buffer, true);
SetIndexBuffer(slow3BufferIndex, slow3Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow3BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow4Buffer, true);
SetIndexBuffer(slow4BufferIndex, slow4Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow4BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow5Buffer, true);
SetIndexBuffer(slow5BufferIndex, slow5Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow5BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
}
//
// 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
)
{
//
// Retireve Values ...
//
double fast1Value = fast1Buffer[bar_index];
double fast2Value = fast2Buffer[bar_index];
double fast3Value = fast3Buffer[bar_index];
double fast4Value = fast4Buffer[bar_index];
double fast5Value = fast5Buffer[bar_index];
//
double slow1Value = slow1Buffer[bar_index];
double slow2Value = slow2Buffer[bar_index];
double slow3Value = slow3Buffer[bar_index];
double slow4Value = slow4Buffer[bar_index];
double slow5Value = slow5Buffer[bar_index];
//
double fastValue = (fast1Value + fast2Value + fast3Value + fast4Value + fast5Value) / 5;
fastMaBuffer[bar_index] = fastValue;
//
double slowValue = (slow1Value + slow2Value + slow3Value + slow4Value + slow5Value) / 5;
slowMaBuffer[bar_index] = slowValue;
}
//
// END Functions ...
//
@@ -0,0 +1,453 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_SSLC SSL Channel
// ----------------------------------------------------
// Name: X121_SSLC
// Description: SSL Channel Indicator
// 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_SSLC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_SSLC"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 30; // Length
//
input group "Calculation";
input ENUM_MA_METHOD method = MODE_SMA; // Method
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Applied To
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Applied To
//
input group "Presentation";
input bool showUp = true; // Show Up
input bool showDown = true; // Show Down
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.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 5
#property indicator_plots 2
//
// PLOTTED Buffers ...
//
#define upBufferIndex 0
double upBuffer[];
//
#property indicator_label1 "X121_SSLC Up"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#define downBufferIndex 1
double downBuffer[];
//
#property indicator_label2 "X121_SSLC Down"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// DATA Buffers ...
//
#define upMaBufferIndex 2
double upMaBuffer[];
//
#define downMaBufferIndex 3
double downMaBuffer[];
//
#define kpiBufferIndex 4
double kpiBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int upHandler = INVALID_HANDLE;
int downHandler = 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;
//
// 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();
//
// Initialize Requierd Handlers ...
upHandler = iMA(
_Symbol,
_Period,
length,
0,
method,
upAppliedTo);
downHandler = iMA(
_Symbol,
_Period,
length,
0,
method,
downAppliedTo);
if (upHandler == INVALID_HANDLE || downHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
return INIT_FAILED;
}
//
// 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
//
// Release Indicators ...
IndicatorRelease(upHandler);
IndicatorRelease(downHandler);
}
//
// 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 upCalculatedBars = BarsCalculated(upHandler);
int downCalculatedBars = BarsCalculated(downHandler);
if (upCalculatedBars < maxLength ||
downCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedUps = CopyBuffer(upHandler, 0, 0, limit, upMaBuffer);
int copiedDowns = CopyBuffer(downHandler, 0, 0, limit, downMaBuffer);
if (copiedUps <= 0 ||
copiedDowns <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i, limit, rates_total, prev_calculated, close);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
// Validate Inputs ...
(length > 2)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(result, length);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// UP ...
//
ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(upBuffer, true);
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType);
//
// DOWN ...
//
ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(downBuffer, true);
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA);
PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_TYPE, downDrawType);
//
// DATA Buffers ...
//
// UP MA ...
ArraySetAsSeries(upMaBuffer, true);
SetIndexBuffer(upMaBufferIndex, upMaBuffer, INDICATOR_CALCULATIONS);
//
// DOWN MA ...
ArraySetAsSeries(downMaBuffer, true);
SetIndexBuffer(downMaBufferIndex, downMaBuffer, INDICATOR_CALCULATIONS);
//
// KPI ...
ArraySetAsSeries(kpiBuffer, true);
SetIndexBuffer(kpiBufferIndex, kpiBuffer, 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
int limit,
int ratesTotal,
int prevCalculated,
const double &close[])
{
//
double upMaValue = upMaBuffer[bar_index];
double downMaValue = downMaBuffer[bar_index];
//
double closeValue = close[bar_index];
//
double kpiValue;
if (closeValue > upMaValue) {
kpiValue = 1;
} else if (closeValue < downMaValue) {
kpiValue = -1;
} else {
kpiValue = kpiBuffer[bar_index + 1];
}
//
kpiBuffer[bar_index] = kpiValue;
//
double upValue = kpiValue < 0 ? downMaValue : upMaValue;
upBuffer[bar_index] = upValue;
//
double downValue = kpiValue < 0 ? upMaValue : downMaValue;
downBuffer[bar_index] = downValue;
}
//
// END Functions ...
//
@@ -0,0 +1,355 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XTM
// Description: Trend Magic 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_XTM Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "X121_XTM"
//
// XTM Indicator States ...
enum ENUM_X_XTM_STATES
{
X_XTM_BULLISH = 0,
X_XTM_BEARISH = 2,
X_XTM_NEUTURAL = 1,
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Makret";
input int length = 35; // Length
input int shift = 0; // Shift
//
input group "Calculations";
input ENUM_MA_METHOD method = MODE_SMA; // Method
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
//
input group "Presentation";
input bool showLine = true; // Show Line
//
// END Inputs ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 2
#property indicator_plots 2
//
// maBuffer ...
#define maBufferIndex 0
double maBuffer[];
#define maColorBufferIndex 1
double maColorBuffer[];
//
#property indicator_label1 "X121 XTM"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLime, clrGray, clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int maHandler = INVALID_HANDLE;
//
// 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();
//
// Initializing MA Handler ...
maHandler = iMA(
_Symbol,
_Period,
length,
shift,
method,
appliedTo);
if (maHandler == INVALID_HANDLE)
{
//
string message = "Error Initializing Ma Handler ...";
Print(message);
//
return INIT_FAILED;
}
//
// 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
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(maHandler);
}
//
// 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 maCalculatedBars = BarsCalculated(maHandler);
if (maCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
if (copiedMas <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Do Buffers Calculation ...
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (length >= 2)
{
result = true;
}
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = length;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
//
// Ma Buffer ...
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
//
// Ma Color Buffer ...
ArraySetAsSeries(maColorBuffer, true);
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(int bar_index)
{
//
// Requirements ...
XOHCL candle = GetCandle(bar_index);
//
double maValue = maBuffer[bar_index];
//
double lineColorIndex =
maValue < candle.low ? 0 : maValue > candle.high ? 2
: 1;
//
// Set Ma Buffer Color Index ...
maColorBuffer[bar_index] = lineColorIndex;
}
//
// END Functions ...
//