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

Working with two types of charts

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

    Working with two types of charts

    Hello, please help to solve the problem. I add three multiple charts and an additional unirenko chart type to the strategy.

    Add(indicator);
    Add(second_instr, BarsPeriod.Id, BarsPeriod.Value);
    Add(third_instr, BarsPeriod.Id, BarsPeriod.Value);
    Add(PeriodType.Custom5, 002004002);

    In "OnBarUpdate"
    if (BarsInProgress != 0) return;

    And when I try to call the data of Renko bars the strategy does not react or reacts incorrectly

    For example
    if(Opens[3][1] < Closes[3][1] && Opens[3][0] > Closes[3][1])
    {
    ........
    }

    It's not working

    In addition, when I call in "Print" opens[3][0] and closes[3][0], the closes price is true, and the opens is not

    In this regard, there is a question - how to call the Renko data in the strategy
    Forgot to add, I'm using CalculateOnBarClose = false; Maybe this causes problems, although the open price should still remain unchanged

    #2
    Hello Kovalev,

    Custom bar types are not officially supported for NinjaTrader 7 (but are supported for NinjaTrader 8) so there isn't any information in the help guide about adding a custom series.

    Are there any errors appearing on the Log tab of the Control Center when running the script?


    When printing the Opens[3][0], is this returning a 0?


    Below is a link to another forum thread where users are discussing this.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Kovalev,

      Are there any errors appearing on the Log tab of the Control Center when running the script?

      When printing the Opens[3][0], is this returning a 0?
      Hello NinjaTrader_Chelsea, no, the logs are absolutely clean. As far as I understand, the program does not see any errors, but for some reason it takes the wrong price data, as if I'm making some kind of error when calling. Because the opening price is shown of that instrument, but it is not the price of opening the Renko bar to which it belongs

      Comment


        #4
        Originally posted by Kovalev View Post
        Hello, please help to solve the problem. I add three multiple charts and an additional unirenko chart type to the strategy.

        Add(indicator);
        Add(second_instr, BarsPeriod.Id, BarsPeriod.Value);
        Add(third_instr, BarsPeriod.Id, BarsPeriod.Value);
        Add(PeriodType.Custom5, 002004002);

        In "OnBarUpdate"
        if (BarsInProgress != 0) return;

        And when I try to call the data of UniRenko bars the strategy does not react or reacts incorrectly

        For example
        if(Opens[3][1] < Closes[3][1] && Opens[3][0] > Closes[3][1])
        {
        ........
        }

        It's not working

        In addition, when I call in "Print" opens[3][0] and closes[3][0], the closes price is true, and the opens is not

        In this regard, there is a question - how to call the UniRenko data in the strategy
        Forgot to add, I'm using CalculateOnBarClose = false; Maybe this causes problems, although the open price should still remain unchanged
        Always type out "UniRenko", because "Renko" and "UniRenko" are NOT the same thing.

        Originally posted by Kovalev View Post
        In addition, when I call in "Print" opens[3][0] and closes[3][0], the closes price is true, and the opens is not
        That is correct. The UniRenko BarType (like all Renko-based bars) lie about the Opening price of the bar.

        Originally posted by Kovalev View Post
        Forgot to add, I'm using CalculateOnBarClose = false; Maybe this causes problems, although the open price should still remain unchanged
        Are you using "FirstTickOfBar" to examine EndOfBar values?
        Or are you specifically trying to access Open and Close price on every tick?

        When using COBC=False, such code should be segregated,

        Code:
        protected override void OnBarUpdate()
        {
            if (BarsInProgress == 3)
            {
                if (Historical)
                    /* do nothing -- this example utilizes tick information in real-time */ ;
        
                else if (CalculateOnBarClose)
                {
                    ... here Opens[3][0] is open of most recently closed UniRenko bar
                    ... here Closes[3][0] is close of most recently closed UniRenko bar
                }
        
                else
                {
                    ... here Opens[3][0] is open of current UniRenko bar being built
                    ... here Closes[3][0] is close of current UniRenko bar being built
                    ... here Opens[3][COLOR=#FF0000][1][/COLOR] is open of most recently closed UniRenko bar
                    ... here Closes[3][COLOR=#FF0000][1][/COLOR] is close of most recently closed UniRenko bar
                    if (FirstTickOfBar)
                    {
                        ... previous UniRenko bar has just closed
                        ... use Opens[3][COLOR=#FF0000][1][/COLOR] and Closes[3][COLOR=#FF0000][1][/COLOR] to access previous bar that just closed
                    }
                    else
                    {
                        ... this section runs on every tick for UniRenko bar series
                        ... use Opens[3][0] and Closes[3][0] to access current bar still being built
                        ... use Opens[3][COLOR=#FF0000][1][/COLOR] and Closes[3][COLOR=#FF0000][1][/COLOR] to access previous bar that just closed
                    }
                }
            }
        }
        Last edited by bltdavid; 06-10-2019, 04:35 PM.

        Comment


          #5
          Originally posted by bltdavid View Post

          That is correct. The UniRenko BarType (like all Renko-based bars) lie about the Opening price of the bar.
          That's news to me, thanks for the tip.

          Originally posted by bltdavid View Post
          Always type out "UniRenko", because "Renko" and "UniRenko" are NOT the same thing.
          I did not specify the type of Renko bars because I believed that they all obey the same laws.

          bltdavid, Thank you very much for your help, I did not use FirstTickOfBar, most likely this is my mistake

          Comment


            #6
            I adjusted my code example -- sorry, previous example was wrong.

            Note how when CalculateOnBarClose is True, you use 0 as the index for the most recent closed bar.

            When false, you must use 1 as the index.

            FirstTickOfBar is used to differentiate when a bar has closed.

            Comment


              #7
              Assuming all you care about is COBC=False, here is a slightly better example,

              Code:
              protected override void OnBarUpdate()
              {
                  ...
                  if (BarsInProgress == 3)
                  {
                      if (Historical || CalculateOnBarClose)
                          /* do nothing -- this example utilizes tick information in real-time */ ;
              
                      else
                      {
                          if (FirstTickOfBar)
                          {
                              ... previous UniRenko bar has just closed
                              ... use Opens[3][COLOR=#FF0000][1][/COLOR] and Closes[3][COLOR=#FF0000][1][/COLOR] to access previous bar that just closed
                          }
                          else
                          {
                              ... this section runs on every tick for UniRenko bar series
                              ... use Opens[3][0] and Closes[3][0] to access current bar still being built
                              ... use Opens[3][COLOR=#FF0000][1][/COLOR] and Closes[3][COLOR=#FF0000][1][/COLOR] to access previous bar that just closed
                          }
                      }
                  }
                  ...
              }
              Last edited by bltdavid; 06-10-2019, 04:44 PM.

              Comment


                #8
                bltdavid, thank you very much for your detailed answer, your help is invaluable!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by kempotrader, Today, 08:56 AM
                0 responses
                6 views
                0 likes
                Last Post kempotrader  
                Started by kempotrader, Today, 08:54 AM
                0 responses
                4 views
                0 likes
                Last Post kempotrader  
                Started by mmenigma, Today, 08:54 AM
                0 responses
                2 views
                0 likes
                Last Post mmenigma  
                Started by halgo_boulder, Today, 08:44 AM
                0 responses
                1 view
                0 likes
                Last Post halgo_boulder  
                Started by drewski1980, Today, 08:24 AM
                0 responses
                4 views
                0 likes
                Last Post drewski1980  
                Working...
                X