Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

h/l of n-bars after exit?

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

    h/l of n-bars after exit?

    Hello community,

    i like to get the high/low of n-bars after my trade exited. N-Bars should always be the value of the trade duration multiplied by two. So for example, if the last trade took 4 bars and exited today, i want to have the high or low of the next 8 bars (if data available, e.g. not in the future).

    How can this be done? I poked around with OnExecution() but i can't seem to get it right.

    many thanks in advantage.

    #2
    Hello puravida,

    You can use the OnExecution for this but you will have to create some variables to be able to check for this. Here is an example of how you may do this using the MAX, MIN, and BarsSinceEntry methods







    To Import
    1. Download the attached file to your desktop
    2. From the Control Center window select the menu File > Utilities > Import NinjaScript
    3. Select the downloaded file

    Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.
    Attached Files
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks a lot JC, comes really close to what i am looking for

      How would i finally print the actual P&L of the last trade and the hypothetical
      best P&L when exiting on Max/High for long and Min/Low for short using the original entry?

      Comment


        #4
        Hello puravida,

        You may use the TradeCollection object to be able to get the actual P&L of the last trade inside of your code. Our Help Guide at the following link goes more over this and has an example of how to get the Last Trades profit that you may view.



        As for the hypothetical this will have to be calculated manually so you will have to get the entry price of the order which you can get from the OnExecution event as well to your hypothetical exit price.

        So for this it would be (hypothetical exit price – entry price) for long trades and as (entry price – hypothetical exit price) for short trades, times the number of contracts traded, and times the point value (Instrument.MasterInstrument.PointValue).


        Let us know if you have any questions.
        JCNinjaTrader Customer Service

        Comment


          #5
          works like a charm, you saved my day. Thanks again

          Comment


            #6
            ...just a short question:

            After using the code from your strategy, my output window fills with entries like:
            LONG: 93,3465802284992 92,0575787064835 89,1557403302682 83,3171730997837

            How can i get rid of this? I don't found a Print() statement responsible for this, so i assume this activated automatically by calling certain methods?

            Comment


              #7
              Hello puravida,

              There should be nothing that gets put in the Output window that are not coded to be there. Do you have another script by chance that may be Print() ing this or could you clarify what other Print()s that you are using?
              JCNinjaTrader Customer Service

              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
              369 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
              572 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