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

How to access Additional Instrument in Custom BarsTypes

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

    How to access Additional Instrument in Custom BarsTypes

    Hi

    I am trying to plot as Bars a value of a Instrument adjusted by the values of another instrument i.e. Price of DJIA in Gold, etc. How can I access the gold price in a custom BarsTypes implementation in order to do the recalculation of the open, high, low, close on the DJIA.

    Is there another way to create a Data series of DJIA in gold so I can plot it with the standard Candle bar type ?

    Tzanimir

    #2
    Hello,

    Thank you for the post.

    You will have to use an indicator to render bars if you need more than one data source.

    Here is a good example of how this is done:


    In this example, there are custom Series<Double> data series objects for the Open, High, Low, and Close. In OnBarUpdate() the actual OHLC values have operations performed on them and are then set in the corresponding custom series.

    The other important section of this code is the OnRender() function. This is where you will draw the bars on the chart based on the price data.

    More information on the OnRender() function can be found here:





    Please let us know if we may be of any further assistance.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you. This works for me. There are 2 issues with this solution:

      1. As the base instrument value and the calculated value differ significantly the, "auto scale" option on the base instrument causes improper scaling as the main instrument is not visible but being scaled against. Manually unchecking the "auto scale" option fixes the issue. What will be the programmatic way to switch the "auto scale" off when the indicator is applied. Where will be the place to reenable the "auto scale" when indicator is removed.

      2. The example of HeikenAshi8 has an issue with the relative position of the rectangle of the bar with the vertical line marking the high low distance - the vertical line is often not in the middle of the rectangle.

      Tzanimir

      Comment


        #4
        Hello,

        Thank you for the reply.

        IsAutoScale is set in State.SetDefaults. The only way to change the value of IsAutoScale is during the OnStateChange function's SetDefault or Configure states, so it could not be dynamically changed while the script is running

        https://ninjatrader.com/support/help...sautoscale.htm - IsAutoScale

        Here is an overview of the NinjaScript lifecycle:


        However, turning IsAutoScale to false will not allow you to call OnCalculateMinMax() to adjust the scaling when the price goes up or down.

        Here is more information on OnCalculateMinMax():


        This script was supplied "as is" no further modifications will be made to the source on the forum. You can edit the source code of this indicator and see if you can get it to display the way you wish.

        Please let me know if you have any questions.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          The "Auto scale" option needs to be set on the Main Instrument and not on the Indicator. How to do that programmatically ?

          Tzanimir

          Comment


            #6
            Hello,

            Thank you for the reply.

            The DataSeries autoscale option is for including specifically the DataSeries and is a manual action through the user interface. An indicator cannot set this option but the indicator can be set to Overlay so the AutoScale will not compress the different values.

            Please try to set the indicators scale justification to "Overlay" (Indicator menu>Scale Justification). This should fix the scaling issues between price data.

            I look forward to hearing of your results.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by funk10101, Today, 09:43 PM
            0 responses
            6 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            37 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            44 views
            0 likes
            Last Post bill2023  
            Started by yertle, Today, 08:38 AM
            6 responses
            26 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            24 views
            0 likes
            Last Post algospoke  
            Working...
            X