Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

setting IOrder when the position closed

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

    setting IOrder when the position closed

    Hi
    In my startegy first I defined IOrder entryOrder, then entryOrder=EnterShort(), then I set the stoploss with SetStopLoss.
    It works. My question is: When the position closed (because the price equals the stoploss), is the entryOrder set to null automatically, or I have to detect the closing of the position, and set the entryOrder to null.

    Kind regards
    Akos

    #2
    Originally posted by akkiss View Post
    Hi
    In my startegy first I defined IOrder entryOrder, then entryOrder=EnterShort(), then I set the stoploss with SetStopLoss.
    It works. My question is: When the position closed (because the price equals the stoploss), is the entryOrder set to null automatically, or I have to detect the closing of the position, and set the entryOrder to null.

    Kind regards
    Akos
    If you must, you will have to nullify your IOrders when flat.

    I have never seen the need to do so. After all, I intend to reuse the IOrders, and they are fully assignable, so why nullify them?
    Last edited by koganam; 04-22-2015, 07:29 AM.

    Comment


      #3
      Hi Koganam
      Thank you for your answer. The IOrder object is readable only, but is it nullable, when the position is flat?
      The background of my question:
      I want to use the IOrder object as a "flag", to know if there is an opened position or there isn't. It works only if he IOrder is null everitime, when there is no position.
      Or I need a method, or something, to show that at the moment there is live position or there isn't.

      Kind regards
      Akos

      Comment


        #4
        Originally posted by akkiss View Post
        Hi Koganam
        Thank you for your answer. The IOrder object is readable only, but is it nullable, when the position is flat?
        The background of my question:
        I want to use the IOrder object as a "flag", to know if there is an opened position or there isn't. It works only if he IOrder is null everitime, when there is no position.
        Or I need a method, or something, to show that at the moment there is live position or there isn't.

        Kind regards
        Akos
        Code:
        if (Position.MarketPosition == MarketPosition.Flat)
        {
        //means that there is no position
        }
        That is completely independent of the existence or state of any IOrders.

        ref: http://www.ninjatrader.com/support/h...etposition.htm

        Comment


          #5
          Hello Akos,

          Thank you for your post.

          You may run into an instance where you assign the IOrder to the entry order but the order does not fill before the next bar update and the check for MarketPosition.Flat is true and thus sets the order back to null. So you may wish to set the order to null when the Stop Loss fills and check that it is null before entering into a new position:
          Code:
          // in OnBarUpdate()
          if(myEntryCondition && myOrder == null)
          {
          myOrder = EnterShort();
          }
          // in OnOrderUpdate()
          if(order.Name == "Stop loss" && order.OrderState == OrderState.Filled)
          {
          myOrder == null;
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          647 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          367 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          571 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X