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 pechtri, 06-22-2023, 02:31 AM
          9 responses
          122 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by frankthearm, 04-18-2024, 09:08 AM
          16 responses
          66 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by habeebft, Today, 01:18 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by benmarkal, Today, 12:52 PM
          2 responses
          18 views
          0 likes
          Last Post benmarkal  
          Started by f.saeidi, Today, 01:38 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X