Plotting Questions  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Plotting Questions

Postby GTrader » 17 Jun 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.

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

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Plotting Questions  [SOLVED]

Postby Henry MultiСharts » 18 Jun 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.
Hello GTrader,

That is possible to do the required plot with the help of the IChartCustomDrawer interface. Sample code can be found here.
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?
Unfortunately there is no such property at the moment.
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.
The indicator applied to the chart will keep its current plot settings even if the plot parameters in the source code have been changed. You will need to remove and re-add the study to the chart to apply the new plot parameters from the code.


Return to “MultiCharts .NET”