In the following code I am getting a CS0103 Issue for the variables "OrderQuantity" and "OrderQuantityMultiplier" yet I thought I have defined it as a variable on lines 59 and 60 (emphasized in bold below)
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class OneTradeADayUnlocked : Strategy
{
private EMA EMA1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "OneTradeADayUnlocked";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 350;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 1;
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;
StopLoss = 100;
Target = 10;
EntryTime = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture);
OrderQuantity = 1;
OrderQuantityMultiplier = 2.0;
}
else if (State == State.Configure)
{
AddDataSeries("ES 09-20", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, 20);
SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
SetProfitTarget("", CalculationMode.Ticks, Target);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((Times[0][0].TimeOfDay > new TimeSpan(0, 0, 0))
&& (Close[0] < Open[0])
&& (Times[0][0].TimeOfDay < new TimeSpan(4, 0, 0))
&& (Close[0] < EMA1[0]))
{
int orderQuantity = OrderQuantity;
if( SystemPerformance.AllTrades.Count > 0 )
if( SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count-1].ProfitTicks < 0 ) // last trade is a loss
orderQuantity = Math.Max(1, Convert.ToInt32(orderQuantity * OrderQuantityMultiplier));
EnterLongLimit(orderQuantity, (Low[0] + (1 * TickSize)) ,"") ;
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="StopLoss", Order=1, GroupName="Parameters")]
public int StopLoss
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Target", Order=2, GroupName="Parameters")]
public int Target
{ get; set; }
[NinjaScriptProperty]
[PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
[Display(Name="EntryTime", Order=3, GroupName="Parameters")]
public DateTime EntryTime
{ get; set; }
#endregion
}
}
Comment