Files
MQL5Data/Documents/Pack/V1.0/Source/Indicators/x-saherelm.xadxtd.mq5
T
2024-06-29 10:53:40 +03:30

223 lines
5.0 KiB
Plaintext

///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XADXTD
// Description: ADX TD Channel ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XADXTD Indicator"
#property strict
//
#define ShortName "XADXTD"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
input int length = 21; // Length
//
// BUFFERS ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 0
//
#define strengthBufferIndex 0
double strengthBuffer[];
//
#define bullpBufferIndex 1
double bullpBuffer[];
//
#define bearpBufferIndex 2
double bearpBuffer[];
//
int maxLength = 0;
int mHandler = INVALID_HANDLE;
//
// 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();
//
mHandler = iADX(
_Symbol,
_Period,
length //
);
if (mHandler == INVALID_HANDLE)
{
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
//
IndicatorRelease(mHandler);
}
//
// 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 ...
)
{
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
int adxCalculatedBars = BarsCalculated(mHandler);
if (adxCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedADXStrength = CopyBuffer(mHandler, MAIN_LINE, 0, limit, strengthBuffer);
int copiedADXBullp = CopyBuffer(mHandler, PLUSDI_LINE, 0, limit, bullpBuffer);
int copiedADXBearP = CopyBuffer(mHandler, MINUSDI_LINE, 0, limit, bearpBuffer);
if (copiedADXBullp <= 0 ||
copiedADXBearP <= 0 ||
copiedADXStrength <= 0)
{
return prev_calculated;
}
//
return rates_total;
}
//
// Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
(length > 0)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(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()
{
//
ArraySetAsSeries(strengthBuffer, true);
SetIndexBuffer(strengthBufferIndex, strengthBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(bullpBuffer, true);
SetIndexBuffer(bullpBufferIndex, bullpBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(bearpBuffer, true);
SetIndexBuffer(bearpBufferIndex, bearpBuffer, INDICATOR_CALCULATIONS);
}