Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy open and sell close

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

    Buy open and sell close

    I just started using NinjaTrader last week and I've read the section on "Multi-Time Frame and Instruments" in the NT doc several times and reviewed the code that NinjaTrader_Josh wrote "SampleMultiTimeFrame" and I still can't seem to figure out how to liquidate a position on the same bar that it was entered on. Here's the code I'm currently running for test purposes...I'm trying to go long if the current daily bars close is greater the pervious bars high, and at the close of the the entry day bar I want to liquidate the long position. But this code that I'm running is not accomplishing this.

    protected override void OnBarUpdate()
    {
    // Primary bar is daily
    if(BarsInProgress==0)
    {
    if(Close[0]>High[1])
    {
    EnterLong();
    }
    }

    // Secondary bar is 1 minute
    if(BarsInProgress==1)
    {
    if(ToTime(Time[0])>145800)
    {
    ExitLong();
    }
    }
    }

    Any answers/suggestions on what I'm doing wrong here?
    Last edited by JayNice; 07-10-2009, 11:57 AM.

    #2
    JayNice,

    When backtesting you can only exit on the same bar if you have enough intrabar granularity. Instead of looking at the SampleMultiTimeFrame you should check out this reference: http://www.ninjatrader-support2.com/...ead.php?t=6652
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Okay, I just checked out "SampleIntrabarBacktest"...what am I suppose to get out of this that I'm not already doing in the code that I'm current running? I don't see how this assist me understanding how to sell at the close of the entry bar. "SampleIntrabarBacktest" simply takes long position in the secondary bar based on primary bar indicator crossover and reverses the position on indicator crossover in the opposite direction...I don't see how the information you provided is of any assistance to what I'm asking.

      Comment


        #4
        You need to use the correct signature methods for your orders as demonstrated in the reference sample.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Jay, likewise I am a new member. I generated a simple crossover (long/short) using the wizard and backtested it. Then I downloaded the script "SampleIntrabarbacktest" and backtested against the same data. Exactly the same result.

          Q1: In a live run, does the EnterLong (or short) occur at the close of the bar that caused the OnBarUpdate? Or does the entry ocurr at the close of the follwing bar?

          Q2: Can the sample NJ script be used in a live environment? If not, why? And what changes need be made to allow it to be used outside of backtesting?

          Q3: Can I copy and rename the downloaded script? If so, I can edit and test a modified script without "destroying" the original.

          TY

          Comment


            #6
            1. Submitted at close of bar.

            2. For sure it can be used in a live environment, but the sample is just a sample and may not contain any useful real-world trading logic.

            3. Yes, right click in the Editor and select Save As.
            Josh P.NinjaTrader 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
            368 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
            571 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