Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsType Issues

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

    BarsType Issues

    Hi,

    I am running into the following two issues when constructing a custom bar type:

    1. The function
    Code:
            public override void ApplyDefaultValue(BarsPeriod period)
            {
                period.BarsPeriodTypeName = "MyBars";
                period.Value = 6;
                period.Value2 = 1;
            }
    does not seem to work properly. The assignment
    Code:
                period.BarsPeriodTypeName = "MyBars";
    does work but the setting of custom values for Value and Value2 does not work.

    2. How do you set the default chartStyle to a custom style, say MyStyle?
    Code:
                DefaultChartStyle = ???
    Any insight and suggestions would be greatly appreciated. Thank you.

    #2
    Thanks for your post Zeos6,

    Please be aware that you will have to restore the preset in the Data Series window to reload defaults. I tested with a custom BarsType to see the default values in the Data Series window, change the defaults in source, recompile, and then restoring presets with the function in the lower right hand corner of the Data Series window. Everything worked as I would expect it.

    Code:
    DefaultChartStyle = (ChartStyleType) 0;
    Setting this is in ApplyDefaultValue will modify the default ChartStyle for your BarsType. You would have to supply the ChartStyleType index for your custom CharStyle for it to point to yours.

    Also to note, BarsPeriodTypeName was used in beta but was not used in production releases and is now a deprecated property and not required for BarsTypes. It would be recommended to cast the BarsPeriodType index similarly to ChartStyles when adding programmatically from another NinjaScript. For example:

    Code:
    AddDataSeries(new BarsPeriod { BarsPeriodType = (BarsPeriodType)501, BaseBarsPeriodValue = 2, Value = 2, Value2 = 6 });
    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi ChrisL,

      Thank you for your reply.

      First, regarding DefaultChartStyle, thanks for the syntax clarification.

      Second, can you please clarify the BarsPeriodTypeName information you sent? I am building a ChartStyle, I am not adding series to an indicator.

      Third, I am specifically asking about ChartStyles, and how to set default values for Value and Value 2 in the method
      Code:
              public override void ApplyDefaultValue(BarsPeriod period)
              {
                  period.BarsPeriodTypeName = "MyBars";
                  period.Value = 6;
                  period.Value2 = 1;
              }
      Maybe it's too early in the morning cause I sure am missing something here.

      EDIT: By the way, the info you gave me in terms of the DefaultChartStyle does not work. I am working with BarsType here. The error given is that thee type or namespace ChartStylesType could not be found.
      Last edited by Zeos6; 08-17-2018, 09:36 AM.

      Comment


        #4
        Hello Zeos6,

        BarsPeriodTypeName is an undocumented and unused item in current releases. It was created in Beta, but is not used with our final BarsTypes. In the past, people have used this property when adding their custom BarsType to an indicator or strategy. The line of code to use the BarsPeriodType when adding a data series was a suggestion if your intentions for using BarsPeriodTypName were to add the data series programmatically.

        For further clarification on my last post please try the following:
        1. In your Custom BarsType please make the following changes:
          Code:
                  public override void ApplyDefaultValue(BarsPeriod period)
                  {
                      [B]DefaultChartStyle = (ChartStyleType) 0;[/B] // bolded for later reference in this post
                      period.Value = 10;
                      period.Value2 = 20;
                  }
        2. Recompile your NinjaScript assembly
        3. Create a new chart (Open a Data Series Window)
        4. Assign your custom BarsType
        5. From the lower right hand corner of the Data Series window, select preset and restore
        6. "Box" should be the new default Chart Style and the values for Value1 and Value2 will be the new values assigned in code.


        We would reference custom ChartStyles similar to how we add a custom BarsTypes.
        Code:
        AddDataSeries(new BarsPeriod { [B]BarsPeriodType = (BarsPeriodType)501[/B], BaseBarsPeriodValue = 2, Value = 2, Value2 = 6 });
        In the ChartStyle, the custom index would be applied as follows:
        Code:
        protected override void OnStateChange()
        {
        	if (State == State.SetDefaults)
        	{
        		Name			= "CustomCandleStyle";
        		[B]ChartStyleType	= (ChartStyleType)5001;[/B]
        	}
        }
        The platform will need to be reset in order for new ChartStyles to be available.

        If you have any additional questions on this matter, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks for the clarification Jim.

          But...
          The info you gave in terms of the DefaultChartStyle does not work. The error I get is that the type or namespace ChartStylesType could not be found.

          EDIT: Figured it out. D'oh!! One of those days.
          (Gui.Chart.ChartStyleType) 0

          But, is there a way to check if a ChartStyle exists? I tried using
          Code:
          DefaultChartStyle = (Gui.Chart.ChartStyleType) 100 ?? Gui.Chart.ChartStyleType.OpenClose;
          and the error stated that the ?? operator cannot be used with ChartStyleType.

          EDIT: I have tried Enum.IsDefined() but that doesn't seem to work either.
          Last edited by Zeos6; 08-17-2018, 10:25 AM.

          Comment


            #6
            Hello Zeos6,

            I'd suggest taking an approach similar to how NinjaTrader_Jesse fetches the available BarsTypes to accomplish this goal.

            For example:
            Code:
            public override void ApplyDefaultValue(BarsPeriod period)
            {
            period.BaseBarsPeriodValue = 2;
            period.Value = 10;
            period.Value2 = 20;
            
            bool indexFound = false;
            
            Type[] types = NinjaTrader.Core.Globals.AssemblyRegistry.GetDerivedTypes(typeof(NinjaTrader.NinjaScript.ChartStyles.ChartStyle));
                    for (int i = 0; i < types.Length; i++)
                    {
                        Type type = types[i];
                        if (type == null || type.FullName.IsNullOrEmpty()) continue;
                        var type2 = NinjaTrader.Core.Globals.AssemblyRegistry.GetType(type.FullName);
                        if (type2 == null) continue;
                        NinjaTrader.NinjaScript.ChartStyles.ChartStyle style = Activator.CreateInstance(type2) as NinjaTrader.NinjaScript.ChartStyles.ChartStyle;
                        if (style != null)
                        {
                 style.SetState(State.SetDefaults);
            int id = (int)style.ChartStyleType;
            style.SetState(State.Terminated);
            
            // Signal that we found the index
            if (id == 5001) indexFound = true;
                        }
                    }
            
            if (indexFound)
            DefaultChartStyle = (ChartStyleType) 5001;
            else
            DefaultChartStyle = (ChartStyleType) 1;
            }
            NinjaTrader_Jesse's tool for BarsType identification can be found here: https://ninjatraderecosystem.com/use...pe-identifier/

            The link above is publicly available.

            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.


            I look forward to being of further assistance.
            Last edited by NinjaTrader_Jim; 12-21-2021, 07:43 AM. Reason: Updated link
            JimNinjaTrader Customer Service

            Comment


              #7
              Wow! Bit of an overkill as ChartStyle is essentially an Enum.

              Comment


                #8
                Thanks Jim.

                The code sample provided works, with minor revision to IsNullOrEmpty(). The only issue is that the property grid is not refreshed.

                Comment


                  #9
                  Hello Zeos6,

                  ChartStyleType is an enum, but we cannot add new enum names and are left with casting the index as the ChartStyleType as described in posts 2 and 4. If you include the BarsType and ChartStyle together in your distribution package, you would not need to worry about checking if the ChartStyle exists and can just use the index.

                  When I test the code provided and reset the presets, the ChartStyle changes to the custom ChartStyle when I select my custom BarsType in the Data Series window. Strategies and Indicators could use a TypeConverter to override default property grid behavior for further types of changes, but this would not be possible with ChartStyles or BarsTypes through supported NinjaScript since a BaseConverter class does not exist for these NinjaScripts.

                  I've submitted a vote on your behalf for a supported means to update property grids for ChartStyles and BarsTypes programmatically. Ticket ID is SFT-1870 for supporting additional types of TypeConverters. (As with other feature requests, interest will be aggregated before implementing and the feature will be noted in the help guide once implmented.)

                  Release Notes - https://ninjatrader.com/support/help...ease_notes.htm

                  Please let us know if there is anything else we can do to help.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Jim.

                    I appreciate the explanation, and yes, that would be a useful feature. Thank you for submitting it on my behalf.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jim View Post
                      NinjaTrader_Jesse's tool for BarsType identification can be found here: https://ninjatrader.com/support/foru...php?linkid=913
                      That link is invalid and needs to be updated.

                      Here is a simpler method to print all registered BarsType names,

                      Code:
                      foreach (BarsPeriodType b in BarsType.GetSupported())
                          Print(string.Format("BarsType Id={0} Name='{1}'", (int)b, BarsType.GetBarsPeriodTypeName(b)));


                      Comment


                        #12
                        Thanks bltdavid, I've updated the link.

                        Thanks also for the simplified tip.
                        JimNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by jclose, Today, 09:37 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post jclose
                        by jclose
                         
                        Started by WeyldFalcon, 08-07-2020, 06:13 AM
                        10 responses
                        1,414 views
                        0 likes
                        Last Post Traderontheroad  
                        Started by firefoxforum12, Today, 08:53 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post firefoxforum12  
                        Started by stafe, Today, 08:34 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post stafe
                        by stafe
                         
                        Started by sastrades, 01-31-2024, 10:19 PM
                        11 responses
                        169 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Working...
                        X