last ...
This commit is contained in:
@@ -7095,6 +7095,163 @@ bool SetChartVolumesColor(
|
||||
// END Chart Info ...
|
||||
//
|
||||
|
||||
//
|
||||
// START ATR ...
|
||||
//
|
||||
|
||||
/**
|
||||
* Calculate True Range of Specified Bar ...
|
||||
*
|
||||
* @param _symbol: string, Symbol ...
|
||||
* @param _period: ENUM_TIMEFRAMES, period ...
|
||||
* @param _barIndex: int, Specified Bar Index ...
|
||||
* @param ignorePC: bool, Ignore Previous Bar ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double GetTrueRange(
|
||||
string _symbol = NULL,
|
||||
ENUM_TIMEFRAMES _period = NULL,
|
||||
int _barIndex = 0,
|
||||
bool ignorePC = false // Ignore Previous Close ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
_symbol = NormalizeSymbol(_symbol);
|
||||
_period = NormalizePeriod(_period);
|
||||
_barIndex = NormalizeInt(_barIndex, 0);
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
XOHCL pBar;
|
||||
|
||||
//
|
||||
bool has =
|
||||
bar.Init(
|
||||
_symbol,
|
||||
_period,
|
||||
_barIndex //
|
||||
);
|
||||
if (!ignorePC)
|
||||
{
|
||||
//
|
||||
has = has &&
|
||||
bar.GetPreviousBar(pBar);
|
||||
}
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double hlDiff = bar.high - bar.low;
|
||||
|
||||
//
|
||||
if (!ignorePC)
|
||||
{
|
||||
//
|
||||
double hpcDiff = MathAbs(bar.high - pBar.close);
|
||||
double lpcDiff = MathAbs(bar.high - pBar.close);
|
||||
|
||||
//
|
||||
result = MathMax(hlDiff, hpcDiff);
|
||||
result = MathMax(result, lpcDiff);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = hlDiff;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
bar.Clean();
|
||||
pBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate ATR ...
|
||||
*
|
||||
* @param _symbol: string, Symbol ...
|
||||
* @param _period: ENUM_TIMEFRAMES, period ...
|
||||
* @param _barIndex: int, Specified Bar Index ...
|
||||
* @param _length: int ATR Period ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double GetAverageTrueRange(
|
||||
string _symbol = NULL,
|
||||
ENUM_TIMEFRAMES _period = NULL,
|
||||
int _barIndex = 0,
|
||||
int _length = 14 //
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
_symbol = NormalizeSymbol(_symbol);
|
||||
_period = NormalizePeriod(_period);
|
||||
_length = NormalizeInt(_length, 2);
|
||||
_barIndex = NormalizeInt(_barIndex, 0);
|
||||
|
||||
//
|
||||
// Collect True Ranges ...
|
||||
double itr;
|
||||
double _trs[];
|
||||
bool has = false;
|
||||
int start = _barIndex;
|
||||
int end = start + _length;
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
//
|
||||
itr = GetTrueRange(
|
||||
_symbol,
|
||||
_period,
|
||||
_barIndex,
|
||||
i == end - 1 // Ignore PC ...
|
||||
);
|
||||
has = NotEmptyZero(itr);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
itr,
|
||||
_trs //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(_trs);
|
||||
has = HasChild(_trs);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = GetAverage(_trs);
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
XClean(_trs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END َATR ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Linear Regression ...
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user