Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsInProgress

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

    BarsInProgress

    Custom Indicators:




    ERROR: BarsInProgress always equals Zero even when I have added multiple data series

    protected override void OnMarketData(MarketDataEventArgs e) {
    ....
    else if (e.MarketDataType == MarketDataType.Last) {
    str = string.Format( templateStr ,e.Time,e.Price,e.Volume.ToString("#####"));
    myForm.Print(str+"Ask "+myint+" BIP: "+BarsInProgress);
    }
    ....
    }

    generates:
    01:14:09 81.59 1 Ata 0 BIP: 0
    01:14:02 81.59 1 Ata 0 BIP: 0
    01:14:01 81.59 1 Ata 0 BIP: 0
    01:14:01 81.59 1 Ata 0 BIP: 0

    with 1 data series

    I add another data series and I get the following output


    01:18:49 81.51 1 Atb 0 BIP: 0
    01:18:49 81.51 1 Atb 0 BIP: 0
    01:18:48 81.52 1 Ata 0 BIP: 0
    01:18:48 81.52 1 Ata 0 BIP: 0
    01:18:35 81.51 1 Bet 0 BIP: 0
    01:18:35 81.51 1 Bet 0 BIP: 0
    01:18:30 81.52 1 Ask 0 BIP: 0
    01:18:30 81.52 1 Ask 0 BIP: 0



    ..BarsInProgress is ALWAYS ZERO!!!... even though the event is triggered twice and the help says that you should use this property when in this event


    when I add the data series ...
    protected override void Initialize() {

    Add( PeriodType.Minute, 1);
    ...


    from the help file:
    Tips
    1. With multi-time frame and instrument strategies, OnMarketData will be called for all unique instruments in your strategy. Use the BarsInProgress to filter the OnMarketData() method for a specific instrument.
    2. Do not leave an unused OnMarketData() method declared in your NinjaScript object. This will unnecessarily attach a data stream to your strategy which uses unnecessary CPU cycles.
    Last edited by mjc4118; 10-11-2010, 11:26 PM.

    #2
    mjc4118, do you add another instrument's series or just another timeframe?

    Thanks
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Time frame.

      On a 7 Range Bar chart ..added a 1 minute ..same instrument
      Add( PeriodType.Minute, 1);

      Comment


        #4
        Then the outcome is expected, it's the same level 1 data you subscribe to for both.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          according to your help documentation... BIP should be set. Either your documentation is unclear or incomplete..

          ..it may be expected...it is not logical ..according to your help doumentation BIP should be set.but you are saying that it is not if it is the SAME instrument .. so there is not way to differentiate the source of the event

          Thuis means that the logic gets executed 2 times ..once for each series . unfortunately this is not acceptable end game for me in this case...and I can only have it executed once ...how do we resolve this..so i can have my logic executed only one time?

          Comment


            #6
            Mark, according to the help guide it's called per unique instrument- this is exactly the outcome you see.

            The OnMarketData() itself is not tied to any bars event, it's called on each Level 1 data change.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              No BarsInProgress Event for Secondary Instrument

              I created an indicator in which I ADDed a secondary instrument in the Initialize() method. So far so good.

              But whenever the secondary instrument updates, I want to use its value. This should happen when BarsInProgress == 1.

              However BarsInProgress NEVER equals 1. The only time I get OnBarUpdate events is when BarsInProgres==0. So I am missing lots of data that occurs when the secondary series updates, without the primary series having updated.

              I would appreciate if you could send me ANY code sample that shows OnBarUpdate being generated when BarsInProgress has any value other than zero.
              Attached Files
              Last edited by Ricam; 10-22-2010, 07:34 PM.

              Comment


                #8
                Please ensure you have actually met all the BarsRequired requirement on all series first. This needs to occur for real-time events to come in for all Bars objects. You can see how many bars are loaded in each BarsInProgress context by printing CurrentBars[].

                CurrentBars[0] <-- for BIP0
                CurrentBars[1] <-- for BIP1

                You will want both to be greater than your BarsRequired setting.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  No BarsInProgress Event for Secondary Instrument - continued

                  I will try hardcoding the name of the secondary instrument and will let you know if that works. I would encourage you guys to see if you can get my script to work properly. It's very useful for trading!

                  Regarding the previous two responses from Ninjatraders, this is what I was thinking:

                  Had I not correctly ADDed the second dataseries, I would expect to get NOTHING plotted. Instead, the values of the secondary instrument ARE plotted, but only when the PRIMARY series updates (BarsInProgress==0)

                  If I don't have the dataseries of the chart set far back enough (bars back too low a value), I get NOTHING plotted. If I DO have the bars back set high enough, I DO get a plot of the secondary series, but again, it only updates when there is an OnBarUpdate event for the PRIMARY series.

                  Comment


                    #10
                    Hello,

                    When I manually code the instrument in your code works on my side.

                    When I run your code as you posted it I got no results plotted however.

                    Comment


                      #11
                      ADDed secondary instrument works when not hard coded

                      "When I manually code the instrument in your code works on my side.

                      When I run your code as you posted it I got no results plotted however."
                      ....Brett


                      Do you have TICK in your instrument manager? Are you connected to a datafeed that supports TICK, such as Kinetick? Do you have bars back set to at least 1 DAY back?

                      It sure DOES work here, and it has for months. The only issue is, as I stated originally, that there are OnBarUpdate events ONLY for BarsInProgress==0 and NEVER for BarsInProgress==1.

                      The attached screen shot shows a chart of the ES with four instances of the secondary line plot indicator, for TICK, ADD, 6E, and YM.

                      Just for fun I also added a chart showing that equally spaced CANDLES of a secondary dataseries can also be added. It is important to understand that these candles are of variable duration; the lifetime of each one of them corresponding to the lfetime of each of the candles of the primary dataseries. However, we STILL have the problem of no OnBarUpdate events for BarsInProgress !=0, and the candles work in real time only.

                      I would appreciate if you can show me any sample code that demonstrates that the OnBarUpdate event is indeed actually capable of firing when BarsInProgress != 0. Then perhaps I will be able to get my indicator to update correctly.

                      If you can't show me how to get a bar update event when a non primary series is updated, that would seem to indicate that there is a bug.
                      Attached Files
                      Last edited by Ricam; 10-23-2010, 10:00 AM.

                      Comment


                        #12
                        Ricam, I will have Brett get back to you with the specifics of his test on Monday. Until then, here is some sample code that correctly shows OnBarUpdate() being called for each bar series:
                        Code:
                        protected override void Initialize()
                        {
                            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                            Add("TF 12-10", PeriodType.Minute, 60);
                            Add("YM 12-10", PeriodType.Minute, 60);
                            Overlay                = false;
                        }
                        
                        protected override void OnBarUpdate()
                        {
                            Print("BIP: " + BarsInProgress + " Close: " + Close[0] + " at: " + Time[0]);
                        }
                        The above code generates the following output when run on a 60 minutes ES 12-10 chart:
                        Code:
                        BIP: 0 Close: 1176.5 at: 10/22/2010 8:00:00 AM
                        BIP: 1 Close: 697.2 at: 10/22/2010 8:00:00 AM
                        BIP: 2 Close: 11073 at: 10/22/2010 8:00:00 AM
                        BIP: 0 Close: 1178.75 at: 10/22/2010 9:00:00 AM
                        BIP: 1 Close: 699.8 at: 10/22/2010 9:00:00 AM
                        BIP: 2 Close: 11086 at: 10/22/2010 9:00:00 AM
                        BIP: 0 Close: 1176.75 at: 10/22/2010 10:00:00 AM
                        BIP: 1 Close: 698 at: 10/22/2010 10:00:00 AM
                        BIP: 2 Close: 11065 at: 10/22/2010 10:00:00 AM
                        BIP: 0 Close: 1178.25 at: 10/22/2010 11:00:00 AM
                        BIP: 1 Close: 700.4 at: 10/22/2010 11:00:00 AM
                        BIP: 2 Close: 11075 at: 10/22/2010 11:00:00 AM
                        BIP: 0 Close: 1176.5 at: 10/22/2010 12:00:00 PM
                        BIP: 1 Close: 699.4 at: 10/22/2010 12:00:00 PM
                        BIP: 2 Close: 11062 at: 10/22/2010 12:00:00 PM
                        BIP: 0 Close: 1177.5 at: 10/22/2010 1:00:00 PM
                        BIP: 1 Close: 700.5 at: 10/22/2010 1:00:00 PM
                        BIP: 2 Close: 11066 at: 10/22/2010 1:00:00 PM
                        BIP: 0 Close: 1179.25 at: 10/22/2010 2:00:00 PM
                        BIP: 1 Close: 701.4 at: 10/22/2010 2:00:00 PM
                        BIP: 2 Close: 11081 at: 10/22/2010 2:00:00 PM
                        Please let us know if you have any questions.
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          It works now...

                          Here is an indicator in which a secondary data series does update between updates of the primary dataseries.

                          My original attempt failed to work because of some sneaky extraneous code that was making it impossible for the OnBarUpdate module to respond when BarsInProgress was not equal to zero.

                          The secondary instrument is not hard coded. Any symbol can be entered by the user.
                          Attached Files

                          Comment


                            #14
                            Hello,


                            Glad to hear you found the code bug and thanks for reporting back what the issue was.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by lorem, 04-25-2024, 09:18 AM
                            7 responses
                            27 views
                            0 likes
                            Last Post lorem
                            by lorem
                             
                            Started by junkone, Today, 02:19 PM
                            3 responses
                            32 views
                            1 like
                            Last Post junkone
                            by junkone
                             
                            Started by Karado58, 11-26-2012, 02:57 PM
                            9 responses
                            14,846 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by Haiasi, 04-25-2024, 06:53 PM
                            3 responses
                            28 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by Option Whisperer, Yesterday, 09:55 AM
                            3 responses
                            26 views
                            0 likes
                            Last Post Option Whisperer  
                            Working...
                            X