Can't get horizantal lines to draw
Can't get horizantal lines to draw
15 Apr 2015, 21:47
I'm trying to write a simple "indicator" which is really just a peice of code to store support and resistance levels (which I have found manually and manually added to the code). It is not actually responding to price action in any way. I just want to draw lines at arbitrary levels. I am having trouble getting the DrawLine function to do anything.
The ChartObjects.DrawLine function wants x min and x max values and it has on overload that takes indexes and an overload that takes DateTimes. I would prefer to use DateTime.MinValue and DateTime.MaxValue, so that the levels cover the entire chart forever, but since that is not working, I have also tried using numerical x limits like 0-20, which is also not working.
Here is the code
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; using System.Collections.Generic; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class EURUSDSR : Indicator { [Output("Main")] public IndicatorDataSeries Result { get; set; } //[Parameter()] //public LineStyle LevelStyle { get; set; } [Parameter("Color", DefaultValue = "Gray")] public string LevelColorString { get; set; } private Dictionary<TimeFrame, List<double>> timeFrameLists = new Dictionary<TimeFrame, List<double>>(); private Colors levelColor; private double[] levels1h = new double[] { 1.06, 1.05 }; protected override void Initialize() { Enum.TryParse(LevelColorString, out levelColor); timeFrameLists.Add(TimeFrame.Hour, new List<double>(levels1h)); foreach (TimeFrame thisTimeFrame in timeFrameLists.Keys) { Print("current timeframe = {0}, applying {1}", TimeFrame.ToString(), thisTimeFrame.ToString()); if (TimeFrame > thisTimeFrame) continue; foreach (double level in timeFrameLists[thisTimeFrame]) { DrawLevel(level, 1); } } } public override void Calculate(int index) { } private void DrawLevel(double level, double thickness) { Print("{0}", level); ChartObjects.DrawLine("$" + level, DateTime.MinValue, level, DateTime.MaxValue, level, Colors.Red); // levelcolor); //, thickness); //, LevelStyle); } } }
I can tell from the logs that it is entering my DrawLevel method (with the given levels), but I am not seeing anything appear on my chart. Am I missing something?
Replies
WhiteSage
16 Apr 2015, 08:42
Curious DateTime min and max don't work. You could use the OpenTime's. Try replacing DateTime's with MarketSeries.OpenTime[0]; and MarketSeries.OpenTime.Last[0];
Or the index based overload. 0 and MarketSeries.Count
@WhiteSage
GunArm
15 Apr 2015, 23:00
Sorry, I had not found the DrawHorizantalLine method. It is working for me. I still wonder why the DrawLine wasn't also working...
@GunArm