Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.


    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.
          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.


              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.
              JCNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rdtdale, Today, 01:02 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by alifarahani, Today, 09:40 AM
              3 responses
              16 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by RookieTrader, Today, 09:37 AM
              4 responses
              19 views
              0 likes
              Last Post RookieTrader  
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              10 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              41 views
              0 likes
              Last Post love2code2trade  
              Working...
              X