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

Possible bug or am I missing something?

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

    Possible bug or am I missing something?

    Scenario:

    I add an additional 1 tick time frame using: Add(PeriodType.Tick, 1); Works fine.

    My code wasn't working correctly so I put in a Print to see the values.

    protected override void OnBarUpdate()
    {
    Print("TimeFrame3 " + BarsInProgress + " " + BarsPeriod.Id + " " + BarsPeriod.Value);
    .. user code

    I added the time frame as 1 tick in "Initialize" but BarsPeriod.Id shows as "Range".
    Below is the log from the Print. The "0" BarsInProgress is the chart timeframe and the "1'" BarsInProgress is my added timeframe.

    TimeFrame3 0 Range 1
    TimeFrame3 1 Range 1
    TimeFrame3 0 Range 1
    TimeFrame3 1 Range 1
    TimeFrame3 0 Range 1
    TimeFrame3 1 Range 1
    TimeFrame3 0 Range 1
    TimeFrame3 1 Range 1
    TimeFrame3 0 Range 1
    TimeFrame3 1 Range 1
    TimeFrame3 0 Range 1

    Question:
    Why does my added timeframe show as "Range"? Does tick not support "BarsPeriod.Id"? How can I tell if a tick was from my 1 added tick timeframe? It works fine on just 1 chart time frame but if the user adds an additional chart time frame (which I have no control over) the BarsInProgress changes to 2 for my added time frame and "0" and "1" are used by the chart time frames.

    Cheers
    Last edited by ct; 02-19-2019, 01:54 PM.

    #2
    You are printing the BarsPeriod.Id of the primary series.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      Originally posted by eDanny View Post
      You are printing the BarsPeriod.Id of the primary series.
      Duh! thanks.

      Comment


        #4
        Hello ct,

        Thanks for your question.

        BarsPeriod is reflective of the primary data series. If you would like to reference the BarsPeriod for the iterating data series, I would suggest to use Bars.Period instead.

        For example:

        Code:
        protected override void Initialize()
        {
            Overlay                = false;
            Add("ES 03-19", PeriodType.Range, 5);
            Add("ES 03-19", PeriodType.Tick, 150);
        }
        
        protected override void OnBarUpdate()
        {
            if (BarsInProgress == 0)
            {
                Print(String.Format("BarsInProgress: {0} Bars.Period.Id: {1} Bars.Period.Value: {2}", BarsInProgress, Bars.Period.Id, Bars.Period.Value));
            }
            else if (BarsInProgress == 1)
            {
                Print(String.Format("BarsInProgress: {0} Bars.Period.Id: {1} Bars.Period.Value: {2}", BarsInProgress, Bars.Period.Id, Bars.Period.Value));
            }
            else if (BarsInProgress == 2)
            {
                Print(String.Format("BarsInProgress: {0} Bars.Period.Id: {1} Bars.Period.Value: {2}", BarsInProgress, Bars.Period.Id, Bars.Period.Value));
            }
        }
        Please let me know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Or, without using BarsInProgress you could use BarsArray[1].Period.Id and BarsArray[1].Period.Value.
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by 309338, Today, 12:06 PM
          0 responses
          6 views
          0 likes
          Last Post 309338
          by 309338
           
          Started by AaronKoRn, Yesterday, 08:38 PM
          2 responses
          51 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by rocketstock, 08-05-2022, 09:36 PM
          2 responses
          75 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by ronyggg83, Yesterday, 03:48 PM
          4 responses
          52 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by preqc, 08-05-2022, 09:10 AM
          1 response
          36 views
          0 likes
          Last Post NinjaTrader_Jim  
          Working...
          X