Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Bar after 'IsFirstTickOfBar'

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

    Current Bar after 'IsFirstTickOfBar'

    I have a strategy that Calcs 'OnEachTick' but I want to enter the trade at the Open of the next bar. I have tried IsFirstTickOfBar' and in trying to Debug, I have placed a Print statement before and after but the CurrentBars[0] is the same which leads me to believe that the IsFirst is not after the close of the original bar. As stated what want to do is enter the trade at the open of the next bar.

    #2
    Hello galsermil,

    Thank you for your note.

    Could you provide a code sample of what you've tried (or screenshots of your Strategy Builder logic if that's how you created the Strategy)? I'd need to check to see how you've structured your print statements to understand the result you're seeing.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

      Kate, I sent 3 pictures which is the total of my script. It deals with two indicators and I made a Strategy for each and then combined them. I would have sent the CS file but I couldn't find it. My only interest to be able to enter a position at the open of the next bar.

      Comment


        #4
        Kate,

        I found the .cs file which can replace those three pictures I sent you.
        Attached Files

        Comment


          #5
          Hello galsermil,

          Thank you for your reply.

          Printing the CurrentBar value just before checking if it's the first tick of the bar would be expected to return the same value, as you're still on the same iteration of OnBarUpdate caused by that first tick of the bar.

          Each time a tick comes in, all your code in OnBarUpdate will be run. If it is the first tick of the bar, and you print the CurrentBar before and after checking IsFirstTickOfBar I would expect to see 2 matching prints.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Kate,

            There has been a lot of water under the bridge for me with <IsFirstTickOfBar> since I gave you that code and I want to give you a real world example with my code. I am looking for two signals everytime OnBarUpdate cycles and it will cycle everytime there is a new tick. I found one signal after 13 ticks and the other after 55 ticks. This is what I am looking for because it is on the same bar but by time time either of the signals are found there can never be another instance of <IsFirstTickOfBar> until the next bar because the first of the current bar is long gone. The Users Guide says you cannot be sure a bar is closed until you see the first tick of the next bar so the way I way see it, is if I print CurrentBars[0] after I find my signals and then again after<IsFirstTickOfBar> this should be the first tick of the next bar. I have changed my code trying again to place my entry at the Open of the next bar and I would think that that Open would coincide with the first tick of the next bar. I created an if statement using if(IsFirstTickOfBar}
            if( Condition1)
            Enter Long
            else if (Condition 2)
            Enter Short
            It will cause the short entries to be made all day long but it will never make the Long entry and believe me the Conditions for Longs are true. I am going to move that condition around as I have discovered that it will not work as the first statement in OnBarUpdate but does work if it is the third statement.

            If you disagree with what I have said, please let me know.

            Comment


              #7
              Hello glasermil,

              Thank you for your reply.

              It seems you have a fundamental misunderstanding of how OnBarUpdate, CurrentBar and IsFirstTick of bar work.

              For each tick that comes in, OnBarUpdate will be run in its entirety. The CurrentBar value will be the same for the whole iteration through OnBarUpdate and will not change part of the way through. IsFirstTickOfBar is only true when the tick being evaluated is the first tick of the bar. You've got this code commented out in your example above:

              //Print( " Current bar just ahead of First Tick"+CurrentBars[0]);
              //if(IsFirstTickOfBar)

              if(CurrentBars[0] == BarCount +1)
              {
              //Print( " Current bar just after First Tick"+CurrentBars[0]);

              Both those print statements would be expected to print the same current bar value.

              What I would suggest in your use case would be to set a bool variable when a signal occurs, one for each signal. If the condition occurs during the bar, set the bool to true. Then, on the first tick of the next bar, check if the bool for the entry condition is set to true, and if so, submit an entry, then set the bool to false so you can find if the condition occurs again on that bar.

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by futtrader, 04-21-2024, 01:50 AM
              4 responses
              41 views
              0 likes
              Last Post futtrader  
              Started by Option Whisperer, Today, 09:55 AM
              1 response
              11 views
              0 likes
              Last Post bltdavid  
              Started by port119, Today, 02:43 PM
              0 responses
              3 views
              0 likes
              Last Post port119
              by port119
               
              Started by Philippe56140, Today, 02:35 PM
              0 responses
              4 views
              0 likes
              Last Post Philippe56140  
              Started by 00nevest, Today, 02:27 PM
              0 responses
              2 views
              0 likes
              Last Post 00nevest  
              Working...
              X