Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CS0103 Issue Yet I Think I Have Already Defined A Variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    CS0103 Issue Yet I Think I Have Already Defined A Variable

    Hi,

    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)

    PHP Code:
    //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
    
        }
    } 
    
    Many thanks

    #2
    Hello, thanks for your question.

    I do not see any definition for these two:

    OrderQuantity
    OrderQuantityMultiplier

    Please make sure there is a public property set up for these two variables.

    Code:
    #region Properties
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="OrderQuantity", Order=4, GroupName="Parameters")]
            public double OrderQuantity
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="OrderQuantityMultiplier", Order=5, GroupName="Parameters")]
            public double OrderQuantityMultiplier
            { get; set; }

    Please let me know if I can assist any further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    72 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X