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

Change atm strategy entry order if not filled

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

    Change atm strategy entry order if not filled

    I am running a strategy which implements an ATM limit entry order if conditions are met. Before I added the line which checks for an existing order before entering another order, the strategy blasted a new atm entry order every time my conditions were satisfied for entry, which meant, in some cases at the close of each new bar. The version of this strategy that I was using before going to an atm implementation, would "walk" the entry order up a series of upper bar closes (or down for series lower bar closes). I would like to implement that with this atm strategy but cancel the old atm order, and enter a new one at the new limit price. I am having trouble figuring out how to get the existing atm limit entry price, so I can check it against current price, and update it if conditions warrant.This is the construct I am using right now, but I can't figure out how to get that existing, but unfilled current entry limit order price.

    Code:
    			if (orderId.Length > 0)
    			{
    			string[] status = GetAtmStrategyEntryOrderStatus(orderId);
    				if (status.GetLength(0) > 0)
    				{
    					if (status[2] == "Working"
    						&& GetCurrentAsk() > //NEED THE CURRENT ATM ENTRY ORDER PRICE RIGHT HERE
    						//&& OTHER ENTRY CONDITIONS)
    						)
    					{
        				AtmStrategyChangeEntryOrder(GetCurrentAsk() - OE_Offset * TickSize, 0, "orderId");						
    					}
    				}
    			}
    Hope you can give me some guidance about how to get this done.
    Thanks
    DaveN

    #2
    DaveN, the resting but unfilled limit order price of the entry could unfortunately not be accessed this way, so I would suggest storing the limit price to a tracking variable at the time you submit so you would be able to compare to it later on when deciding on updating the order via the ChangeEntryOrder call.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Cancel and Resubmit an ATM Order

      That's what I tried to do, plus a variable that will tell me what direction the limit entry is for.
      Here's what I tried but it doesn't work, the order doesn't cancel and it isn't resubmitted, perhaps a tweak or two is needed?
      Thanks
      DaveN

      Code:
      			// Update price to new limit entry if price moves more than OE_Offset from current price	
      			if (orderId.Length > 0)
      			{
      			string[] status = GetAtmStrategyEntryOrderStatus(orderId);
      				if (status.GetLength(0) > 0)
      					{
      					if (status[2] == "Working"
      						&& m_position == "Long"
      						&& GetCurrentAsk() > Variable0 + OE_Offset * TickSize
      						&& Close[0] > Open[0])
      							{
          						AtmStrategyChangeEntryOrder(GetCurrentAsk() - OE_Offset * TickSize, 0, "orderId");						
      							}
      					else if(status[2] == "Working"
      						&& m_position == "Short"
      						&& GetCurrentBid() < Variable0 - OE_Offset * TickSize
      						&& Close[0] < Open[0])
      							{
          						AtmStrategyChangeEntryOrder(GetCurrentBid() + OE_Offset * TickSize, 0, "orderId");						
      							}
      					}
      
      			}
      Later in the code, when the order is flat, I reset the direction variable m_position to "flat" and reset Variable0 to 0 but I'm not sure if that is correct, can I reset it to "null"? OE_Ofset is the positive integer I use to place the order above or below the current bid or ask, (below for a long, above for a short).

      Comment


        #4
        Hi DaveN, guess I'm not following you - why Cancel the order? The entry is working at price x and then when conditions warrant you would to update the order to price y, right?

        I would start debugging by printing the conditions contents for the adjustment to understand why this is not triggered - m_Positon is set when you make the initial entry call?

        Setting the price to 0 should be fine, as you would reset it to a valid initial value when another entry sequence is done - if you prefer there's a nullable int type as well in C# -

        BertrandNinjaTrader Customer Service

        Comment


          #5
          Cancel and Resubmit an ATM Orde

          So I don't have to worry about cancelling and resubmitting, I simply update the new entry price? Okay, that should be simpler, so my only issue now is why isn't it executing. I'll add some print statements as you suggested to see if I can figure out what is going on. Other than the 0 value for variable0 is my construct basically sound?
          Thanks
          DaveN

          Comment


            #6
            Yes, correct, just use the ChangeOrder to update the orderid on your condition - just like with a regular NS script order.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by nuobo, Today, 07:43 PM
            0 responses
            1 view
            0 likes
            Last Post nuobo
            by nuobo
             
            Started by ETFVoyageur, Today, 02:04 PM
            3 responses
            21 views
            0 likes
            Last Post ETFVoyageur  
            Started by cre8able, Today, 06:18 PM
            0 responses
            5 views
            0 likes
            Last Post cre8able  
            Started by ETFVoyageur, Today, 06:05 PM
            0 responses
            6 views
            0 likes
            Last Post ETFVoyageur  
            Started by TAJTrades, 04-28-2024, 09:46 AM
            2 responses
            17 views
            0 likes
            Last Post TAJTrades  
            Working...
            X