Description
This indicator drawing FibonacciRetracement (FR) object into chart, and the parameters of FR are definated based on Decycler Ocillator values (pic.2).
The highest price for FR is definated from price highest-high (pic 2 greenarrow) during last positive zone of Decycler indicator of the last completed positive cycle (pic 2 green shadow), also the lowest price for FR is definated from price lowest-low (pic 2 red arrow) during last negative zone of Decycler indicator of the last completed negative cycle (pic 2 red shadow).
This indicator can called also Automated-FibonacciRetracement, and this is good news for new traders and lazy traders :D.
Decycler Oscillator you can download by clicking here.
Enjoy
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class mDecyclerFibonacciRetracement : Indicator
{
[Parameter("HP Period (125)", DefaultValue = 125)]
public int inpPeriodHP { get; set; }
[Parameter("Coefficient (1.0)", DefaultValue = 1.0)]
public double inpCoefficient { get; set; }
[Parameter("Show Level 11.4", DefaultValue =false)]
public bool inpLevel11 { get; set; }
[Parameter("Show Level 23,6", DefaultValue =false)]
public bool inpLevel23 { get; set; }
[Parameter("Show Level 70.7", DefaultValue =false)]
public bool inpLevel70 { get; set; }
[Parameter("Show Level 76.4", DefaultValue =false)]
public bool inpLevel76 { get; set; }
[Parameter("Show Level 88.6", DefaultValue =false)]
public bool inpLevel88 { get; set; }
[Parameter("Show Level 161.8", DefaultValue =true)]
public bool inpLevel161 { get; set; }
[Parameter("Show Level 261.8", DefaultValue =true)]
public bool inpLevel261 { get; set; }
[Parameter("Color (black)", DefaultValue ="Black")]
public Color inpColor { get; set; }
double angle1, angle2, alpha1, alpha2;
private IndicatorDataSeries _hp, _decycle, _decycle2, _do;
private double a1, a2, a3, a4, b1, b2, b3, b4, pr2, pr3, pr4, pr5;
private bool _end, _start;
private int j, _dir;
private int _imin, _imax;
private double _pmin, _pmax;
protected override void Initialize()
{
angle1 = 1.414 * 3.14159265358979323846 / inpPeriodHP;
angle2 = 2.0*angle1;
alpha1 = (Math.Cos(angle1) + Math.Sin(angle1) - 1.0) / Math.Cos(angle1);
alpha2 = (Math.Cos(angle2) + Math.Sin(angle2) - 1.0) / Math.Cos(angle2);
a1 = 1.0 - alpha1;
a2 = 1.0 - alpha1 / 2.0;
a3 = a1 * a1;
a4 = a2 * a2;
b1 = 1.0 - alpha2;
b2 = 1.0 - alpha2 / 2.0;
b3 = b1 * b1;
b4 = b2 * b2;
_hp = CreateDataSeries();
_decycle = CreateDataSeries();
_decycle2 = CreateDataSeries();
_do = CreateDataSeries();
}
public override void Calculate(int i)
{
pr2 = 2.0 * (i>1 ? Bars.ClosePrices[i-1] : Bars.ClosePrices[i]);
pr3 = Bars.ClosePrices[i] - pr2 + (i>2 ? Bars.ClosePrices[i-2] : Bars.ClosePrices[i]);
_hp[i] = a4 * pr3 + (2.0 * a1 * (i>1 ? _hp[i-1] : 0)) - (a3 * (i>2 ? _hp[i-2] : 0));
_decycle[i] = Bars.ClosePrices[i] - _hp[i];
pr4 = 2.0 * (i>1 ? _decycle[i-1] : 0);
pr5 = _decycle[i] - pr4 + (i>2 ? _decycle[i-2] : 0);
_decycle2[i] = b4 * pr5 + (2.0 * b1 * (i>1 ? _decycle2[i-1] : 0)) - (b3 * (i>2 ? _decycle2[i-2] : 0));
_do[i] = (Bars.ClosePrices[i]!=0 ? 100.0 * inpCoefficient * _decycle2[i] / Bars.ClosePrices[i] : 0);
if(IsLastBar)
{
j = i;
_dir = _do[i] > 0 ? +1 : -1;
_start = false;
_end = false;
_imin = i;
_imax = i;
_pmin = _pmax = Bars.ClosePrices[i];
while(_end == false)
{
if(_start == true && _do[j] < 0 && Bars.LowPrices[j] < _pmin)
{
_imin = j;
_pmin = Math.Min(_pmin, Bars.LowPrices[j]);
}
if(_start == true && _do[j] > 0 && Bars.HighPrices[j] > _pmax)
{
_imax = j;
_pmax = Math.Max(_pmax, Bars.HighPrices[j]);
}
if(_start == true && _dir == +1 && _do[j] > 0 && _do[j-1] < 0)
_end = true;
if(_start == true && _dir == -1 && _do[j] < 0 && _do[j-1] > 0)
_end = true;
if(_start == false && _dir == +1 && _do[j] > 0 && _do[j-1] < 0)
{
_start = true;
_pmin = Bars.LowPrices[j];
_pmax = Bars.HighPrices[j];
}
if(_start == false && _dir == -1 && _do[j] < 0 && _do[j-1] > 0)
{
_start = true;
_pmin = Bars.LowPrices[j];
_pmax = Bars.HighPrices[j];
}
j--;
}
var fib = Chart.DrawFibonacciRetracement("mDecyclerFibonacciRetracement", _imin, _pmax, _imax, _pmin, inpColor);
foreach(var level in fib.FibonacciLevels)
{
level.IsVisible = false;
if(level.PercentLevel == 0.0)
level.IsVisible = true;
if(level.PercentLevel == 11.4)
level.IsVisible = inpLevel11;
if(level.PercentLevel == 23.6)
level.IsVisible = inpLevel23;
if(level.PercentLevel == 38.2)
level.IsVisible = true;
if(level.PercentLevel == 50.0)
level.IsVisible = true;
if(level.PercentLevel == 61.8)
level.IsVisible = true;
if(level.PercentLevel == 70.7)
level.IsVisible = inpLevel70;
if(level.PercentLevel == 76.4)
level.IsVisible = inpLevel76;
if(level.PercentLevel == 88.6)
level.IsVisible = inpLevel88;
if(level.PercentLevel == 100.0)
level.IsVisible = true;
if(level.PercentLevel == 161.8)
level.IsVisible = inpLevel161;
if(level.PercentLevel == 261.8)
level.IsVisible = inpLevel261;
}
}
}
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mDecyclerFibonacciRetracement.algo
- Rating: 5
- Installs: 1586
- Modified: 23/02/2023 12:18