Problem with indicator
Created at 27 Oct 2015, 14:15
Problem with indicator
27 Oct 2015, 14:15
Hello,
I have created an indicator, which draws lines on a high and low levels from a higher timeframe. Sometimes, on timeframe H8 and at 4 pm line is not drawn. Can you help me?
Piotr Dymek
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 High_And_Low_Zone : Indicator { [Parameter("Timeframe", DefaultValue = "Hour")] public TimeFrame Period { get; set; } [Parameter("Periods To Plot", DefaultValue = 5)] public int PeriodsToPlot { get; set; } [Parameter("High Color", DefaultValue = "Green")] public string HighColor { get; set; } [Parameter("High Thick", DefaultValue = "3")] public int HighThick { get; set; } [Parameter("High Style", DefaultValue = "Solid")] public string HighStyle { get; set; } [Parameter("Low Color", DefaultValue = "Red")] public string LowColor { get; set; } [Parameter("Low Thick", DefaultValue = "3")] public int LowThick { get; set; } [Parameter("Low Style", DefaultValue = "Solid")] public string LowStyle { get; set; } [Parameter("Shift", DefaultValue = 0)] public int ShiftMinute { get; set; } private Colors _colorHigh; private Colors _colorLow; private LineStyle _styleHigh; private LineStyle _styleLow; protected override void Initialize() { // Initialize and create nested indicators if (!Enum.TryParse(HighColor, out _colorHigh)) { ChartObjects.DrawText("errorMsg1", "Invalid Color for High Line", StaticPosition.TopLeft, Colors.Red); _colorHigh = Colors.Green; } if (!Enum.TryParse(LowColor, out _colorLow)) { ChartObjects.DrawText("errorMsg2", "\nInvalid Color for Low Line", StaticPosition.TopLeft, Colors.Red); _colorLow = Colors.Red; } if (!Enum.TryParse(HighStyle, out _styleHigh)) { ChartObjects.DrawText("errorMsg3", "\nInvalid Style for High Line", StaticPosition.TopLeft, Colors.Red); _styleHigh = LineStyle.Solid; } if (!Enum.TryParse(LowStyle, out _styleLow)) { ChartObjects.DrawText("errorMsg4", "\nInvalid Style for Low Line", StaticPosition.TopLeft, Colors.Red); _styleLow = LineStyle.Solid; } } public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... //DateTime today = MarketSeries.OpenTime[index].Date; if (index != MarketSeries.Low.Count - 1) return; MarketSeries series = MarketData.GetSeries(Period); double minutes1 = ((TimeSpan)((series.OpenTime[series.OpenTime.Count - 1] - series.OpenTime[series.OpenTime.Count - 2]))).TotalMinutes; //ostatnia i przedostatnia swieca double minutes2 = ((TimeSpan)((series.OpenTime[series.OpenTime.Count - 2] - series.OpenTime[series.OpenTime.Count - 3]))).TotalMinutes; //przedostatnia swieca i przedprzedostatnia double minutes3 = ((TimeSpan)((series.OpenTime[series.OpenTime.Count - 3] - series.OpenTime[series.OpenTime.Count - 4]))).TotalMinutes; //przedprzedostatnia i przedprzedprzedostatnia swieca double periodMinute = minutes1; if (minutes1 != minutes2) { if (minutes2 == minutes3) periodMinute = minutes2; } for (int i = 0; i < PeriodsToPlot; i++) { DateTime startTime = DateTime.Now; startTime = series.OpenTime[series.OpenTime.Count - i - 1].AddMinutes(ShiftMinute); int ind = MarketSeries.OpenTime.GetIndexByTime(startTime.AddMinutes(periodMinute)); if (ind != MarketSeries.OpenTime.Count - 1) ind--; DateTime endTime = MarketSeries.OpenTime[ind]; double high = 0; double low = double.MaxValue; // for (int j = MarketSeries.OpenTime.Count - 1; j >= 0; j--) { if (MarketSeries.OpenTime[j] < startTime) break; if (MarketSeries.OpenTime[j] <= endTime) { if (MarketSeries.High[j] >= high) high = MarketSeries.High[j]; if (MarketSeries.Low[j] <= low) low = MarketSeries.Low[j]; } } ChartObjects.DrawLine("high " + startTime, startTime, high, endTime, high, _colorHigh, HighThick, _styleHigh); ChartObjects.DrawLine("low " + startTime, startTime, low, endTime, low, _colorLow, LowThick); } //ChartObjects.DrawText("errorMsg4", msg, StaticPosition.TopLeft, Colors.Red); } } }
Spotware
28 Oct 2015, 07:36
Dear Trader,
We would like to inform you that we do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.
@Spotware