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

Comparing order time to current bar

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

    Comparing order time to current bar

    Is there any way I can compare current time/bar to order time?

    I want achieve that strategy will not enter position in first 20 bars after last order made before it was enabled.

    I am using something like:

    Initialize()
    Code:
    			foreach (Account acct in Cbi.Globals.Accounts) {
    				if(acct.Name == Account.Name) {
    					PositionCollection positions = acct.Positions;
    					if (acct.Positions != null)	{
    						foreach (Position pos in positions)	{
    							if(pos.MarketPosition == MarketPosition.Long && pos.Instrument.FullName == Instrument.FullName && pos.Account.Name == Account.Name) {
    								isLongAccountPosition = 1;
    							}
    						}	
    					}
    					if (acct.Orders != null) {
    						OrderCollection orders = acct.Orders;
    						foreach (Order ord in orders) {
    							if(ord.Instrument.FullName == Instrument.FullName && ord.Account.Name == Account.Name) {
    								lastLongAccountOrderBar = ord.Time.Ticks;
    							}
    						}
    					}
    				}
    			}
    to get order time. But I werent able to get anything I could compare to CurrentBar. Is there a way to achieve that or somehow get time of 20 bars and compare it?

    Thanks.

    #2
    Hello Dukecz,

    Thank you for your post.

    You can use BarsSinceEntry() or BarsSinceExit() to check that there has been twenty or more bars since the last trade.

    Example -
    Code:
    if(BarsSinceExit() >= 20)
    {
        //take another trade
    }
    http://www.ninjatrader.com/support/h...ssinceexit.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Does it work when the position entry was not made by strategy? I have made buy order (entering long) before starting strategy (so the Account is Long but strategy is Flat) and i still get:

      BarsSinceEntry() returns 0 and BarsSinceExit() returns -1

      Thanks for your help.

      Comment


        #4
        Dukecz,

        This is expected. The Entry requires that there is an entry from an order and the Exit requires that there was an exit to a position.

        Are you looking to do number of bars since the order was placed?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Cal View Post
          Dukecz,

          This is expected. The Entry requires that there is an entry from an order and the Exit requires that there was an exit to a position.
          Well I have made the order manualy so its in the account... but not in the strategy.

          Originally posted by NinjaTrader_Cal View Post
          Are you looking to do number of bars since the order was placed?
          Yes... I am looking for number of bars since the last (filled) order that was placed from any source (any strategy or made manually). Thats why I have tried to work with that list of all orders in initialize function.

          Thanks.

          Comment


            #6
            Dukecz,

            Getting filled order updates from a global event is unsupported and would not have any documentation on it.
            If you are looking for when the order was last filled from the strategy then you would want to use BarsSinceEntry().

            Let me know if I can be of further assistance.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Is there a way to get time before x bars or bar time length (so when I am in CL 07-14 (1 min) it would be 60 seconds)? I am able to get time of each order and I would be fine with just comparing two times.

              Thanks for your effort.

              Comment


                #8
                Dukecz,

                To find the length of a bar's time you can take Time[0] - Time[1].
                This will grab the bars time stamp and subtract the previous time stamp from it.
                Cal H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by WHICKED, Today, 12:56 PM
                2 responses
                14 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by Felix Reichert, Today, 02:12 PM
                0 responses
                1 view
                0 likes
                Last Post Felix Reichert  
                Started by Tim-c, Today, 02:10 PM
                0 responses
                1 view
                0 likes
                Last Post Tim-c
                by Tim-c
                 
                Started by cre8able, Today, 01:16 PM
                2 responses
                9 views
                0 likes
                Last Post cre8able  
                Started by chbruno, 04-24-2024, 04:10 PM
                3 responses
                49 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X