• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:
    http://www.ninjatrader.com/support/f...d=7&linkid=730

    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:

    https://ninjatrader.com/support/help..._rendering.htm

    https://ninjatrader.com/support/help.../?onrender.htm

    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:
        https://ninjatrader.com/support/help...fecycle_of.htm

        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():
        https://ninjatrader.com/support/help...lateminmax.htm

        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 SuneSorgenfrei, Today, 05:02 PM
            2 responses
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by shishir_nse, Today, 11:02 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by crazyhorse2393, Today, 07:31 PM
            0 responses
            9 views
            0 likes
            Last Post crazyhorse2393  
            Started by Jschmelz, Today, 01:13 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by Newtrader101, Today, 12:37 PM
            2 responses
            13 views
            0 likes
            Last Post Newtrader101  
            Working...
            X