• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The name "__" does not exist in the current context

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

    The name "__" does not exist in the current context

    I am trying to develop a strategy and am fairly new to coding, but have a little experience. However, I cannot figure out what I am missing. I am sure it is something so simple, but can anyone help me?

    Code as follows:

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class AutomatedHMAUnlocked : Strategy
    {
    private HMAFilterexample HMAFilterexample1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "AutomatedHMAUnlocked";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.High;
    OrderFillResolutionType = BarsPeriodType.Minute;
    OrderFillResolutionValue = 1;
    Slippage = 0;
    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
    int SlopeBars = 3;
    int Quantity = 1;
    int HMAPeriod = 50;
    double HMAthreshold = 0.300;
    bool PrintSlope = false;

    IsInstantiatedOnEachOptimizationIteration = false;

    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    HMAFilterexample = HMAFilterexample(Close, HMAPeriod, SlopeBars, HMAthreshold, false);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < Math.Max(HMAPeriod, SlopeBars))
    {
    return;
    }

    double HMAslope = Slope(HMAFilterexample1, SlopeBars, 0); // Calculate slope of HMA line


    if (PrintSlope)
    {
    Print ("Time: "+Time[0].TimeOfDay+" Slope: "+HMAslope);
    }

    if (HMAslope > HMAthreshold)
    {
    PlotBrushes[0][0] = Brushes.Green;
    EnterLong(Convert.ToInt32(Quantity), "");
    }
    else if (HMAslope < -HMAthreshold)
    {
    PlotBrushes[0][0] = Brushes.Red;
    EnterShort(Convert.ToInt32(Quantity), "");
    }
    else
    {
    PlotBrushes[0][0] = Brushes.Gold;
    }


    }
    }
    }

    #2
    Hello bigc0220,

    Thank you for the question.

    I tried the code you provided but it looks like this is both not complete and uses non-standard indicators. Can you tell me, is this the entire syntax of the script or is there more you omitted from the bottom?

    The error The name "__" does not exist in the current context
    means that some variable you are using does not exist where you are trying to use it. If this is not the full script, I wouldnt be sure what specifically is the problem. If this is the full script, the problem is that you are missing the public properties you used such as HMAPeriod.

    When posting on the support forum, it is helpful to include the actual script instead of a copy paste to avoid any confusions. For a script that cannot compile, you can just include the .cs file from the folder NinjaTrader 8\bin\Custom\{type of item}\{items name}.cs

    For items that can compile, you can export them: https://ninjatrader.com/support/help...tAsSourceFiles

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello bigc0220,

      Thank you for the question.

      I tried the code you provided but it looks like this is both not complete and uses non-standard indicators. Can you tell me, is this the entire syntax of the script or is there more you omitted from the bottom?

      The error The name "__" does not exist in the current context
      means that some variable you are using does not exist where you are trying to use it. If this is not the full script, I wouldnt be sure what specifically is the problem. If this is the full script, the problem is that you are missing the public properties you used such as HMAPeriod.

      When posting on the support forum, it is helpful to include the actual script instead of a copy paste to avoid any confusions. For a script that cannot compile, you can just include the .cs file from the folder NinjaTrader 8\bin\Custom\{type of item}\{items name}.cs

      For items that can compile, you can export them: https://ninjatrader.com/support/help...tAsSourceFiles

      I look forward to being of further assistance.

      My apologies. I did copy and paste the full script, but I also linked it below. I compared it to strategy done in the wizard and for the most part, everything was the same except for some little things. Are the public properties not lines 57-61? I tried using the CS0103 link associated with the error, but I don't think that is what I needed because I tried what it said and it is still giving me errors. I apologize for any inconvenience or headaches and thank you for your time!
      Attached Files

      Comment


        #4
        Hello bigc0220,

        Thank you for providing the script and actually, your comment points out the problem. I had overlooked where you placed the variables as this is not usually where you would see the public properties defined.

        Public properties are actually going to be outside of the methods you define, this is a C# concept so this is where your problem resides.

        What you have done in this script is declared a "local variable" instead of a "property".

        The error comes when you try to use the local variable out of the scope where it was declared. How you have it now, the variable HMAPeriod could only be used inside the { and }
        or :

        Code:
        if (State == State.SetDefaults)
        {
        //these variables can only be used inside of the { and } of this if statement because they have been declared here. 
        
        int SlopeBars	= 3;
        int Quantity	= 1;
        int HMAPeriod	= 50;
        double HMAthreshold	= 0.300;
        bool PrintSlope	= false;
        }

        If you intend for these values to be settable in the user interface and also can be used througout your code, you need to delete these variables and instead make them like the following:

        Code:
        [Range(1, int.MaxValue), NinjaScriptProperty]
        [Display(Name = "HMAPeriod", GroupName = "NinjaScriptParameters", Order = 0)]
        public int HMAPeriod
        { get; set; }
        This is one property along with the correct attributes. You would additionally need to set a default value in SetDefaults:

        Code:
        if (State == State.SetDefaults)
        {
        
            HMAPeriod = 50;
        }
        You can find more on properties in the attributes section here: https://ninjatrader.com/support/help...attributes.htm

        Properties are defined near the bottom of the file inside of the main class but outside of any methods in the class. In the file you provided, this would start after line 106 or after OnBarUpdate but inside the class.

        You can view the SMA indicator for an example of a single property and how it is used in the remainder of the script. It has the Period property.

        Alternatively, you can generate a new strategy or indicator and use the "Input Parameters" section to generate this syntax for each type of input. This is suggested for Brushes specifically to generate the serialization syntax.

        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 09-18-2018, 09:56 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you so much! You have been very helpful and it all makes more sense now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by TazoTodua, Today, 12:21 AM
          0 responses
          7 views
          0 likes
          Last Post TazoTodua  
          Started by U0000999, Today, 12:20 AM
          0 responses
          7 views
          0 likes
          Last Post U0000999  
          Started by sidviciousX, Yesterday, 06:47 AM
          1 response
          21 views
          0 likes
          Last Post bltdavid  
          Started by Mykro, Yesterday, 10:22 PM
          0 responses
          10 views
          0 likes
          Last Post Mykro
          by Mykro
           
          Started by rudccv, Yesterday, 08:42 PM
          0 responses
          6 views
          0 likes
          Last Post rudccv
          by rudccv
           
          Working...
          X