Fibonacci Bands indicator not building.
Fibonacci Bands indicator not building.
26 Jan 2013, 21:11
Hi Support I tryimng to get the Fibonacci Bands indicator to work, I have built the Average True Range using /algos/show/10 as required by Fibonacci Bands indicator to work the other option will not build either.
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true)]
public class FibonacciBands : Indicator
{
private AverageTrueRange _averageTrueRange;
private ExponentialMovingAverage _exponentialMovingAverage;
[Parameter(DefaultValue = 55)]
public int PeriodEma { get; set; }
[Parameter(DefaultValue = 21)]
public int PeriodAtr { get; set; }
[Output("Upper Band 1", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand1 { get; set; }
[Output("Upper Band 2", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand2 { get; set; }
[Output("Upper Band 3", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand3 { get; set; }
[Output("Upper Band 4", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand4 { get; set; }
[Output("Lower Band 1", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand1 { get; set; }
[Output("Lower Band 2", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand2 { get; set; }
[Output("Lower Band 3", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand3 { get; set; }
[Output("Lower Band 4", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand4 { get; set; }
[Output("EMA", Color = Colors.Blue)]
public IndicatorDataSeries Ema { get; set; }
protected override void Initialize()
{
_averageTrueRange = Indicators.GetIndicator<AverageTrueRange>(PeriodAtr);
_exponentialMovingAverage = Indicators.ExponentialMovingAverage(MarketSeries.Close, PeriodEma);
}
public override void Calculate(int index)
{
double ema = _exponentialMovingAverage.Result[index];
double atr = _averageTrueRange.Result[index];
UpperBand1[index] = ema + 1.62*atr;
UpperBand2[index] = ema + 2.62*atr;
UpperBand3[index] = ema + 4.23*atr;
UpperBand4[index] = ema + 1*atr;
LowerBand1[index] = ema - 1.62*atr;
LowerBand2[index] = ema - 2.62*atr;
LowerBand3[index] = ema - 4.23*atr;
LowerBand4[index] = ema - 1*atr;
Ema[index] = ema;
}
}
}
Thanks
Scott
Replies
Scott
15 Feb 2013, 23:51
( Updated at: 21 Dec 2023, 09:20 )
RE:
Regarding the error you are receiving you need to add a reference of the Average true range algo file. You can do this by clicking the button next to the build button on the top of the text editor.
I still can not get this to work
Build failed Errors: 1 Error: 'cAlgo.Indicators.averageTrueRange' does not contain a definition for 'Results' and no extension method 'Result' accepting a first argument of type 'cAlgo.Indicators.averageTrueRange' could be found (are you missing a using directive or an assembly reference?)
//#reference: C:\Users\scott\Documents\cAlgo\Sources\Indicators\averageTrueRange.algo
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true)]
public class FibonacciBands : Indicator
{
private averageTrueRange _averageTrueRange;
private ExponentialMovingAverage _exponentialMovingAverage;
[Parameter(DefaultValue = 55)]
public int PeriodEma { get; set; }
[Parameter(DefaultValue = 21)]
public int PeriodAtr { get; set; }
[Output("Upper Band 1", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand1 { get; set; }
[Output("Upper Band 2", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand2 { get; set; }
[Output("Upper Band 3", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand3 { get; set; }
[Output("Upper Band 4", Color = Colors.DarkCyan)]
public IndicatorDataSeries UpperBand4 { get; set; }
[Output("Lower Band 1", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand1 { get; set; }
[Output("Lower Band 2", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand2 { get; set; }
[Output("Lower Band 3", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand3 { get; set; }
[Output("Lower Band 4", Color = Colors.DarkGreen)]
public IndicatorDataSeries LowerBand4 { get; set; }
[Output("EMA", Color = Colors.Blue)]
public IndicatorDataSeries Ema { get; set; }
protected override void Initialize()
{
_averageTrueRange = Indicators.GetIndicator<averageTrueRange>(PeriodAtr);
_exponentialMovingAverage = Indicators.ExponentialMovingAverage(MarketSeries.Close, PeriodEma);
}
public override void Calculate(int index)
{
double ema = _exponentialMovingAverage.Result[index];
double atr = _averageTrueRange.Result[index];
UpperBand1[index] = ema + 1.62*atr;
UpperBand2[index] = ema + 2.62*atr;
UpperBand3[index] = ema + 4.23*atr;
UpperBand4[index] = ema + 1*atr;
LowerBand1[index] = ema - 1.62*atr;
LowerBand2[index] = ema - 2.62*atr;
LowerBand3[index] = ema - 4.23*atr;
LowerBand4[index] = ema - 1*atr;
Ema[index] = ema;
}
}
}
The code for the averageTrueRange that I'm using that builds
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = false,ScalePrecision = 5)]
public class averageTrueRange : Indicator
{
[Parameter(DefaultValue = 14, MinValue = 2)]
public int Period { get; set; }
[Output("AverageTrueRange", Color = Colors.Orange)]
public IndicatorDataSeries atr { get; set; }
private ExponentialMovingAverage ema;
public IndicatorDataSeries tr;
private TrueRange tri;
protected override void Initialize()
{
tr = CreateDataSeries();
tri = Indicators.TrueRange();
ema = Indicators.ExponentialMovingAverage(tr,Period);
}
public override void Calculate(int index)
{
if(index<Period+1)
{atr[index] = tri.Result[index];}
if(index>=Period){
atr[index] = (atr[index-1]*(Period-1)+tri.Result[index]) / Period;}
}
}
}
Thanks
@Scott
admin
18 Feb 2013, 09:54
You need to replace Result with atr in the FibonacciBands indicator or replace atr with Result in the averageTrueRange indicator (this requires a build of the averageTrueRange indicator as well)
First option(FibonacciBands):
public override void Calculate(int index) { double ema = _exponentialMovingAverage.Result[index]; double atr = _averageTrueRange.atr[index];
Second option (averageTrueRange ):
[Output("AverageTrueRange", Color = Colors.Orange)] public IndicatorDataSeries Result { get; set; }
@admin
Scott
20 Feb 2013, 00:11
RE:
You need to replace Result with atr in the FibonacciBands indicator or replace atr with Result in the averageTrueRange indicator (this requires a build of the averageTrueRange indicator as well)
First option(FibonacciBands):
public override void Calculate(int index) { double ema = _exponentialMovingAverage.Result[index]; double atr = _averageTrueRange.atr[index];
Second option (averageTrueRange ):[Output("AverageTrueRange", Color = Colors.Orange)] public IndicatorDataSeries Result { get; set; }
Thank you, it now builds I went with the first solution. Is there a way to shade in the space between lines, it would make it a lot easyer to see at a glance than looking for the lines?
@Scott
admin
28 Jan 2013, 11:11 ( Updated at: 21 Dec 2023, 09:20 )
Regarding the error you are receiving you need to add a reference of the Average true range algo file. You can do this by clicking the button next to the build button on the top of the text editor.
@admin