Description
The GaussianBands indicator works like BollingerBands and performs centerline and deviation band filtering based on input deviation parameters.
This indicator identifies the price squeeze, and this means the beginning of the open trade position, and the direction of the trade is determined by the price position with the central line of the indicator (above/beelow).
This indicator also identifies the state of momentum and trend based on extended internal and external bands
Use the ZScore indicator for confirmation. (download ZScore from here)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Cloud("Gaussian Outer Top", "Gaussian Inner Top", FirstColor = "#fff9dc", SecondColor = "#fff9dc", Opacity = 0.2)]
[Cloud("Gaussian Inner Bottom", "Gaussian Outer Bottom", FirstColor = "#fffacd", SecondColor = "#fffacd", Opacity = 0.2)]
[Indicator(IsOverlay = true, ScalePrecision = 5, AccessRights = AccessRights.None)]
public class mGaussianBands : Indicator
{
[Parameter("Main Period (12)", DefaultValue = 12, MinValue = 2)]
public int inpPeriodMain { get; set; }
[Parameter("Deviation Period (12)", DefaultValue = 12, MinValue = 1)]
public int inpPeriodDev { get; set; }
[Parameter("Multiplier Narrow % (2.0)", DefaultValue = 2.0)]
public int inpMultiplierNarrow { get; set; }
[Parameter("Multiplier Wide % (4.0)", DefaultValue = 4.0)]
public int inpMultiplierWide { get; set; }
[Parameter("Data Source (close)")]
public DataSeries inpDataSource { get; set; }
[Output("Gaussian Main", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outGC { get; set; }
[Output("Gaussian Inner Top", LineColor = "#ffb6e1", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outGCinnertop { get; set; }
[Output("Gaussian Inner Bottom", LineColor = "#97eda8", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outGCinnerbottom { get; set; }
[Output("Gaussian Outer Top", LineColor = "#ffb6e1", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outGCoutertop { get; set; }
[Output("Gaussian Outer Bottom", LineColor = "#97eda8", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outGCouterbottom { get; set; }
private double cof, alphacen, alphadev;
private MovingAverage _pr;
private IndicatorDataSeries _gma, _raw1, _raw2;
protected override void Initialize()
{
cof = (1.0 - Math.Cos(2.0 * Math.PI / inpPeriodMain)) / (Math.Pow(1.414, 2.0/3.0) - 1.0);
alphacen = (-cof + Math.Sqrt(cof * cof + 2.0 * cof));
cof = (1.0 - Math.Cos(2.0 * Math.PI / inpPeriodDev)) / (Math.Pow(1.414, 2.0/3.0) - 1.0);
alphadev = (-cof + Math.Sqrt(cof * cof + 2.0 * cof));
_pr = Indicators.MovingAverage(inpDataSource, 1, MovingAverageType.Simple);
_gma = CreateDataSeries();
_raw1 = CreateDataSeries();
_raw2 = CreateDataSeries();
}
public override void Calculate(int i)
{
_gma[i] = i> 4 ? (
Math.Pow(alphacen,4.0) * _pr.Result[i]
+ 4.0 * (1.0 - alphacen) * _gma[i-1]
- 6.0 * Math.Pow(1.0 - alphacen, 2.0) * _gma[i-2]
+ 4.0 * Math.Pow(1.0 - alphacen, 3.0) * _gma[i-3]
- 1.0 * Math.Pow(1.0 - alphacen, 4.0) * _gma[i-4])
: Math.Pow(alphacen,4.0) * _pr.Result[i] ;
_raw1[i] = Math.Abs(_pr.Result[i] - _gma[i]);
_raw2[i] = i> 4 ? (
Math.Pow(alphadev,4.0) * _raw1[i]
+ 4.0 * (1.0 - alphadev) * _raw2[i-1]
- 6.0 * Math.Pow(1.0 - alphadev, 2.0) * _raw2[i-2]
+ 4.0 * Math.Pow(1.0 - alphadev, 3.0) * _raw2[i-3]
- 1.0 * Math.Pow(1.0 - alphadev, 4.0) * _raw2[i-4])
: Math.Pow(alphadev,4.0) * _raw1[i] ;
outGC[i] = _gma[i];
outGCinnertop[i] = _gma[i] + _raw2[i] * inpMultiplierNarrow;
outGCinnerbottom[i] = _gma[i] - _raw2[i] * inpMultiplierNarrow;
outGCoutertop[i] = _gma[i] + _raw2[i] * inpMultiplierWide;
outGCouterbottom[i] = _gma[i] - _raw2[i] * inpMultiplierWide;
}
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mGaussianBands.algo
- Rating: 5
- Installs: 715
- Modified: 12/12/2022 12:00
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
Thanks at last someone code Gaussian band for ctrader. Hope to see you code another Quantile Band indicator