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

Custom bartype objects

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

    Custom bartype objects

    Hi,

    I've created a custom bar type, it seems to be working fine. But I'm running into a problem trying to create a strategy that uses this bar type. I'd like to create an object of the custom bar type so I can reference it in my script. I'm using the reference code for OrderFlow Volumetric bars as a loose guide for this but I can't get it to work for my custom type, the object is always NULL.

    The Volumetric Bars reference code looks like this:
    protectedoverridevoidOnBarUpdate()
    {​
    if (Bars==null)
    return;

    // This sample assumes the Volumetric series is the primary DataSeries on the chart, if you would want to add a Volumetric series to a
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pebarsType=Bars.BarsSeries.BarsTypeas
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

    if (barsType==null)
    return;
    ​}

    --------------------------------------------------------------------------------------
    My code looks like this:

    if (Bars == null)
    return;

    // attempt to cast the bars object as Imbalance bars, if cast fails, then it's not an imbalance bar
    NinjaTrader.NinjaScript.BarsTypes.FixedDollarImbBa rs imbalanceType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.FixedDollarImbBa rs;


    if ( imbalanceType == null )
    imbalanceCheck = false;
    else
    imbalanceCheck = true;​


    But this cast never works, my object is always NULL. Can you fill me in on why it's not working?

    Thanks

    #2
    Hello NickyD,

    Thank you for your post.

    Following the Volumetric Bars as an example and attempting to cast your bars is not the proper way to add a custom BarsType to a script. You will need to call AddDataSeries():You can specify your custom BarsType through the BarsPeriod object. The barsPeriodType contains an enumeration for each bar type:As mentioned in the Tip on that page, "When creating custom BarsTypes, it is recommended to pick high, unique enumeration value to avoid conflict from other BarsTypes that may be used by a single installation.

    Code:
    BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType)123456, BarsPeriodTypeName = "MyCustomBars", Value = 1 };
    "


    You may want to use an indicator that identifies BarsPeriodType IDs to help with this concept. This indicator is publicly available on our NinjaTrader Ecosystem website:
    Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

    Note — To import NinjaScripts you will need the original .zip file.

    To Import:
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.

    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    Once installed, you may add the indicator to a chart by:
    • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK

    Here is a short video demonstration of the import process:
    Please let me know if I can be of further assistance.

    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.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      The primary series is already my custom bartype though... the strategy is applied to a chart of this custom bar type. So do I still have to use AddDataSeries? There's no way around that?

      Comment


        #4
        Hello NickyD,

        Thank you for your reply.

        If the primary series is already the custom Bars Type, then you should be able to reference it as BarsArray[0] and you do not need to call AddDataSeries(). What data are you trying to get from your custom bars in the strategy?

        I look forward to your clarification.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          The custom bars have some public properties I am trying to access.

          If I use BarsArray[0].BarsType, then casting as I was initially doing seems to be working as I'd hoped. So I think I'm good for now.


          i.e.
          NinjaTrader.NinjaScript.BarsTypes.FixedDollarImbBa rsV2 imbalanceType = BarsArray[0].BarsType as NinjaTrader.NinjaScript.BarsTypes.FixedDollarImbBa rsV2;

          instead of
          NinjaTrader.NinjaScript.BarsTypes.FixedDollarImbBa rsV2 imbalanceType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.FixedDollarImbBa rsV2;

          Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by mishhh, 05-25-2010, 08:54 AM
          19 responses
          6,189 views
          0 likes
          Last Post rene69851  
          Started by gwenael, Today, 09:29 AM
          0 responses
          4 views
          0 likes
          Last Post gwenael
          by gwenael
           
          Started by Karado58, 11-26-2012, 02:57 PM
          8 responses
          14,830 views
          0 likes
          Last Post Option Whisperer  
          Started by Option Whisperer, Today, 09:05 AM
          0 responses
          2 views
          0 likes
          Last Post Option Whisperer  
          Started by cre8able, Yesterday, 01:16 PM
          3 responses
          11 views
          0 likes
          Last Post cre8able  
          Working...
          X