Im Trying to write my first indicator that will show the number of consecutive hekin-ashi bars with the same color.
However the indicator does not work as intended, I do think that the HABars object do not contain what I think. I would like it to contain the heking-ashi bars but the count does not match what is show in the chart with regards to number of up and down bars.
My question is now how to access hekin-ashi bars form an indicator.
And any additional feedback on my indicator is much appreciated.
This is what I have so far:
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
{
[Levels(0, 5 , 10 , 20)]
[Indicator(AccessRights = AccessRights.None, IsOverlay = false)]
public class HeikinAshiAction : Indicator
{
#region user defined parameters
[Parameter("Trigger Level", Group = "Indicator Level", MinValue=0, MaxValue = 20, DefaultValue = 10)]
public int ActionAlertLevel { get; set; }
[Parameter("Time Frame", Group = "Indicator Data", DefaultValue = "Hm1")]
public TimeFrame UserSelectedTimeFrame { get; set; }
[Output("Action Size Output")]
public IndicatorDataSeries Result { get; set; }
[Output("Trigger", LineColor = "Red")]
public IndicatorDataSeries TriggerLine { get; set; }
#endregion
private Bars HABars {get; set;}
private int _lastNotifiedBarIndex;
protected override void Initialize()
{
HABars = MarketData.GetBars(UserSelectedTimeFrame);
}
public override void Calculate(int index)
{
if (!IsLastBar || _lastNotifiedBarIndex == index) return;
_lastNotifiedBarIndex = index;
if (HABars.ClosePrices[index] > HABars.OpenPrices[index])
{
Print("Up Bar Closed");
if (Functions.IsRising(HABars.ClosePrices)) {
Result[index] = Result[index - 1] + 1;
} else {
Result[index] = 1;
}
}
else if (HABars.ClosePrices[index] < HABars.OpenPrices[index])
{
Print("Down Bar Closed");
if (Functions.IsFalling(HABars.ClosePrices)) {
Result[index] = Result[index - 1] + 1;
} else {
Result[index] = 1;
}
}
TriggerLine[index] = ActionAlertLevel;
Print(Result[index]);
if (Result.HasCrossedAbove(TriggerLine, 0)) {
Notifications.PlaySound("C:\\Windows\\Media\\Alarm09.wav");
}
}
}
}