Description
Average Daily Range. Defaults to the last 5 days DAILY average irrespective of chart time frame. Calculates average of last x days (high - low) values.
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using cAlgo.API;
// Name: DCT - ADR
// Purpose: To indicate average Daily range irrespective of the timeframe of the current chart.
// Author: TimT - Deckchair Trader, timt@deckchairtrader.com
// Version: 1.0
// Date Created: 26 May 2023
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Deckchair Trader 2023
namespace cAlgo.Indicators
{
#if DEBUG
[Indicator(IsOverlay = false, AccessRights = AccessRights.FullAccess)]
#else
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
#endif
public class ADR : Indicator
{
[Parameter("Periods", Group = "ADR", DefaultValue = 5)]
public int Periods { get; set; } // how many daily periods to take into account
[Parameter("Multiplier", Group = "ADR", DefaultValue = 1)]
public double Multiplier { get; set; } // useful if we only want half of the ADR or twice the ADR for ref purposes
[Output("ADR", LineColor = "Cyan", PlotType = PlotType.Line, Thickness = 2)]
public IndicatorDataSeries ADRSeries { get; set; }
private Bars DailyBars;
protected override void Initialize()
{
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif
ReLoadDailyBars();
}
private void ReLoadDailyBars()
{
DailyBars = MarketData.GetBars(TimeFrame.Daily); // we always measure against days, get the main set
}
public override void Calculate(int index)
{
DrawValue(index);
}
private void DrawValue(int index)
{
double val = 0;
int DailyIndex = DailyBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]); // work out the correct index for the daily chart
//Print($"HourlyOpenTime={Bars.OpenTimes[index]} index={index} DailyOpenTime={DailyBars.OpenTimes[DailyIndex]} DailyIndex={DailyIndex} DailyBarsCount={DailyBars.Count} Periods={Periods} High={DailyBars[DailyIndex].High} Low={DailyBars[DailyIndex].Low}" );
if (DailyIndex >= Periods)
{
for (int n = 1; n <= Periods; n++)
{
val += (DailyBars[DailyIndex - n].High - DailyBars[DailyIndex - n].Low);
}
ADRSeries[index] = val / Periods * Multiplier; // get average
}
}
}
}
DeckchairTrader
Joined on 15.05.2023
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: DCT - ADR.algo
- Rating: 0
- Installs: 677
- Modified: 26/05/2023 14:20
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.