Plotting Questions
Posted: Jun 17 2014
a) Is it possible to fill in the surface area of an oscillator plot? I mimic this by creating a histogram with the same value of the oscillator value, but it would be better if I could just fill in a given background area between 2 plot lines.
b) It seems the visual plot order is dictated by the order you call the AddPlot Methods. Is there also a property that can be set to order the plots?
c) Is there a way to hard code plot attributes? You can set the default value through code but if the indicator is already plotted it will keep it's current values and settings.
Here is my code for the example I am working on.
b) It seems the visual plot order is dictated by the order you call the AddPlot Methods. Is there also a property that can be set to order the plots?
c) Is there a way to hard code plot attributes? You can set the default value through code but if the indicator is already plotted it will keep it's current values and settings.
Here is my code for the example I am working on.
Code: Select all
using System;
using System.Drawing;
namespace PowerLanguage.Indicator{
public class m_310_Osc : IndicatorObject {
private Function.AverageFC m_fastAverage;
private Function.AverageFC m_slowAverage;
private Function.AverageFC m_trigAverage;
private VariableSeries<double> m_osc;
private Function.NormGradientColor m_hist_color;
public m_310_Osc(object _ctx) :
base(_ctx)
{
fastLength = 3;
slowLength = 10;
trigLength = 16;
}
private IPlotObject plotOsc;
private IPlotObject plotZero;
private IPlotObject plotTrig;
private IPlotObject plotHist;
[Input]
public int fastLength { get; set; }
[Input]
public int slowLength { get; set; }
[Input]
public int trigLength { get; set; }
protected override void Create() {
m_fastAverage = new Function.AverageFC(this);
m_slowAverage = new Function.AverageFC(this);
m_trigAverage = new Function.AverageFC(this);
m_osc = new VariableSeries<double>(this);
m_hist_color = new Function.NormGradientColor(this);
plotHist = AddPlot(new PlotAttributes("Hist", EPlotShapes.Histogram, Color.Green,Color.Transparent,3,0,false));
plotZero = AddPlot(new PlotAttributes("ZeroLine", EPlotShapes.Line, Color.DarkGray));
plotTrig = AddPlot(new PlotAttributes("TrigLine", EPlotShapes.Line, Color.Yellow));
plotOsc = AddPlot(new PlotAttributes("OscLine", EPlotShapes.Line, Color.White));
}
protected override void StartCalc() {
m_fastAverage.price = Bars.Close;
m_fastAverage.length = fastLength;
m_slowAverage.price = Bars.Close;
m_slowAverage.length = slowLength;
m_trigAverage.price = m_osc;
m_trigAverage.length = trigLength;
m_hist_color.dataseriesvalue = m_osc;
m_hist_color.crosseszero = true;
m_hist_color.colornormlength = fastLength;
m_hist_color.upcolor = Color.Green;
m_hist_color.dncolor = Color.Red;
m_osc.DefaultValue = 0;
}
protected override void CalcBar(){
m_osc.Value = m_fastAverage.Value - m_slowAverage.Value;
plotHist.Colors[0] = m_hist_color.Value;
plotHist.Set(m_osc.Value);
plotZero.Set(0);
plotTrig.Set(m_trigAverage.Value);
plotOsc.Set(m_osc.Value);
}
}
}