"The name 'SMA1' does not exist in the current context CS0103 "
I've gone about as a far as I can with the Strategy Builder and Google searches. I have been trying to translate ThinkScript (ThinkOrSwim) into NinjaScript (NinjaTrader) with limited coding experience.
Any thoughts?
Here is what the actual code looks like so far, with trouble area in bold.
namespace NinjaTrader.NinjaScript.Strategies
{
public class DAY2test : Strategy
{
private double HourPlus;
private double HourMinus;
private double HourBullishZone;
private double HourBearishZone;
private double HourNeutralZone;
private double HourHighDifference;
private double HourLowDifference;
private double HourPlusDM;
private double HourMinusDM;
private int ZERO;
private SMA SMA1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "LearningALGObasics";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
HourPlus = 1;
HourMinus = 1;
HourBullishZone = 1;
HourBearishZone = 1;
HourNeutralZone = 1;
HourHighDifference = 1;
HourLowDifference = 1;
HourPlusDM = 1;
HourMinusDM = 1;
ZERO = 0;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
SMA1 = SMA(Close, 14);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
{
HourHighDifference = (High[0] - High[1]);
}
{
HourLowDifference = (Low[1] - Low[0]);
}
if (HourHighDifference > HourLowDifference
&& HourHighDifference > ZERO);
{
HourPlusDM = 1;
}
if (HourLowDifference > HourHighDifference
&& HourLowDifference > ZERO);
{
HourMinusDM = 1;
}
if (SMA1(HourPlusDM,0)[0]);
{
HourPlus = 1;
}
if (SMA1(HourMinusDM,0)[0]);
{
HourMinus = 1;
}
if (HourPlus > HourMinus)
{
HourBullishZone = 1;
}
if (HourPlus < HourMinus)
{
HourBearishZone = 1;
}
if ((HourBullishZone != Close[0])
&& (HourBearishZone != Close[0]));
{
HourNeutralZone = 1;
}
if (HourBullishZone >= Close[0])
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
if ((HourNeutralZone == Close[0])
|| (HourBearishZone == Close[0]))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
if (HourBearishZone <= Close[0])
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
if ((HourBullishZone == Close[0])
|| (HourNeutralZone == Close[0]))
{
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
}
}
}
}
input averageType = AverageType.SIMPLE;
input length = 14;
def HourPlus;
def HourMinus;
def HourBullishZone;
def HourBearishZone;
def HourNeutralZone;
def HourHiDiff;
def HourLoDiff;
def HourPlusDM;
def HourMinusDM;
HourHiDiff = high - high[1];
HourLoDiff = low[1] - low;
HourPlusDM = if HourHiDiff > HourLoDiff and HourHiDiff > 0 then HourHiDiff else 0;
HourMinusDM = if HourLoDiff > HourHiDiff and HourLoDiff > 0 then HourLoDiff else 0;
HourPlus = MovingAverage(averageType, HourPlusDM, length);
HourMinus = MovingAverage(averageType, HourMinusDM, length);
HourBullishZone = HourPlus > HourMinus;
HourBearishZone = HourPlus < HourMinus;
HourNeutralZone = !HourBullishZone and !HourBearishZone;
AddOrder(OrderType.BUY_TO_OPEN, hourbullishzone,close, 1);
AddOrder(OrderType.SELL_TO_CLOSE, HourNeutralZone or HourBearishZone, close, 1);

Comment