Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Entries when using Sample ATM as a template

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

    Multiple Entries when using Sample ATM as a template

    I am trying to implement a strategy that invokes a named ATM as represented by the Sample ATM code that you provide. The strategy compiles and runs but I am getting multiple entires from my code, as many as 4 extra entries. I check to see that the order id and atmStrategyId.Length are both 0 before entering but that doesn't seem to prevent multiple orders. Here is the code I am using for order entry:

    Code:
    && orderId.Length == 0 && atmStrategyId.Length == 0)
    		{	
    		Print(counter + "   " + " BFI_Avg Executing ATM_CL_Buy");
    		atmStrategyId = GetAtmStrategyUniqueId();
    		orderId = GetAtmStrategyUniqueId();
    		AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Market, 0, 0 , TimeInForce.Day, orderId, "BFI_ATM_CL", atmStrategyId);
               	}
    Is there some other kind of check I should be adding. I've used this construct before and not had this problem but for some reason this time around I am getting these unwanted additional entries.
    DaveN

    #2
    Which CalculateOnBarClose setting do you use to run this script Daven?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I am running the strategy of four instruments, CL, ES, 6E, and NQ. They are all set for CalculateonBarClose=True. Also, I discovered this problem while running on replay, but this morning I just noticed that the problem occurred on CL running real-time in sim. I have one other issue with the strategy. It has timed entries and it shouldn't be entering any trades until 6 AM PDT at the earliest, and judging by what I just saw when I got up this morning, it has been executing trades all night, so I have another issue to investigate. Anything else I should be checking on the multiple entry issue?
      DaveN

      Comment


        #4
        Hi Dave, can you please post the section where you reset the id's as well? Could it be that the trades just last quickly based on the ATM template settings, the condition then staying true so it would reenter basically the next bar for you?

        What time filter and bars type are you using for your charts?

        Thanks,
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Posting Multiple Entries with ATM Strategy

          I am using a Bar Type I got from Big Mike's forum, BetterRenko, basically a Renko bar with better wick visibility. Here is my code for time filtering:

          Code:
          && ((ToTime(Time[0]) > TT1_Start && ToTime(Time[0]) < TT1_End ) || (ToTime(Time[0]) > TT2_Start && ToTime(Time[0]) < TT2_End ))
          Here is the variable section for that code:

          Code:
          		// Timed Trading Variables
          		private int tt1_Start =060000 ; // Start Time for first trading period
          		private int tt1_End = 124500 ; // End Time for first trading period
          		private int tt2_Start = 103000 ; // Start Time for second trading period
          		private int tt2_End = 103000 ; // end Time for second trading period
          And here is the Properties section for the code:

          Code:
                  [Description("")]
                  [Category("Parameters")]
                  public int TT1_Start
                  {
                      get { return tt1_Start; }
                      set { tt1_Start = Math.Max(000001, value); }
                  }
          		
                  [Description("")]
                  [Category("Parameters")]
                  public int TT1_End
                  {
                      get { return tt1_End; }
                      set { tt1_End = Math.Max(000001, value); }
                  }
          		
                  [Description("")]
                  [Category("Parameters")]
                  public int TT2_Start
                  {
                      get { return tt2_Start; }
                      set { tt2_Start = Math.Max(000001, value); }
                  }
          		
                  [Description("")]
                  [Category("Parameters")]
                  public int TT2_End
                  {
                      get { return tt2_End; }
                      set { tt2_End = Math.Max(000001, value); }
                  }
          Here is the section where the id's are reset:

          Code:
          			#region Status Checking and Print Out
          	        // Get Strategy identification information in order to print it out    	
          					
                 		// Check for a pending entry order
          			// Print where we are in the program
          			{
          				Print("  CL  " + counter);
          				Print(" CL Code has entered the status print out.");
          			}
          			if (orderId.Length > 0)
          				{
          				string[] status = GetAtmStrategyEntryOrderStatus(orderId);
                          
          				// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
          				if (status.GetLength(0) > 0)
          					{
          					// Print out some information about the order to the output window
          					Print("The entry order average fill price is: " + status[0]);
          					Print("The entry order filled amount is: " + status[1]);
          					Print("The entry order order state is: " + status[2]);
          
          					// If the order state is terminal, reset the order id value
          					if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
          						orderId = string.Empty;
          					}
          					}
          				// If the strategy has terminated reset the strategy id
          					else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
          					atmStrategyId = string.Empty;
          
          
          				if (atmStrategyId.Length > 0)
          					{
          					// Print some information about the strategy to the output window
          					Print("The current BFI_ATM_CL Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
          					Print("The current BFI_ATM_CL Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
          					Print("The current BFI_ATM_CL Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
          					Print("The current BFI_ATM_CL Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
          					}
          				#endregion
          But I have on other question. I was looking through some other code I have and I noticed there appears to be two ways to check on whether there is an active ATM running.

          1
          Code:
          		&& orderId.Length == 0 && atmStrategyId.Length == 0))
          or 2
          Code:
          		&& GetAtmStrategyMarketPosition("PT_BCM_ES") == MarketPosition.Flat
          Which of these two methods (if either of them) is the correct way to ensure there is not active ATM already running?

          Thanks for your help.

          DaveN

          Comment


            #6
            ATM Multiple Entries continued

            I found the problem for the timed entry issue, and it may be the issue with the multiple entries as well. I was missing a parentheses from the right side of the timed entry filter for shorts only. As a result, I was entering trades outside of the desired time. Now that I look at the code, I don't think that is causing the multiple entry issue, since I had the right number of parentheses for the code itself, and once the order placement section was entered, the problem was already passed. the last part of my previous post is germane though. What is the best way (of the two I showed) to ensure there is not already an active ATM in place already?
            Thanks
            DaveN

            Comment


              #7
              Thanks for the update, glad to hear on the time condition error spot.

              There are two parts at play here for checking the ATM strategy entries, the order and strategy id, which checks are included in your entry condition. If those are not in reset state, a new entry could not be done.

              The Market Position check for ATM's you cited would be used on the reset for the strategy related identifier, so adding this in as well into your entry would not be needed.

              So for the entry, your print statement is triggered multiple times for the same entry point? What stops and targets do you use here?
              BertrandNinjaTrader Customer Service

              Comment


                #8
                The ATM specifies a stop loss of 12 and a profit target of 12, but here's the weird thing. I fixed the trade timing problem in all of the strategies, and restarted everything. I just got a trigger for the CL strategy and I sequentially had three trades entered, with stops a few ticks apart, but the three profit strategies, 12 ticks apart. So where I should have had one entry with a stop of 12 and a target of 12, I got three entries with stops of 12 and profit targets of 12, 24 and 36. Very strange indeed.
                DaveN

                Comment


                  #9
                  Thanks Dave, to further isolate : do you see the same on a standard NT chart with the test script attached? Note : it would need a AtmStrategyTemplate strategy defined in your NT to run.
                  Attached Files
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    I am finding some discrepancies between what is defined in the "AtmStrategyCreate" section of the Help Guide vs what is provided in the SampleATM strategy. Here's what I see:

                    The Help Guide specifies the following:

                    AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
                    TimeInForce.Day, GetAtmStrategyUniqueId(), "MyTemplate",
                    GetAtmStrategyUniqueId());
                    It specifies "GetAtmStrategyUniqueId() twice but never speficies GetorderId at all.

                    In the SampleAtm strategy here is what is provided:
                    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
                    It doesn't use the GetAtmStrategyId at all, it simply provides the words atmStrategyId().

                    Which is the correct syntax for this function?

                    Thanks

                    DaveN

                    Comment


                      #11
                      Dave, you would want to go with the sample instructions - the helpguide is just showing a possible syntax here, but this would be creating a unique id each time and don't limit trade placement as the sample does. I will note this down to enhance / streamline better in a future HG upgrade.
                      BertrandNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by RideMe, Today, 09:30 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post RideMe
                      by RideMe
                       
                      Started by onlinebusiness, Today, 09:30 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post onlinebusiness  
                      Started by max1ci6, 12-15-2021, 04:07 AM
                      4 responses
                      812 views
                      0 likes
                      Last Post NinjaTrader_ChrisL  
                      Started by Mindset, 12-01-2022, 05:43 AM
                      6 responses
                      50 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by RookieKiwi, 01-28-2022, 11:59 AM
                      5 responses
                      119 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Working...
                      X