• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM Order Entry Lasts Too Long

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

    ATM Order Entry Lasts Too Long

    I have an automated strategy which calls an ATM. It is working but sometimes price moves away from my entry price, and remains past the time that the entry is a good idea.
    I tried adding some code which saves the value of CurrentBar when the order is place, then checks to see if the order is still working and compares it to a value for how many bars I'd like the order to last. The problem is, it doesn't work. When the offending code is live, every order is cancelled as soon as it is placed. My preference is to have two checks: bars past order placement, and if price moves too far away from my entry price, (past the two profit targets in the ATM for instance). Here is the code, any idea why it should execute immediately instead of waiting for the current bar value to exceed the order current bar value plus my offset? Also, how can I add that price check as an alternative test.
    Thanks for your help.
    DaveN

    The code below shows the order entry where I set the barcode value, then the order status test where I compare and cancel if there are too many bars past entry.

    Code:
    				&& orderId.Length == 0 && atmStrategyId.Length == 0)			
                		{
    					Print(counter + "   " + " Executing RC_ATM_Sell");
    					atmStrategyId = GetAtmStrategyUniqueId();
    					orderId = GetAtmStrategyUniqueId();
    					AtmStrategyCreate(OrderAction.Sell, OrderType.Limit, Close[0] + Offset * TickSize, 0, TimeInForce.Day, orderId, "RC_ATM", atmStrategyId);
    					barcount.Set(CurrentBars[0]);
    					}
    			#endregion
    					
                #region Order Fill Status and Adjustment
    				if (orderId.Length > 0)
    				{
    				string[] status = GetAtmStrategyEntryOrderStatus(orderId);
    					if (status[2] == "Working" && (CurrentBars[0] > Bars_Past_OE + barcount[0]))
    					{
    					Print(counter + "  cancelling order because CurrentBars > Bars_Past_OE + Barcount");
    					Print(counter + CurrentBars[0] + "   " + barcount[0]);
    					AtmStrategyCancelEntryOrder(orderId);
    					}
    				}
    			#endregion

    #2
    Daven,

    I am happy to assist you.

    Is this a multi-timeframe or multi-instrument strategy? Have you tried printing the CurrentBars[0] and Bars_Past_OE + barcount[0] separately to compare?

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      It is a single instrument, single time frame strategy. I am trying to print out barcode and CurrentBar values, but they don't seem to be printing. Do I need to convert the above values into a string before printing? If so, what does that command look like?
      Thanks
      DaveN

      Comment


        #4
        Daven,

        Thanks for your note.

        Print() will print to the output window in Tools > Output Window.

        You can use something like My_Value.ToString() to convert something to a string.

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          ATM Order Entry Closing Early

          I tried posting a reply but for some reason it never showed up. I am adding a screenshot which shows and explains the code and what is going on. Bottom line, the order, if not filled on the entry bar cancels immediately, when it should be lasting five more bars. I am testing on barcount, which is set to currentbar when the order is placed, and in the next section of code, order status is tested to see if five bars have elapsed yet. But for some reason the value of barcount, that was equal to currentbar in the previous section of code, resets to zero and forces the order to close early. I can't figure out, why it is being reset to zero. There is nothing in the code, that I can see would be doing that. At any rate, the screen shot with explanations is attached.
          DaveN
          Attached Files

          Comment


            #6
            daven,

            What sort of time frame are you running this on? What is your Calculate on Bar Close setting?
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              I'm running it on a 5 Renko bar and I have calculate on close set to true.

              Comment


                #8
                Hi daven,

                Thank you for including the code and screenshots detailing the issue. I believe this stems from using a DataSeries for your captured CurrentBar value. They are synced to bars and will have a value of 0 if not set for a given bar. If you change barcount from DataSeries to int, it should work the way you expect.
                Last edited by NinjaTrader_RyanM1; 02-02-2012, 07:30 AM.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  ATM Orders Cancelling when Filling

                  That appears to have fixed the issue, though now I have a new one. It appears the order is sometimes being cancelled as soon as it tries to fill. Is there something about this code below that would make it behave that way?
                  Thanks
                  DaveN
                  Code:
                              #region Order Fill Status and Adjustment
                  				if (orderId.Length > 0)
                  				{
                  				string[] status = GetAtmStrategyEntryOrderStatus(orderId);
                  					if (status[2] == "Working" && (CurrentBars[0] > Bars_Past_OE + barcount))
                  					{
                  					Print(counter + "  cancelling order because CurrentBars > Bars_Past_OE + barcount");
                  					Print(counter + " CurrentBars = " + CurrentBars[0] + " barcount =    " + barcount + "Bars_Past_OE = "  +  Bars_Past_OE);
                  					AtmStrategyCancelEntryOrder(orderId);
                  					}
                  				}
                  			#endregion

                  Comment


                    #10
                    You have some print statements there already checking values, so would want to look at each one to see which is not returning the values you expect it to.

                    Print(counter + " CurrentBars = " + CurrentBars[0] + " barcount = " + barcount + "Bars_Past_OE = " + Bars_Past_OE);
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by zacharydw00, Today, 02:29 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post zacharydw00  
                    Started by timcjpfx, Today, 06:22 AM
                    4 responses
                    22 views
                    0 likes
                    Last Post timcjpfx  
                    Started by welson, Today, 08:26 AM
                    2 responses
                    13 views
                    0 likes
                    Last Post NinjaTrader_PatrickG  
                    Started by brucerobinson, Today, 08:27 AM
                    3 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by Leeroy_Jenkins, Today, 07:45 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_PaulH  
                    Working...
                    X