Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can strategy enter/exit at current day's close price

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

    How can strategy enter/exit at current day's close price

    Hi,

    I am backtesting an indicator. But I found my strategy can only enter/exit at the open price of the next day after the signal is triaggered. Actually I want to enter/exit at the close price of the day when the signal is triaggered.

    Please see my code below.

    Thanks,
    Jing

    protected override void OnBarUpdate()
    {
    if( Position.MarketPosition == MarketPosition.Flat && MyIndicator().BuySignal[0])
    EnterLong("L");
    if (Position.MarketPosition == MarketPosition.Long && MyIndicator().SellSignal[0])
    ExitLong("L");
    }

    #2
    Jing, this is expected for backtesting per default - you can add a finer granularity to simulate intrabar executions with the concept of this sample - http://www.ninjatrader-support2.com/...ead.php?t=6652

    Comment


      #3
      When I use Add(PeriodType.Minute, 1), during the backtest, it first tries to load the data, and throw a dialog "ERROR: BACKFILL "SPY" Hdr: 400 Validation failed for 1 of 1 requests. Your request is not valid".

      If I use Add(PeriodType.Day, 1), it does not report failure but I still enter/exit at the open of next day.

      Is the failure because it can not find minutes data? Actually I want to backtest 10-year daily data but my broker does not provider 10-year minutes data.

      Thanks,
      Jing

      Comment


        #4
        Yes, this looks like an error related to data availability on your connection. To simulate the intrabar fills concept however you would need this access. Can you try a shorter data range back?

        Comment


          #5
          It works for start date from 2007. And I am sure my broker does not provide interday data older than 2 month.

          Comment


            #6
            Ok, thanks for reporting back - unfortunately you would need access to this smaller granularity for task at hand - have you considered connecting to a third party data provider first that would offer this data?

            Comment


              #7
              Is there any way to do this without using a shorter time-frame?? For example, I want to test a daily strategy over the long-term with yahoo finance...therefore there is no intraday data available.

              There must be a way of doing this - the gap between open/close is too big for backtest results to make sense.

              Comment


                #8
                pmorissette, unfortunately not - to simulate intrabar fills you need smaller than daily granularity available, as in backtesting only the OHLCV values would be used.

                Comment


                  #9
                  closestrategy & Flatteneverything

                  How do I use the CloseStrategy and the flatteneverything commands in my strategy?
                  What is the syntax. I'm getting an error for CLOSESTRATEGY(atm1); I'm also getting
                  an error "Flatteneverything" does not exist in the current context.

                  Comment


                    #10
                    Bill, you would need to use the AtmStrategyClose() as documented here - http://www.ninjatrader.com/support/h...ategyclose.htm

                    'FlattenEverything' from NinjaScript is unfortunately not supported.

                    Comment


                      #11
                      How to close the ATM strategy at the market price? Or how to move the stop to the current market price? How to get the current market price?

                      Comment


                        #12
                        To close the ATM just use the AtmStrategyClose command available, the current price is Close[0] if CalculateOnBarClose is false.

                        Comment


                          #13
                          Bertran please help me with the code to automatically close all the orders and unchecked or disable all the strategies in the strategy tab in Ninja just like the function of CLOSE button of the DOM. Or just a code to activate or trigger the CLOSE button of the DOM. Please.....
                          Last edited by luxurious_04; 02-11-2011, 02:22 AM.

                          Comment


                            #14
                            Unfortunately there's no supported method for this purpose - as a hint you can look into this thread though - http://www.ninjatrader.com/support/f...pported&page=6

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by argusthome, 03-08-2026, 10:06 AM
                            0 responses
                            69 views
                            0 likes
                            Last Post argusthome  
                            Started by NabilKhattabi, 03-06-2026, 11:18 AM
                            0 responses
                            42 views
                            0 likes
                            Last Post NabilKhattabi  
                            Started by Deep42, 03-06-2026, 12:28 AM
                            0 responses
                            24 views
                            0 likes
                            Last Post Deep42
                            by Deep42
                             
                            Started by TheRealMorford, 03-05-2026, 06:15 PM
                            0 responses
                            27 views
                            0 likes
                            Last Post TheRealMorford  
                            Started by Mindset, 02-28-2026, 06:16 AM
                            0 responses
                            54 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Working...
                            X