Description
The Fractal Graph Dimension Indicator (FGDI) shows the market state: trend or volatility.
It was described in the article "Technical Analysis of Stocks and Commodities" in March 2007 by Radha Panini, based on the article "A Procedure to Estimate the Fractal Dimension of Waveforms" by Carlos Sevcik.
The Fractal Dimension Index (FDI) determines the amount of market volatility (the indicator's black component).
The easiest way to use this indicator is to understand that a value of 0 suggests the market is behaving in a completely random fashion. As the market deviates from 0, the opportunity for earning profits increases in proportion to the amount of deviation.
However, be careful as the indicator does not show the direction of trends! In fact, it compares and shows the correlation between trend and range.
In this version, when all indicator components are above the zero value, it indicates a market trend. When all indicator components are below the zero value, it signifies no velocity and a range-bound condition, indicating that a trend has ended, the market has become erratic, and high volatility is present. These conditions usually do not last for a long time and are followed by the emergence of a new trend.
In conditions when not all indicator components are above or below zero, the market condition is considered to be in a transitional state.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class mFGDI : Indicator
{
[Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
public enumPriceTypes inpPriceType { get; set; }
[Parameter("Periods (30)", DefaultValue = 30, MinValue = 1)]
public int inpPeriod { get; set; }
[Parameter("Threshold (1.5)", DefaultValue = 1.5)]
public double inpThreshold { get; set; }
[Output("FGDI", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outFGDI { get; set; }
[Output("FGDI Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outFGDItop { get; set; }
[Output("FGDI Bottom", LineColor = "Green", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outFGDIbottom { get; set; }
private IndicatorDataSeries _price, _hh, _ll;
private double diff, len, priordiff, sum, fdi, delta, variance;
protected override void Initialize()
{
_price = CreateDataSeries();
_hh = CreateDataSeries();
_ll = CreateDataSeries();
}
public override void Calculate(int i)
{
switch (inpPriceType)
{
case enumPriceTypes.Open:
_price[i] = Bars.OpenPrices[i];
break;
case enumPriceTypes.Close:
_price[i] = Bars.ClosePrices[i];
break;
case enumPriceTypes.High:
_price[i] = Bars.HighPrices[i];
break;
case enumPriceTypes.Low:
_price[i] = Bars.LowPrices[i];
break;
case enumPriceTypes.Median:
_price[i] = Bars.MedianPrices[i];
break;
case enumPriceTypes.Typical:
_price[i] = Bars.TypicalPrices[i];
break;
case enumPriceTypes.Weighted:
_price[i] = Bars.WeightedPrices[i];
break;
default:
_price[i] = Bars.ClosePrices[i];
break;
}
_hh[i] =i>inpPeriod ? _price.Maximum(inpPeriod) : Bars.HighPrices[i];
_ll[i] =i>inpPeriod ? _price.Minimum(inpPeriod) : Bars.LowPrices[i];
diff = len = priordiff = sum = fdi = delta = variance = 0;
if(_hh[i] != _ll[i])
{
for(int j=i-inpPeriod-1; j<=i; j++)
{
diff = (_price[j] - _ll[i]) / (_hh[i] - _ll[i]);
if(j!=i-inpPeriod-1)
len += Math.Sqrt(Math.Pow(diff - priordiff, 2.0) + 1.0 / Math.Pow(inpPeriod, 2.0));
priordiff=diff;
}
}
if(len > 0)
{
fdi = 1.0 + (Math.Log(len) + Math.Log(2)) / Math.Log(2.0 * (inpPeriod - 1.0));
if(_hh[i] != _ll[i])
{
for(int j=i-inpPeriod-1; j<=i; j++)
{
diff=(_price[j] - _ll[i]) / (_hh[i] - _ll[i]);
if(j != i+inpPeriod-1)
{
delta =Math.Sqrt(Math.Pow(diff - priordiff, 2) + 1.0 / Math.Pow(inpPeriod, 2.0));
sum += Math.Pow(delta - len / (inpPeriod-1.0), 2.0);
}
priordiff=diff;
}
}
variance = sum / (Math.Pow(len, 2.0) * Math.Log(2.0 * (inpPeriod - 1)) * Math.Log(2.0 * (inpPeriod - 1)));
}
else
{
fdi = 0;
variance = 0;
}
outFGDI[i] = (fdi - inpThreshold) / -Symbol.PipSize;
outFGDItop[i] = ((fdi + Math.Sqrt(variance)) - inpThreshold) / -Symbol.PipSize;
outFGDIbottom[i] = ((fdi - Math.Sqrt(variance)) - inpThreshold) / -Symbol.PipSize;
}
}
public enum enumPriceTypes
{
Open,
Close,
High,
Low,
Median,
Typical,
Weighted
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mFGDI.algo
- Rating: 5
- Installs: 592
- Modified: 18/07/2023 11:19