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

Real time and on bar close

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

    Real time and on bar close

    I've just starting working on an automated strategy last week. I began using the wizard having the strategy check for conditions as each bar closes.

    I've moved past the wizard now trying to get more complex with the coding. I'd like to check for certain conditions tick by tick during the frist few minutes and last few minutes of each trading session to deal with things like up/down gaps at the start of the day, and sell conditions that happen on the last bar of the day.

    I've read several things but am not clear how I can get a section of my code to update tick by tick.

    From the wizard I have 3 condition sets in my code. I'd like to add a 4th set now that will check tick by tick for a condition during the last 5 minutes of trading.

    Thanks,

    David

    #2
    Hi ddurocher,

    You can separate your code to either calculate once per bar or on a tick by tick basis.

    The following sample details this topic.
    TimNinjaTrader Customer Service

    Comment


      #3
      OK, I had already looked at that sample several times but could not figure it out. I think I have now so let me summarize to see if I'm getting the gist and possibly to help anyone else that may be as dense as I am ...

      If you want any/all of your strategy code to calculate tick by tick, in the initialize secition you need to have

      CalculateOnBarClose = false;

      instead of

      CalculateOnBarClose = true;

      Then, any code that you want to calculate only on each "bar close" would then requires the use of:

      FirstTickOfBar

      This checks for the first tick of a new bar. Once the first tick of a new bar comes in, you then run the code against the previous bar (1). This is instead of running it against the current bar (0), what you would have used with CalculateOnBarClose = true; in the initialize section.

      So if I want to check tick by tick for the first and last 5 minutes during a session, how much additional overhead will this approach require from my system for the other 7 hours and 20 minutes the strategy is running? Presumably we are now checking each tick to see if it is the first of a new bar or not, so this would add some overhead ...

      Comment


        #4
        Hi ddurocher,

        Your understanding and interpretation is correct.

        As for the "overhead", it's hard to quantify exactly how much more CPU intensive the requesting of tick by tick would be, however tick data bursts do happen, so ensure you have plenty of reserve or unused memory available.
        TimNinjaTrader Customer Service

        Comment


          #5
          I suppose another possible answer is that there would be no additional requirement. Would it be incorrect to say that NT is using some process to check each tick anyway to determine when a bar has closed ...

          Comment


            #6
            Hi ddurocher,

            With CalculateOnBarClose = true, correct, processes are of course still there, and data stored, however, calculations on indicators, for example would not be done intrabar.
            TimNinjaTrader Customer Service

            Comment


              #7
              I have got as far as reprogramming the parts of my strategy that check my indicators once a bar has closed (or a new one has opened as the case may be).

              I've got CalculateOnBarClose = false; in the initialize section and I've added FirstTickOfBar to the beginning of each of my condition statements. When I increment the bar references in my condition statements, for example from 0 to 1, my entries and exits are now a bar late when I backtest.

              It seems I'm not getting something ...

              Comment


                #8
                Hi ddurocher,

                During a backtest, the logic will always operate as CalculateOnBarClose = true.

                More info at - http://www.ninjatrader-support.com/H...TimeVsBacktest
                TimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Segwin, 05-07-2018, 02:15 PM
                10 responses
                1,769 views
                0 likes
                Last Post Leafcutter  
                Started by Rapine Heihei, 04-23-2024, 07:51 PM
                2 responses
                30 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by Shansen, 08-30-2019, 10:18 PM
                24 responses
                943 views
                0 likes
                Last Post spwizard  
                Started by Max238, Today, 01:28 AM
                0 responses
                10 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by rocketman7, Today, 01:00 AM
                0 responses
                7 views
                0 likes
                Last Post rocketman7  
                Working...
                X