This commit is contained in:
2024-12-19 04:20:54 +03:30
parent 2a3138402d
commit 00d93a36d6
30 changed files with 1678 additions and 56620 deletions
@@ -1,394 +0,0 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: X3MA
// Description: X3MA Trend Detector ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X3MA Indicator"
#property strict
//
#define ShortName "X3MA"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int fastLength = 50; // Fast Length
input int midLength = 100; // Mid Length
input int slowLength = 200; // Slow Length
input int shiftLength = 0; // Shift
input ENUM_MA_METHOD method = MODE_SMA; // Mode
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
//
// Parts ...
input bool showFast = true; // Show Fast
input bool showMid = true; // Show Mid
input bool showSlow = true; // Show Slow
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 3
//
// Current ...
//
// Fast ...
#define fastBufferIndex 0
double fastBuffer[];
//
#property indicator_label1 "X3MA F"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// Mid ...
#define midBufferIndex 1
double midBuffer[];
//
#property indicator_label2 "X3MA M"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrOrange
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
// Slow ...
#define slowBufferIndex 2
double slowBuffer[];
//
#property indicator_label3 "X3MA S"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrMagenta
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// Variables ...
//
int maxLength;
//
// Handlers ...
int fastHandler = INVALID_HANDLE;
int midHandler = INVALID_HANDLE;
int slowHandler = INVALID_HANDLE;
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitHandlers())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Release Handlers ...
IndicatorRelease(fastHandler);
IndicatorRelease(midHandler);
IndicatorRelease(slowHandler);
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(low, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(close, true);
//
// this counts Available Bars ...
int limit;
//
// Validate Calculated Bars ...
bool isPassedRequiredCalculatedBars =
//
BarsCalculated(fastHandler) >= maxLength &&
BarsCalculated(midHandler) >= maxLength &&
BarsCalculated(slowHandler) >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit =
(prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
int copiedFasts = CopyBuffer(fastHandler, 0, 0, limit, fastBuffer);
int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer);
int copiedSlows = CopyBuffer(slowHandler, 0, 0, limit, slowBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
copiedFasts > 0 &&
copiedMids > 0 &&
copiedSlows > 0
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
fastLength > 2 &&
midLength > fastLength &&
slowLength > midLength &&
//
shiftLength >= 0
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Current ...
result = MathMax(fastLength, midLength);
result = MathMax(result, slowLength);
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Fast ...
bool canShowFast = showFast;
ENUM_DRAW_TYPE fastDrawType = canShowFast ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(fastBuffer, true);
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
PlotIndexSetDouble(fastBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, canShowFast);
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
//
// Mid ...
bool canShowMid = showMid;
ENUM_DRAW_TYPE midDrawType = canShowMid ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(midBuffer, true);
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, canShowMid);
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType);
//
// Slow ...
bool canShowSlow = showSlow;
ENUM_DRAW_TYPE slowDrawType = canShowSlow ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(slowBuffer, true);
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
PlotIndexSetDouble(slowBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, canShowSlow);
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
}
//
// Initial Indicator Handlers ...
bool InitHandlers()
{
//
bool result = false;
//
// Initialize Handlers ...
//
// Fast ...
fastHandler = iMA(
_Symbol,
_Period,
fastLength,
shiftLength,
method,
appliedTo //
);
//
// Mid ...
midHandler = iMA(
_Symbol,
_Period,
midLength,
shiftLength,
method,
appliedTo //
);
//
// Slow ...
slowHandler = iMA(
_Symbol,
_Period,
slowLength,
shiftLength,
method,
appliedTo //
);
//
result =
//
fastHandler != INVALID_HANDLE &&
midHandler != INVALID_HANDLE &&
slowHandler != INVALID_HANDLE
//
;
//
return result;
}
//
@@ -1,564 +0,0 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: X3VWAP
// Description: X3VWAP Trend Detector ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X3VWAP Indicator"
#property strict
//
#define ShortName "X3VWAP"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int fastLength = 50; // Fast Length
input int midLength = 100; // Mid Length
input int slowLength = 200; // Slow Length
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
input bool showFast = true; // Show Fast
input bool showMid = true; // Show Mid
input bool showSlow = true; // Show Slow
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 11
#property indicator_plots 3
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
// Current ...
//
// Fast ...
#define fastBufferIndex 0
double fastBuffer[];
#define fastColorBufferIndex 1
double fastColorBuffer[];
//
#define fastPlotBufferIndex 0
#property indicator_label1 "X3VWAP F"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// Mid ...
#define midBufferIndex 2
double midBuffer[];
#define midColorBufferIndex 3
double midColorBuffer[];
//
#define midPlotBufferIndex 1
#property indicator_label2 "X3VWAP M"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
// Slow ...
#define slowBufferIndex 4
double slowBuffer[];
#define slowColorBufferIndex 5
double slowColorBuffer[];
//
#define slowPlotBufferIndex 2
#property indicator_label3 "X3VWAP S"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// Data Buffers ...
//
// Volumes ...
#define volumeBufferIndex 6
double volumeBuffer[];
//
// Price ...
#define priceBufferIndex 7
double priceBuffer[];
//
// Fast State ...
#define fastStateBufferIndex 8
double fastStateBuffer[];
//
// Mid State ...
#define midStateBufferIndex 9
double midStateBuffer[];
//
// Slow State ...
#define slowStateBufferIndex 10
double slowStateBuffer[];
//
// Variables ...
//
int maxLength;
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(low, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, 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,
tick_volume //
);
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
fastLength > 2 &&
midLength > fastLength &&
slowLength > midLength
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Current ...
result = MathMax(fastLength, midLength);
result = MathMax(result, slowLength);
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Fast ...
ArraySetAsSeries(fastBuffer, true);
ArraySetAsSeries(fastColorBuffer, true);
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
SetIndexBuffer(fastColorBufferIndex, fastColorBuffer, INDICATOR_COLOR_INDEX);
//
// Mid ...
ArraySetAsSeries(midBuffer, true);
ArraySetAsSeries(midColorBuffer, true);
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
SetIndexBuffer(midColorBufferIndex, midColorBuffer, INDICATOR_COLOR_INDEX);
//
// Slow ...
ArraySetAsSeries(slowBuffer, true);
ArraySetAsSeries(slowColorBuffer, true);
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
SetIndexBuffer(slowColorBufferIndex, slowColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// Volumes ...
ArraySetAsSeries(volumeBuffer, true);
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
//
// Price ...
ArraySetAsSeries(priceBuffer, true);
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
//
// Fast State ...
ArraySetAsSeries(fastStateBuffer, true);
SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS);
//
// Mid State ...
ArraySetAsSeries(midStateBuffer, true);
SetIndexBuffer(midStateBufferIndex, midStateBuffer, INDICATOR_CALCULATIONS);
//
// Slow State ...
ArraySetAsSeries(slowStateBuffer, true);
SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS);
}
//
// 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[],
const long &tickVolume[] //
)
{
//
// Calculate Volumes and Price ...
//
if (ratesTotal - bar_index <= maxLength)
{
//
CalculateDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
return;
}
//
CalculateDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
CalculateVWAPS(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
//
// Calculate Required Data Buffers ...
void CalculateDataBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double price = GetAppliedPrice(
appliedTo,
open,
high,
low,
close,
bar_index //
);
priceBuffer[bar_index] = price;
volumeBuffer[bar_index] = (double)tickVolume[bar_index];
}
//
// Calculate Different VWaps ...
void CalculateVWAPS(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
fastLength,
showFast,
fastBuffer,
fastColorBuffer,
fastStateBuffer //
);
//
// Mid ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
midLength,
showMid,
midBuffer,
midColorBuffer,
midStateBuffer //
);
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
slowLength,
showSlow,
slowBuffer,
slowColorBuffer,
slowStateBuffer //
);
}
//
// Calculate VWAP ...
void CalculateVWAP(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[],
//
int _length, // Calculation Length
bool _show,
double &_buffer[],
double &_colorBuffer[],
double &_stateBuffer[] //
)
{
//
double vSum = 0;
double pSum = 0;
double mSum = 0;
for (int x = 0; x < _length; x++)
{
//
pSum += priceBuffer[x + bar_index];
vSum += volumeBuffer[x + bar_index];
mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index];
}
//
double iValue = mSum / vSum;
iValue = NormalizeDouble(iValue, _Digits);
//
_buffer[bar_index] = iValue;
//
bool isBullish = low[bar_index] > iValue;
bool isBearish = high[bar_index] < iValue;
//
double iColor =
isBullish
? bullishColorIDX
: isBearish
? bearishColorIDX
: neuturalColorIDX;
//
_colorBuffer[bar_index] = hideColorIDX;
_stateBuffer[bar_index] = iColor;
if (_show)
{
_colorBuffer[bar_index] = iColor;
}
}
//
@@ -1,691 +0,0 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XCHM
// Description: XCHMrend Detector ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XCHM Indicator"
#property strict
//
#define ShortName "XCHSAR"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input double sarStep = 0.02; // Step
input double sarMax = 0.2; // Maximum
//
input group "Cycles";
//
input group "Short";
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
//
input group "Medium";
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
//
input group "Long";
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
//
input group "Hind";
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
//
// Presentation ...
input group "Presentation";
//
input int cArrowCode = 225; // Current Cycle Arrow Code
input int sArrowCode = 225; // Short Cycle Arrow Code
input int mArrowCode = 225; // Medium Cycle Arrow Code
input int lArrowCode = 225; // Long Cycle Arrow Code
input int hArrowCode = 225; // Hind Cycle Arrow Code
//
input bool showCurrent = true; // Show Current Cycle
input bool showShort = false; // Show Short Cycle
input bool showMedium = false; // Show Medium Cycle
input bool showLong = false; // Show Long Cycle
input bool showHind = false; // Show Hind Cycle
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 5
#property indicator_plots 5
//
// Current ...
#define cBufferIndex 0
double cBuffer[];
//
#property indicator_label1 "XCHSAR C"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrYellow
#property indicator_width1 2
//
// Short ...
#define sBufferIndex 1
double sBuffer[];
//
#property indicator_label2 "XCHSAR S"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta
#property indicator_width2 2
//
// Medium ...
#define mBufferIndex 2
double mBuffer[];
//
#property indicator_label3 "XCHSAR M"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrDodgerBlue
#property indicator_width3 2
//
// Long ...
#define lBufferIndex 3
double lBuffer[];
//
#property indicator_label4 "XCHSAR L"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrLime
#property indicator_width4 2
//
// Hind ...
#define hBufferIndex 4
double hBuffer[];
//
#property indicator_label5 "XCHSAR H"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrRed
#property indicator_width5 2
//
// Variables ...
//
int maxLength;
//
// Current ...
int cHandler = INVALID_HANDLE;
//
// Short ...
ENUM_TIMEFRAMES mSCPeriod = NULL;
int sHandler = INVALID_HANDLE;
//
// Medium ...
ENUM_TIMEFRAMES mMCPeriod = NULL;
int mHandler = INVALID_HANDLE;
//
// Long ...
ENUM_TIMEFRAMES mLCPeriod = NULL;
int lHandler = INVALID_HANDLE;
//
// Hind ...
ENUM_TIMEFRAMES mHCPeriod = NULL;
int hHandler = INVALID_HANDLE;
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitMarketCycles())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Current ...
IndicatorRelease(cHandler);
//
// Short ...
IndicatorRelease(sHandler);
//
// Medium ...
IndicatorRelease(mHandler);
//
// Long ...
IndicatorRelease(lHandler);
//
// Hind ...
IndicatorRelease(hHandler);
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(low, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(close, true);
//
// this counts Available Bars ...
int limit;
//
// Validate Calculated Bars ...
bool isPassedRequiredCalculatedBars =
//
// Current ...
BarsCalculated(cHandler) >= maxLength &&
//
// Short ...
BarsCalculated(sHandler) >= maxLength &&
//
// Medium ...
BarsCalculated(mHandler) >= maxLength &&
//
// Long ...
BarsCalculated(lHandler) >= maxLength &&
//
// Hind ...
BarsCalculated(hHandler) >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit =
(prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// Current ...
int copiedCs = CopyBuffer(cHandler, 0, 0, limit, cBuffer);
//
// Short ...
int copiedSs = CopyBuffer(sHandler, 0, 0, limit, sBuffer);
//
// Medium ...
int copiedMs = CopyBuffer(mHandler, 0, 0, limit, mBuffer);
//
// Long ...
int copiedLs = CopyBuffer(lHandler, 0, 0, limit, lBuffer);
//
// Hind ...
int copiedHs = CopyBuffer(hHandler, 0, 0, limit, hBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
//
// Current ...
copiedCs > 0 &&
//
// Short ...
copiedSs > 0 &&
//
// Medium ...
copiedMs > 0 &&
//
// Long ...
copiedLs > 0 &&
//
// Hind ...
copiedHs > 0
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
// Main Loop ...
// for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
// {
// CalculateBuffers(i);
// }
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
sarStep > 0 &&
sarMax > sarStep &&
//
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// CURRENT ...
//
ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(cBuffer, true);
SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_DATA);
PlotIndexSetInteger(cBufferIndex, PLOT_ARROW, cArrowCode);
PlotIndexSetDouble(cBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(cBufferIndex, PLOT_SHOW_DATA, showCurrent);
PlotIndexSetInteger(cBufferIndex, PLOT_DRAW_TYPE, cDrawType);
//
// SHORT ...
//
ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(sBuffer, true);
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
PlotIndexSetInteger(mBufferIndex, PLOT_ARROW, sArrowCode);
PlotIndexSetDouble(mBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(sBufferIndex, PLOT_SHOW_DATA, showShort);
PlotIndexSetInteger(sBufferIndex, PLOT_DRAW_TYPE, sDrawType);
//
// MEDIUM ...
//
ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(mBuffer, true);
SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA);
PlotIndexSetInteger(mBufferIndex, PLOT_ARROW, mArrowCode);
PlotIndexSetDouble(mBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(mBufferIndex, PLOT_SHOW_DATA, showMedium);
PlotIndexSetInteger(mBufferIndex, PLOT_DRAW_TYPE, mDrawType);
//
// LONG ...
//
ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(lBuffer, true);
SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lBufferIndex, PLOT_ARROW, lArrowCode);
PlotIndexSetDouble(lBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(lBufferIndex, PLOT_SHOW_DATA, showLong);
PlotIndexSetInteger(lBufferIndex, PLOT_DRAW_TYPE, lDrawType);
//
// HIND ...
//
ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(hBuffer, true);
SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA);
PlotIndexSetInteger(hBufferIndex, PLOT_ARROW, hArrowCode);
PlotIndexSetDouble(hBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(hBufferIndex, PLOT_SHOW_DATA, showHind);
PlotIndexSetInteger(hBufferIndex, PLOT_DRAW_TYPE, hDrawType);
}
//
// Initial Market Cycles ...
bool InitMarketCycles()
{
//
bool result = false;
//
// Current Cycle Initialization ...
//
int cPeriodSeconds = PeriodSeconds(_Period);
//
// Initialize Handlers ...
//
// Current ...
cHandler = iSAR(
_Symbol,
_Period,
sarStep,
sarMax //
);
result = cHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// Short Cycle Initialization ...
//
// Find Cycle Period ...
if (scMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mSCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_SHORT,
_Period //
);
}
else
{
mSCPeriod = scPeriod;
}
//
result = IsValid(mSCPeriod);
if (!result)
{
return result;
}
//
sHandler = iSAR(
_Symbol,
mSCPeriod,
sarStep,
sarMax //
);
result = sHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// Medium Cycle Initialization ...
//
// Find Cycle Period ...
if (mcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mMCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_MEDIUM,
_Period //
);
}
else
{
mMCPeriod = mcPeriod;
}
//
result = IsValid(mMCPeriod);
if (!result)
{
return result;
}
//
mHandler = iSAR(
_Symbol,
mMCPeriod,
sarStep,
sarMax //
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// Long Cycle Initialization ...
//
// Find Cycle Period ...
if (lcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mLCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_LONG,
_Period //
);
}
else
{
mLCPeriod = lcPeriod;
}
//
result = IsValid(mLCPeriod);
if (!result)
{
return result;
}
//
lHandler = iSAR(
_Symbol,
mLCPeriod,
sarStep,
sarMax //
);
result = lHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// Hind Cycle Initialization ...
//
// Find Cycle Period ...
if (hcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mHCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_HIND,
_Period //
);
}
else
{
mHCPeriod = hcPeriod;
}
//
result = IsValid(mHCPeriod);
if (!result)
{
return result;
}
//
hHandler = iSAR(
_Symbol,
mHCPeriod,
sarStep,
sarMax //
);
result = hHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Do all Custom Calculations ...
void CalculateBuffers(int barIndex)
{
}
//
File diff suppressed because it is too large Load Diff
@@ -1,643 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: XTick Oscillator
// Description: Tick Charts ...
//
//
// 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 XTick Oscillator"
#property strict
//
// Definitions ...
//
#define ShortName "XTick"
//
// Declaration of the enumeration
enum ENUM_X_PRICE_TYPES
{
X_Bid, // Bid
X_Ask // Ask
};
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Makret";
//
input group "Chart Config";
input int ticksCount = 3; // Ticks Count
input ENUM_X_PRICE_TYPES appliedPrice = 0; // Price
//
input group "Moving Average";
input int maLength = 10; // Length
input int maShift = 0; // Shift
input ENUM_MA_METHOD maMethod = MODE_SMA; // Mode
input ENUM_X_PRICE maAppliedTo = X_PRICE_CLOSE; // Applied To
//
input group "Presentation";
input bool showBars = true; // Show Bars
input bool showMa = true; // Show Moving Average
//
// Buffers ...
//
#property indicator_separate_window
//
#property indicator_buffers 8
#property indicator_plots 2
//
double openBuffer[];
#define openBufferIndex 0
//
double highBuffer[];
#define highBufferIndex 1
//
double lowBuffer[];
#define lowBufferIndex 2
//
double closeBuffer[];
#define closeBufferIndex 3
//
double colorBuffer[];
#define colorBufferIndex 4
//
#define barBufferIndex 0
#property indicator_label1 "Open;High;Low;Close"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 CLR_NONE, clrGray, clrAqua, clrMagenta
//
double maBuffer[];
#define maBufferIndex 5
#define maPlotBufferIndex 1
//
#property indicator_label2 "MA"
#property indicator_type2 DRAW_LINE // DRAW_COLOR_LINE
#property indicator_color2 clrRoyalBlue // CLR_NONE, clrGreen, clrRed
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
double ticksBuffer[];
#define ticksBufferIndex 6
//
double maPriceBuffer[];
#define maPriceBufferIndex 7
//
#define hideColorIDX 0;
#define neuturalColorIDX 1;
#define bullishColorIDX 2;
#define bearishColorIDX 3;
//
// The variable contains the number of stored quotes ...
int ticks_stored;
//
// The variable specifies the path and prefix to the file name ...
string path_prefix = ""; // FileName Prefix
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
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
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
int OnCalculate(
const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[] //
)
{
//
// 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);
//
int file_handle; // is a file handle
int bidPosition; // are positions of Bid prices in the string
int askPosition; // are positions of Ask prices in the string
int line_string_len; // is a length of a string, read from the file
int barNumber; // number of candle, for which the prices OHLC are determined
int i; // loop counter
//
// the recent received Bid price ...
double last_price_bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
//
// the recent received Ask price ...
double last_price_ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
//
string filename; // name of a file, the file_buffer is a string
string file_buffer; // a buffer for reading and writing of string data
//
// Setting the size of ticksBuffer array ...
ArrayResize(ticksBuffer, ArraySize(closeBuffer));
//
// File name formation from the path_prefix variable, name
// of financial instrument and ".Txt" symbols
StringConcatenate(filename, path_prefix, Symbol(), ".txt");
//
// Opening a file for reading and writing, codepage ANSI, shared reading mode
file_handle = FileOpen(filename, FILE_READ | FILE_WRITE | FILE_ANSI | FILE_SHARE_READ);
if (prev_calculated == 0)
{
//
// Reading the first line from the file and determine the length of a string ...
line_string_len = StringLen(FileReadString(file_handle)) + 2;
//
// if file is large (contains more quotes than rates_total/2) ...
if (FileSize(file_handle) > (ulong)line_string_len * rates_total / 2)
{
//
// Setting file pointer to read the latest rates_total/2 quotes
FileSeek(file_handle, -line_string_len * rates_total / 2, SEEK_END);
//
// Moving file pointer to the beginning of the next line
FileReadString(file_handle);
}
//
// if file size is small
else
{
//
// Moving file pointer at the beginning of a file
FileSeek(file_handle, 0, SEEK_SET);
}
//
// Reset the counter of stored quotes
ticks_stored = 0;
//
// Reading until the end of the file
while (FileIsEnding(file_handle) == false)
{
//
// Reading a string from thefile
file_buffer = FileReadString(file_handle);
//
// Processing of string if its length is larger than 6 characters
if (StringLen(file_buffer) > 6)
{
//
// Finding the start position of Bid price in the line
bidPosition = StringFind(file_buffer, " ", StringFind(file_buffer, " ") + 1) + 1;
//
// Finding the start position of Ask price in the line
askPosition = StringFind(file_buffer, " ", bidPosition) + 1;
//
// If the Bid prices are used, adding the Bid price to ticksBuffer[] array
if (appliedPrice == 0)
{
ticksBuffer[ticks_stored] = StringToDouble(StringSubstr(file_buffer, bidPosition, askPosition - bidPosition - 1));
}
//
// If the Ask prices are used, adding the Ask price to ticksBuffer[] array
if (appliedPrice == 1)
{
ticksBuffer[ticks_stored] = StringToDouble(StringSubstr(file_buffer, askPosition));
}
//
// Increasing the counter of stored quotes
ticks_stored++;
}
}
}
//
// If the data have been read before
else
{
//
// Moving file pointer at the end of the file
FileSeek(file_handle, 0, SEEK_END);
//
// Forming a string, that should be written to the file
StringConcatenate(file_buffer, TimeCurrent(), " ", DoubleToString(last_price_bid, _Digits), " ", DoubleToString(last_price_ask, _Digits));
//
// Writing a string to the file
FileWrite(file_handle, file_buffer);
//
// If the Bid prices are used, adding the last Bid price to ticksBuffer[] array
if (appliedPrice == 0)
{
ticksBuffer[ticks_stored] = last_price_bid;
}
//
// If the Ask prices are used, adding the last Ask price to ticksBuffer[] array
if (appliedPrice == 1)
{
ticksBuffer[ticks_stored] = last_price_ask;
}
//
// Increasing the quotes counter
ticks_stored++;
}
//
// Closing the file
FileClose(file_handle);
//
// If number of quotes is more or equal than number of bars in the chart
if (ticks_stored >= rates_total)
{
//
// Removing the first tick_stored/2 quotes and shifting remaining quotes
for (i = ticks_stored / 2; i < ticks_stored; i++)
{
//
// Shifting the data to the beginning in the ticksBuffer[] array on tick_stored/2
ticksBuffer[i - ticks_stored / 2] = ticksBuffer[i];
}
//
// Changing the quotes counter
ticks_stored -= ticks_stored / 2;
}
//
// We assign the barNumber with a number of invalid candle
barNumber = -1;
//
// Search for all the price data available for candle formation
for (i = 0; i < ticks_stored; i++)
{
//
// If this candle is forming already
if (barNumber == (int)(MathFloor((ticks_stored - 1) / ticksCount) - MathFloor(i / ticksCount)))
{
//
// The current quote is still closing price of the current candle
closeBuffer[barNumber] = ticksBuffer[i];
//
// If the current price is greater than the highest price of the current candle, it will be a new highest price of the candle
if (ticksBuffer[i] > highBuffer[barNumber])
{
highBuffer[barNumber] = ticksBuffer[i];
}
//
// If the current price is lower than the lowest price of the current candle, it will be a new lowest price of the candle
if (ticksBuffer[i] < lowBuffer[barNumber])
{
lowBuffer[barNumber] = ticksBuffer[i];
}
//
// If the candle is bullish ...
if (closeBuffer[barNumber] > openBuffer[barNumber])
{
colorBuffer[barNumber] = bullishColorIDX;
}
//
// If the candle is bearish ...
if (closeBuffer[barNumber] < openBuffer[barNumber])
{
colorBuffer[barNumber] = bearishColorIDX;
}
//
// If the opening and closing prices are equal, then the candle will have a color with index 0 (grey)
if (closeBuffer[barNumber] == openBuffer[barNumber])
{
colorBuffer[barNumber] = neuturalColorIDX;
}
}
//
// If this candle hasn't benn calculated yet
else
{
//
// Let's determine the index of a candle
barNumber = (int)(MathFloor((ticks_stored - 1) / ticksCount) - MathFloor(i / ticksCount));
//
// The current quote will be the opening price of a candle
openBuffer[barNumber] = ticksBuffer[i];
//
// The current quote will be the highest price of a candle
highBuffer[barNumber] = ticksBuffer[i];
//
// The current quote will be the lowest price of a candle
lowBuffer[barNumber] = ticksBuffer[i];
//
// The current quote will be the closing price of a candle
closeBuffer[barNumber] = ticksBuffer[i];
//
// The candle will have a color with index 0 (gray)
colorBuffer[barNumber] = 0;
}
}
//
// Custom Calculations ...
//
int 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 //
);
}
//
// Return from OnCalculate(), return a value, different from zero
return (rates_total);
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result =
//
ticksCount > 0
//
;
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Color ...
ArraySetAsSeries(colorBuffer, true);
SetIndexBuffer(colorBufferIndex, colorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Bar Buffer ...
PlotIndexSetDouble(barBufferIndex, PLOT_EMPTY_VALUE, 0.0);
//
PlotIndexSetInteger(barBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(colorBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openBuffer, true);
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highBuffer, true);
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeBuffer, true);
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowBuffer, true);
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
//
bool canShowMa = showMa;
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetDouble(maPlotBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(maPlotBufferIndex, PLOT_DRAW_BEGIN, maLength);
PlotIndexSetInteger(maPlotBufferIndex, PLOT_SHOW_DATA, showMa);
//
// Data Buffers ...
//
// The TicksBuffer[] array is used for intermediate calculations
SetIndexBuffer(ticksBufferIndex, ticksBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(maPriceBuffer, true);
SetIndexBuffer(maPriceBufferIndex, maPriceBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param barIndex: Integer ...
*/
void CalculateBuffers(
int barIndex,
int prevCalculated,
int ratesTotal //
)
{
//
bool canDoMovingAverage =
maLength > 0 &&
maAppliedTo != X_PRICE_UP &&
maAppliedTo != X_PRICE_DOWN;
if (canDoMovingAverage)
{
//
// Do Moving Average Calculations ...
//
// Select Ma Price ...
double iPrice = 0;
switch (maAppliedTo)
{
//
case X_PRICE_HIGH:
iPrice = highBuffer[barIndex];
break;
//
case X_PRICE_OPEN:
iPrice = openBuffer[barIndex];
break;
//
case X_PRICE_CLOSE:
iPrice = closeBuffer[barIndex];
break;
//
case X_PRICE_LOW:
iPrice = lowBuffer[barIndex];
break;
}
//
maPriceBuffer[barIndex] = iPrice;
int total = ArraySize(closeBuffer);
//
int calculatedMas = iMAOnBuffer(
total,
prevCalculated,
barIndex,
maLength,
maPriceBuffer,
maBuffer,
maMethod //
);
}
}
//