Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar and Multi Time Frame

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

    CurrentBar and Multi Time Frame

    Can I return a value for CurrentBar from an Added Bars object?

    #2
    Yes. Just do it under the bars context you want.
    Code:
    if (BarsInProgress == 1)
         Print(CurrentBar);
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I have a similar problem

      Originally posted by NinjaTrader_Josh View Post
      Yes. Just do it under the bars context you want.
      Code:
      if (BarsInProgress == 1)
           Print(CurrentBar);
      I hope you're looking at old threads.
      Above doesn't solve my problem. I'm implementing a multi - frame strategy with the same instrument, where Closes[0] are time based, Closes[1] are range.

      I have a code snippet in OnBarUpdate:
      double d = (Close[0] - Closes[1][0]) / TickSize ;
      // Print(TickSize) ;
      if (d >= 0)
      StrategyPlot(0).Value.Set(d);
      else
      StrategyPlot(1).Value.Set(d);

      I don't see any data on plots. I assume that at the first bars of of series 0 , there is no Closes[1][0] available yet, an exception is thrown and the strategy stops to work.

      I may try to use a brute force, at the first lines of OnBarUpdate like :
      if ((BarsInProgress == 0) && (CurrentBar <100))
      return ;

      Assuming that after first 100 time based bars I have a range bar availble, but I really don't like it.

      Please advice.

      Comment


        #4
        If no bars exist yet you will not be able to access it. I suggest you first start off and just print from within the two BarsInProgress to see what kind of data you have when. Then after you get a feel for the bars then you should be able to access them after they exist.

        Also note that StrategyPlot has limited functionality and NT7 will bring about multi-instrument/time frame indicators which will be able to handle plotting.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          If no bars exist yet you will not be able to access it. I suggest you first start off and just print from within the two BarsInProgress to see what kind of data you have when. Then after you get a feel for the bars then you should be able to access them after they exist.

          Also note that StrategyPlot has limited functionality and NT7 will bring about multi-instrument/time frame indicators which will be able to handle plotting.
          Thank a lot for a rocket-fast answer !!! You guessed properly I'm using a multiframe strategy instead of non-existent multiframe indicator.
          I don't want to wait for NT7, I'm trying to implement a solution now.

          The following doesn't work either, and I think it should :

          bar1Ready = false ;
          is set in Initialize()
          and
          .......................
          protected override void OnBarUpdate()
          {
          string sDbg ;
          Print("BP , cBar : " + BarsInProgress.ToString() + CurrentBar.ToString()) ;
          if (!bar1Ready)
          {
          return ;
          }
          if (BarsInProgress == 1)
          {
          // Print(CurrentBar);
          if (CurrentBar > 1)
          {
          if (!bar1Ready)
          bar1Ready = true ;
          }
          }

          double d = (Close[0] - Closes[1][0]) ;
          // Print(TickSize) ;
          if (d >= 0)
          StrategyPlot(0).Value.Set(d);
          else
          StrategyPlot(1).Value.Set(d);

          }
          Surprisingly, nothing isn't printed in output window, it means OnBarUpdate fails at the beginning.

          Should I implement my own exception mechanism as long as Closes[1][0] is not ready ?

          Comment


            #6
            What errors are you receiving? Try using a try-catch block to figure out where you run into issues.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I didn't look at a log.

              Originally posted by NinjaTrader_Josh View Post
              What errors are you receiving? Try using a try-catch block to figure out where you run into issues.
              http://www.ninjatrader-support2.com/...ead.php?t=9825
              I was an idiot enough to forget about it.

              The log says:
              31/07/2009 21:33:06,Strategy,The strategy 'SampleMultiInstrument' has called the Add() method with an invalid instrument. Either 'ES 12-08' does not exist in the Instrument Manager or the specified exchange has not been configured.,
              31/07/2009 21:32:03,Strategy,The strategy 'SampleMultiInstrument' has called the Add() method with an invalid instrument. Either 'ES 12-08' does not exist in the Instrument Manager or the specified exchange has not been configured.,

              Of course, because I'm using a strategy as a substitute to a multiframe indicator, i have no choice, but to use a simulated feed.

              So another, may be less stupid question is how to configure a simulated feed to provide a data for my real instrument , $EURUSD instead of ES 12-08. I'm sure it appears somewhere in the help, but I cannot find it.

              Above is needed for debugging only. During a real trading, I'm getting a data from MB Trading.
              Thanks.

              Comment


                #8
                SampleMultiInstrument error is a different error that can be safely ignored. The Simulated Data Feed provides a feed for any instrument setup for it in the Instrument Manager. What you need to do is setup a starting sim price for your instruments and then reconnect to the sim feed to get it flowing.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                637 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                366 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                572 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X