how can I plot lines of size of one bar at open and close price?
how can I plot lines of size of one bar at open and close price?
16 Mar 2018, 19:14
Hello, I am not an experienced coder. I am having a problem plotting a line at open and close of the price. Below are codes I wrote.
ChartObjects.DrawLine("LineHA2" + index, index, MarketSeries.Open[index], index, MarketSeries.Open[index], Color, CandleWidth2, LineStyle.Solid);
ChartObjects.DrawLine("LineHA3" + index, index, MarketSeries.Close[index], index, MarketSeries.Close[index], Color, CandleWidth2, LineStyle.Solid);
The problem is that LineHA2 and 3 do not appear. Compilation showed no problem, saying a successful build.
I think the problem here is that Y coordinate of starting point and ending point is the same.
I came up with the idea of drawing lines in vertical size of 0.1 pip, but I failed, having attempted "MarketSeries.Open[index] - 1" and "MarketSeries.Open[index] - 0.1"
But I dont know how to do that. Plz help.
Thank you.
Replies
Singleton
19 Mar 2018, 11:57
RE:
Panagiotis Charalampous said:
Hi Singleton,
It would be easier for us to help you if you shared with us the complete indicator code.
Best Regards,
Panagiotis
Thank you for a comment. I am seeking the way to mark open and close price on heiken ashi candles. I came up with the idea of drawing a line at open and close price, with its width big enough to denote actual open and close.
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] public class HeikenAshiSmoothed : Indicator { [Parameter(DefaultValue = 5, MinValue = 1)] public int Periods { get; set; } [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)] public MovingAverageType MAType { get; set; } [Parameter("Candle width", DefaultValue = 5)] public int CandleWidth { get; set; } private MovingAverage maOpen; private MovingAverage maClose; private MovingAverage maHigh; private MovingAverage maLow; private IndicatorDataSeries haClose; private IndicatorDataSeries haOpen; protected override void Initialize() { maOpen = Indicators.MovingAverage(MarketSeries.Open, Periods, MAType); maClose = Indicators.MovingAverage(MarketSeries.Close, Periods, MAType); maHigh = Indicators.MovingAverage(MarketSeries.High, Periods, MAType); maLow = Indicators.MovingAverage(MarketSeries.Low, Periods, MAType); haOpen = CreateDataSeries(); haClose = CreateDataSeries(); } public override void Calculate(int index) { double haHigh; double haLow; Colors Color; if (index > 0 && !double.IsNaN(maOpen.Result[index - 1])) { haOpen[index] = (haOpen[index - 1] + haClose[index - 1]) / 2; haClose[index] = (maOpen.Result[index] + maClose.Result[index] + maHigh.Result[index] + maLow.Result[index]) / 4; haHigh = Math.Max(maHigh.Result[index], Math.Max(haOpen[index], haClose[index])); haLow = Math.Min(maLow.Result[index], Math.Min(haOpen[index], haClose[index])); Color = (haOpen[index] > haClose[index]) ? Colors.Red : Colors.Blue; ChartObjects.DrawLine("BarHA" + index, index, haOpen[index], index, haClose[index], Color, 5, LineStyle.Solid); ChartObjects.DrawLine("LineHA" + index, index, haHigh, index, haLow, Color, 1, LineStyle.Solid); ChartObjects.DrawLine("LineHA2" + index, index, MarketSeries.Open[index], index, MarketSeries.Close[index], Color, CandleWidth, LineStyle.Solid); ChartObjects.DrawLine("LineHA3" + index, index, MarketSeries.Close[index], index, MarketSeries.Close[index], Color, CandleWidth, LineStyle.Solid); } else if (!double.IsNaN(maOpen.Result[index])) { haOpen[index] = (maOpen.Result[index] + maClose.Result[index]) / 2; haClose[index] = (maOpen.Result[index] + maClose.Result[index] + maHigh.Result[index] + maLow.Result[index]) / 4; haHigh = maHigh.Result[index]; haLow = maLow.Result[index]; } } } }
@Singleton
Singleton
19 Mar 2018, 12:03
RE: RE:
I tried changing width and colors, but to no avail. I think the issue is that in "ChartObjects.DrawLine," the starting point and finishing point of line is the same. I just need to see open and close of actual price on top of a heiken ashi chart.
This would have been no issue if I can have a main bar chart on the foreground - on the top of the layer, as in MT4 and MT5. but it seems that I cannot put indicators back to the original price chart; indicators always get plotted on the top of charts.
Thank you
@Singleton
PanagiotisCharalampous
19 Mar 2018, 14:23
Hi Singleton,
Indeed you need to have some width to draw horizontal lines. Another suggestion would be to output these prices as indicator outputs. You could have output series with a Points plot type like below
[Output("Open", Color = Colors.Blue, PlotType = PlotType.Points)] public IndicatorDataSeries Open{ get; set; } [Output("Close", Color = Colors.Red, PlotType = PlotType.Points)] public IndicatorDataSeries Close{ get; set; }
and fill them with the relevant data.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Singleton
23 Mar 2018, 11:27
RE:
Sorry for a late reply
I tried your suggestion, but I was disappointed that it did not solve the problem. result in the same as having a original bar chart behind heiken ashi. The objects "Points" are drawn behind heiken ashi. This was, regrettably, no better than having a original bar chart behind heiken ashi, in which open and close of bars occasionally get covered behind heiken ashi bars.
May I seek another suggestion from you?
Incidentally, I think it is critical to allow original charts, whether bars or candlesticks, to be drawn on the top of indicators, ideally with options of choosing layers on which indicators are plotted, imaginably by way of an object tree.
Thank you
@Singleton
PanagiotisCharalampous
19 Mar 2018, 10:09
Hi Singleton,
It would be easier for us to help you if you shared with us the complete indicator code.
Best Regards,
Panagiotis
@PanagiotisCharalampous