A sub-panel with each bar producing a dot of a constant value. I want to change the color of that dot based off of a different indicator. In this case, I want the dot to be green if the slope of the EMA is positive and red if the slope is negative, black if it is neutral (if ever).
Right now I have two EMAs that I am trying to calculate and two dot plots.
Any help or links to material or other threads in the right direction would be appreciated. Thanks in advance!
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.LawnGreen), PlotStyle.Dot, "EMA9"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "EMA8"));
Add(new Line(Color.FromKnownColor(KnownColor.White), 4, "Divider"));
CalculateOnBarClose = true;
Overlay = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
EMA9.Set(9);
EMA8.Set(8);
// define each EMA period
double slope9 = (EMA(Ema9p)[0]- EMA(Ema9p)[1]);
double slope8 = (EMA(Ema8p)[0]- EMA(Ema8p)[1]);
// If the slope is rising turn plot green, if falling turn red, if neutral leave black
if ( slope9 > 0 )
Plots[0].Pen = new Pen(Color.LimeGreen);
else if ( slope9 < 0 )
Plots[0].Pen = new Pen(Color.Red);
else
Plots[0].Pen = new Pen(Color.Black);
if ( slope8 > 0 )
Plots[1].Pen = new Pen(Color.LimeGreen);
else if ( slope8 < 0 )
Plots[1].Pen = new Pen(Color.Red);
else
Plots[1].Pen = new Pen(Color.Black);
}
Comment