Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set last complete bar based on Calculation

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

    Set last complete bar based on Calculation

    NT Forum,

    Please find attached two indicators :
    - ExampleIndicator, and
    - HostIndicator.

    The crux of ExampleIndicator is simple. It attempts to set the _lastCompleteBar based on the value of Calculation. This _lastCompleteBar would be used in indicator calculations but is outside of this question.
    Code:
    _lastCompleteBar = Calculate == Calculate.OnBarClose ? 0 : 1;
    This issue is _lastCompleteBar is only evaluated when the Indicator is added to a chart.
    To illustrate:
    1. Add ExampleIndicator to chart (NinjaScript Output window prints as expected)
    2. In NinjaScript Editor, change the Calculation to OnPriceChange and compile
    3. Refresh the chart (NinjaScript Output window does NOT print as expected)
    4. Remove ExampleIndicator from chart
    5. Add ExampleIndicator to chart (NinjaScript Output window again prints as expected)

    Please find a brief video showing above at http://screencast.com/t/t36pAQyU

    The HostIndicator simply "hosts" ExampleIndicator with the potential to "host" other indicators. The purpose is to set and align Calculation of ExampleIndicator with the Calculation of other indicators.

    While a long winded, is there a better approach to effect this functionality?
    Both the hosting and aligning functionality, and negating the requirement to remove and re-add an indicator to have it correctly evaluate _lastCompletedBar.

    Thanks
    Shannon
    Attached Files
    Last edited by Shansen; 08-01-2016, 01:30 PM.

    #2
    Hello Shannon,

    Thank you for your post.

    The attachments did not come through. May I ask that you attach the two files indicated in your post?

    Comment


      #3
      Apologies. The attachments are now attached to the original post.

      Comment


        #4
        Hello Shansen, and thank you for your question.

        If I understand your goals correctly, I believe you would benefit from a single multi-time frame indicator with layered session templates. I am including some help guide documentation on both multi-time-frame indicators and how session templates are applied.



        Here are some complete code samples where this approach has been implemented.



        If this was not quite what you were looking for, could you clarify your goal and where I missed the mark in plain language? Please also let us know if there are any other questions we could answer.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          JessicaP,

          Thank you for your quick reply. Sorry to say your very complete response missed the mark. Apologies for my lack of clarity in the original question.

          I have several indicators which are designed (I hope) to broadly operate the same whether calculated at the end of each bar (i.e. OnBarClose) or calculated intrabar (i.e. OnEachTick or OnPriceChange).

          These indicators create and retain a collection of previous price data (or calculated data). Data is collected once and only once per complete bar and as soon as the bar is complete. Where Calculation is OnBarClose, this is simple. OnBarUpdate occurs once per bar, at the point Bar[0] is complete. Data can be collected from Bar[0] (lastCompleteBar = 0).

          Where Calculation is intrabar, it requires a little more structure. OnBarUpdate occurs multiple times per bar. However IsFirstTickOfBar occurs once per bar, at that point Bar[1] is complete. Data can be collected from Bar[1] (lastCompleteBar = 1).

          As I have several such indicators, using a "HostIndicator" (similar to HostIndicator) I've attempted to synchronize each of their respective Calculation settings which in turn adjusts each of their lastCompleteBar settings. However, after attempting to debug unexpected behaviour for a week, I found the issue was resolved by removing the "HostIndictor" from the chart and re-adding it. Similar behaviour as demonstrated with ExampleIndicator.

          I hope to remove the possibility of having this unexpected behaviour reoccur. I wish to understand whether the behaviour demonstrated is in line with how NT8 is intended to operate. If it is not, please suggest this for development.

          That said, while it is my understanding both the above OnBarClose and intrabar approach work correctly through Historical, Transition and Realtime States, I imagine I am not the only one to tackle this problem. Where a better solution exists, I am all ears.

          Again thanks
          Shannon

          Comment


            #6
            Thank you for this additional information Shansen.

            First I would like to address this.

            I hope to remove the possibility of having this unexpected behaviour reoccur
            To verify, the interaction between indicators and strategies added to other indicators and strategies, especially with regard to their data series, is in fact an area under active development. We are working very hard and making changes in this area. As such, if you do see indicators not behaving correctly when added to other indicators, it is best if you can first attempt to reproduce what occurred with built-in indicators such as the SMA, and then if you could report it to us.

            Or in fewer words, what you are trying to do is supported, but because we are working on it, changes we make may break your code.

            If you are looking for suggestions, it seems your approach is a valid approach. I would only like to suggest that the calculation mode for your host indicator be set to OnEachTick , since everything below it will have as granular or less granular data.

            Since you would like to avoid situations like the one you experienced, and because you are working in an area of active development, the best answer I can give is to suggest organized software testing. This publicly available blog sponsored by Microsoft has a terrific approach toward testing and is, in my opinion, worth reading.



            Since there is a lot there, if you are like me and you prefer skimming down to the information important to you, I can provide you with some keywords. I apologize in advance if this is information you already have, I am providing this with the intention of giving you a complete answer only.

            • Testing your "guest" indicators by themselves is known as unit testing
              • You can unit test your host too by creating a very simple "do nothing" guest indicator. That guest indicator is then called a "stub"

            • Testing a single "guest" indicator together with your "host" is called "integration testing"
            • Testing all the guests you intend to use together with your host is called "systems testing"

            Please let us know if there are any other ways we can help.
            Last edited by NinjaTrader_JessicaP; 08-02-2016, 09:58 AM.
            Jessica P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Today, 06:40 PM
            0 responses
            4 views
            0 likes
            Last Post algospoke  
            Started by maybeimnotrader, Today, 05:46 PM
            0 responses
            7 views
            0 likes
            Last Post maybeimnotrader  
            Started by quantismo, Today, 05:13 PM
            0 responses
            6 views
            0 likes
            Last Post quantismo  
            Started by AttiM, 02-14-2024, 05:20 PM
            8 responses
            168 views
            0 likes
            Last Post jeronymite  
            Started by cre8able, Today, 04:22 PM
            0 responses
            9 views
            0 likes
            Last Post cre8able  
            Working...
            X