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

Daily bars loading within indicators called by modules on minute bars

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

    Daily bars loading within indicators called by modules on minute bars

    if an indicator/strategy trading on minute bars had to use/create an indicator -which in turn had to load daily bars - Is there a way of spinning the primary thread until all indicators which are loading seocndary bars are completed?

    Is there some control via property/moethod available to only start when all dependant bars are loaded in other referenced modules.

    I was getting inconsistent results with bar data loading in chained indicators - .ie. one which is called by another - it was neccessarty to hit F5 to get them to load daily bars before the other indicator/strategy ran - the ends result was the daily bars loaded at some point in the other indicator after the primary bars had loaded and were plotted on the chart up to the current bar.

    The attached images show successful operation and failed operation - which is resolved by pressing F5

    The reason to load secondary bars within indicators called by others is to negate the need to load the extra bars within the calling indicator/strategy by encapsulating the logic with am indiator that can be used many times by many modulss etc...

    Import attachment and add MTTest1 adn MTTest2 to a 10Min chart with 30days of data

    Scenario
    #1 Indicator HTFATR
    Run on a 10Min chart or any intraday time series min chart.
    It loads on initialise DailyBars

    It plots the seconday bars ATR within the primary bars Plot.
    E.G Dailly ATR set in the 10Min values[0]
    When tested on its own it always loads daily data and displays ok.

    #2 Indicator HTF ATR Watcher

    This will test on each bar update on a 10min chart it will test the HTFATR().value
    to see if the current day range >= HTFATR().value and plot if so.

    #3 Strategies

    Several strategies will use indicator #2 to only trade when the HTFATRWatcher()[0] is set. If the daily bars do not load in #1 then #2 will always be false for historical testing
    I am assuming this is a valid use of secondary bars.


    I have found that #2 does not always respond as the bars loading in #1 have not completed and the primaary bars go ahead and plot without it - then on the current ba and !historical it will start to plot
    Attached Files
    Last edited by MicroTrends; 08-25-2010, 12:29 PM.
    MicroTrends
    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

    #2
    Hi MicroTrends,

    What version of NinjaTrader are you using.

    Before jumping in to your code specifics, can you take a look at the following samples to ensure you have coded the multi-time frames in the best way.

    Synchronizing a DataSeries object to a secondary time frame:
    Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for


    Using BIP and Multi-Time frame script properly:
    TimNinjaTrader Customer Service

    Comment


      #3
      Hi

      I can confirm the product is NinjaTrader 7 version 7.0.0.20

      The code sample you pointed too is useful to sense check the pattern but it is not 100% relevent to the scenario - there is 1 common element the use of secondary bars and using conditional code for barsinprogress. That sample will simply create duplicate dataseries which are simply synced with the underlying bars according to the barsinprogess. I can confirm that the pattern is correct for adding secondary bars and for access them.

      The scenario I supplied is a little more sophisticated - wherein the secondary bars are created inside an indicator #1. The secondary bars are then used to plot ATR on the default dataseries which is intrinsic to the primary bars oarray object Value.. or Values[0] - the pattern is a standard one.

      That indicator is then referenced by another indicator #2 which performs a comparion using the
      #1 indicator default plot series Values[0].
      . If created on the chart directly #1 works perfectly - sometimes if accessed by another indicator which uses only primary bars - the indicator #1 fails to load the secondary bars histroically - so therefore the primary plot has an empty value (or a default of 0). The indicator does start to plot when bar is the currentbar and when data is not historical - i have attached a diagram to illustrate the issue.
      This does pose some issues for backtesting - if for example the daily bars do not load historically.

      Within the framework i have built it assumed that strategies should not need concern themselves with loading secondary bars if this task can be allocated to the internals of the indicator it is referencing. So in a similar way to the pivots where secondary bars are loaded within the indicator and not the module using it... I realise the pivots technique is not 100% relevant as i am not back filling when historical data is loaded via a callback - I am just requiring all the data loads up front before the primary bars plot on the chart -so historical daily bars are loaded in time.


      It might just be easier to view the indicator code which i wrote specifically to illustrate the example and is not ambigous like english... its alos very minimal and simple - the chart images provided show a grphicall representation of the issue i was having.

      sorry for the essay :-)
      Last edited by MicroTrends; 08-25-2010, 04:15 PM.
      MicroTrends
      NinjaTrader Ecosystem Vendor - micro-trends.co.uk

      Comment


        #4
        Tom, we'll look into the code you provided as sample and get back to you - thanks for the patience.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Tom, to clarify further - your issue is calling MTTest1 in a strategy and get the correct value for the MultiSeries indicator loading daily bars?
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hi
            The issue is that the #2 indicator calls the #1 indicator and fails sometimes to plot - because the #1 indicator has not loaded its daily bars in time up front before the primary bars in #2 start -
            #2 performs a calculation on the dataseries of #1 - #2 could be used in a strategy... these indicators are simplified verisons of the actual. you can see in the images that with normal behaviour both indicators plot - when the #1 fails to load inside #2 then #2 has nothing to plot - allthough #1 indicator created on the chart always loads...
            MicroTrends
            NinjaTrader Ecosystem Vendor - micro-trends.co.uk

            Comment


              #7
              MicroTrends,

              What you want to do is in the host script make sure the hosted script actually has valid plots before doing anything. You can do this through the .IsValidPlot property.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Hi Josh
                As I understand it - testing valid plot is on a bar by bar basis - that would be called during the host script onbarupdate - which will start even if the secondary bars in the called script are not loaded - that is the issue. I need to wait for them to load or timeout.

                perhaps logically it would be something like

                onbarupdate

                while(!Indie1()[0].isvalidPlot)
                {
                thread.sleep(3000);
                }

                however i believe that wont work due to the threading etc...


                The main problem is if i run a test of some 1000000 iterations over 3 weeks and data is not loading consistently in called indicators.



                some ramblings here....
                so perhaps what i actually want to do is to block theonbarupdate in the host script until the daily bars are loaded - -i.e when the called scripts has loaded and all bars it can set a property or raise and event so then the host bars can load and so when the onbarupdate event fires in the hosting script the plots in the other are ready... is there a way of controlling that ? - not a single thread....

                Perhaps one way is to load the daily bars inside the host script and pass them in barsarray by reference or copy. can indicators point to / share bars/ static cache...
                Last edited by MicroTrends; 08-26-2010, 04:27 PM.
                MicroTrends
                NinjaTrader Ecosystem Vendor - micro-trends.co.uk

                Comment


                  #9
                  What you can do in your hosted script is to just not set any values (therefore making the plot invalid) until you have all bar series loaded.

                  Code:
                  if (CurrentBars[0] < 0 || CurrentBars[1] < 0)
                       return;
                  Then in your host script check .IsValidPlot before doing anything. If you are worried about checking on an every single bar basis you can just use a bool switch. Once .IsValidPlot returns true once.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Current code is similar without the else:

                    if(CurrentBar<0 || BarsInProgress>0)return;

                    if(CurrentBars.Length>1 && CurrentBars[1]>=0)
                    {
                    //plot secondary bars daily atr on the primary bars plot
                    Plot0.Set(ATR(BarsArray[1],4)[0]);
                    }
                    else
                    {
                    Plot0.Set(
                    0);
                    }

                    I think I can understand what you saying but the hosting script bars will have moved on by N bars by the time the hosted script bars are valid...

                    For example the hosted script secondary bars might not have loaded until the current bar has been hit or bar n of the primary bars.

                    procedurally it would be good to check pre onbarupdate of the primary bars of the host that all hosted scripts have loaded...

                    while(!indiehosted().barsLoaded)
                    {
                    wait.....
                    }


                    The consistent pattern was that it either compelety failed to load at all until the current bar was hit in the primary ie not historical or it loaded up front as required... if it fails to load it would be neccessary to reload until it loaded historical bars...
                    Last edited by MicroTrends; 08-26-2010, 04:52 PM.
                    MicroTrends
                    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

                    Comment


                      #11
                      I can see we are talking a little at cross purposes - the validplot will always be false when the daily bars failed to load - until the primary bars currentbar is hit...then they do load - starting at 1st bar at the currentbar. The bars in the hosted script completely failed to load for historical bars - they did eventually load when primary bars were current. The issue is that historical backtesting was not possible when this occured.. or was intermittent - inconsistent - on the day this issue occured the internet connection was playing up - today i cannot replicate it.... is that the link- perhaps... I will perform more testing in this area...video it if possible.

                      From what you are posting hosting other indicators that create secondary bars is not out of scope or a bad practice.

                      So for defensive coding all i need to do is work out where the 1st bar should have loaded and abort further processing - or as you say test for validplot(currentBar)

                      Or I can simply load the secondary bars in the host script
                      and use a public method from the other indie ...so it is not unworkable.

                      MicroTrends
                      NinjaTrader Ecosystem Vendor - micro-trends.co.uk

                      Comment


                        #12
                        This is correct Tom, Add() the second series would be the 'cleanest' way, or you wait until you get a valid plot.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Hi

                          Ok thats great thank you for listening :-)

                          Tom
                          MicroTrends
                          NinjaTrader Ecosystem Vendor - micro-trends.co.uk

                          Comment


                            #14
                            IsValidPlot

                            Hello Josh,

                            re
                            You can do this through the .IsValidPlot property.
                            Does this mean we can rely on the IsValidPlot property being present (in iDataSeries) in the release version of NT 7?
                            Just asking because IsValidPlot does not seem to have made it into the documentation yet.

                            Comment


                              #15
                              Hello,

                              .IsValidPlot will not be in the documentation as this is internal property.

                              However what is in the documentation is .ContainsValue() which is what we suggest you use.

                              Let me know if I can be of further assistance.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,227 views
                              0 likes
                              Last Post xiinteractive  
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              440 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post FAQtrader  
                              Working...
                              X