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

Getting multiple ATM orders OnBarClose=false

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

    Getting multiple ATM orders OnBarClose=false

    I'm using the "SampleATM" strategy method of creating ATM orders in my strategy, but am getting multiple ATM orders within rapid succession. This strategy runs OnBarClose=false, is there some issues with that? Can the tick by tick cause problems?

    #2
    Hello TiggerTrader,

    Thank you for your post.

    The item here will be that if your entry conditions are returning true multiple times then you are entering multiple positions.

    You can limit the amount of entries on either side of the market by using EntryHandling and EntriesPerDirection.

    For information on EntryHandling please visit the following link: http://www.ninjatrader.com/support/h...ryhandling.htm

    For information on EntriesPerDirection please visit the following link: http://www.ninjatrader.com/support/h...rdirection.htm

    Please let me know if you have any questions.

    Comment


      #3
      That info is for EnterLong technique, I'm using ATM's.

      Comment


        #4
        Hello TiggerTrader,

        Thank you for your response.

        EntriesPerDirection and EntryHandling apply to all order entry methods.

        Please let me know if I may be of further assistance.

        Comment


          #5
          OK, I will try it. However, with ATM's, how do you interpret "EntryHandling.UniqueEntries"? Unique by TemplateName?

          Comment


            #6
            Hello TiggerTrader,

            Thank you for your response.

            As you have suggested there would not be any unique signal names created when using the ATM Strategy Methods to enter, the EntryHandling.UniqueEntries method would not work here.

            In the SampleAtmStrategy NinjaScript strategy you will see the use of the following line to check for existing ATM Strategies before processing any additional entries:
            Code:
            if (orderId.Length == 0 && atmStrategyId.Length == 0)
            To view the SampleAtmStrategy code please go to the NinjaTrader Control Center > Tools > Edit NinjaScript > Strategy > SamplAtmStrategy > OK.

            Please let me know if you have any questions.

            Comment


              #7
              OK, that's exactly what I thought. I used the sample as a basis for my code. I am checking the orderID & startegryID BUT it still gives me multiple entries!!!! I have that exact if statement around my entry conditions.

              Any ideas? Is there a way with ATM's to see if you are flat, even though your orderID & startegryID say they are empty? Can I generically say
              Code:
              [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
              [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]if( Position.MarketPosition != MarketPosition.Flat)[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

              Comment


                #8
                Hello TiggerTrader,

                Thank you for your response.

                Are you resetting the orderId and atmStrategyId when the order is filled?

                You can check the position with GetAtmStrategyMarketPosition(atmStrategyId), so to check if you are flat would look like the following:
                Code:
                if(GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                You can find examples of resetting the orderId and atmStrategyId as well as checking the market position of an ATM Strategy in the SampleAtmStrategy NinjaScript code.

                Please let me know if you have any questions.

                Comment


                  #9
                  Yes, I have used ALL of the code example in SampleATMStrategy. No need to ask about that. However, I still get multiple entries and it seems to be the same orderID...

                  Comment


                    #10
                    Hello TiggerTrader,

                    Thank you for your response.

                    Please provide your code for the entry conditions and the code used to check your position and reset your orderId and atmStrategyId.

                    I look forward to your response.

                    Comment


                      #11
                      First off, the following code does nothing, I am watching my strategy place multiple orders time after time:
                      Code:
                      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
                      [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]( Use_Black_Text )[/SIZE][/FONT]
                      [SIZE=2][FONT=Courier New]clrTextColor = Color.Black;[/FONT][/SIZE]
                      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT]
                      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]clrTextColor = Color.White;[/SIZE][/FONT]
                       
                       
                      [SIZE=2][FONT=Courier New]EntriesPerDirection = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]; [/SIZE][/FONT]
                      [SIZE=2][FONT=Courier New]EntryHandling = EntryHandling.AllEntries; [/FONT][/SIZE]
                       
                      [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                      [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                      [/SIZE][/FONT]

                      Comment


                        #12
                        Here is 1/2 the order stuff:
                        if( (orderId.Length == 0) && (atmStrategyId.Length == 0) )
                        {
                        if( Close[0] <= entry_bot+Order_Offset_Ticks*TickSize )
                        {
                        atmStrategyId = GetAtmStrategyUniqueId();
                        orderId = GetAtmStrategyUniqueId();
                        AtmStrategyCreate( OrderAction.Buy, OrderType.Market,
                        0, 0, TimeInForce.Day, orderId, sATMTemplate, atmStrategyId );
                        }
                        else
                        if( Close[0] >= entry_top-Order_Offset_Ticks*TickSize )
                        {
                        atmStrategyId = GetAtmStrategyUniqueId();
                        orderId = GetAtmStrategyUniqueId();
                        AtmStrategyCreate( OrderAction.Sell, OrderType.Market,
                        0, 0, TimeInForce.Day, orderId, sATMTemplate, atmStrategyId );
                        }
                        }

                        Comment


                          #13
                          and the last 1/2:
                          Code:
                          [FONT=Courier New][SIZE=2][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (orderId.Length > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][] status = GetAtmStrategyEntryOrderStatus(orderId);[/SIZE][/FONT]
                           
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (status.GetLength([/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]) > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (status[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Filled"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] || status[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Cancelled"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] || status[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Rejected"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]orderId = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Empty;[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                          [SIZE=2][FONT=Courier New]} [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// If the strategy has terminated reset the strategy id[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (atmStrategyId.Length > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)[/COLOR][/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]atmStrategyId = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Empty;[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New] [/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                          [/SIZE][/FONT]

                          Comment


                            #14
                            Hang on, I see a logic error. Let me fix it and see if it changes anything.

                            Comment


                              #15
                              Looks like I fixed it... thanks for your patience.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by maybeimnotrader, Today, 12:58 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by ETFVoyageur, Today, 10:27 AM
                              1 response
                              8 views
                              0 likes
                              Last Post bltdavid  
                              Started by sofortune, Today, 11:48 AM
                              1 response
                              5 views
                              0 likes
                              Last Post Danila
                              by Danila
                               
                              Started by schlabsm3129, 02-06-2024, 06:28 PM
                              2 responses
                              32 views
                              0 likes
                              Last Post karenmkrohn  
                              Started by Mr Bread, Today, 12:01 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post Mr Bread  
                              Working...
                              X