Coding Help Please  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
dave2013
Posts: 3
Joined: 15 Sep 2013
Has thanked: 1 time
Been thanked: 1 time

Coding Help Please

Postby dave2013 » 16 Sep 2013

Hi,

I'm trying to modify the DMI study to color (DMIplus - DMIminus) and the ADX line according to their slopes as shown in the attached image.

I only need two colors, not a gradient.

I believe that I have to create an array of the indicators to be able to refer to its previous value. I've tried using examples from other studies as well as documentation but I can't figure out how to doit.

Any help will be appreciated.

The code is below including the error message:

Code: Select all

using System.Drawing;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
public class dl_DMIdiff_2 : IndicatorObject
{
private DirMovement m_dirmovement1;

private IPlotObject Plot1;

private IPlotObject Plot2;

private IPlotObject Plot3;

public dl_DMIdiff_2(object ctx) :
base(ctx){
adxtrend = 8;
length = 8;
}

[Input]
public int length { get; set; }

[Input]
public double adxtrend { get; set; }

protected override void Create(){
m_dirmovement1 = new DirMovement(this);
Plot1 =
AddPlot(new PlotAttributes("DMI+", EPlotShapes.Histogram, Color.Blue,
Color.Empty, 0, 0, true));
Plot2 =
AddPlot(new PlotAttributes("DMI-",EPlotShapes.Histogram, Color.Magenta,
Color.Empty,
0, 0, true));
Plot3 =
AddPlot(new PlotAttributes("ADX", 0, Color.Cyan,
Color.Empty, 0, 0, true));
}

protected override void StartCalc(){
m_dirmovement1.PriceH = Bars.High;
m_dirmovement1.PriceL = Bars.Low;
m_dirmovement1.PriceC = Bars.Close;
m_dirmovement1.Length = length;
}

//private ISeries<double> dmi_diff;
protected override void CalcBar(){
m_dirmovement1.Call();

double dmi_diff = m_dirmovement1.DMIPlus.Value - m_dirmovement1.DMIMinus.Value;
//Plot1.Set(0, m_dirmovement1.DMIPlus.Value - m_dirmovement1.DMIMinus.Value);
Plot1.Set(0,0);
Plot2.Set(0,0);


if (PublicFunctions.DoubleGreater(dmi_diff, dmi_diff[1]))
// >>>> (error: Cannot apply indexing with [] to an expression of type 'double' "dl_DMIdiff_2" [Indicator] Ln 59
)

{
Plot1.Set(0, m_dirmovement1.DMIPlus.Value - m_dirmovement1.DMIMinus.Value);

}
else
{
Plot2.Set(0, m_dirmovement1.DMIPlus.Value - m_dirmovement1.DMIMinus.Value);

}

//Plot2.Set(0, 20);
Plot3.Set(0, m_dirmovement1.ADX.Value);

if (PublicFunctions.DoubleGreater(m_dirmovement1.ADX.Value, adxtrend))
{
if (this.CrossesOver(m_dirmovement1.DMIPlus, m_dirmovement1.DMIMinus))
{
Alerts.Alert("Bullish alert");
}
else{
if (this.CrossesUnder(m_dirmovement1.DMIPlus, m_dirmovement1.DMIMinus))
{
Alerts.Alert("Bearish alert");
}
}
}
}
}
}
Attachments
dmi image.png
(1.64 KiB) Downloaded 502 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Coding Help Please  [SOLVED]

Postby JoshM » 17 Sep 2013

Hi,

I'm trying to modify the DMI study to color (DMIplus - DMIminus) and the ADX line according to their slopes as shown in the attached image.

I only need two colors, not a gradient.

I believe that I have to create an array of the indicators to be able to refer to its previous value. I've tried using examples from other studies as well as documentation but I can't figure out how to doit.

Any help will be appreciated.
I think you're approaching it too difficult. Yes, you can use an array for that, but a simple double variable that holds the previous value will also do.

For example:

Code: Select all

namespace PowerLanguage.Indicator
{
public class CustomDMI : IndicatorObject
{
#region Inputs
[Input]
public int length { get; set; }

[Input]
public double adxTrend { get; set; }

[Input]
public Color DMIPlusColor { get; set; }

[Input]
public Color DMIMinColor { get; set; }

[Input]
public Color ADXColorUp { get; set; }

[Input]
public Color ADXColorDown { get; set; }
#endregion

private DirMovement funDirMovement;
private IPlotObject plot1, plot2, plot3;
private double previousADX = 0;
private double previousDMI = 0;

public CustomDMI(object _ctx):base(_ctx)
{
length = 8;
adxTrend = 8;
DMIPlusColor = Color.Blue;
DMIMinColor = Color.Magenta;
ADXColorUp = Color.Yellow;
ADXColorDown = Color.LightGray;
}

protected override void Create()
{
funDirMovement = new DirMovement(this);

plot1 = AddPlot(new PlotAttributes("DMI+", EPlotShapes.Histogram, DMIPlusColor, Color.Empty, 0, 0, true));
plot2 = AddPlot(new PlotAttributes("DMI-", EPlotShapes.Histogram, DMIMinColor, Color.Empty, 0, 0, true));
plot3 = AddPlot(new PlotAttributes("ADX", EPlotShapes.Line, Color.Cyan, Color.Empty, 0, 0, true));
}

protected override void StartCalc()
{
funDirMovement.PriceH = Bars.High;
funDirMovement.PriceL = Bars.Low;
funDirMovement.PriceC = Bars.Close;
funDirMovement.Length = length;
}

protected override void CalcBar()
{
funDirMovement.Call();

double dmiValue = funDirMovement.DMIPlus.Value - funDirMovement.DMIMinus.Value;

if (dmiValue > previousDMI)
{
plot1.Set(dmiValue);
}
else
{
plot2.Set(dmiValue);
}

// Check for rising ADX to change colors of ADX
if (funDirMovement.ADX.Value > previousADX)
{
plot3.Set(funDirMovement.ADX.Value, ADXColorUp);
}
else
{
plot3.Set(funDirMovement.ADX.Value, ADXColorDown);
}

previousDMI = dmiValue;
previousADX = funDirMovement.ADX.Value;
}
}
}
Which will give:
Image
Attachments
scr.17-09-2013 10.23.08.png
(4.01 KiB) Downloaded 685 times

dave2013
Posts: 3
Joined: 15 Sep 2013
Has thanked: 1 time
Been thanked: 1 time

Re: Coding Help Please

Postby dave2013 » 17 Sep 2013

JoshM,

Nice.


Thanks


Return to “MultiCharts .NET”