Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Type or namespace definition, or end-pf-file expected

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

    Type or namespace definition, or end-pf-file expected

    I am trying to create a dual time frame strategy and when I hit "compile" I keep getting this error message.
    I think I am supposed to attach a .cs file, but I don't know how to find this file.

    Thank-you for your help!

    #2
    Hello nrevell,

    Welcome to the NinjaTrader forums!

    Its possible you have an opening curly brace that does not have a matching close curly brace.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I had read that this might be the problem and have checked all of the curly brackets and they seem to be matching (I don't see that any are missing).

      Comment


        #4
        Hello nrevell,

        Place the cursor to the outside of every opening curly brace. Do you see a highlighted paired closing brace?
        Do the same for every closing curly brace. Do you see the highlighted paired opening curly brace?
        Do the same for every opening and closing parenthesis and opening and closing bracket.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Per your suggestion, I did this check with the cursor and all opening braces have closing braces and vice versa.
          Any other ideas?
          Thanks for your help.

          Comment


            #6
            Hello nrevell,

            I would still expect there is an improper amount of curly braces, brackets, or parenthesis.

            If you comment out all of the logic in OnBarUpdate() and OnStartUp() can you compile?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              No, it is still giving me the same error.
              But I didn't see "OnStartUp", only "OnStateChange()"
              I commented out all the logic in OnBarUpdate() and OnStateChange() and am still getting the same error.

              Comment


                #8
                Was I also supposed to comment out the lines that had the curly braces?

                Comment


                  #9
                  Hello nrevell,

                  Apologies I meant OnStateChange().

                  The code within OnStateChange() would be after the opening curly brace and before the closing curly brace for that action block. Not including the curly braces for that action block.

                  If you are still getting the error, this is telling you the error is in the code that is left.

                  If there are variables or custom methods, comment out these out next, all variables and all custom methods (including the the declaration, action blocks, and their curly braces).

                  Still able to reproduce? Comment out all code in the class (but not the classes curly braces). Are you still able to reproduce?

                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Ok, there must be some weird error in the template I used, because even when I comment virtually everything out, it is still showing the error. Do you know where I can get an example two time frame strategy that I could use as a model?

                    Comment


                      #11
                      Hello nrevell,

                      What code is left?

                      Below is a link to the reference sample that uses AddDataSeries() to add a data series.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Ok, I have resolved the error issue, however, now when I test the strategy, no orders get executed. The strategy is supposed to create a second bars array in the 15 minute time period and is supposed to execute an order when the closing price of the primary bar sequence crosses over the 20 period SMA of the 15 minutes time period. I tried to run this on a 5 minute chart. Can you tell me why no orders are executing?

                        Thank-you for your help!

                        Here is the code for the stragey:

                        ​​​​​​namespace NinjaTrader.NinjaScript.Strategies
                        {
                        public class SMALongShortCopy : Strategy
                        {
                        private SMA SMA1;

                        protected override void OnStateChange()
                        {
                        if (State == State.SetDefaults)
                        {
                        Description = @"Enter the description for your new custom Strategy here.";
                        Name = "SMALongShortCopy";
                        Calculate = Calculate.OnBarClose;
                        EntriesPerDirection = 1;
                        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 = 20;
                        // Disable this property for performance gains in Strategy Analyzer optimizations
                        // See the Help Guide for additional information
                        IsInstantiatedOnEachOptimizationIteration = true;
                        }
                        else if (State == State.Configure)
                        {
                        //Add a 15 minute bars object to the strategy
                        AddDataSeries(BarsPeriodType.Minute, 15);
                        }
                        else if (State == State.DataLoaded)
                        {
                        SMA1 = SMA(BarsArray[1], 20);
                        //SMA1.Plots[0].Brush = Brushes.Goldenrod;
                        //AddChartIndicator(SMA1);
                        //Note can only add indicators based on primary data series so can't add line above
                        //SetProfitTarget(@"150", CalculationMode.Ticks, 0);
                        //SetStopLoss(@"100", CalculationMode.Ticks, 0, false);
                        }
                        }

                        protected override void OnBarUpdate()
                        {
                        if (BarsInProgress != 0)
                        return;

                        if (CurrentBars[0] < 1)
                        return;

                        // Set 1
                        if (CrossAbove(Close[0], SMA1, 1))
                        {
                        EnterLong(1, "");
                        }

                        // Set 2
                        if (CrossBelow(Close[0], SMA1, 1))
                        {
                        EnterShort(1, "");
                        }

                        }
                        }
                        }

                        Comment


                          #13
                          Hello nrevell,

                          To understand why no order is being submitted print the time of the bar, print the close of the current bar, print the sma1 of the previous bar and current bar.

                          Below is a link to a forum post that demonstrates using Print() and TraceOrders to understand behavior.


                          Save the output to a text file and include this with your next post and I will be happy to assist with analyzing the output.
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Today, 05:17 AM
                          0 responses
                          52 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          130 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          70 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          44 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          49 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X