Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninjascript Error

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

    Ninjascript Error

    So I created the following strategy and it won't compile because there is an error LINE 87. How can I solve it?


    Click image for larger version

Name:	Screenshot_1.png
Views:	228
Size:	49.1 KB
ID:	1227987



    Code:
    // This strategy enters a trade when the bid/ask imbalances are stacked in a certain way and exits when the imbalances change or a certain profit target is reached
    
    // Include the necessary NinjaScript libraries
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Strategy;
    
    // Declare the strategy class and inherit from the Strategy base class
    public class Footprint_Stacking_Imbalances_Strategy : Strategy
    {
        // Set the input parameters for the strategy
        private int stackingThreshold = 3;
        private int profitTarget = 10;
    
        // Declare variables to track the bid and ask imbalances
        private int bidImbalance = 0;
        private int askImbalance = 0;
    
        // Override the Initialize method to set up the strategy
        protected override void Initialize()
        {
            // Set the default order type to market order
            DefaultOrderType = OrderType.Market;
    
            // Set the entry and exit types for the strategy
            EntryHandling = EntryHandling.UniqueEntries;
            ExitHandling = ExitHandling.UseDefault;
        }
    
        // Override the OnBarUpdate method to specify the strategy's logic
        protected override void OnBarUpdate()
        {
            // Check if the current bar is the first bar
            if (CurrentBars[0] == 0)
            {
                // If it is, initialize the bid and ask imbalances to 0
                bidImbalance = 0;
                askImbalance = 0;
            }
    
            // Check if the bid imbalance is greater than or equal to the stacking threshold
            if (bidImbalance >= stackingThreshold)
            {
                // If it is, enter a long position
                EnterLong();
            }
    
            // Check if the ask imbalance is greater than or equal to the stacking threshold
            if (askImbalance >= stackingThreshold)
            {
                // If it is, enter a short position
                EnterShort();
            }
    
            // Check if the trade has reached the profit target
            if (Position.ProfitCurrency >= profitTarget)
            {
                // If it has, exit the trade
                ExitLong();
                ExitShort();
            }
    
            // Reset the bid and ask imbalances to 0 at the end of each bar
            bidImbalance = 0;
            askImbalance = 0;
        }
    
        // Override the OnOrderUpdate method to track the bid and ask imbalances
        protected override void OnOrderUpdate(IOrder order)
        {
            // Check if the order is a buy or sell order
            if (order.OrderAction == OrderAction.Buy)
            {
                // If it is a buy order, increment the bid imbalance
                bidImbalance++;
            }
            else if (order.OrderAction == OrderAction.Sell)
            {
                // If it is a sell order, increment the ask imbalance
                askImbalance++;
            }
    ​

    #2
    You need a right bracket "}" to close the opening one at line 76. The "}" would be line 88.

    Comment


      #3
      Originally posted by deblanka View Post
      You need a right bracket "}" to close the opening one at line 76. The "}" would be line 88.
      Same Error after adding the "}"


      Click image for larger version

Name:	image.png
Views:	122
Size:	50.2 KB
ID:	1227991
      Attached Files

      Comment


        #4
        zakarianada Same error, but different line (88 vs 87) and only one of them now, not two. This means the same error is still there and you've only fixed one of the two occurrences of it. This remaining error is because there needs to be (yet another) closing brace (i.e. "}"), after the one in line 88 to close the Strategy class declaration "public class Footprint_..." opening brace.

        Thanks.
        Multi-Dimensional Managed Trading
        jeronymite
        NinjaTrader Ecosystem Vendor - Mizpah Software

        Comment


          #5
          Originally posted by jeronymite View Post
          zakarianada Same error, but different line (88 vs 87) and only one of them now, not two. This means the same error is still there and you've only fixed one of the two occurrences of it. This remaining error is because there needs to be (yet another) closing brace (i.e. "}"), after the one in line 88 to close the Strategy class declaration "public class Footprint_..." opening brace.

          Thanks.
          It has been resolved but other errors appeared.. I don't think I can do it after all. Thank you for ur response

          Comment


            #6
            Hi,

            review your code and check that for each { is present also an }.
            Every block of code must have an begin and an end.

            Best regards,
            Valter

            Comment


              #7
              Hello zakarianada,

              Thanks for your post.

              "It has been resolved but other errors appeared.. I don't think I can do it after all. Thank you for ur response"

              I am happy to hear you were able to resolve the compile error mentioned in your initial post.

              What exactly do the other compile errors you mentioned state?

              If possible, please share a screenshot of the compile errors left so that I may provide further direction on resolving them.

              I look forward to assisting further.
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CarlTrading, 03-31-2026, 09:41 PM
              1 response
              43 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 04-01-2026, 02:41 AM
              0 responses
              21 views
              0 likes
              Last Post CarlTrading  
              Started by CaptainJack, 03-31-2026, 11:44 PM
              0 responses
              30 views
              1 like
              Last Post CaptainJack  
              Started by CarlTrading, 03-30-2026, 11:51 AM
              0 responses
              50 views
              0 likes
              Last Post CarlTrading  
              Started by CarlTrading, 03-30-2026, 11:48 AM
              0 responses
              40 views
              0 likes
              Last Post CarlTrading  
              Working...
              X