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");
}
}
}
}
}
}