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

Unexpected error " #endregion directive expected"

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

    Unexpected error " #endregion directive expected"

    I am getting the above error when I try and compile my code. I have been thou it several times and cant find a #region without a #endregion. In total I have 7 regions. Its also refers to the error on line 752 when my code only has 748 lines?? Why would this be happening.

    #2
    Problem solved. Error went away when I corrected other compile errors.

    Comment


      #3
      Thanks for letting us know. Yes NT will always compile all your files, so could be also sometimes an issue in a non related file.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Hi, I am getting the following error with the code below, can you please let me know what to change?

        CS1038 #endregion-Direktive erwartet (enregion rirective expected)

        //
        // Copyright (C) 2015, NinjaTrader LLC <www.ninjatrader.com>.
        // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
        //
        #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.Data;
        using NinjaTrader.NinjaScript;
        using NinjaTrader.Core.FloatingPoint;
        using NinjaTrader.NinjaScript.Indicators;
        using NinjaTrader.NinjaScript.DrawingTools;
        #endregion

        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Strategies
        {
        public class SamplePnL : Strategy
        {
        privateint maxprofit = 1000; // Max profit before halt strategy
        privateint maxloss = 1500; // Max loss before halt strategy

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Using trade performance statistics for money management";
        Name = "Sample PnL";
        Calculate = Calculate.OnBarClose;
        EntriesPerDirection = 2;
        EntryHandling = EntryHandling.AllEntries;
        IsExitOnSessionCloseStrategy = true;
        ExitOnSessionCloseSeconds = 30;
        IsFillLimitOnTouch = false;
        MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
        OrderFillResolution = OrderFillResolution.Standard;
        Slippage = 0;
        StartBehavior = StartBehavior.WaitUntilFlat;
        TimeInForce = TimeInForce.Gtc;
        TraceOrders = false;
        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
        StopTargetHandling = StopTargetHandling.PerEntryExecution;
        BarsRequiredToTrade = 5;
        }

        }

        protectedoverridevoid OnBarUpdate()
        {

        // Only run on real-time data
        if (Historical)
        return;

        if (Performance.AllTrades.TradesPerformance.Currency. CumProfit<-maxloss ||
        Performance.AllTrades.TradesPerformance.Currency.C umProfit>maxprofit)

        #region Properties

        [Description("Maximum profit.")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("\t\t\tMax Profit")]
        publicint MaxProfit
        {
        get { return maxprofit; }
        set { maxprofit = Math.Max(1, value); }
        }

        [Description("Maximum loss (enter positive value!).")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("\t\t\tMax Loss")]
        publicint MaxLoss
        {
        get { return maxloss; }
        set { maxloss = Math.Max(1, value); }
        }
        }
        }
        }

        Comment


          #5

          Hi Tiger,

          You declared a region,
          #region Properties, but no #endregion. So just add an #endregion after the end of the properties section or remove the #region Properties


          Originally posted by CelticTiger View Post
          Hi, I am getting the following error with the code below, can you please let me know what to change?

          CS1038 #endregion-Direktive erwartet (enregion rirective expected)

          //
          // Copyright (C) 2015, NinjaTrader LLC <www.ninjatrader.com>.
          // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
          //
          #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.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.Indicators;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.NinjaScript.Strategies
          {
          public class SamplePnL : Strategy
          {
          privateint maxprofit = 1000; // Max profit before halt strategy
          privateint maxloss = 1500; // Max loss before halt strategy

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Using trade performance statistics for money management";
          Name = "Sample PnL";
          Calculate = Calculate.OnBarClose;
          EntriesPerDirection = 2;
          EntryHandling = EntryHandling.AllEntries;
          IsExitOnSessionCloseStrategy = true;
          ExitOnSessionCloseSeconds = 30;
          IsFillLimitOnTouch = false;
          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
          OrderFillResolution = OrderFillResolution.Standard;
          Slippage = 0;
          StartBehavior = StartBehavior.WaitUntilFlat;
          TimeInForce = TimeInForce.Gtc;
          TraceOrders = false;
          RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
          StopTargetHandling = StopTargetHandling.PerEntryExecution;
          BarsRequiredToTrade = 5;
          }

          }

          protectedoverridevoid OnBarUpdate()
          {

          // Only run on real-time data
          if (Historical)
          return;

          if (Performance.AllTrades.TradesPerformance.Currency. CumProfit<-maxloss ||
          Performance.AllTrades.TradesPerformance.Currency.C umProfit>maxprofit)

          #region Properties

          [Description("Maximum profit.")]
          [Category("Parameters")]
          [Gui.Design.DisplayName("\t\t\tMax Profit")]
          publicint MaxProfit
          {
          get { return maxprofit; }
          set { maxprofit = Math.Max(1, value); }
          }

          [Description("Maximum loss (enter positive value!).")]
          [Category("Parameters")]
          [Gui.Design.DisplayName("\t\t\tMax Loss")]
          publicint MaxLoss
          {
          get { return maxloss; }
          set { maxloss = Math.Max(1, value); }
          }
          }
          }

          #endregion
          }


          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by stafe, 04-15-2024, 08:34 PM
          7 responses
          31 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by adeelshahzad, Today, 03:54 AM
          4 responses
          30 views
          0 likes
          Last Post adeelshahzad  
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          17 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Working...
          X