I'm trying to create an study that will plot 3 lines on the price chart
1. A line of the open price
2. A line of the mid range ((high-low)/2)
3. An EMA
The code I'm using complies but I when I try to add the indicator to a chart I get an error (See attached).
I've attached the code and the screenshot
What is the problem ?
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class Market_Status : IndicatorObject
{
private VariableObject<Double> m_Open;
private VariableObject<Double> m_Mid;
private VariableObject<Double> m_TodaysHigh;
private VariableObject<Double> m_TodaysLow;
private VariableObject<Double> m_TodaysOpen;
private VariableObject<Int32> m_Counter;
private Mov_Avg_Exponential m_FEMA;
private IPlotObject Plot1;
private IPlotObject Plot2;
private IPlotObject Plot3;
public Market_Status(object ctx):
base(ctx) {}
protected override void Create()
{
m_Mid = new VariableObject<Double>(this);
m_TodaysHigh = new VariableObject<Double>(this);
m_TodaysLow = new VariableObject<Double>(this);
m_TodaysOpen = new VariableObject<Double>(this);
m_FEMA = new Mov_Avg_Exponential(this); //http://www.multicharts.com/discussion/viewtopic.php?f=19&t=12593
Plot1 = AddPlot(new PlotAttributes("Open", EPlotShapes.Line ,Color.Blue, Color.Empty, 2,0,true));
Plot2 = AddPlot(new PlotAttributes("Mid", EPlotShapes.Line, Color.Aqua, Color.Empty, 2, 0, true));
Plot3 = AddPlot();
m_FEMA = (Mov_Avg_Exponential)AddIndicator("EMA"); // Use EMA
m_FEMA.length = 10;
}
protected override void CalcBar()
{
EResolution resolution = Bars.Info.Resolution.Type;
if (resolution == EResolution.Quarter || EResolution.Week <= resolution && resolution <= EResolution.Year)
return;
if (Bars.Time[0].Date != Bars.Time[1].Date)
{
m_TodaysHigh.Value = Bars.High[0];
m_TodaysLow.Value = Bars.Low[0];
m_TodaysOpen.Value = Bars.Open[0];
m_Mid.Value = ((m_TodaysHigh.Value - m_TodaysLow.Value) + m_TodaysLow.Value);
Plot1.Set(0, m_Open.Value); //First line is the open of the day
Plot2.Set(0, m_Mid.Value); //Second line is the mid level of the day
Plot3.Set(m_FEMA.Plots[0].Values[0]); //Third line is the EMA
}
}
}
}