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

How to check IOrder object to see if a trade exited or not?

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

    How to check IOrder object to see if a trade exited or not?

    I have an IOrder object and would like to make sure that the trade exited at the limit price (my strategy has multiple entries & exits).

    I looked through the OrderState properties but do not see one that corresponds to having "filled and exited at the limit price."

    #2
    Hi texasnomad,

    You could do something like...
    if (order.OrderState == OrderState.Filled && entryOrder.AvgFillPrice == tryOrder.LimitPrice)

    But since this is a limit order, the price is guaranteed.
    Last edited by NinjaTrader_Tim; 07-22-2010, 12:42 PM.
    TimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Tim View Post
      Hi texasnomad,

      You could do something like...
      if (order.OrderState == OrderState.Filled && entryOrder.AvgFillPrice == tryOrder.AvgFillPrice.LimitPrice)

      But since this is a limit order, the price is guaranteed.
      Tim,

      I don't understand why you used 3 different object names; order, entryOrder and tryOrder

      At the time I place the trade, my code is:
      g1 = EnterLongStopLimit(Lots1, currentLimitPrice, "LongG1");

      Do I need to track the status of g1 with other IOrder objects? If so, how and when?
      Last edited by texasnomad; 07-22-2010, 11:30 AM.

      Comment


        #4
        Hi texasnomad,

        My apologies for the typos, should be "entryOrder"

        If you want to create an IOrder and access information, you can set up the order as in at this page:


        Code:
        private IOrder entryOrder = null;
        
        protected override void OnBarUpdate() 
        { 
            if (entryOrder == null && Close[0] > Open[0]) 
                entryOrder = EnterLong(); 
        }
        TimNinjaTrader Customer Service

        Comment


          #5
          Code:
                  protected override void OnPositionUpdate(IPosition position) { 
                      if( position.Quantity == Lots2 + Lots3 && g3.OrderState == OrderState.Filled ) {
                          /*if( position.MarketPosition == MarketPosition.Long ) {
                              SetStopLoss("LongG2", CalculationMode.Price, g2.AvgFillPrice + 0.5 * atr, false);    
                              SetStopLoss("LongG3", CalculationMode.Price, g3.AvgFillPrice + 0.5 * atr, false);    
                          }*/
                          if( position.MarketPosition == MarketPosition.Short  ) {
                              SetStopLoss("ShortG2", CalculationMode.Price, g2.AvgFillPrice - 0.5 * atr, false);    
                              SetStopLoss("ShortG3", CalculationMode.Price, g3.AvgFillPrice - 0.5 * atr, false);    
                          }                
                      }
                      
                      //Print("Position changed at " + Time[0].ToString() + ". Total lots: " + Position.Quantity);
                  }
          OK, I stumbled across OnPositionUpdate, which is half the battle. Initially, my problems was that all 3 order groups execute simultaneously. Because OnPositionUpdate keeps getting called, G3 enters and then immediately attempted to update the stops. I resolved it by refusing to update until G3 finishes entering and my total market units matches what I expect.

          That said, I'm still curious how I can know if g1 is an open or closed trade...
          Last edited by texasnomad; 07-22-2010, 12:31 PM. Reason: Typos

          Comment


            #6
            Originally posted by NinjaTrader_Tim View Post
            Hi texasnomad,

            My apologies for the typos, should be "entryOrder"

            If you want to create an IOrder and access information, you can set up the order as in at this page:


            Code:
            private IOrder entryOrder = null;
            
            protected override void OnBarUpdate() 
            { 
                if (entryOrder == null && Close[0] > Open[0]) 
                    entryOrder = EnterLong(); 
            }
            Tim,

            I just saw your latest post. I tried replacing
            if( position.Quantity == Lots2 + Lots3 && g3.OrderState == OrderState.Filled ) {

            with
            if( g1.OrderState == OrderState.Filled && g1.AvgFillPrice == g1.AvgFillPrice.LimitPrice ) {

            but g1.AvgFillPrice.LimitPrice is not recognized as a valid property of AvgFillPrice. Did you intend to say:
            g1.AvgFillPrice == g1.LimitPrice ?

            Also, do g1's properties update even after I create the object with EnterShortStopLimit()?
            Last edited by texasnomad; 07-22-2010, 12:45 PM.

            Comment


              #7
              Hi texasnomad,

              entryOrder.AvgFillPrice == entryOrder.LimitPrice
              TimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,609 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              9 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              19 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              6 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              16 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X