Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by timmbbo, Today, 08:59 AM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by KennyK, 05-29-2017, 02:02 AM
    2 responses
    1,281 views
    0 likes
    Last Post marcus2300  
    Started by fernandobr, Today, 09:11 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by itrader46, Today, 09:04 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by bmartz, 03-12-2024, 06:12 AM
    5 responses
    33 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Working...
    X