Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Storing data when position is opened

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

    Storing data when position is opened

    Hi

    I want to store the low of the previous when a long position is opened. What is the best way to do this? I know how to use variables - and how the find the close of the bar - and therefore do not help with that. What I need help with something like:

    if (long position was just opened)
    closevar = Close[1]

    what is the condition I must use for "long position was just opened). This condition would only be true for the bar on which the position was opened - and not for the next bar although the long position would still be open.

    Verge

    #2
    verge, there are several ways to do this - easiest would be to just save the close value to a variable at the time your entry condition evaluates to true, if you place for example a limit or stop order that would last for same bars until filled and you wanted to get the close of the bar the order was filled on, then work with the IOrder objects to access the orderstate change to OrderState.Filled - http://www.ninjatrader-support.com/H...V6/IOrder.html

    Comment


      #3
      Some additional information

      Originally posted by NinjaTrader_Bertrand View Post
      verge, there are several ways to do this - easiest would be to just save the close value to a variable at the time your entry condition evaluates to true, if you place for example a limit or stop order that would last for same bars until filled and you wanted to get the close of the bar the order was filled on, then work with the IOrder objects to access the orderstate change to OrderState.Filled - http://www.ninjatrader-support.com/H...V6/IOrder.html
      I did not give you enough information. My entry condition is not valid for one bar only - but a number of consecutive bars. A easy way to explain it would be the condition if (High[0] > High[1]) - it could be true for a number of bars. I will enter on the bar where the condition becomes true - but cannot save the close[1] in a variable because on the next bar (when the condition is still true) it will be updated - and I don't want it to update.

      Thank you for suggesting IOrder - I had a look at it. It is a pity that it does not have a "bar on which fill occurred" property included. I will try and code something that saves the bar number on which the property filled changed. Working with IOrders are still a bit difficult for me - still learning (will never stop) - can you give me a code snippet or a reference example to look at please

      Verge

      Comment


        #4
        Thanks for the info, you can check into this sample for working with IOrder objects - http://www.ninjatrader-support2.com/...ead.php?t=7499

        Here's a snippet -

        Code:
         
        private IOrder entryOrder = null;
        private double myClose;
         
        protected override void OnBarUpdate() 
        { 
            if (entryOrder == null && Close[0] > Open[0]) 
                entryOrder = EnterLong(); 
        }
        protected override void OnOrderUpdate(IOrder order) 
        { 
            if (entryOrder != null && entryOrder.Token == order.Token) 
            { 
                if (order.OrderState == OrderState.Filled) 
                    {
                     entryOrder = null;
                     myClose    = Close[0]; 
                    }
            } 
        }

        Comment


          #5
          Thank you

          Thank you Bertrand

          Verge

          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
          368 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