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

Enter on Close

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

    Enter on Close

    Hi

    I don't know if this is the right forum for my question, but I'll try it anyway. My problem is, that I have a strategy, where I want to buy (or sell) a position on the close of the bar. How can I do that? If I enter EnterLong(), then it enters on the following open instead of the current close.
    Can anybody help me?

    Greetz

    Sepp

    #2
    Sepp,

    One of our Support Member trainees will respond to this post shortly. Thank you for your patience in this matter.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Sepp, when backtesting, the only data points provided to the backtester are the open, high, low, and close. When the close data point comes in, that bar is no longer tradable because a new bar is now being formed. If a signal is generated from the close of the bar, that would mean the next tradable location is the open of the next bar.

      During real-time testing, if you have CalculateOnBarClose = false, the orders will fire as soon as the conditions are true.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Hmm, I see... The problem is, that the system calculates with the close of the bar. Is there a way to calculate the price 15 seconds before close instead of the close and therefore also enter 15 seconds before close of the bar? I know, this is difficult to program, but I hope there will be a way.
        Can you help me again please?

        Greetings

        Sepp

        Comment


          #5
          Sepp, please see this reference sample about backtesting NinjaScript strategies with an intrabar granularity.
          AustinNinjaTrader Customer Service

          Comment


            #6
            That's not really what I need... I really want to enter on the close of the current bar or 3 secs before and use this "early close" as the normal Close in the strategy for calculating Profits, etc. Is there any possibility? Because one minute before (in the 5 Minute bars) entering is way too much.

            Regards,

            Sepp

            Comment


              #7
              Sepp, unfortunately not, you would need to use the sample concept Austin provided and then for example submit orders to a 1 tick chart to come as close to the 5 min bar close as possible.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                I have a question regarding the sample with the intrabar granularity: I've tried it on my own and got this one:

                But there are no trades when I backtest it on a 5 Min chart. I almost copied the samlpe and it still doesn't work. What am I doing wrong?

                Sepp

                P.S. code comes in next post

                Comment


                  #9
                  Part 1

                  protectedoverridevoid Initialize()
                  {

                  Add(PeriodType.Minute,
                  1);

                  CalculateOnBarClose =
                  true;
                  }
                  ///<summary>///</summary>
                  protectedoverridevoid OnBarUpdate()
                  {

                  if (BarsInProgress == 1)
                  {

                  if (Close[0] > Open[4])
                  {
                  if(Close[0] - Open[4] > 1)
                  {
                  EnterLong(
                  1, DefaultQuantity, "");
                  }
                  }



                  if (Close[0] > Open[4])
                  {
                  if(Close[0] - Open[4] < -1)
                  {
                  EnterLong(
                  1, DefaultQuantity, "");
                  }
                  }

                  Comment


                    #10
                    Part 2

                    if (Close[0] < Open[4])
                    {
                    if(Close[0] - Open[4] > 1)
                    {
                    EnterShort(
                    1, DefaultQuantity, "");
                    }
                    }
                    if (Close[0] < Open[4])
                    {
                    if(Close[0] - Open[4] < -1)
                    {
                    EnterShort(
                    1, DefaultQuantity, "");
                    }
                    }

                    Comment


                      #11
                      Part 3

                      if (CurrentBar < 1)
                      return;

                      if (BarsSinceEntry() == 0)
                      {
                      ExitLong(
                      "", "");
                      ExitShort(
                      "", "");
                      }

                      if (BarsSinceEntry() == 0)
                      {
                      ExitLong(
                      "", "");
                      ExitShort(
                      "", "");
                      }

                      if (Close[0] == Open[4])
                      {
                      ExitLong(
                      "","");
                      ExitShort(
                      "","");
                      }
                      }
                      }

                      Comment


                        #12
                        MasterSepp, please try simpler rules for entry and add a drawing to those to verify your conditions trigger, the ones you used may be too 'hard' to produce any trades....also check the log tab for any errors being listed as you run the strategy on the 5min chart.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          It isn't because of the entry conditions. I used the same in another strategy with just one bar series and it worked without problems. There has to be another error in the strategy...

                          Comment


                            #14
                            MasterSepp, please attach the strategy so I can give it a test run on my end - thanks
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              if (Close[0] > Open[0])
                              {
                              EnterShort(DefaultQuantity, "");
                              }
                              if (Close[0] > Open[0])
                              {

                              EnterShort(DefaultQuantity,
                              "");
                              }
                              if (Close[0] < Open[0])
                              {

                              EnterLong(DefaultQuantity,
                              "");
                              }
                              if (Close[0] < Open[0])
                              {

                              EnterLong(DefaultQuantity,
                              "");
                              }
                              if (CurrentBar < 1)
                              return;
                              if (BarsSinceEntry() == 0)
                              {
                              ExitLong(
                              "", "");
                              ExitShort(
                              "", "");
                              }



                              This is the original one.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rocketman7, Today, 02:12 AM
                              7 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by guillembm, Yesterday, 11:25 AM
                              3 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by junkone, 04-21-2024, 07:17 AM
                              10 responses
                              148 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by tsantospinto, 04-12-2024, 07:04 PM
                              6 responses
                              101 views
                              0 likes
                              Last Post tsantospinto  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              7 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X