Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter Long at Bar "Open" and Close Position at Bar "Close"

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

    Enter Long at Bar "Open" and Close Position at Bar "Close"

    Guys,

    I have a daily bars strategy being backtested, seems to be OK, the only problem is that even being day bar I want to open the day Entering positions and in the end of SAME bar close it,

    EnterLong (OPEN Price)

    EnterShort(Close position) (Close Price)

    Can you give me a piece of code for that?

    Best

    #2
    Hello artarian,

    When backtesting Calculate on bar close is always true.
    http://www.ninjatrader.com/support/h...onbarclose.htm

    When Calculate on bar close is true, OnBarUpdate() is called once per bar.
    If SetStopLoss is used, if the price is within the price of the new bar it will exit on the same bar.
    (Try using a 1 tick SetStopLoss to demonstrate what I mean)
    If an ExitLong() or ExitShort() is called, this is called in OnBarUpdate() and cannot be submitted until the next bar.

    To get around this, you can add intra-bar granularity to your script so that you can submit orders on a smaller time frame (within the larger day bar).

    Below is a link to an example reference sample that shows how to add intra-bar granularity and submit an order to a smaller time frame.
    http://www.ninjatrader.com/support/f...ead.php?t=6652
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    646 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    107 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 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