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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    227 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    145 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    159 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    237 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    197 views
    0 likes
    Last Post CarlTrading  
    Working...
    X