• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering and Exiting on the same day

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

    Entering and Exiting on the same day

    Hi,

    I would like to be able to enter and exit positions on the same day when back testing a strategy in Ninja Trader on daily data.

    For e.g. enter at today's open and exit at today's close ( do not delay entry or exit by one bar)

    It would seem that this should be something very simple to code yet I have seen a number of people have had the same problem with no current resolution available.

    Does anyone know of a solution as to how this can be achieved with out having to use intra day data?

    I'm an experienced C# programmer so any kind of work around would be most help full.

    #2
    Hello Beach01,

    The trouble is that the close price is not known for the next day since you only have access to the Daily Data. So the only way that you can have an exit order on the same day without Intraday data would be to use the SetStopLoss or SetProfitTarget orders.

    Note that you can use Market Replay for some intraday data so that you can test out your strategy.

    Here is a link to our Market Replay webinar that you may view to see if this will work for you.
    http://youtu.be/cgB1y3df7l0

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC,

      Thank you for your response.

      It is extremely frutrating that Ninja Trader can not do such a simple back test as entering a trade at the open and exiting the trade at the close on the same day. I have looked around the web and there have been numerous queries/complaints on various forums including this one that such an easy task can not be achieved in Ninja Trader.

      As I'm back testing stocks entering and exiting at the close in real life is a basic strategy that I trade regularly and should be really simple to test as it is with many other programs.

      As far as I understand the market replay is only for 90 days and only for futures and forex which doesn't help as I'm trying to back-test data for the last 20 years.

      There must be some kind of work around to be able to enter and exit on the same day.

      You mentioned using SetStopLoss or SetProfitTarget orders. Is it possible to set these to the days open and the close to force the algorithm to enter or exit at today's open and close???

      Comment


        #4
        Hi Beach,

        I run several strategies live which close on last bar of the day. What i do is enable the option "ExitOnClose" as True and Choose a parameter such as 30 seconds for ExitOnCloseSeconds property.

        ExitOnClose = true;
        ExitOnCloseSeconds = 30;

        Is this what you are looking for. Hope this helps.

        Comment


          #5
          Hello Beach01,

          This is something that can be achieved in NinjaTrader but you would need intraday data to be able to accomplish this using all of the default NinjaTrader methods.

          NinjaTrader also give you access to about a years worth of Market Replay data for free for the most common Futures and Forex instruments.

          Since, NinjaTrader uses C# as its base of NinjaScript there is a lot of different things that you can do to get around items but they just could not be supported by us.

          For example I have attached a Sample strategy that uses the Unmanaged Approach that peeks ahead of the bar to get the Close price so you can have an exit at the Close price. Note this is not supported in NinjaTrader but it is possible to do.

          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.

          There is another user that created a custom fill type that will something similar to this but it looks like the date that the order is filled is off but you may still look into this at the following thread.
          http://www.ninjatrader.com/support/f...ad.php?t=13993
          Attached Files
          JCNinjaTrader Customer Service

          Comment


            #6
            Hi JC,

            This is exactly what i was looking for. It looks like the the un-managed approach is what I need to be able to enter and exit positions on the same bar.

            The sample strategy was helpful, although I noticed that on days where the high is equal to the close the exit is drawn on the next bar even though the price that it exits is still the correct close price. When I use this code in some of my strategies it causes the strategy to not enter on that bar because it still thinks its in a trade. Is there any way to correct this?

            Also I have written some code for my strategy to exit on the next profitable close using the un-managed approach. Unfortunately the strategy only seems to be using the stop loss and not taking profit when its supposed to.

            I have attached the code to this post. Any comments on what I've done wrong or what I'm missing would be much apprenticed?

            P.S. Does anyone have any sample code using the un-managed approach in strategies?
            Attached Files

            Comment


              #7
              Hello Beach01,

              The reason why the order is not being filled when the close price is equal to the high price is because of the Historical Fill Processing selecting. Using the "Default" limit orders will be filled only when the price has been traded through. You may want to use the "Liberal" Histoical Fill Processing to have limit order filled if the price touches it.

              As for your strategy that you sent you may want to check the stop price is being set to the one that you want. So you may use the Print() statements to verify values are what you expect. Here is a good thread on how to use the Print() method that you may view.
              http://www.ninjatrader.com/support/f...ead.php?t=3418

              Also, when using strategies adding TraceOrders = true to your Initialize() method will allow you to view valuable output related to strategy submitted orders through Tools > Output window.
              http://www.ninjatrader.com/support/f...ead.php?t=3627
              JCNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by vhjscv, Yesterday, 10:31 PM
              0 responses
              8 views
              0 likes
              Last Post vhjscv
              by vhjscv
               
              Started by buick, Yesterday, 09:37 PM
              0 responses
              5 views
              0 likes
              Last Post buick
              by buick
               
              Started by Hagar, Yesterday, 07:12 PM
              0 responses
              6 views
              0 likes
              Last Post Hagar
              by Hagar
               
              Started by jtrading82, Yesterday, 01:55 PM
              4 responses
              28 views
              0 likes
              Last Post bppayne
              by bppayne
               
              Started by Hagar, Yesterday, 06:52 PM
              0 responses
              4 views
              0 likes
              Last Post Hagar
              by Hagar
               
              Working...
              X