Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable does not exist in the current context

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

    Variable does not exist in the current context

    The error is:
    Code:
     [TABLE]
    [TR]
    NinjaScript File 			Error 			Code 			Line 			Column 		[/TR]
    [TR]
    [TD]CustomRender16.cs[/TD]
     			[TD]The name 'sj' does not exist in the current context[/TD]
     			[TD]CS0103[/TD]
     			[TD]398[/TD]
     			[TD]14[/TD]
     		[/TR]
    [/TABLE]

    Here is my code:

    Code:
    public class General{
        public bool noWeighting;            
    }
    
    public class Symbol :General {
    
            public Symbol(double weight){
                  Weight = weight;
            }
            public double Weight {
                   get{
                       if(base.noWeighting == true){
                           return 100;
                       }
                       else{
                           return value;
                       }    
                   }
                   set{ Weight = value;}
               }
    }
    
    protected override void OnStateChange(){
        if (State == State.SetDefaults) {
            General sj = new General();
            sj.noWeighting = false; 
            Symbol spy = new Symbol(15.25);       
        }
    }
    
    [Display(Name = "No Weighting", Order = 0, GroupName = "General Settings")]
      public bool NoWeighting{
        get {
          return sj.noWeighting;    //I am getting the error at this line
        }
        set{sj.noWeighting = value;}      //and another error at this line
      }

    #2
    Hello swooke,

    Thanks for your post.

    These sorts of questions referring to custom C# implementations begin to escape the scope of support we provide with NinjaScript.

    The error is letting you know that the object you are referencing does not exist in the context in which you are referencing. To look into this sort of issue the following questions should be asked:
    1. What scope are you trying to access this object?
    2. What scope have you created this object?
    3. Have you tried declaring this object at class level?
    Please let us know if you have any questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    46 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    28 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    163 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    98 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    158 views
    2 likes
    Last Post CaptainJack  
    Working...
    X