If we take an example of SampleUniversalMovingAverage
it has enum for MA.
If I want to create a strategy that also selects ENUM for MA without me having to define all logic of enum from indicator.
I understand that in strategy I still need to create ENUM,but how do i modify switch statement so only SMA or EMA or HMA is selected without defining values. Because values are defined in indicator already.
private CustomEnumNamespace.UniversalMovingAverage maType = CustomEnumNamespace.UniversalMovingAverage.SMA;
protected override void OnBarUpdate()
{
// We use a switch which allows NinjaTrader to only execute code pertaining to our case
switch (maType)
{
// If the maType is defined as an EMA then...
case CustomEnumNamespace.UniversalMovingAverage.EMA:
{
// Sets the plot to be equal to the EMA's plot
Value[0] = (EMA(Period)[0]);
break;
}
// If the maType is defined as a HMA then...
case CustomEnumNamespace.UniversalMovingAverage.HMA:
{
// Sets the plot to be equal to the HMA's plot
Value[0] = (HMA(Period)[0]);
break;
}
// If the maType is defined as a SMA then...
case CustomEnumNamespace.UniversalMovingAverage.SMA:
{
// Sets the plot to be equal to the SMA's plot
Value[0] = (SMA(Period)[0]);
break;
}
// If the maType is defined as a WMA then...
case CustomEnumNamespace.UniversalMovingAverage.WMA:
{
// Sets the plot to be equal to the WMA's plot
Value[0] = (WMA(Period)[0]);
break;
}
}
}
public CustomEnumNamespace.UniversalMovingAverage MAType
{
get { return maType; }
set { maType = value; }
}
namespace CustomEnumNamespace
{
public enum UniversalMovingAverage
{
EMA,
HMA,
SMA,
WMA,
}
}

Comment