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

Plot that takes data simultaneously from 2 instruments with different Trading Hours

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

    Plot that takes data simultaneously from 2 instruments with different Trading Hours

    I took the “SampleSecondarySeriesAsInputSeries” as base to try to get a line-on-close plot where its data comes from 2 different fixed-by-code DataSeries instruments, and each of two with different Trading Hours, so the main plot works and needs to get its final graph result simultaneously from the data of these 2 instruments.

    The “special” situation I can see here is that the 2 instruments are 1 Future and 1 Index, specifically the VX Future (VX 05-22) and the VIX Index (^VIX), and the problem is I don’t get the desired result that is a plot based on the data from these 2 instruments at the same time.

    I’ve tried:
    • Changing the primary instrument in the chart, rotating between a Future and an Index to see if with a specific combination I get the plot working, but no result and what I get is a blank chart.
    • Selecting other Trading Hours for the Index instrument, when is the Index that is the primary instrument loaded in the chart.
    • Loading the 2 kind of instruments simultaneously in the chart, a Future as primary and an Index as secondary, trying to match the script plot with what is loaded in the chart.

    Well, nothing of this has worked in my side.

    I think that maybe the problem is the different and “non-standard” Trading Hours of the VIX that maybe causes that where the Future has data for example at 8pm ET, then at that time the VIX doesn’t have data because its Exchange hours are different than the hours that could have a Future, so for the hours where the Future has data but the Index doesn’t have any data because “its Exchange is closed”, then I think that the most logical procedure would be that the plot could work in the way that it always takes the last Index price-quote found.

    For example:
    If any day at 9:41pm ET the VX 05-22 quote is 26.70 and the VIX doesn’t have present quote for that time but the last quote data found for the VIX for that day was 24.86 at its close at 4:00pm ET, then I think the way to proceed would be to automatically work with what has present data in X time and taking the last quote found of the other instrument, and in that way always have a result with the last available and more current data of the two instruments. But I haven’t found the way to get that because the idea would be to have the desired plot having data every time the instrument with more available data during day has available data, in this case taking the VX Future as reference and main data-source because is the instrument with a wider range of time during the day.


    I’ve attached the modified “SampleSecondarySeriesAsInputSeries” script for more reference, to please see how you can help me to work these kind of cases where is needed to work with multiple instruments with different Exchange Hours.


    Thank you in advance!

    Attached Files

    #2
    Hello futurenow,

    An indicator can only have 1 input series. So the SampleSecondarySeriesAsInputSeries_NT8 reference sample is using BarsArray[0] and BarsArray[1] for the input series for two separate SMA calls.


    However, you can add a secondary data series internally in the indicator with AddDataSeries() and use a different trading hours template.
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)


    When adding series with different trading hours, all series must be in session for OnBarUpdate() to run. If one series is out of session, the script will wait until both series are in session and then will process all bars queued for any series that was in session while the other was not.

    From the help guide:
    "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your fast response Chelsea.


      Originally posted by NinjaTrader_ChelseaB View Post
      Hello futurenow,
      When adding series with different trading hours, all series must be in session for OnBarUpdate() to run. If one series is out of session, the script will wait until both series are in session and then will process all bars queued for any series that was in session while the other was not.
      What I understand is that ‘OnBarUpdate()’ will only work and will only generate the plot when both series be in session, and as we already know, for a Future and an Index this is something that won’t always match during the day and the week, and this part is exactly the point where I need an alternative way to handle this kind of situations.

      So, wouldn’t be alternatives to work this kind of cases in a similar way as I described in the first main post here? In order to cover the cases where a symbol is in session and the other is out of session:

      For example, where if any day at 9:40pm E.T. the VX 05-22 is in session with a quote = 26.70 and at this time the VIX isn’t in session but the last VIX quote found for that day was 24.86 at its session close at 4:00pm E.T., then maybe it could be a way where the script could “say” something like
      • When I have the instruction ‘Plot1[0] = ( Closes[1][0] + Closes[2][0] ) / 2’,
      • let me previously check what is the last available data quote for 2nd added series, i.e. the symbol that has a non-Future Trading Hours or in fact a shorter period of time in its Trading Hours during the day,
      • then let me take and use that last quote found, either being a quote that is in session or being out of session,
      • and finally let me do the instruction process taking the 2 series Closes,
        • first the sum the Closes,
        • then divide the sum result by 2,
        • and lastly plot in the chart the result bar-by-bar as the normal for a line-on-close plot.


      Maybe working part of the code outside of ‘OnBarUpdate()’ where you could specify something like:
      Code:
      …
      // pseudo-code of a possible pre-process maybe before to enter inside ‘OnBarUpdate()’:
      // outside of ‘OnBarUpdate()’
      // Closes[2][0] = last quote found of the second added series, in the case of the attached script: ‘AddDataSeries("^VIX")’
      …
      
      protected override void OnBarUpdate()
      {
      …
      Plot1[0] = ( Closes[1][0] + Closes[2][0] ) / 2 ; // At this time being ‘Closes[2][0]’ = the last available found Close quote of the VIX Index.
      …
      }
      …
      Code:
      [FONT=Arial][/FONT]


      So in this way you would get something like:

      @9:40pm E.T.
      • VX 05-22 Close quote in the present = 26.70
      • VIX last Close quote at the closing of its session = 24.86
      Then: Plot1[0] = ( Closes[1][0] + Closes[2][0] ) / 2
      ..= (26.70 + 24.86) / 2
      ..= 25.78

      @9:45pm E.T.
      • VX 05-22 Close quote in the present = 26.05
      • VIX last Close quote at the closing of its session = 24.86
      Then: Plot1[0] = ( Closes[1][0] + Closes[2][0] ) / 2
      ..= (26.05 + 24.86) / 2
      ..= 25.46


      @4:00am E.T. (next calendar day)
      • VX 05-22 Close quote in the present = 25.50
      • VIX last Close quote in the present = 23.95
      Then: Plot1[0] = ( Closes[1][0] + Closes[2][0] ) / 2
      ..= (25.50 + 23.95) / 2
      ..= 24.73



      I’m really hope not to be the first person with this kind of situations and that this can be handled in any way, because I need exactly what I’m describing here and in the scipt code, i.e. to get the script working at any time where the Future session be open and just taking for the needed calculations the last price quote found of the Index symbol, because this is exactly the way where the indicator needs to work, giving a plot either being on Monday at 2:45pm E.T. or being on Monday at 11:35pm.


      Thank you!



      Comment


        #4
        Hello futurenow,

        There would not be a way around this when using AddDataSeries().

        You could use a BarsRequest to get out-of-sync data for another instrument.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NUVERSA, Today, 09:31 AM
        0 responses
        3 views
        0 likes
        Last Post NUVERSA
        by NUVERSA
         
        Started by ttrader23, Yesterday, 09:04 AM
        8 responses
        37 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by tonynt, Yesterday, 01:48 PM
        2 responses
        12 views
        0 likes
        Last Post tonynt
        by tonynt
         
        Started by goodknight777, Today, 08:43 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Salahinho99, 05-05-2024, 04:13 AM
        5 responses
        47 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X