Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

using ONBARCLOSE UPDATE AND ONEACHTICK

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

    using ONBARCLOSE UPDATE AND ONEACHTICK

    HELLO,

    I have particular need for my strategy.

    I have made my strategy calculate on CALCULATE.ONBARCLOSE for most of data points.

    But for a specific section of strategy- I have a need to utilize- CALCULATE.ONEACHTICK.


    Is it possible to use both oneachtick and onbarclose calculation within same strategy?

    Can you please guide on work around?

    #2
    ##ADDING MORE INFO ON QUESTION:

    Or may be - can I use certain calculations using- ONTICKUPDATE instead of ONBARUPDATE? so, certain entry/exit triggers based on ONTICKUPDATE, but other area of strategy still follows ONBARUPDATE.

    .....

    Please guide me

    Comment


      #3
      Hello manitshah915,

      Use IsFirstTickOfBar in a condition to trigger events only after a bar has closed while using Calculate.OnEachTick.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        NinjaTrader_ChelseaB- i got it. understood.

        This leads me to follow up question: If i switch my strategy to - ONEACTICK, and avoid using onbarupdate, does that mean, Ninjatrader will consume so much load memory to run the code? and that can slow down operation, if I run 10 to 15 strategies at the same time?

        Comment


          #5
          Hello manitshah915,

          That would depend on what the script is doing.

          If there is no logic in OnBarUpdate() then what is being run?

          Yes, if there is no logic to evaluate, then there is nothing being processed or added into memory.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            NinjaTrader_ChelseaB- sorry for confusion. what I mean to ask was- if i switch from using strategy calculation onbarCLOSE to ONEACHTICK, will that cause memory heavy usage and can cause some slow running of ninjatrader or strategy?

            Mainly during the times, when I use 10 to 15 strategies running at the same time

            Comment


              #7
              Hello manitshah915,

              It depends on what the script is doing.

              If new objects are being created on every tick, this will be way more objects using more memory than if new objects are being created on bar close.

              If there is just logic checking conditions, this wouldn't create objects and wouldn't be using more memory no matter how often the condition is checked.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                NinjaTrader_ChelseaB- excellent. got it.

                Let me give you example: for NQ_03-24. I am keeping 5 mins bar. Assume, this BAR has OHLC (open high Low close)- as O=55, H= 61, L=53 and C=58.


                Now, If I am using my entry method: If upon 5 mins Bar close- Open value >Low value of 5 minutes bar to Enter LONG.

                how my Long entry will be impacted, when I switch from Onbarclose calculation to ISFirstTickofBar use.

                will my entry be same? because technically, when bar closes on 5 minutes, that also begins as first tick of next new 5 minute bar.

                ---


                I think, onbarclose condition check for entry method, can be possibly almost similar identical entry when I use ISFirstTickofBar

                Am I right?


                Comment


                  #9
                  Hello manitshah915,

                  The order would be submitted as a new bar opens with either approach.

                  Yes, IsFirstTickOfBar is used to trigger events after a bar closes, which is the behavior of Calculate.OnBarClose.

                  Note, the barsAgo index of 0 will refer the newly opened bar with Calculate.OnEachTick, while the barsAgo index of 0 will refer to the most recently fully closed bar with Calculate.OnBarClose.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Bool Flag with IsFirstTickOfBar Sample use:



                    private bool onetradeperBar;

                    if (IsFirstTickOfBar)
                    {
                    onetradeperBar = false;
                    }​

                    if ( ( onetradeperBar == false )
                    && Your Conditional statement here )
                    {
                    EntryLong();

                    onetradeperBar = true;
                    }


                    Code:
                    namespace NinjaTrader.NinjaScript.Strategies
                    {
                        public class _ArmedButtons : Strategy
                        {
                    
                               ...
                                
                                #region region class variables: One Trade Per bar only
                                    
                                    private bool onetradeperBar;
                                    
                                #endregion​
                    
                                ...
                    
                          
                            protected override void OnBarUpdate()
                            {    
                                    ...
                                
                                    #region BOOLFLAG - One Trade Per bar only
                                        
                                        if (IsFirstTickOfBar)
                                        {
                                            onetradeperBar = false;
                                        }
                                        
                                    #endregion
                    
                                    #region region ARMED / UNARMED BUTTONS
                    
                                        #region Long Entry
                                        
                                            bool CondLong1 = ( Close[1] < Open[2] );
                                            bool CondLong2 = ( Close[1] > High[2] );
                                        
                                             // Set 2
                                            if (
                                                    Button0Clicked
                                                    && ( CondLong1 )
                                                    && ( Position.MarketPosition == MarketPosition.Flat )
                                                    && ( onetradeperBar == false )
                                                )
                                            {
                                                EnterLong(Convert.ToInt32(Q), "Long Entry #1");
                                                
                                                #region One Trade Per bar only reset
                                                    
                                                    onetradeperBar = true;
                                                    
                                                #endregion
                                                
                                            }​
                    
                                         ...

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    58 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    133 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    50 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X