I keep seeing MC.NET supplied code that uses VariableObject types and I can't figure out why.
Floor_Trader_Pivots Indicator
Code: Select all
private VariableObject<Double> m_s1;
With thanks in advance,
MK
Code: Select all
private VariableObject<Double> m_s1;
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator{
public class variable_sample : IndicatorObject {
public variable_sample(object _ctx):base(_ctx){}
private IPlotObject plot1, plot2;
private AverageFC f_avg;
VariableObject <double> simple_var;
VariableSeries <double> series_var;
[Input]
public int length { get; set; }
protected override void Create() {
plot1 = AddPlot(new PlotAttributes("1", EPlotShapes.Line, Color.Red));
plot2 = AddPlot(new PlotAttributes("2", EPlotShapes.Line, Color.Yellow));
f_avg = new Function.AverageFC(this);
simple_var = new VariableObject<double>(this);
series_var = new VariableSeries<double>(this);
}
protected override void StartCalc() {
f_avg.length = length;
f_avg.price = Bars.Close;
}
protected override void CalcBar() {
simple_var.Value = series_var.Value = f_avg[0];
plot1.Set(simple_ [0] - simple_var[var 1]);
plot2.Set(series_var[0] - series_var[1]);
}
}
}
Code: Select all
protected override void CalcBar() {
//simple_var.Value = series_var.Value = f_avg[0];
simple_var.Value = series_var.Value = Bars.Close[0];
plot1.Set(0,simple_var[0] - simple_var[1]);
plot2.Set(0,series_var[0] - series_var[1]);
Output.WriteLine(Bars.CurrentBar +" simple_var[0]=" + simple_var[0]+" series_var[0]=" + series_var[0] );
Output.WriteLine(Bars.CurrentBar +" simple_var[1]=" + simple_var[1]+" series_var[1]=" + series_var[1] );
Output.WriteLine(Bars.CurrentBar +" simple_var[2]=" + simple_var[2]+" series_var[2]=" + series_var[2] );
Output.WriteLine(" ");
} // CalcBar()
Please refer to the Barsback section of Functions and Special Variables article.Hello MidKnight,
I encounter an issue running the code provided: the first 6 bars in chart are not taken into consideration by CalcBar(). Please find attached the .CSV file I worked with.
Why this happens ? Thank you.
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator{
public class variable_sample : IndicatorObject {
public variable_sample(object _ctx):base(_ctx){}
private IPlotObject plot1, plot2;
private AverageFC f_avg;
VariableObject <double> simple_var;
VariableSeries <double> series_var;
[Input]
public int length { get; set; }
protected override void Create() {
plot1 = AddPlot(new PlotAttributes("1", EPlotShapes.Line, Color.Red));
plot2 = AddPlot(new PlotAttributes("2", EPlotShapes.Line, Color.Yellow));
f_avg = new Function.AverageFC(this);
simple_var = new VariableObject<double>(this);
series_var = new VariableSeries<double>(this);
}
protected override void StartCalc() {
f_avg.length = length;
f_avg.price = Bars.Close;
}
protected override void CalcBar() {
simple_var.Value = series_var.Value = f_avg[0];
plot1.Set(simple_ [0] - simple_var[var 1]);
plot2.Set(series_var[0] - series_var[1]);
}
}
}
Thanks.bobrovartiom,
replace
plot1.Set(simple_ [0] - simple_var[var 1]);
with
plot1.Set(simple_var [0] - simple_var[1]);