Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to know the bar last trade was closed?

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

    How to know the bar last trade was closed?

    Hi:

    I'm trying to implement an strategy, and I need to know, for the last trade executed, which was the bar of the close of the trade.

    In other words, which bar caused the target or stop loss to be filled? How many bars ago did my last trade close?

    I guess there must be a way to know it, but I couldn't find it. Any help will be appreciated!

    #2
    One simple way can be to implement OnExecution method. This method gets invoked whenever there is a execution.

    In this method, initialize a global integer variable and then on each OnBarUpdate increment the variable by 1. So you will know at any time, how many bars have passed since the last execution.

    Hope this helps.

    Comment


      #3
      Pakricard,

      Thank you for your post.

      StockFundoo is correct. You can declare your variable from the variables region first then increment it in the OnBarUpdate() method.

      When an execution gets called you would want to reset the variable in the OnExecution() method so you can have it start over in the counting.

      Below is a link for the OnExecution() method -
      OnExecution
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by StockFundoo View Post
        One simple way can be to implement OnExecution method. This method gets invoked whenever there is a execution.

        In this method, initialize a global integer variable and then on each OnBarUpdate increment the variable by 1. So you will know at any time, how many bars have passed since the last execution.

        Hope this helps.
        Thanks! Simple and it worked like a charm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by popecapllc, 08-09-2023, 07:42 PM
        8 responses
        1,344 views
        0 likes
        Last Post Johng22
        by Johng22
         
        Started by ETFVoyageur, 04-30-2024, 02:04 PM
        11 responses
        100 views
        0 likes
        Last Post ETFVoyageur  
        Started by bubblegum, 03-18-2024, 10:41 AM
        3 responses
        44 views
        0 likes
        Last Post vjsworld  
        Started by JamesK1, Today, 02:48 PM
        1 response
        13 views
        0 likes
        Last Post JamesK1
        by JamesK1
         
        Started by llanqui, Today, 03:51 PM
        0 responses
        11 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Working...
        X