Cannot draw different up/down colors with DiscontinuousLine properties
Cannot draw different up/down colors with DiscontinuousLine properties
02 Sep 2020, 05:27
Hi everyone:
Here's the output I'm receiving from the sample code below:
I'm trying to have the code draw green lines every time the current value is > previous value, and red lines every time the current value is < previous value.
Is this possible in cTrader? If so, what am I doing wrong in the example code below?
using System;
using cAlgo.API;
namespace cAlgo.Indicators
{
[Levels(-2,-1,0,1,2)]
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class Test : Indicator
{
[Output("UpTrend", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, LineColor = "Green", Thickness = 3)]
public IndicatorDataSeries ResultUpTrend { get; set; }
[Output("DownTrend", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, LineColor = "Red", Thickness = 3)]
public IndicatorDataSeries ResultDownTrend { get; set; }
[Output("Main", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, LineColor = "Blue", Thickness = 1)]
public IndicatorDataSeries Result { get; set; }
private int[] values = new int[10] { -1, 1, -1, -2, -2, -1, 0, -2, 2, 0 };
protected override void Initialize()
{
}
public override void Calculate(int index)
{
if (index < values.Length)
return;
ResultDownTrend[index] = Double.NaN;
ResultUpTrend[index] = Double.NaN;
Result[index] = values[index % values.Length];
if (Result[index] > Result[index - 1])
{
ResultUpTrend[index] = Result[index];
ResultUpTrend[index - 1] = Result[index - 1];
}
else if (Result[index] < Result[index - 1])
{
ResultDownTrend[index] = Result[index];
ResultDownTrend[index - 1] = Result[index - 1];
}
}
}
}
Thank you.
Replies
firemyst
02 Sep 2020, 08:24
( Updated at: 21 Dec 2023, 09:22 )
RE:
PanagiotisCharalampous said:
Hi firemyst,
Yes it is. I don't see anything wrong. Can you elaborate?
Best Regards,
Panagiotis
Hi @Panagiotis:
In the sample screen capture above, the expected output is that all lines going up should be green, all the lines going down should be red as shown below:
However, I'm unable to get the simple code above to do what I want.
What am I missing?
Thank you.
@firemyst
PanagiotisCharalampous
02 Sep 2020, 08:28
Hi firemyst,
You are missing the case where the values are equal :)
Best Regards,
Panagiotis
@PanagiotisCharalampous
firemyst
02 Sep 2020, 08:43
( Updated at: 21 Dec 2023, 09:22 )
RE:
PanagiotisCharalampous said:
Hi firemyst,
You are missing the case where the values are equal :)
Best Regards,
Panagiotis
HI @Panagiotis:
I don't think it's that simple because I had some code for the equal scenario.
Here's why. Look at the graphic below:
Point "A" is -2; "B" is 2; "C" is 0.
So at those points ResultsDownTrend[index] is -2, 2, and 0 respectively.
A has to be -2 because it's coming down from the previous point.
B has to be 2 because it's going down to point C.
cTrader is then automatically drawing the line between values A & B because both A & B have values for the preceeding/postceeding points even though I don't want the line drawn between those two points.
How do we get around this?
@firemyst
PanagiotisCharalampous
02 Sep 2020, 09:06
Hi firemyst,
The only way I can think of to get around this is to use two IndicatorDataSeries for each case and use them interchangeably so that gaps are maintained.
Best Regards,
Panagiotis
@PanagiotisCharalampous
firemyst
02 Sep 2020, 12:31
RE:
PanagiotisCharalampous said:
Hi firemyst,
The only way I can think of to get around this is to use two IndicatorDataSeries for each case and use them interchangeably so that gaps are maintained.
Best Regards,
Panagiotis
So essentially every developed cTrader indicator that uses different data series for up/down colors will have this issue?
Thanks for your suggestion @Panagiotis, but as I think you understand it isn't really practical to have two dataseries for "up" colors and two dataseries for "down" colors and having to interchange them..
Is this functionality something Spotware is working on to resolve?
I mean, every other platform out there allows for separate up/down colors in their indicators without this issue.
Why is it so hard to include it within cTrader?
Thank you.
@firemyst
PanagiotisCharalampous
02 Sep 2020, 12:36
Hi firemyst,
So essentially every developed cTrader indicator that uses different data series for up/down colors will have this issue?
No. This not a problem with cTrader but with your logic. So there is nothing to resolve here. cTrader leaves gaps when there are no values in the data series. But you leave no gaps, therefore there is no way cTrader to know that you do not want a line to be drawn. If your dataseries has values then cTrader will join the dots.
Best Regards,
Panagiotis
@PanagiotisCharalampous
firemyst
02 Sep 2020, 16:17
RE:
PanagiotisCharalampous said:
Hi firemyst,
So essentially every developed cTrader indicator that uses different data series for up/down colors will have this issue?
No. This not a problem with cTrader but with your logic. So there is nothing to resolve here. cTrader leaves gaps when there are no values in the data series. But you leave no gaps, therefore there is no way cTrader to know that you do not want a line to be drawn. If your dataseries has values then cTrader will join the dots.
Best Regards,
Panagiotis
"No. This not a problem with cTrader but with your logic."
But you just told me there's no way to accomplish the logic without having two dataseries objects to use interchangeably for the same trend:
"The only way I can think of to get around this is to use two IndicatorDataSeries for each case and use them interchangeably"
That means I need two separate indicator dataseries for the uptrend and two separate indicator downseries for the downtrend:
If I understand correctly, that means at least 4 Indicatordataseries objects just to draw two lines correctly?
If there's an error with my logic, are you able to post or show me an example where it works with the alternating color lines properly drawn with the data I provided in the sample code?
Thank you,
@firemyst
PanagiotisCharalampous
02 Sep 2020, 16:25
Hi firemyst,
But you just told me there's no way to accomplish the logic without having two dataseries objects to use interchangeably for the same trend:
Yes because you are using the wrong tool for the job. You are trying to display discontinuous lines with continuous data series. Why don't you use trendlines instead?
if (Result[index] > Result[index - 1])
{
Chart.IndicatorAreas[0].DrawTrendLine(index.ToString(), Bars.OpenTimes[index - 1], Result[index - 1], Bars.OpenTimes[index], Result[index], Color.Green);
}
if (Result[index] < Result[index - 1])
{
Chart.IndicatorAreas[0].DrawTrendLine(index.ToString(), Bars.OpenTimes[index - 1], Result[index - 1], Bars.OpenTimes[index], Result[index], Color.Red);
}
Best Regards,
Panagiotis
@PanagiotisCharalampous
firemyst
03 Sep 2020, 04:59
( Updated at: 21 Dec 2023, 09:22 )
RE:
PanagiotisCharalampous said:
Hi firemyst,
But you just told me there's no way to accomplish the logic without having two dataseries objects to use interchangeably for the same trend:
Yes because you are using the wrong tool for the job. You are trying to display discontinuous lines with continuous data series. Why don't you use trendlines instead?
if (Result[index] > Result[index - 1]) { Chart.IndicatorAreas[0].DrawTrendLine(index.ToString(), Bars.OpenTimes[index - 1], Result[index - 1], Bars.OpenTimes[index], Result[index], Color.Green); } if (Result[index] < Result[index - 1]) { Chart.IndicatorAreas[0].DrawTrendLine(index.ToString(), Bars.OpenTimes[index - 1], Result[index - 1], Bars.OpenTimes[index], Result[index], Color.Red); }
Best Regards,
Panagiotis
Your right in that those would work. But that kind of defeats the purpose of having an indicatordataseries with "discontinuous lines" for plotting. So developers have to add in extra parameters for line style, plot type, color, thickness, etc to chart, since the API doesn't allow for us to obtain those properties from the IndicatorDataSeries objects.
In otherwords, It would be great to be able to avoid cluttering up the parameter interface with the associated parameters users can't even see the preview of:
Unless there's another way to do it or a way from the API to get the settings from the IndicatorDataSeries settings under "Lines"?
@firemyst
PanagiotisCharalampous
03 Sep 2020, 07:45
Hi firemyst,
But that kind of defeats the purpose of having an indicatordataseries with "discontinuous lines" for plotting.
Discontinuous lines work fine when they are ... discontinuous :) Your lines are not discontinuous.
Unless there's another way to do it or a way from the API to get the settings from the IndicatorDataSeries settings under "Lines"?
No there isn't at the moment.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
02 Sep 2020, 08:07
Hi firemyst,
Yes it is. I don't see anything wrong. Can you elaborate?
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous