Change the appearance of the round number indicator
Change the appearance of the round number indicator
30 Dec 2021, 14:05
Hello I would like to change the dotted lines and put the color in blue on the indicator "round number" thank you for your help
Replies
romainvellu
30 Dec 2021, 14:58
RE:
amusleh said:
Hi,
Please post the code of indicator and then we will be able to help you.
using
System;
using
cAlgo.API;
namespace
cAlgo.Indicators
{
[Indicator(IsOverlay =
true
, AccessRights = AccessRights.None)]
public
class
RoundNumbers : Indicator
{
[Parameter(DefaultValue = 100)]
public
int
StepPips {
get
;
set
; }
protected
override
void
Initialize()
{
double
max = MarketSeries.High.Maximum(MarketSeries.High.Count);
double
min = MarketSeries.Low.Minimum(MarketSeries.Low.Count);
double
step = Symbol.PipSize*StepPips;
double
start = Math.Floor(min/step)*step;
for
(
double
level = start; level <= max + step; level += step)
{
ChartObjects.DrawHorizontalLine(
"line_"
+ level, level, Colors.Gray);
}
}
public
override
void
Calculate(
int
index)
{
}
}
}
@romainvellu
romainvellu
30 Dec 2021, 15:02
( Updated at: 21 Dec 2023, 09:22 )
RE: RE:
Hello is it possible to put the same line and the same color blue please
romainvellu said:
amusleh said:
Hi,
Please post the code of indicator and then we will be able to help you.
using
System;
using
cAlgo.API;
namespace
cAlgo.Indicators
{
[Indicator(IsOverlay =
true
, AccessRights = AccessRights.None)]
public
class
RoundNumbers : Indicator
{
[Parameter(DefaultValue = 100)]
public
int
StepPips {
get
;
set
; }
protected
override
void
Initialize()
{
double
max = MarketSeries.High.Maximum(MarketSeries.High.Count);
double
min = MarketSeries.Low.Minimum(MarketSeries.Low.Count);
double
step = Symbol.PipSize*StepPips;
double
start = Math.Floor(min/step)*step;
for
(
double
level = start; level <= max + step; level += step)
{
ChartObjects.DrawHorizontalLine(
"line_"
+ level, level, Colors.Gray);
}
}
public
override
void
Calculate(
int
index)
{
}
}
}
@romainvellu
amusleh
30 Dec 2021, 15:45
Hi,
Try this:
using System;
using cAlgo.API;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class RoundNumbers : Indicator
{
[Parameter("Line Color", DefaultValue = "Gray")]
public string LineColor { get; set; }
[Parameter("Color", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
public int ColorAlpha { get; set; }
[Parameter(DefaultValue = 100)]
public int StepPips { get; set; }
protected override void Initialize()
{
double max = Bars.HighPrices.Maximum(Bars.HighPrices.Count);
double min = Bars.LowPrices.Minimum(Bars.LowPrices.Count);
double step = Symbol.PipSize * StepPips;
double start = Math.Floor(min / step) * step;
var color = GetColor(LineColor, ColorAlpha);
for (double level = start; level <= max + step; level += step)
{
Chart.DrawHorizontalLine("line_" + level, level, color);
}
}
public override void Calculate(int index)
{
}
private Color GetColor(string colorString, int alpha = 255)
{
var color = colorString[0] == '#' ? Color.FromHex(colorString) : Color.FromName(colorString);
return Color.FromArgb(alpha, color);
}
}
}
You can use any Color name or hexadecimal color code for line color parameter, with Color alpha you can control the color transparency.
@amusleh
romainvellu
30 Dec 2021, 15:47
RE:
Ok great thanks a lot
How do I enter this on ctrader now?
Hi,
Try this:
using System; using cAlgo.API; namespace cAlgo.Indicators { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] public class RoundNumbers : Indicator { [Parameter("Line Color", DefaultValue = "Gray")] public string LineColor { get; set; } [Parameter("Color", DefaultValue = 255, MinValue = 0, MaxValue = 255)] public int ColorAlpha { get; set; } [Parameter(DefaultValue = 100)] public int StepPips { get; set; } protected override void Initialize() { double max = Bars.HighPrices.Maximum(Bars.HighPrices.Count); double min = Bars.LowPrices.Minimum(Bars.LowPrices.Count); double step = Symbol.PipSize * StepPips; double start = Math.Floor(min / step) * step; var color = GetColor(LineColor, ColorAlpha); for (double level = start; level <= max + step; level += step) { Chart.DrawHorizontalLine("line_" + level, level, color); } } public override void Calculate(int index) { } private Color GetColor(string colorString, int alpha = 255) { var color = colorString[0] == '#' ? Color.FromHex(colorString) : Color.FromName(colorString); return Color.FromArgb(alpha, color); } } }
You can use any Color name or hexadecimal color code for line color parameter, with Color alpha you can control the color transparency.
@romainvellu
amusleh
31 Dec 2021, 07:25
Hi,
Please follow this instruction: Creating an Indicator | cTrader Help Center
@amusleh
amusleh
31 Dec 2021, 11:55
( Updated at: 31 Dec 2021, 11:56 )
Hi,
I added line style:
using System;
using cAlgo.API;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class RoundNumbers : Indicator
{
[Parameter("Line Color", DefaultValue = "Blue")]
public string LineColor { get; set; }
[Parameter("Color", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
public int ColorAlpha { get; set; }
[Parameter("Style", DefaultValue = LineStyle.Dots)]
public LineStyle Style { get; set; }
[Parameter(DefaultValue = 100)]
public int StepPips { get; set; }
protected override void Initialize()
{
double max = Bars.HighPrices.Maximum(Bars.HighPrices.Count);
double min = Bars.LowPrices.Minimum(Bars.LowPrices.Count);
double step = Symbol.PipSize * StepPips;
double start = Math.Floor(min / step) * step;
var color = GetColor(LineColor, ColorAlpha);
for (double level = start; level <= max + step; level += step)
{
Chart.DrawHorizontalLine("line_" + level, level, color, 1, Style);
}
}
public override void Calculate(int index)
{
}
private Color GetColor(string colorString, int alpha = 255)
{
var color = colorString[0] == '#' ? Color.FromHex(colorString) : Color.FromName(colorString);
return Color.FromArgb(alpha, color);
}
}
}
@amusleh
amusleh
30 Dec 2021, 14:57
Hi,
Please post the code of indicator and then we will be able to help you.
@amusleh