Description
TMA Band v2
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TMABandsv2 : Indicator
{
[Parameter(DefaultValue = 60, MinValue = 1)]
public int HalfLength { get; set; }
[Parameter()]
public DataSeries Price { get; set; }
[Parameter(DefaultValue = 2.5)]
public double ATRMultiplier { get; set; }
[Parameter(DefaultValue = 100)]
public int ATRPeriod { get; set; }
[Output("Center", LineColor = "red", PlotType = PlotType.Points)]
public IndicatorDataSeries Center { get; set; }
[Output("Upper", LineColor = "blue")]
public IndicatorDataSeries Upper { get; set; }
[Output("Lower", LineColor = "blue")]
public IndicatorDataSeries Lower { get; set; }
private AverageTrueRange _atr;
private bool previousClosesAbove;
private bool previousClosesBelow;
private int arrowLastCalculated;
protected override void Initialize()
{
_atr = Indicators.AverageTrueRange(ATRPeriod, MovingAverageType.Simple);
}
public override void Calculate(int index)
{
if (index < HalfLength)
return;
double sum = (HalfLength + 1) * Price[index];
double sumw = (HalfLength + 1);
for (int j = 1, k = HalfLength; j <= HalfLength; j++,k--)
{
sum += k * Price[index - j];
sumw += k;
}
double range = _atr.Result[index - 10] * ATRMultiplier;
Center[index] = sum / sumw;
Upper[index] = Center[index] + range;
Lower[index] = Center[index] - range;
paintArrows(index);
}
private void paintArrows(int index)
{
if (arrowLastCalculated == index || index == 0)
{
return;
}
arrowLastCalculated = index;
previousClosesAbove = Bars[index - 2].Close > Upper[index - 2];
previousClosesBelow = Bars[index - 2].Close < Lower[index - 2];
if (previousClosesAbove && Bars[index - 1].Close < Upper[index - 1])
{
Chart.DrawIcon(index + "AD", ChartIconType.DownArrow, Bars[index - 1].OpenTime, Math.Max(Bars[index - 2].High, Bars[index - 1].High), Color.Yellow);
}
if (previousClosesBelow && Bars[index - 1].Close > Lower[index - 1])
{
Chart.DrawIcon(index + "AU", ChartIconType.UpArrow, Bars[index - 1].OpenTime, Math.Min(Bars[index - 2].Low, Bars[index - 1].Low), Color.LightBlue);
}
}
}
}
SE
seony.keo
Joined on 07.04.2024
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: TMABands v2.algo
- Rating: 0
- Installs: 132
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.
No comments found.