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

IsFirstTickOfBar on secundary series

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

    IsFirstTickOfBar on secundary series

    Hello

    I am working in a multi-instrument strategy running OnEachTick and 10 seconds timeframe.

    I use IsFirstTickOfBar, cumulativeDelta.DeltaClose[1] and cumulativeDelta1.DeltaClose[1] and cumulativeDelta2.DeltaClose[1].

    The problem is that there is just one FirstTickOfBar and a lot of times the script has not Close[1] of three instruments and it takes Close[2] of any of them.

    How can I call my conditions wait till FirstTickOfBar of all instruments exists?

    Thanks a lot

    #2
    Hello Impeesa,

    To confirm, you want to wait until all of the series have had a new bar close?

    You can use a set of bools for each series that is set to true when IsFirstTickOfBar is true, and then when they are all true they can all be set back to false.

    if (BarsInProgress == 0 && IsFirstTickOfBar == true)
    Series1BarClosed = true;

    if (BarsInProgress == 1 && IsFirstTickOfBar == true)
    Series2BarClosed = true;

    if (Series1BarClosed && Series2BarClosed)
    {
    // trigger action
    Series1BarClosed = false;
    Series2BarClosed = false;
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea

      What I need is to use Close[1] of three diferent instruments, and using IsFirstTickOfBar there are a lot of bars where script uses Close[1] of primary series but Close[2] of others instruments.

      I will try your bools suggestion but I thought IsFirstTickOfBar was always referring to primary series...

      Thanks

      Comment


        #4
        Hello Impeesa,

        IsFirstTickOfBar relates to the current bar series that is updating OnBarUpdate().
        .
        Close also refers to the bars series updating OnBarUpdate().

        OnBarUpdate() will run for every bar series.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea

          I have tried bools you suggest yesterday in file attached, and prices are printed ok Closes[1] of two instruments but in case of deltas it prints Close[2].

          I have also tried modify these lines as was suggested in this post and there is an "Error on Calling "OnBarUpdate" method on bar -1: Index was outside the bounds of the array."

          if (BarsInProgress == 1)
          {
          cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
          }
          if (BarsInProgress == 3)
          {
          cumulativeDelta1.Update(cumulativeDelta1.BarsArray[2].Count - 1, 1);
          }

          What am I doing wrong?

          Thanks
          Attached Files

          Comment


            #6
            Hello Impeesa,

            In the file you are not using the Update() in the correct BarsInProgress.

            If we take a look at the help guide sample, there is only 1 added series so BarsInProgress 1 is used for the Update and other indexes shown. In your script you have more series so you would use the BarsInProgress for the 1 Tick series or 3.

            Code:
            if (BarsInProgress == 3)
            {
            cumulativeDelta.Update(cumulativeDelta.BarsArray[3].Count - 1, 1);
            cumulativeDelta1.Update(cumulativeDelta1.BarsArray[3].Count - 1, 1);
            }

            The Update specifically needs the 1 tick series, that is a utility function which this indicator needs to be called on the 1 tick series always. When you want a value from the indicator you could call it from any of the other BarsInProgress, similar to what the help guide sample shows. https://ninjatrader.com/support/help...lightsub=delta

            I look forward to being of further assistance.


            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Jesse

              Thanks for your reply.

              Sorrry, but I do not understand how can get the code working... All I want is get delta values (Close, High, Low) of three different instruments in bar[1] and, when all three new bars has started (there are first tick of bar in every instrument), use these values as conditions for entry.

              What do you suggest?

              Thanks a lot

              Comment


                #8
                Hello Impeesa,

                I would likely suggest to start over starting from the help guide sample. I am not certain what you were going for overall in the OnBarUpdate but there are multiple items which could lead to problems.

                One is that you are doing the Update method as the first line of code in OnBarUpdate before your data checks, data checks should always come first.

                Another item would be the BarsArrays being used, again I don't know the overall goal you had to advise here so it would likely be best to start with 1 series and get that working as you wanted. After doing that you could make it into a multi instrument script by duplicating what you did for the first indicator.

                The data checks that you are using are < 0 but you use [1] BarsAgo in some areas, you would need to check for at least 1 bar of data is present if you want to use 1 bars ago.

                I have attached a quick sample removing the extra series from your script, this is just to demonstrate how you would use the indicator for a single series. If you take a look at how the script is structured you would need to replicate any additionally added series in the same way. Placing the code how its shown in OnBarUpdate/the help guide is important to avoid errors.

                I look forward to being of further assistance.
                Attached Files
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse

                  I have already working indicators and strategies using cumulativedelta of primary series and a secondary serie of another instrument and other parameters (in this case, not using cumulativedelta). So, no problem with single series nor secondary ...

                  The goal is using cumulativedelta of two or more instruments in the strategy, and use them when new bar begin in all instruments, and not wait to Close[2]... This relay only occurs usiong cumulativedelta. The idea that gave me Chelsea yesterday was very logic and I am very thankful, but it does not work.

                  Maybe my bad english is making more difficult to explain a question that can not be imposible.... Runnning an strategy OnEachTick in a timeframe of 15S, get the cumulativedelta of two instruments, and when there is new bar of both of them (first tick in both) entry short or long depending of other conditions...

                  In any case, thanks for your patience

                  Comment


                    #10
                    Hello Impeesa,

                    I understand you want to use more instruments however in the sample that you provided you had not satisfied the basic use of the orderflow indicator based on how the help guide shows to use it. You need to use the same structure/approach for any additional series or instruments you add as well so getting that part right is important.

                    When you add other instruments you will need to add additional conditions for those instruments BarsInProgress for the 1 tick series. In your sample you grouped those into a single condition which will not work. You would need to follow what the help guide shows and replicate a condition for each instrument to call Update. That's why I suggest to start over because having the structure the sample shows would be correct across the board for any number of instruments you use.

                    I would suggest avoiding adding the extra logic you had until you are able to call each of the order flow indicators in a print from BarsInprogress 0. That will let you know you have the right code for each Update() to work.

                    This would be what adding an additional instrument looks like:

                    Code:
                    if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1)
                    return;
                    
                    if (BarsInProgress == 0)
                    {
                        Print(cumulativeDelta.DeltaClose[0]);
                        Print(cumulativeDelta1.DeltaClose[0]);
                    }
                    
                    if (BarsInProgress == 1)
                    {
                       cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
                    }
                    
                    if (BarsInProgress == 3)
                    {
                       cumulativeDelta1.Update(cumulativeDelta1.BarsArray[1].Count - 1, 1);
                    }


                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Jesse

                      I will try working on this new option.

                      I really appreciate your patience and help. Thanks!

                      Comment


                        #12
                        Hello

                        I have been working with cumulativedelta for three instruments following your advise, but obviously I am doing something wrong.

                        I attach strategy file and two images showing that delta close in Market Analyzer and Volumetric Bars are different that values I get in the script...

                        How can I Solve this?

                        Thanks
                        Attached Files

                        Comment


                          #13
                          Hello Impeesa,

                          From the image I couldn't really say what may be different. Are you certain that the analyzer has loaded the same data? It would generally be easier to try to do comparisons from a chart first to make sure the data series settings are the same and everything aligns. You could then replicate the sittings in other areas which is less easy to visualize the whole data set like the MA. .

                          Please let me know if I may be of additional assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Hello Jesse

                            Thanks for your time one more time. Images show different delta close values between market analyzer, volumetric bars and strategy created following your advise...

                            It is probably same isssue related in this post, but I would like to be sure that my code attached correct. Have you run it and compare?

                            Sincerely,
                            Carlos T

                            Comment


                              #15
                              Hello Impeesa,

                              I understand you are seeing a difference, if that's the case you would need to see what is different between those two uses. The first item to check would be if the strategy has the same data series settings used as the analyzer. Are you loading the same amount of data and otherwise have the same settings used?

                              In the script you provided you are using multiple secondary series. Before trying that I would suggest to test the sample from the help guide using the primary to make sure the tools you have are lined up in regard to data. If you can see the primary being used printing the same as the MA you would know the settings are correct and could then debug the multi series use.

                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RideMe, 04-07-2024, 04:54 PM
                              5 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by f.saeidi, Today, 08:13 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by DavidHP, Today, 07:56 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by kujista, Today, 06:23 AM
                              3 responses
                              10 views
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by Mindset, Yesterday, 02:04 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_RyanS  
                              Working...
                              X