add adxtd into indicator for control behaviour ...
This commit is contained in:
@@ -0,0 +1,223 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// 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);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+143
-62
@@ -39,21 +39,25 @@ input group "Makret 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 int scLength = 0; // Length
|
||||
|
||||
//
|
||||
input group "Medium";
|
||||
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||
// input int mcLength = 0; // Length
|
||||
|
||||
//
|
||||
input group "Long";
|
||||
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||
// input int lcLength = 0; // Length
|
||||
|
||||
//
|
||||
input group "Hind";
|
||||
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||
// input int hcLength = 0; // Length
|
||||
|
||||
//
|
||||
input group "Fibonacci";
|
||||
@@ -381,24 +385,32 @@ int maxLength;
|
||||
double mHideColorIDX = 0;
|
||||
|
||||
//
|
||||
XMarketCycle sc;
|
||||
// XMarketCycle sc;
|
||||
int mSCLength = 0;
|
||||
double mLastSCHH = 0;
|
||||
double mLastSCLL = 0;
|
||||
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||
|
||||
//
|
||||
XMarketCycle mc;
|
||||
// XMarketCycle mc;
|
||||
int mMCLength = 0;
|
||||
double mLastMCHH = 0;
|
||||
double mLastMCLL = 0;
|
||||
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||
|
||||
//
|
||||
XMarketCycle lc;
|
||||
// XMarketCycle lc;
|
||||
int mLCLength = 0;
|
||||
double mLastLCHH = 0;
|
||||
double mLastLCLL = 0;
|
||||
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||
|
||||
//
|
||||
XMarketCycle hc;
|
||||
// XMarketCycle hc;
|
||||
int mHCLength = 0;
|
||||
double mLastHCHH = 0;
|
||||
double mLastHCLL = 0;
|
||||
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||
|
||||
//
|
||||
double lastPeak = 0;
|
||||
@@ -516,10 +528,10 @@ bool ValidateInputs()
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
IsValid(scMethod, scPeriod) &&
|
||||
IsValid(mcMethod, mcPeriod) &&
|
||||
IsValid(lcMethod, lcPeriod) &&
|
||||
IsValid(hcMethod, hcPeriod)
|
||||
(IsValid(scMethod, scPeriod) &&
|
||||
IsValid(mcMethod, mcPeriod) &&
|
||||
IsValid(lcMethod, lcPeriod) &&
|
||||
IsValid(hcMethod, hcPeriod))
|
||||
//
|
||||
;
|
||||
|
||||
@@ -536,9 +548,9 @@ int ExtractMaxLengthOfInputs()
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(sc.length, mc.length);
|
||||
result = MathMax(result, lc.length);
|
||||
result = MathMax(result, hc.length);
|
||||
result = MathMax(mSCLength, mMCLength);
|
||||
result = MathMax(result, mLCLength);
|
||||
result = MathMax(result, mHCLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -834,60 +846,101 @@ bool InitMarketCycles()
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Short ...
|
||||
result = sc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
scMethod,
|
||||
scPeriod
|
||||
//
|
||||
);
|
||||
if (!result)
|
||||
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (scMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
return result;
|
||||
//
|
||||
// Select Period ...
|
||||
mSCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSCPeriod = scPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
result = mc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
mcMethod,
|
||||
mcPeriod
|
||||
//
|
||||
);
|
||||
if (!result)
|
||||
if (IsValid(mSCPeriod))
|
||||
{
|
||||
return result;
|
||||
mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||
}
|
||||
|
||||
//
|
||||
// Long ...
|
||||
result = lc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_LONG,
|
||||
lcMethod,
|
||||
lcPeriod
|
||||
//
|
||||
);
|
||||
if (!result)
|
||||
// Find Cycle Period ...
|
||||
if (mcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
return result;
|
||||
//
|
||||
// Select Period ...
|
||||
mMCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMCPeriod = mcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
result = hc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_HIND,
|
||||
hcMethod,
|
||||
hcPeriod
|
||||
if (IsValid(mMCPeriod))
|
||||
{
|
||||
mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (lcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
);
|
||||
// Select Period ...
|
||||
mLCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_LONG,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLCPeriod = lcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValid(mLCPeriod))
|
||||
{
|
||||
mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (hcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mHCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_HIND,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mHCPeriod = hcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValid(mHCPeriod))
|
||||
{
|
||||
mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||
}
|
||||
|
||||
//
|
||||
result = mSCLength > 0 &&
|
||||
mMCLength > mSCLength &&
|
||||
mLCLength > mMCLength &&
|
||||
mHCLength > mLCLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -897,7 +950,7 @@ bool InitMarketCycles()
|
||||
// Calculate Specified Cycles HH and LL ...
|
||||
void CalculateCycle(
|
||||
int barIndex,
|
||||
XMarketCycle &cycle,
|
||||
ENUM_X_MARKET_CYCLES cycle,
|
||||
double &lastHH,
|
||||
double &hhBuffer[],
|
||||
double &hhColorBuffer[],
|
||||
@@ -906,9 +959,6 @@ void CalculateCycle(
|
||||
double &llColorBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
cycle.Update(barIndex);
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bar.Init(
|
||||
@@ -918,9 +968,40 @@ void CalculateCycle(
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
int mLength = 0;
|
||||
switch (cycle)
|
||||
{
|
||||
//
|
||||
case X_MARKET_CYCLE_SHORT:
|
||||
mLength = mSCLength;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MARKET_CYCLE_MEDIUM:
|
||||
mLength = mMCLength;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MARKET_CYCLE_LONG:
|
||||
mLength = mLCLength;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MARKET_CYCLE_HIND:
|
||||
mLength = mHCLength;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
if (mLength <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double hhValue = bar.FindHighest(
|
||||
cycle.length,
|
||||
mLength,
|
||||
hhMode
|
||||
//
|
||||
);
|
||||
@@ -946,7 +1027,7 @@ void CalculateCycle(
|
||||
|
||||
//
|
||||
double llValue = bar.FindLowest(
|
||||
cycle.length,
|
||||
mLength,
|
||||
llMode
|
||||
//
|
||||
);
|
||||
@@ -981,7 +1062,7 @@ void CalculateCycles(
|
||||
// Short ...
|
||||
CalculateCycle(
|
||||
barIndex,
|
||||
sc,
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
//
|
||||
mLastSCHH,
|
||||
scHHBuffer,
|
||||
@@ -997,7 +1078,7 @@ void CalculateCycles(
|
||||
// Medium ...
|
||||
CalculateCycle(
|
||||
barIndex,
|
||||
mc,
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
//
|
||||
mLastMCHH,
|
||||
mcHHBuffer,
|
||||
@@ -1013,7 +1094,7 @@ void CalculateCycles(
|
||||
// Long ...
|
||||
CalculateCycle(
|
||||
barIndex,
|
||||
lc,
|
||||
X_MARKET_CYCLE_LONG,
|
||||
//
|
||||
mLastLCHH,
|
||||
lcHHBuffer,
|
||||
@@ -1029,7 +1110,7 @@ void CalculateCycles(
|
||||
// Hind ...
|
||||
CalculateCycle(
|
||||
barIndex,
|
||||
hc,
|
||||
X_MARKET_CYCLE_HIND,
|
||||
//
|
||||
mLastHCHH,
|
||||
hcHHBuffer,
|
||||
|
||||
Reference in New Issue
Block a user