Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cover position on Close of the bar

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

    Cover position on Close of the bar

    How can I cover position on the close of the bar?

    #2
    nysetrader,

    I am happy to assist you.

    Is this for an automated strategy? What is tour calculated on bar close setting? How are you entering these orders?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      It is for a code-based strategy. Calculated on bar close is true. I want to open position on monday on market open and close on friday on market close using daily bars only.
      if (Time[0].DayOfWeek == DayOfWeek.Friday)
      {
      {
      EnterLong(BarsInProgress,200,Instruments[BarsInProgress].FullName + " long");
      }
      }
      That's code for open position. But I can't find how to close on the close of the bar.

      Comment


        #4
        nysetrader,

        You can use something like :

        if ( BarsSinceEntry() == 1)
        {
        ExitLong();
        }

        If you are using a multi series indicator here you may need to filter by bars in progress as well.

        Last edited by NinjaTrader_AdamP; 04-16-2012, 11:48 AM.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          I've tried it, but it close on the open price of bar, and I need the close price.

          Comment


            #6
            nysetrader,

            So you want an order to exist for a whole bar, then close?
            Last edited by NinjaTrader_AdamP; 04-16-2012, 11:41 AM.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              It doesn't work
              if (BarsSinceEntry(BarsInProgress,Instruments[BarsInProgress].FullName + " long", 0) == 3)
              {
              ExitLong(BarsInProgress,200,Instruments[BarsInProgress].FullName + " position covered on " + Time[0].DayOfWeek.ToString(),Instruments[BarsInProgress].FullName + " long");
              }
              I've used this. With the previous code the position was opened on Monday Open, then it skips 3 days and cover on the open of fourth day(Friday), but I need to cover on close!
              Last edited by nysetrader; 04-16-2012, 10:03 AM.

              Comment


                #8
                No more ideas?

                Comment


                  #9
                  nysetrader,

                  I guess I am not sure what you are doing here. Is this strategy on a daily chart?

                  With the previous code the position was opened on Monday Open, then it skips 3 days and cover on the open of fourth day(Friday),
                  I am not sure what you mean here. The previous code looks like it should open a position on Friday. Also, you are using the BarsInProgress item. Did you add a second data series here? Could you possible post your Initialize() section?
                  Adam P.NinjaTrader Customer Service

                  Comment


                    #10
                    The strategy is on daily chart. I add daily dataseries for 500 symbols of s&p500 in my init section.
                    This code
                    if (Time[0].DayOfWeek == DayOfWeek.Friday)
                    {
                    {
                    EnterLong(BarsInProgress,200,Instruments[BarsInProgress].FullName + " long");
                    }
                    }
                    calculated on friday bar close, so position opens on Monday bar open.

                    Comment


                      #11
                      nyse,

                      You don't need the double brackets here.

                      Also, since BarsInProgress is being called for 500 symbols, if you did indeed add 500 symbols, is your strategy designed to enter 500 orders one for each symbol?

                      Without filtering for BarsInProgress you may have some strange behaviors here.
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        There is no strange behavior actually. It enters one order for each symbol. But the problem is that I need to use bar close price to cover the position!
                        Last edited by nysetrader; 04-16-2012, 11:42 AM.

                        Comment


                          #13
                          Nysetrader,

                          Please find a simple example of something that does what you ask for below :

                          Code:
                               public class Example : Strategy
                              {
                                  #region Variables
                                  // Wizard generated variables
                                  // User defined variables (add any user defined variables below)
                                  #endregion
                          
                                  /// <summary>
                                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                                  /// </summary>
                                  protected override void Initialize()
                                  {
                                      CalculateOnBarClose = true;
                                  }
                          
                                  /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                                  protected override void OnBarUpdate()
                                  {
                                      // Condition set 1
                                      if (Close[0] >= Open[0])
                                      {
                                          EnterLong(DefaultQuantity, "");
                                      }
                          
                                      // Condition set 2
                                      if (BarsSinceEntry() == 0)
                                      {
                                          ExitLong("", "");
                                      }
                                  }
                          
                                  #region Properties
                                  #endregion
                              }
                          With the calculate on bar close setting, it would wait one bar before the exit is called.
                          Attached Files
                          Last edited by NinjaTrader_AdamP; 04-16-2012, 11:47 AM.
                          Adam P.NinjaTrader Customer Service

                          Comment


                            #14
                            And the execution is on the OPEN price of bar. That is not what I need!
                            Attached Files

                            Comment


                              #15
                              Nyse,

                              Apologies, I think I am misunderstanding your needs here. Please verify this is what you want so I may construct an appropriate response.

                              1. Enter on one bar on a Friday, using a daily chart.
                              2. Exit at the CLOSE price of the next bar.

                              You do not want to exit at the next bar, you want to exit at the CLOSE of the next bar correct?
                              Adam P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              661 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              375 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              579 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X