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

Buy on Close (Today)

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

    Buy on Close (Today)

    Hi folks,

    I want to implement the following logic:

    If the Close today is higher than the Close yesterday, buy on today's close and sell at tomorrows close.
    Short analog.


    Seems like forcing NT to buy or short on the Close of the actual bar is only possible with Index -1
    with:

    if (Close[-1] >Close[0])
    {
    EnterLongStopLimit(1, Close[-1], Close[-1], "Long-Entry");
    }

    short analog,

    and to exit on the actual bar with:

    if (BarsSinceEntry("Long-Entry") == 0 )
    {

    ExitLongStopLimit(Close[-1], Close[-1], "Exit Long", "Long-Entry");
    }

    Unfurtunately that's not supported by the support.

    The system is always in market, evaluating Close-prices only and positions are sometimes subject to reversion.
    I just realized that NT is generating exit orders by itself in that case and so an open position is getting two exit-orders. So I figured out a work around for that case.
    But it's still not always working-there are bars where no new entries are generated, although I set max. entries per direction to 2.

    I have uploaded the strategy - so if anyone knows a fix - awesome!
    Maybe there is a much simplier way to code a system that evaluates Closes only - so in that case - please tell me :-)

    I don't want to belief it's unpossible with NT...

    Thanks in advance!
    Stephan
    Attached Files
    Last edited by Stephan123; 02-28-2011, 06:51 PM.

    #2
    Stefan, with the approach posted you're unfortunately running into the Internal Order Handling Rules of the managed approach in NT - http://www.ninjatrader.com/support/h...d_approach.htm

    To enter at the close of today or shortly before it, please submit the order to a finer minute series - or work directly from the intraday series by reformulating your conditions to work with the Current and PriorDayOHLC indicator methods.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Buy on Close

      -Is there a way to implement the desired logic
      via unmanaged approach?

      It has to run on daily OHLC data, therefore I can't increase granularity.

      Comment


        #4
        Stephan123,

        You can run a multi-time frame strategy to add the granularity you need to allow for the trade while still taking signals off your daily OHLC data. Please see here for more information: http://www.ninjatrader.com/support/h...nstruments.htm
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          -Unfurtunately I only have daily data available, which is why I can't provide any higher
          granularity. I have to figure out a way to do it with that daily resolution.
          Do unmangedorders work in this case?

          Comment


            #6
            Unfortunately not. The issue is not about managed or unmanaged, but rather that you need more data points to be able to trade at the level you are trying to trade at.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Can't I look one bar into the future to submit a limit order with the limit beeing the Close
              of the desired bar. This order would be filled on the close of the next bar.
              I tried it like that with manged orders, which worked, but only in 50-60%
              of all entries.

              Comment


                #8
                Stephan123,

                Unfortunately there is absolutely no way to peak into the future. Likewise, there is absolutely no way to trade at points in the past once you've seen data further forward.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  The command DrawText("My text" + CurrentBar, Close[-1].ToString(), 0, High[0], Color.Red); plots absolutely correct the Close of the bar x+1 on bar x.
                  Therefor I can generate all entry/exit signals one bar in advance. Correct?
                  At the next bar, the one bar in advance generated (limit)order is executed at a given price, in that case, the Close.price
                  The only question to me is 1) Do limit orders in backtests always fill if the limit price is the close of the bar and 2) how to handle an execution of an exit and an entry at the same bar at the same price, in this case the close price.

                  Comment


                    #10
                    Stephan, unfortunately working with the negative bar indices is not supported - filling of limit orders in backtesting will depend on the type of fill algorithm chosen, with the default one price has to trade through the limit price, a touch is ok in liberal mode.

                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Does that mean, there is absolutely no way to
                      implement a logic in NT as it is done with any easy language package like this:

                      If CloseD(0) > OpenD(0) then begin
                      Buy this bar at Close;
                      End;

                      If marketposition = 1 then begin
                      Exitlong ("Exit_Long") this bar at close;
                      End;

                      Comment


                        #12
                        Stephan, there is for sure a way to test a strategy like this in NinjaTrader as well: you would need to more granular intraday data though to allow for more conservative backtesting - as we do not allow historical backtest orders to execute on the close of the bar, as if you recognize this bar you would be on the next bar already when attempting to trade such a setup live.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          I have a similar question when working on intra-day bars. For example,

                          If Time=1200 Then ExitShort This Bar on Close;

                          Is this possible? I know how to set up the NT exits but they are market (which is next bar at open) or limit or stops, but no exit on closes based on a specific time that I have found.

                          Comment


                            #14
                            Originally posted by capstonetrader View Post
                            I have a similar question when working on intra-day bars. For example,

                            If Time=1200 Then ExitShort This Bar on Close;

                            Is this possible? I know how to set up the NT exits but they are market (which is next bar at open) or limit or stops, but no exit on closes based on a specific time that I have found.
                            If Time=1200 && Close[0] >= 0 Then ExitShort This Bar;

                            Comment


                              #15
                              Thanks, the best I could do in the Ninja Script was:
                              If (ToTime(Time[0]) == 1200 && Close[0]>=0)
                              {
                              ExitShort("exit signal name", "entry signal name");
                              }

                              It would not let me compile if I just state:

                              Then ExitShort This Bar on Close;

                              after the Time and Close >= 0 condition.

                              So with the Ninja script above, it still exits at the open of the next bar instead of the close of the current bar.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by JonesJoker, 04-22-2024, 12:23 PM
                              6 responses
                              32 views
                              0 likes
                              Last Post JonesJoker  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              12 responses
                              3,239 views
                              0 likes
                              Last Post Leafcutter  
                              Started by AveryFlynn, Today, 04:57 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post AveryFlynn  
                              Started by RubenCazorla, 08-30-2022, 06:36 AM
                              3 responses
                              79 views
                              0 likes
                              Last Post PaulMohn  
                              Started by f.saeidi, Yesterday, 12:14 PM
                              9 responses
                              25 views
                              0 likes
                              Last Post f.saeidi  
                              Working...
                              X