Issues with OutputAttribute
Issues with OutputAttribute
08 Mar 2019, 19:47
Hello Spotware,
I was trying to change the line color or thickness of an Indicator line with OutputAttribute and I couldn't, I think with the API we should be able to do this, (i.e. a blinking indicator), what's the expected behavior of these properties? They are get / set so I should be able to override and get these values.
Also, the Color property is hidden and set as Green, while the LineColor property is set at null instead of the default value.
Please fix, or let me know if I'm doing something wrong.
Best Regards,
using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)] public class TestOutputAttributes : Indicator { [Parameter("Periods", DefaultValue = 14)] public int Periods { get; set; } [Output("Main", LineColor = "Turquoise")] public IndicatorDataSeries Result { get; set; } private OutputAttribute _output; protected override void Initialize() { _output = new OutputAttribute("Main"); var outputProperties = _output.GetType().GetProperties(); foreach (var p in outputProperties) { Print("{0}:{1}", p.Name, p.GetValue(_output, null)); } //Response: // TypeId:cAlgo.API.OutputAttribute // PlotType:Line // IsHistogram:False // Thickness:1 // LineColor:null // Color:Green // Name:Main // LineStyle:Solid } public override void Calculate(int index) { } } }
Replies
Waxy
12 Mar 2019, 19:48
Hello Panagiotis,
This may get the default color specified using LineColor = Color, however, if the user changes the color or line-style this is not possible to retrieve, it should be able to get the properties the user has changed, not the one hard coded, I think this is a bug.
The code below prints Red despite I'm changing it to various colors.
Thanks for your support,
using System; using System.Reflection; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class ReadOutputAttribute : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main", LineColor = "Red")] public IndicatorDataSeries Result { get; set; } Color _myColor; protected override void Initialize() { } public override void Calculate(int index) { PropertyInfo[] props = typeof(ReadOutputAttribute).GetProperties(); foreach (PropertyInfo prop in props) { object[] attrs = prop.GetCustomAttributes(true); foreach (object attr in attrs) { OutputAttribute outputAttr = attr as OutputAttribute; if (outputAttr != null) { if (outputAttr.LineColor != null) { Print(outputAttr.LineColor.ToString()); _myColor = Color.FromName(outputAttr.LineColor.ToLower()); } else Print("Line Color is null"); } } } Chart.DrawStaticText("Text", "This text changes color", VerticalAlignment.Top, HorizontalAlignment.Right, _myColor); } } }
@Waxy
PanagiotisCharalampous
13 Mar 2019, 08:57
Hi Xavier,
You are using Reflection to get the default value of the property. Reflection cannot give you the current value in memory, just the value compiled in the assembly.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Waxy
19 Mar 2019, 07:57
I think maybe adding these parameters to IndicatorDataSeries would a better option, reflection shouldn't be used for this in my opinion, and also is not enough because it doesn't get the values if they are changed.
Please consider fixing this for 3.6
Thanks for your support
@Waxy
PanagiotisCharalampous
12 Mar 2019, 15:49
Hi Xavier,
What you are trying to do is not supported. The proper way to read output attributes is the below
Best Regards,
Panagiotis
@PanagiotisCharalampous