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

Repeat Orders

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

    Repeat Orders

    Is there a reason why this code keeps entering orders over and over again and then at some point finally executes the ATM? I just want it to enter one order and then execute the ATM Strat. For example if I put that I want to order just one contract it will fill that order and then keep filling more orders until I have multiple contracts and then starts the ATM Strat. I am sure I am missing something and any help you can give me would be great. Thank You!

    #region Variables
    // Wizard generated variables
    privateint myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    privatestring atmStrategyId = string.Empty;
    privatestring orderId = string.Empty;
    #endregion
    ///<summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    ///</summary>
    protectedoverridevoid Initialize()
    {


    CalculateOnBarClose = false;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (ToTime(Time[0]) > ToTime(013, 59, 58)
    && ToTime(Time[0]) < ToTime(14, 00, 10))
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Sell, OrderType.StopLimit, Open[0] - 1 * TickSize, Open[0] - 1 * TickSize,TimeInForce.Day, orderId, "TEST DOWN", atmStrategyId);
    }
    }
    #region Properties
    [Description("")]
    [Category("Parameters")]
    publicint MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    You are telling your code to create an ATM strategy at every OnBarUpdate() event within that time period. You have no other limiting condition so naturally it will keep firing off as long as the time is within your time range. If you only want it to do one trade you will need to create a more limiting condition then what you have right now.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh! Is there a command like: checkatmStrategyId=0 or checkorderID=0 that will create a limited condition where the Strategy knows that an order has or has not already been filled so it may or may not execute the condition? I really can't mess with the time frame because I want to be able to adjust it to a very specific time that I want the order filled.

      Comment


        #4
        You can easily add an additional if condition inside your time range condition to further limit your submission of ATM strategy creates. Please check out the Help Guide for a host of available commands you can use to get information on if your order was filled already or whatever the deal with the situation is. Go here: http://www.ninjatrader-support.com/H...helpguide.html Then go to the Index page and scroll down to the G section. Look at any of the methods starting with GetAtm...(). You should be able to find something that will suit what you want to do there.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh I will check that out.

          Comment


            #6
            I tried the below and it still does the same thing as before. Am I even close? Thanks for any help.

            #region
            Variables
            // Wizard generated variables
            privateint myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            privatestring atmStrategyId = string.Empty;
            privatestring orderId = string.Empty;

            #endregion
            ///<summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            ///</summary>
            protectedoverridevoid Initialize()
            {


            CalculateOnBarClose =
            false;
            }
            ///<summary>
            /// Called on each bar update event (incoming tick)
            ///</summary>
            protectedoverridevoid OnBarUpdate()
            {
            // Condition set 1
            if (ToTime(Time[0]) > ToTime(18, 53, 58)
            && ToTime(Time[
            0]) < ToTime(19, 45, 00))

            if (GetAtmStrategyMarketPosition("id") == MarketPosition.Flat)

            if (orderId.Length < 1)

            {
            atmStrategyId = GetAtmStrategyUniqueId();
            orderId = GetAtmStrategyUniqueId();
            AtmStrategyCreate(Action.Sell, OrderType.StopLimit, Open[
            0] - 1 * TickSize, Open[0] - 1 * TickSize,TimeInForce.Day, orderId, "DOWN", atmStrategyId);
            }

            Comment


              #7
              Josh, please disregard the earlier message. I figured it out by using the SampleAtmStrategy and mixing it with the other and it seems to work.
              Thanks Again for your help.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Carolscogginsi, Yesterday, 10:45 PM
              0 responses
              6 views
              0 likes
              Last Post Carolscogginsi  
              Started by RaddiFX, Yesterday, 10:15 AM
              2 responses
              15 views
              0 likes
              Last Post RaddiFX
              by RaddiFX
               
              Started by patrickmlee007, Yesterday, 09:33 AM
              2 responses
              18 views
              0 likes
              Last Post patrickmlee007  
              Started by magnatauren, 08-15-2020, 02:12 PM
              5 responses
              208 views
              0 likes
              Last Post RaddiFX
              by RaddiFX
               
              Started by rene69851, 05-02-2024, 03:25 PM
              1 response
              23 views
              0 likes
              Last Post rene69851  
              Working...
              X