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

Close[1] calculation during U.S. premarket

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

    Close[1] calculation during U.S. premarket

    Hi,

    I am currently using a rangebreakout strategy in Ninjatrader that makes a trade if “Close[1]” > than the high of the calculated range.

    During regular trading hours of the US markets this strategy works fine.

    However, when I am trading this strategy during the premarket, the Close[1] is calculated wrongly.

    I would like to calculate the last traded premarket price… for which I am using “Close[1]”.

    However, instead of calculating the last traded premarket price , Close[1] …during the premarket is calculating the previous days close !

    I have already checked if it has got something to do with the Session settings, but since I have set this to “24 hours” a day, I guess that this is not the issue.

    Does anybody know what is going wrong ? Any help is very appreciated…

    #2
    Hello markus250,

    Thanks for you post and questions.

    How are you calculating the range?

    Are you using a multi-series strategy?

    How are you setting CalculateOnbarClose, true or False?

    What instrument and timeFrame are you using?

    I look forward to your reply.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul,

      Thanks for you reply.

      I didnt develop the strategy myself, but the range is calculated based on the period between a "startrange" time and an "endrange" time, the Lowest value of the range(m_RangeLowest) and the highest value of the range (m_RangeHighest) are always correctly calculated, during regular trading hours, but also during premarket trading hours:

      if(ToTime(e.Time) >= m_StartRangeFrom && ToTime(e.Time) < m_EndRangeTime)
      {
      if(e.MarketDataType == MarketDataType.Bid)
      {
      if(e.Price < m_RangeLowest || m_RangeLowest == 0)
      {
      m_RangeLowest = e.Price;
      }
      }
      if(e.MarketDataType == MarketDataType.Ask)
      {
      if(e.Price > m_RangeHighest || m_RangeHighest == 0)
      {
      m_RangeHighest = e.Price;


      2. I am not using a multi-series strategy


      3. CalculateOnbarclose = false

      4. I am using only Nasdaq or Nyse stocks ( example: CMG) , always using a 10 second time frame..

      Comment


        #4
        Hello marcus250,

        Thanks for your reply and clarity of information.

        It is entirely possible that a given stock may have no or little movement in premarket and so Close[1] could possibly be equal the close of the preceding session.

        Have you confirmed that Close[1] time was from the last bar of the session? You can use
        Code:
        Print ("Close1time= "+Time[1]+"  price: "+Close[1]);
        Place the statement just before your call to Close[1]. This statement output will show up in the output window.

        The code snippet you provided is showing you are using OnMarketUpdate. Can you advise where you are calling Close[1]?

        I look forward to your reply.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello Paul,

          I have made a mistake, the breakout & trade condition are based on Close [0] instead of on Close[1]. I hope that this doesn’t make a difference

          I already placed a log command in the code to see what the strategy sees as the Close[0] value, based on this and the output in the log, I know that it the Close[0] value equals the previous days close and causes the strategy to make erroneous trades.

          I used these 2 formulas in the log to calculate both the range, as well as the Close[0].

          Log("Range High = " + m_RangeHighest + ", Range Low = " + m_RangeLowest, LogLevel.Information);
          Log("Price = " + Close[0], LogLevel.Information);
          m_LogPublished = true;


          If you still want me to use the formula you wrote, than I will copy it into the code, and try it again tomorrow.

          After having called Close[0] when the range is finished, it is called here again to make the entry trade:

          if (tradingTime
          && (m_TradesPerDay==0 || tradeDayCounter<m_TradesPerDay)
          && m_RangeHighest>0
          && (Close[0]-0.008) > m_RangeHighest
          )
          {
          m_LongDir=true;
          m_ShortDir=false;
          }

          I only run the strategy on stocks that have a lot of premarket volume, and a big move, if not there is not enough volume to create a range.

          What is so strange is that the range calculation is 100% correct, and based on premarket data. Just like the chart data, I am able to pull a chart with the premarket data in Ninjatrader.

          The only issue is the Close[0] / Close [1] value.

          Example of what happens:

          Stock X closed yesterday at 15 dollars.

          Today in the premarket it is trading between 12 and 13 dollars.

          The calculated range from 7.20 AM EST until 8.20 AM EST time..rangelow: 12.00 rangehigh: 13.00

          The strategy states that if Close[0] is higher than rangehigh, that it will place a buy entry order.
          However, since Close[0] according to the strategy is equal to the previous days close… which is 15 dollar… The entry condition is directly satisfied when Rangecalculation is finished

          The strategy will send a buy order to enter exactly at the moment, without waiting for the “true” breakout of the tradingrange.

          Thanks so far for your help.

          If you need another details about the code, or the whole code, please let me know and I will send it.

          Remco

          Comment


            #6
            Hello Remco,

            Thanks for the clarity of Close[0] vs Close[1].

            You can certainly modify the Log entries you are using to capture the Close[0] time.

            Code:
            Log('Range High = " + m_RangeHighest + ", Range Low = " +
            m_RangeLowest, LogLevel.Information);
                            Log("Price = " + Close[0][B]+" Time: "+Time[0][/B], LogLevel.Information);
                            m_LogPublished = true;
            I am trying to understand if you are calling close[0] in the OnMarketUpdate section. So perhaps it would be easier to send in your code. Please e-mail to PlatformSupport[at]NinjaTrader[dot]com with refrernece Ticket# 1118002 Atten:Paul in the title.

            I look forward to your reply.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Kaledus, Today, 01:29 PM
            5 responses
            12 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by Waxavi, Today, 02:00 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by alifarahani, Today, 09:40 AM
            5 responses
            23 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by PhillT, Today, 02:16 PM
            2 responses
            7 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Working...
            X