Thank you for replying JoshM.
Yes in a nutshell this is exactly what I'm trying to do, except that I'm having to dynamically set the value of EMA1.price. Because EMA1 is an XAverage (which is an ISeries), and the formula that I am using to get the value of EMA1.price actually returns a double, this is where I keep running into issues.
What I'm trying to do on a bigger picture is convert a script from NT to Multicharts .Net.
Here is the original script (if you're familiar with NT scripts, I've taken out all of the NT specific coding that is added to the bottom of each script)
Code: Select all
namespace NT.Indicator
{
[Description("Stochastic Momentum Index by NT Indicator")]
public class NTISMI : Indicator
{
#region Variables
private int q = 13;
private int r = 25;
private int s = 2;
private int avgPeriod = 3;
private DataSeries rdiff;
private DataSeries diff;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "SMI"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Avg"));
Add(new Line(Color.Gray, -40, "Lower"));
Add(new Line(Color.Gray, 40, "Upper"));
rdiff = new DataSeries(this);
diff = new DataSeries(this);
Overlay = false;
}
protected override void OnBarUpdate()
{
double min_low = MIN(Low, q)[0];
double max_high = MAX(High, q)[0];
rdiff.Set(Close[0] - (max_high + min_low)/2);
diff.Set(max_high - min_low);
double avgrel = EMA(EMA(rdiff, r), s)[0];
double avgdiff = EMA(EMA(diff, r), s)[0];
SMI.Set(avgrel/(avgdiff/2)*100);
Avg.Set(EMA(SMI, avgPeriod)[0]);
}
what I have so far, it compiles without any errors, but it errors out at runtime with the following error message:
Unaccessible property(method): CreateSeriesVar. Construct only.
and finally, here is what I have so far as the code
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator
{
public class TGSMI : IndicatorObject
{
private IPlotObject plot1;
private IPlotObject plot2;
private IPlotObject plot3;
private IPlotObject plot4;
private IPlotObject plot5;
private VariableSeries<Double> SMI;
private VariableSeries<Double> Avg;
private XAverage EMA1;
private XAverage EMA2;
private XAverage EMA3;
private XAverage EMA4;
private XAverage EMA5;
private ISeries<double> rdiff;
private ISeries<double> diff;
private ISeries<double> avgrel1;
private ISeries<double> avgdiff;
[Input]
public int q { get; set; }
[Input]
public int r { get; set; }
[Input]
public int s { get; set; }
[Input]
public int avgPeriod { get; set; }
[Input]
public double OverBought { get; set; }
[Input]
public double OverSold { get; set; }
public TGSMI(object _ctx):base(_ctx)
{
OverBought = 80;
OverSold = 20;
q = 13;
r = 25;
s = 2;
avgPeriod = 3;
}
protected override void Create()
{
// create variable objects, function objects, plot objects etc.
plot1 = AddPlot(new PlotAttributes("ZeroLine", EPlotShapes.Line, Color.Black, Color.Empty, 1, 0, false));
plot2 = AddPlot(new PlotAttributes("OverBought", EPlotShapes.Line, Color.Blue, Color.Empty, 1, 0, false));
plot3 = AddPlot(new PlotAttributes("OverSold", EPlotShapes.Line, Color.Blue, Color.Empty, 1, 0, false));
plot4 = AddPlot(new PlotAttributes("SMI", EPlotShapes.Line, Color.Green, Color.Empty, 1, 0, false));
plot5 = AddPlot(new PlotAttributes("Avg", EPlotShapes.Line, Color.Red, Color.Empty, 1, 0, false));
SMI = new VariableSeries<Double>(this);
Avg = new VariableSeries<Double>(this);
EMA1 = new XAverage(this);
EMA2 = new XAverage(this);
EMA3 = new XAverage(this);
EMA4 = new XAverage(this);
EMA5 = new XAverage(this);
}
protected override void StartCalc()
{
// assign inputs
}
protected override void CalcBar()
{
// indicator logic
plot1.Set(0);
plot2.Set(40);
plot3.Set(-40);
int q = 13;
int r = 25;
int s = 2;
int avgPeriod = 3;
double minlow1 = Bars.Low.Lowest(q, 0);
double maxhigh1 = Bars.High.Highest(q, 0);
rdiff = CreateSeriesVar<double>((Bars.Close[0] - (maxhigh1 + minlow1)/2));
diff = CreateSeriesVar<double>((maxhigh1 - minlow1));
EMA1.Price = CreateSeriesVar<double>(rdiff[0]);
EMA1.Length = r;
EMA2.Price = CreateSeriesVar<double>(EMA1[0]);
EMA2.Length = s;
avgrel1 = CreateSeriesVar<double>(EMA2[0]);
EMA3.Price = CreateSeriesVar<double>(diff[0]);
EMA3.Length = r;
EMA4.Price = CreateSeriesVar<double>(EMA1[0]);
EMA4.Length = s;
avgdiff = CreateSeriesVar<double>(EMA4[0]);
//SMI = (avgrel1[0]/(avgdiff[0]/2)*100);
double smi = (avgrel1[0]/(avgdiff[0]/2)*100);
EMA5.Price = CreateSeriesVar<double>(SMI[0]);
EMA5.Length = avgPeriod;
//Avg = EMA5[0];
double avg = EMA5[0];
plot4.Set(smi);
plot5.Set(avg);
}
}
}
Im no coder, so I wouldnt even know where I'm going wrong.
Thanks again for checking in!