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

#endregion directive expected error but can't find the issue

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

    #endregion directive expected error but can't find the issue

    Hello, I saw this indicator for NT7 and wanted it for NT8, But I'm getting an error #endregion directive expected and can't find where it is missing. I went line for line with the NT7 to compare the smallest of details but I don't see it. Can another set of eyes help me get this to work PLEASE?


    region Variables
    private ToolStrip toolStripForm = null;
    private ToolStripButton Engage_Button = null;
    private int ct = 0;
    private int Bias = -1;
    const int NONE = -1;
    const int SHORT = 0;
    const int LONG = 1;
    private Color upColor = Color.Green;
    private Color downColor = Color.Red;
    private Color neutralColor = Color.DimGray;

    private bool border_On = true; // left or right

    private int vsma = 255;
    private int upOpaclevel = 254;
    private int downOpaclevel = 254;
    private int widthStrip = 10;

    #endregion
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"LeftMarginStripe";
    Name = "LeftMarginStripe";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    UpBrush = Brushes.Honeydew;
    DownBrush = Brushes.MistyRose;


    }
    region Tool Bar Control
    }
    protected override void OnBarUpdate()
    {

    }


    region Tool Bar Control
    protected override void OnStartUp()
    {

    if (toolStripForm==null)
    {
    if (border_On)
    toolStripForm= new ToolStrip() {Dock=DockStyle.Right, Name="ToolStripFormeSenderReceiever", Visible=true};
    else if (!border_On)
    toolStripForm= new ToolStrip() {Dock=DockStyle.Left, Name="ToolStripFormeSenderReceiever", Visible=true};

    toolStripForm.AutoSize = false;
    toolStripForm.CanOverflow = false;
    ChartControl.Controls.Add(toolStripForm);

    this.toolStripForm.BackColor = Color.Gray;
    this.toolStripForm.Width = widthStrip;
    Engage_Button = new ToolStripButton("Switch");
    Engage_Button.Enabled = true;
    Engage_Button.Name = "Switch";
    Engage_Button.Text = "";
    Engage_Button.Click += button1_Click;
    Engage_Button.AutoSize = false;
    toolStripForm.Items.Add(Engage_Button);

    toolStripForm.Resize += toolStripForm_Resize;
    toolStripForm_Resize(null,null);
    }
    return;
    }

    private void toolStripForm_Resize(object sender, System.EventArgs e)
    {
    this.Engage_Button.Height = 50;
    this.Engage_Button.Width = 15 ;
    this.Engage_Button.Invalidate();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    ct = ct + 1;

    switch (ct)
    {
    case 1:
    this.toolStripForm.BackBrushColor = Brushes.Black;
    break;
    case 2:
    this.toolStripForm.BackBrushColor = Brushes.DarkOrange;
    break;
    case 3:
    {
    ct = 0;
    this.toolStripForm.BackBrushColor = Brushes.Gray;
    }
    break;
    }
    return;
    }
    #endregion
    /// <summary>
    ///
    /// </summary>


    protected void Calculate_Bias()
    {
    if (Rising(SMA(BarsArray[0],vsma)))
    {Bias = LONG;return;}

    if (Falling(SMA(BarsArray[0],vsma)))
    {Bias = SHORT;return;}

    Bias = NONE;
    return;
    }

    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.

    if(BarsInProgress != 0) {return;}
    if (CurrentBars[0] < BarsRequired) {return;}
    if(Historical) {return;}

    Calculate_Bias();

    {
    switch (Bias)
    {
    case NONE:
    {
    this.toolStripForm.BackBrush = neutralBrushes;
    }
    break;

    case LONG:
    {
    this.toolStripForm.BackBrushColor = Brushes.FromArgb(upOpaclevel, upBrushes); //BrushesColor

    }
    break;

    case SHORT:
    {
    this.toolStripForm.BackBrushColor = Brushes.FromArgb(downOpaclevel, downBrushes); //BrushesColor;

    }
    break;

    }

    }

    }

    // This is called to shut down the form
    region Termination
    protected override void OnTermination()
    {
    if ( toolStripForm != null )
    {
    toolStripForm.Resize -= toolStripForm_Resize;
    if ( Engage_Button != null )
    toolStripForm.Items.Remove(Engage_Button);
    toolStripForm.Dispose();
    toolStripForm = null;
    Engage_Button = null;

    }
    }
    #endregion
    region Properties
    // Create our user definable color input
    [XmlIgnore()]
    [ Description ("Color for Up.")]
    [GridCategory("Stripe")]
    public Brush UpBrush
    { get; set; }

    // Serialize our Color object
    [Browsable(false)]
    public string UpBrushSerialize
    {
    get { return Serialize.BrushToString(UpBrush); }
    set { UpBrush = Serialize.StringToBrush(value); }
    }

    [XmlIgnore()]
    [ Description ("Color for Down.")]
    [GridCategory("Stripe")]
    public Brush DownBrush
    { get; set; }

    [Browsable(false)]
    public string DownBrushSerialize
    {
    get { return Serialize.BrushToString(DownBrush); }
    set { DownBrush = Serialize.StringToBrush(value); }
    }

    [XmlIgnore()]
    [ Description ("Color for Neutral.")]
    [GridCategory("Stripe")]
    public Brush NeutralBrush
    { get; set; }

    [Browsable(false)]
    public string DownBrushSerialize
    {
    get { return Serialize.BrushToString(NeutralBrush); }
    set { NeutralBrush = Serialize.StringToBrush(value); }
    }


    /// </summary>
    [Description("Chosen value of SMA.")]
    [Category("Parameters")]
    public int Vsma
    {
    get { return vsma; }
    set { vsma = Math.Max(1, value); }
    }

    [Description("True: Right sided stripe. False: Left sided stripe.")]
    [GridCategory("Stripe")]
    public bool Border_On
    {
    get { return border_On; }
    set { border_On = value; }
    }

    /// </summary>
    [Description("Width of stripe.")]
    [GridCategory("Parameters")]
    public int WidthStrip
    {
    get { return widthStrip; }
    set { widthStrip = Math.Max(1, value); }
    }
    /// </summary>
    [Description("Opacity Level for Up. 1-254.")]
    [GridCategory("Stripe")]
    public int UpOpaclevel
    {
    get { return upOpaclevel; }
    set { upOpaclevel = Math.Max(1, value); }
    }

    /// </summary>
    [Description("Opacity Level for Down. 1-254.")]
    [GridCategory("Stripe")]
    public int DownOpaclevel
    {
    get { return downOpaclevel; }
    set { downOpaclevel = Math.Max(1, value); }
    }
    #endregion
    }
    }​

    #2
    Hello JustinaM,

    Thank you for your note.

    It looks like you have somehwere where you start a region with "#region" but the region is not ended with "#endregion"

    For example, the variables region at the beginning has a start and end, shown in bold here:
    #region Variables
    private ToolStrip toolStripForm = null;
    private ToolStripButton Engage_Button = null;
    private int ct = 0;
    private int Bias = -1;
    const int NONE = -1;
    const int SHORT = 0;
    const int LONG = 1;
    private Color upColor = Color.Green;
    private Color downColor = Color.Red;
    private Color neutralColor = Color.DimGray;

    private bool border_On = true; // left or right

    private int vsma = 255;
    private int upOpaclevel = 254;
    private int downOpaclevel = 254;
    private int widthStrip = 10;

    #endregion

    Next, you mention region Tool Bar Control twice but only the second one has an #endregion:

    #region Tool Bar Control
    }
    protected override void OnBarUpdate()
    {

    }

    // missing #endregion here somewhere?

    #region Tool Bar Control
    protected override void OnStartUp()
    {


    You will need to end the region or remove one of the Tool Bar Control regions if it is an extra, and that should resolve the error.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily C. Thank you for the response, when I tried both of the things you suggested I'm getting even more errors.

      Comment


        #4
        Emily C. here is the link to version 7 if you want to compare the two, I went Line for Line trying to get the conversion https://ninjatraderecosystem.com/use...margin-stripe/

        Comment


          #5
          Hello JustinaM,

          Thank you for your reply.

          When converting a script from NinjaTrader 7 to NinjaTrader 8, I recommend reviewing the following code breaking changes page that breaks down what is different between NinjaTrader 7 and NinjaTrader 8:


          My colleague has created a post that details some of the best practices for converting a script from NinjaTrader 7 to NinjaTrader 8 here:


          Please let us know if we may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Waxavi, Today, 02:10 AM
          0 responses
          3 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          9 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          4 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Working...
          X