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 Brevo, Today, 01:45 AM
        0 responses
        6 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        3 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        6 views
        0 likes
        Last Post oviejo
        by oviejo
         
        Working...
        X