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

UniRenko problem

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

    UniRenko problem

    Hi all, im having a prob with an indicator i created and UniRenko bar types, basically the indicator is a MACD converted to multitimeframe that has a "Default" option to use the predetermined bar type be the source for the calculations:


    switch(bType)
    {
    case KBTMACDMTFV1.Default:
    Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Last);
    break;

    case KBTMACDMTFV1.Minute:
    Add(PeriodType.Minute, timeframePeriods);
    break;

    case KBTMACDMTFV1.Day:
    Add(PeriodType.Day, timeframePeriods);
    break;

    case KBTMACDMTFV1.Week:
    Add(PeriodType.Week, timeframePeriods);
    break;

    case KBTMACDMTFV1.Month:
    Add(PeriodType.Month, timeframePeriods);
    break;

    case KBTMACDMTFV1.Range:
    Add(PeriodType.Range, timeframePeriods);
    break;

    case KBTMACDMTFV1.RangeNoGap:
    Add(PeriodType.Custom2, timeframePeriods);
    break;

    case KBTMACDMTFV1.Renko:
    Add(PeriodType.Renko, timeframePeriods);
    break;

    case KBTMACDMTFV1.HybridRenko:
    Add(PeriodType.Final0, timeframePeriods);
    break;

    case KBTMACDMTFV1.UniRenko:
    Add(PeriodType.Custom5, timeframePeriods);
    break;

    }

    the MACD works fine on all chart types except UniRenko, see below image, both indicators r MACD with same settings.
    Click image for larger version

Name:	2016-10-13_183558.jpg
Views:	1
Size:	46.1 KB
ID:	906339

    help plz! thanks in advance!!

    #2
    Try this search which should lead (eventually) to this post.

    That should help get you started.

    Comment


      #3
      Hi bltdavid, thanks for your reply, yes, i remembered that post and consulted it again a couple hours ago, but my question was related to the:
      "Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Last);"
      not working with UniRenkos and how to fix that if possible

      Comment


        #4
        Originally posted by bltdavid View Post
        Try this search which should lead (eventually) to this post.
        Reviewing the example in that post, I would try this,

        Code:
        Add(PeriodType.Custom5, 4008002);
        Note I omitted the leading zeros in the 2nd argument, since those might be misinterpreted as octal. (God knows saying that dates me as old-timer C programmer, but nonetheless, leading zeros are superfluous most of the time anyways)

        If this works, or not, I have no idea ... I did not test it.

        Comment


          #5
          It works, thats how im using it, till i see if there's a way to get a "use default chart source for calculation"

          Comment


            #6
            Originally posted by kabott View Post
            Hi bltdavid, thanks for your reply, yes, i remembered that post and consulted it again a couple hours ago, but my question was related to the:
            "Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Last);"
            not working with UniRenkos and how to fix that if possible
            You already have this case in your switch statement,

            Code:
            case KBTMACDMTFV1.UniRenko:
              Add(PeriodType.Custom5, timeframePeriods);
              break;
            Assuming timeframePeriods comes from a property, just type the value 4008002 into the indicator's property grid when you add it to the chart.
            Last edited by bltdavid; 10-13-2016, 07:36 PM.

            Comment


              #7
              hey bltdavid, yes i have it, but unless i select de bar type and punch in the period manually the indicator doesn't plot right, i know what your thinking "Duh! obviously!" haha, but this code snipet should take care of that when i select "Default" from the indicator bar types drop down menu:
              "case KBTMACDMTFV1.Default:
              Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Last);
              break;"

              it works for every other bar type on the list, i dont understand why it doesn't for Unirenkos forcing me to instead select UniRenko and enter the periods manually.
              anyway isnt such a biggy, i was just curious about it mostly.

              Comment


                #8
                With UniRenko, BarsPeriod.Value does not stay 4008002.

                The internal code of UniRenko breaks up the large number 4008002 into three different numbers, 4, 8, and 2.

                In your case statement, BarsPeriod.Id might surely be Custom5 (if your chart is already UniRenko), but I guarantee you BarsPeriod.Value is not a large number like 4008002.

                Reread my suggested post and understand that 4008002 is parsed into 3 numbers during initialization, after which that original aggregate number itself is not retained or remembered (since there is no need to do so).

                Look at the UniRenko code in bin/Custom/Type -- the source code is in there.

                You'll see some very special processing/initialization performed on the very first bar.

                Code:
                //### First Bar
                            if ((bars.Count == 0) || bars.IsNewSession(time, isRealtime))
                            {
                                    tickSize = bars.Instrument.MasterInstrument.TickSize;
                
                                        //### Parse Long Param Specification
                                    if ( [COLOR=Red]bars.Period.Value[/COLOR] >= 1000000 ) {
                                          int d; string str = bars.Period.Value.ToString("000000000");
                                         [COLOR=Red][COLOR=Black]d=0; Int32.TryParse(str.Substring(0,3), out d); [/COLOR]bars.Period.Value  = d;[/COLOR]
                                         d=0; Int32.TryParse(str.Substring(3,3), out d); bars.Period.Value2 = d;
                                        d=0; Int32.TryParse(str.Substring(6,3), out d); bars.Period.BasePeriodValue = d;
                                     }
                     ... remainder of code ...
                }
                The 'Value' variable is first seen as your 4008002 (which is over a million), so it gets parsed.

                EDIT:
                [4008002 is the original aggregate number you supplied to the Add() method when adding the UniRenko secondary bar series. This aggregate number must get broken down and parsed -- but the original value of 'Value' starts out as 4008002, and the UniRenko code explicitly checks for ridiculously large values in 'Value' and parses it into the 3 smaller numbers it needs -- a neat (and necessary) trick needed for users of Add(). Hint: Study again the suggested post along side my answer, careful re-readings should make things even clearer (I hope) as to what's happening and why.]

                Value is re-assigned to 4 -- this holds the 'Tick Trend' value.
                Value2 is assigned 8 -- this holds the 'Tick Reversal' value.
                BasePeriodValue is assigned 2 - this holds the 'Open Offset' value.

                After parsing, the 4008002 is forgotten, the theory being it is no longer needed, (and also there is no place to retain it, since BarType authors are limited (I think) to the variables already builtin to the internal 'bars' structure.)

                In your case statement, your reuse of 'BarsPeriod.Value' is ultimately coming from that 'bars.Period.Value' re-assignment, and has a value of 4, not 4008002.
                Last edited by bltdavid; 10-14-2016, 10:24 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                7 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                18 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                4 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                12 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                13 views
                0 likes
                Last Post bltdavid  
                Working...
                X