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

Problem with OrderState.TriggerPending ?

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

    Problem with OrderState.TriggerPending ?

    Hello,

    I am having a problem after submitting simulated stop orders in ChartTrader, and working with those orders in OnOrderUpdate. The OrderType shows up as Limit orders instead of StopMarket or StopLimit. Here is the summarized logic of my code:

    Code:
    private void OnOrderUpdate(object sender, OrderEventArgs e)
    {
    
    foreach(Order order in account.Orders)
    {
    if ((order.OrderState == OrderState.Working)  || (order.OrderState == OrderState.Accepted) || (order.OrderState == OrderState.TriggerPending))
    {
    if (order.OrderType == OrderType.Limit)
    
    {
        ProfitValue += (order.LimitPrice * order.Quantity);			  
    }
    
    // when Order State = TriggerPending, the following if statement is never true, instead the OrderType is listed as LIMIT (Debugging in VB)
    
    if ((order.OrderType == OrderType.StopMarket) || (order.OrderType == OrderType.StopLimit))		
    {
    	  StopValue += (order.StopPrice * order.Quantity);			   
    	  StopQty += order.Quantity;
    }								  
    
    
    }
    
    }
    
    }

    #2
    Hello RogBear,

    Thank you for the post.

    I see that you are working with the account orders collection but I don't see that you are using any kind of Prints here for debugging. Also, it is not noted what specific order or action is being completed in the chart trader to know what to expect as the outcome. Can you provide more detail surrounding the specific action you are doing in the chart trader and the specific type of order used?

    It would also be helpful for testing if you can use the passed in order event to review just the last updated order. If you are working with a single order as a test, the output should all pertain to that order.

    Code:
    private void OnOrderUpdate(object sender, OrderEventArgs e)
    {
    	Print(e.Order.ToString());
    }
    Using a Print and a single order from the chart, are you able to see the incorrect order type still? If so, can you provide the instructions and syntax used for me to see that as well?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse for taking the time to look at this. I will clarify.

      I am using chart trader, submitting unprotected initial orders to enter the market. Once an order is executed, and I have a live position, I will watch it for a bit, giving it some wiggle room, and when things look good, I will begin to submit stop limit orders in case the market changes and moves against me. I do this by first making sure that "Simulated Order" is checked by right-clicking in the Chart Trader window. Then I right click on the chart and usually select a "Sell Stop Limit" order (for long positions). I will usually setup a series of "Sell Stop Limit" orders at various prices, the sum of the quantity's should add up to my total market position size.

      Now we're ready for the indicator to do it's thing. Anytime I update an order, by moving the price, or whatever, I want to calculate my total dollars at risk, assuming all of my stops are filled successfully. So I want to iterate through all submitted orders, and calculate the loss on each one, then total up the losses. I use OnOrderUpdate to initiate the process, but I actually iterate though each order (not just the one order updated) using Account.Orders.
      Using your suggestion, I was able to verify my issue using Print statements (but I usually prefer setting breakpoints in VisualStudio)

      Code:
      foreach(Order order in account.Orders)
       	  {
      		  if ((order.OrderState == OrderState.Working)  || (order.OrderState == OrderState.Accepted) || (order.OrderState == OrderState.TriggerPending))
      {
      Print("order: " + order.ToString());
      Print("order.OrderType: " + order.OrderType.ToString());
      }
      }
      When I move the TriggerPending order in ChartTrader, this is the output I see:
      order: orderId='c54a48e2e693499ca566891b871c36db' account='REMOVED' name='' orderState=TriggerPending instrument='ES 09-18' orderAction=Sell orderType='Stop Limit' limitPrice=2898.75 stopPrice=2899 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2922 time='2018-08-28 21:29:53' gtd='2099-12-01' statementDate='2018-08-28'

      order.OrderType: Limit
      As you can see, although the order type is represented correctly as a "Stop Limit" when using order.ToString(), it is listed as a "Limit" order when using order.OrderType.ToString().

      THAT is the problem.

      FYI, I also verified the same behavior when printing from OnOrderUpdate using the e EventArgs variable (e.Order.OrderType).

      Hope this helps to clarify my issue.
      Last edited by RogBear; 08-28-2018, 08:47 PM.

      Comment


        #4
        Hello RogBear,

        Thank you for providing the additional details here. I will review this further to see what I can determine from what you have provided. I will need to form a sample of this, if you already have a simplified test that demonstrates this, that would be helpful if you can provide it so I do not have to try and recreate your test.

        Once I have further information on this, I will reply back here.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Sample Indicator with error

          Hello Jesse,

          Here is a sample bare-bones indicator that shows you the problem which I have called NinjaDemo. The same issue shows up in the Sim101 account. If you are working with a different account, just change the "account" variable in the code to match. This version does not require a live order in the market, you can simply start by entering a simulated sell stop limit order. As you move it in Chart Trader, you should see the output.

          Thanks for your help!
          Attached Files
          Last edited by RogBear; 08-31-2018, 12:43 AM. Reason: clarifying details

          Comment


            #6
            Hello RogBear,

            Thank you for providing the sample that is appreciated.

            I have tested this and do see the same outcome as you are but will need to further research what the expectation around this is. Simulated orders are a subject which we have fairly light documentation for so I will need to clarify this with development further.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello RogBear,

              After further review, it looks like this is expected.

              Simulated orders are not like a standard order in the sense that it sits as a 'regular' order with 'CustomOrder' property set that makes it stay in trigger pending. The internal logic surrounding these orders use additional order properties which the other UI tools and ToString account for but your print does not.

              For the StopLimit case specifically, you would need to check that it is a stop limit and is a simulated stop using its bool properties and not the enum:
              Print("order: " + (order.IsSimulatedStop && order.IsStopLimit));

              There are other currently undocumented order properties that can be used: IsMarket, IsMarketIfTouched, IsSimulatedStop, and IsStopMarket

              I have submitted a feature request for documentation surrounding all of these concepts.

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              27 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 04-23-2024, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              193 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,235 views
              0 likes
              Last Post xiinteractive  
              Working...
              X