I am trying to develop a custom strategy that has many different working pieces...and I want to separate these pieces into their own classes so it does not interefere with these pieces for when I change or alter the strategy in any way, but I am having trouble declaring and initializing the variables and data types. I compile without any errors, but then when i run the strategy it says (Calculating...) at the top and doesn't display anything. It works great when its all in one class ("MyStrategy" class for example), but when I separate out objects like moving average, support, resistance, supply, demand classes, things get complicated really quickly.
To give you an idea of an example, let's say I want to create a multi-timeframe strategy with a moving average class: (I am typing this from memory to give you an idea, so some syntax may not be completely accurate, but I want you to get the idea of what I am trying to achieve)
namespace NinjaTrader.NinjaScript.Strategy
{
//declare a new method where everything related to moving average will be stored
public class MovAvg : IDisposable
{
//declare constructor to instantiate objects within the MyStrategy class
public MovAvg(){}
//declare variables to use within MyStrategy class
public SMA mySMA;
public Brush mySMABrush = Brushes.Blue;
//methods
//method to set Values of the plot equal to the value of the SMA variable.
public void ExecuteMovAvg()
{
Values[1][0] = mySMA;
}
}
public class MyStrategy : Strategy
{
//onstatechange
if(State == State.SetDefaults)
{
AddPlot(new Plot(PlotStyleType.Line, "MyMovAvg"); //Values[1][0]
}
if(State == State.DataLoaded)
{
MovAvg m = MovAvg(); //instantiate the movingAverage object
m.mySMA = SMA(BarsArray[1], 20); //initialize the SMA variable from the moving average class and set to the SMA(BarsArray[1], 20) moving average.
m.Dispose();
}
//onBarUpdate
//section Moving Average
if(BarsInProgress == 1)
{
MovAvg m = new MovAvg();
m.ExecuteMovAvg(); //set the plot to the values of the SMA variable to plot the line on the chart
m.Dispose();
}
//properties
}
}
I also have Lists that I create to hold the objects and properties for each class. So for example, I have a Support and Resistance Class where I create a List<Support> SupportListName and a List<Resistance> ResistanceListName that I add to and alter throughout the strategy that I use to create plots, zones, and lines from.
Is this possible to do, or am I going about this the wrong way? Again, I don't get any compile-time errors, only run-time errors where I cannot see any of the plots or lines appear, only a (Calculating...) at the top of the screen appears.
Thanks so much for any insight you may give me.
--Jake--

Comment