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 Rapine Heihei, 04-23-2024, 07:51 PM
              2 responses
              30 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by Shansen, 08-30-2019, 10:18 PM
              24 responses
              943 views
              0 likes
              Last Post spwizard  
              Started by Max238, Today, 01:28 AM
              0 responses
              9 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by rocketman7, Today, 01:00 AM
              0 responses
              5 views
              0 likes
              Last Post rocketman7  
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              28 views
              0 likes
              Last Post wzgy0920  
              Working...
              X