Belkhayate Timing indicator, multiple time frame support
Belkhayate Timing indicator, multiple time frame support
24 Sep 2014, 22:19
Hi,
So I'm trying to adjust the belkhayate timing indicator as posted in the library to work in a different timeframe. This because I have a bot on one time-frame (say h1) while I want that bot to use the values for the belkhayate timing on a say h4 timeframe. This is how I have it now:
namespace cAlgo.Indicators { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BelkhayateTiming : Indicator { private int LastAlertBar; private MarketSeries MyMarketSeries; [Parameter()] public TimeFrame MyTimeFrame { get; set; } [Output("High", Color = Colors.Gray, PlotType = PlotType.Points)] public IndicatorDataSeries High { get; set; } [Output("Low", Color = Colors.Gray, PlotType = PlotType.Points)] public IndicatorDataSeries Low { get; set; } [Output("Open", Color = Colors.Gray, PlotType = PlotType.Points)] public IndicatorDataSeries Open { get; set; } [Output("Close", Color = Colors.Gray, PlotType = PlotType.Points)] public IndicatorDataSeries Close { get; set; } [Output("SellLine1", Color = Colors.DimGray, PlotType = PlotType.Line, LineStyle = LineStyle.Lines)] public IndicatorDataSeries SellLine1 { get; set; } [Output("SellLine2", Color = Colors.DimGray, PlotType = PlotType.Line, LineStyle = LineStyle.Lines)] public IndicatorDataSeries SellLine2 { get; set; } [Output("BuyLine1", Color = Colors.DimGray, PlotType = PlotType.Line, LineStyle = LineStyle.Lines)] public IndicatorDataSeries BuyLine1 { get; set; } [Output("BuyLine2", Color = Colors.DimGray, PlotType = PlotType.Line, LineStyle = LineStyle.Lines)] public IndicatorDataSeries BuyLine2 { get; set; } protected override void Initialize() { MyMarketSeries = MarketData.GetSeries(MyTimeFrame); } public override void Calculate(int index) { double middle = (((MyMarketSeries.High[index] + MyMarketSeries.Low[index]) / 2) + ((MyMarketSeries.High[index - 1] + MyMarketSeries.Low[index - 1]) / 2) + ((MyMarketSeries.High[index - 2] + MyMarketSeries.Low[index - 2]) / 2) + ((MyMarketSeries.High[index - 3] + MyMarketSeries.Low[index - 3]) / 2) + ((MyMarketSeries.High[index - 4] + MyMarketSeries.Low[index - 4]) / 2)) / 5; double scale = (((MyMarketSeries.High[index] - MyMarketSeries.Low[index]) + (MyMarketSeries.High[index - 1] - MyMarketSeries.Low[index - 1]) + (MyMarketSeries.High[index - 2] - MyMarketSeries.Low[index - 2]) + (MyMarketSeries.High[index - 3] - MyMarketSeries.Low[index - 3]) + (MyMarketSeries.High[index - 4] - MyMarketSeries.Low[index - 4])) / 5) * 0.2; High[index] = (MyMarketSeries.High[index] - middle) / scale; Low[index] = (MyMarketSeries.Low[index] - middle) / scale; Open[index] = (MyMarketSeries.Open[index] - middle) / scale; Close[index] = (MyMarketSeries.Close[index] - middle) / scale; if (Open[index] > Close[index]) { ChartObjects.DrawLine(string.Format("CRS_High_{0}", index), index, High[index], index, Low[index], Colors.Gray, 1, LineStyle.Solid); ChartObjects.DrawLine(string.Format("CRS_Open_{0}", index), index, Open[index], index, Close[index], Colors.DimGray, 11, LineStyle.Solid); } else { ChartObjects.DrawLine(string.Format("CRS_Low_{0}", index), index, High[index], index, Low[index], Colors.Gray, 1, LineStyle.Solid); ChartObjects.DrawLine(string.Format("CRS_Close_{0}", index), index, Open[index], index, Close[index], Colors.LightGray, 11, LineStyle.Solid); } SellLine1[index] = 6; SellLine2[index] = 8; BuyLine1[index] = -6; BuyLine2[index] = -8; } } }
What I want is that I can use the following bit of code in my OnBar () method (running on a h1 timeframe) to capture the last close of the belkhayate timing (which is on a different timeframe). So every time my OnBar () gets called (every hour) I want it to get the results of the last h4 bar.
protected override void OnBar() { if (Timing.Close.Last(1) < Timing.BuyLine2.Last(1)) { // blablalba } }
This gives me a NaN error..
Hope it is clear.
Replies
Spotware
25 Sep 2014, 12:19
We can recommend you to contact one of our Partners or post a job in Development Jobs section.
@Spotware
Pannekoek
24 Sep 2014, 22:23
Additional note. If I just use it as an indicator and change the MyTimeFrame variable, it does show up. However, it also does create a new bar on every new bar on the original time-frame, which is not desired.
@Pannekoek