Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Unexpected error " #endregion directive expected"
Collapse
X
-
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. -
-
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
-
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 PostHi, 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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment