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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    55 views
    0 likes
    Last Post CarlTrading  
    Working...
    X