Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bulding an Array Variable for Multiple Order

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

    Bulding an Array Variable for Multiple Order

    Hi, I'm learning C# and NinjaTrader, I need few suggestion from the Pros. Using this great sample for my study project SampleOnOrderUpdate_NT7.zip

    --this sample only submitted one order at a time and I would like to build a script with 3 orders or more with different entry price.

    I need suggestion on how to submit 3 order using this example code...Other then copy and paste the same code 3 times.

    thanks advance for your suggestion.

    #2
    Hello Tranbo,

    This should not require an array. Yes, you pretty much have to duplicate the structure that's used for the existing entries. You can provide unique names to your multiple entry orders by providing a unique IOrder object name, and unique signal name. You have to duplicate the same structure for each order.

    //Variables region
    private IOrder entryOrder = null;
    private IOrder entryOrder2 = null;

    //condition for entry
    if (entryOrder2 == null && Close[0] > Open[0])
    {

    entryOrder2 = EnterLong(1, "MyEntry2");
    }

    //reset to terminal(null) state when flat or cancelled. Only need one OnOrderUpdate() handler
    if (entryOrder2 != null && entryOrder2 == order)
    {
    // Reset the entryOrder object to null if order was cancelled without any fill
    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
    {
    entryOrder2 = null;
    }
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      simple print code won't compile

      // Print NinjaTrader 100 times to the output window
      for (int x = 0; x < 100; x++)
      {
      Print("NinjaTrader");
      }


      what does it take to get this code above to compile and run? it is just a sample code from the help doc. Every time I tried the error is


      "class member declaration is expected''

      Comment


        #4
        Originally posted by Tranbo View Post
        // Print NinjaTrader 100 times to the output window
        for (int x = 0; x < 100; x++)
        {
        Print("NinjaTrader");
        }


        what does it take to get this code above to compile and run? it is just a sample code from the help doc. Every time I tried the error is


        "class member declaration is expected''
        That code compiles for me, when I put it in the OnBarUpdate() or even in the Initialize() method, so your problem must be elsewhere. In what method is your code located?

        Comment


          #5
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Strategy;
          #endregion

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          /// <summary>
          /// Sample demonstrating the use of the OnOrderUpdate() method.
          /// </summary>
          [Description("Sample strategy demonstrating a use case involving the OnOrderUpdate() method")]
          public class SampleOnOrderUpdate : Strategy
          {
          #region Variables
          private IOrder entryOrder = null; // This variable holds an object representing our entry order
          private IOrder stopOrder = null; // This variable holds an object representing our stop loss order
          private IOrder targetOrder = null; // This variable holds an object representing our profit target order
          #endregion

          /// <summary>
          /// This method is used to configure the strategy and is called once before any strategy method is called.
          /// </summary>
          protected override void Initialize()
          {
          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()

          // Print NinjaTrader 100 times to the output window
          for (int x = 0; x < 100; x++)
          {
          Print("NinjaTrader");
          }

          It is on the top part of a perfectly working script

          Comment


            #6
            It looks like you're missing the needed braces for OnBarUpdate() :

            protected override void OnBarUpdate()
            {
            // Print NinjaTrader 100 times to the output window
            for (int x = 0; x < 100; x++)
            {
            Print("NinjaTrader");
            }
            }
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by samish18, Today, 01:01 PM
            0 responses
            5 views
            0 likes
            Last Post samish18  
            Started by WHICKED, Today, 12:56 PM
            0 responses
            7 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Spiderbird, Today, 12:15 PM
            2 responses
            11 views
            0 likes
            Last Post Spiderbird  
            Started by WHICKED, Today, 12:45 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by FrazMann, Today, 11:21 AM
            2 responses
            8 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Working...
            X