Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time/Range Hybrid Bars: Creating A New Bar Type

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

    Time/Range Hybrid Bars: Creating A New Bar Type

    Let me preface this by saying my main question is could this idea be implemented in ninja trader. Secondly, are there any glaring holes or additions you would make. Also, a picture of a hand drawn diagram of how this new bar type would work is attached below. Referring to it should help you to make sense of the following word vomit. This would be a big project, but one I think has a lot of potential. The rest of the post will discuss what it is and its planned features.

    As the name suggests my goal is to build a new bar type a time (traditional) and range bar hybrid. The basic premise of this bar type is the X axis responds to two variables, price action (range bar) and time (traditional candles). It works using the OR operator. Each bar would have an internal timer that prints a new bar after a selected period of time OR after the selected range value has been exceeded.

    I've researched the ninjatrader ecosystem for potentially helpful projects and this bar timer indicator could be of use in crafting this new bar type, particularly for building the internal timer.

    https://ninjatraderecosystem.com/use.../nt8-bartimes/

    The goal of this hybrid bar type is to be able to keep up with the market when it moves fast in high volatility environments and reduce chop in low volatility environments.

    One of the main features of the bar type is that the thickness of each bar varies depending on what percent of the selected time threshold it took up. For example if the time threshold is set to 1 hour but the candle exceeds its set range in 30 minutes that bar will only be 50% the thickness of a bar that met the time threshold. The user should be able to select how wide 100% thickness is in order to tune the chart to their liking.

    Another feature is that at the end of RTH the current bar will be forced to print regardless of whether or not time or range has been met. The purpose of this is to reset the chart for the next day. The bars should also have no spacing between them and here's why. Due to how the width of each range bar dynamically adjusts by what percent of the time threshold it took up all bars printed for a day will take up the same amount of space on the X axis. By keeping the linearity of the time axis the trader will be able to get a very intuitive sense of the volatility of the market.

    This futures settlement lines indicator should contain some useful code for being able to build out this feature

    https://ninjatraderecosystem.com/use...ement-lines-2/

    This feature would limit the maximum useful time threshold to one day but is more than worth it in my opinion. An example would be a time threshold set to one day that prints a single a bar at 100% width. Then, the next day, 5 bars get printed each at only 20% width. The length along the X axis (time) for each full day remains constant as the bars whose range condition triggered automatically adjust their widths to fit within the specified width of a time threshold print. This same principle can be applied to any time threshold the trader desires (5 min 30min 1hr). The total length along the X axis (time) taken up by the hybrid bars will always be the same for each trading day even though a vastly different number of bars could print day to day.

    To create this feature bar width would need to be tied to time. I believe code from this equivolume bar type could be useful as here volume gets tied to bar width (just replace that with time)

    https://ninjatraderecosystem.com/use...e-chart-style/

    The idea for this Time/Range Hybrid bar type was born out of the fact that when using traditional time based bars, short time spans display excessive chop and noise. Meanwhile, longer time frames fail to capture the volatility of a fast moving market. Range/renko bars that completely ignore time do not allow for periods of accumulation to be displayed and do a poor job of putting volatility into perspective with regard to time. Basically, I realized that an X axis that only responds to price action or time will always be putting you at some sort of massive disadvantage. Especially if you like to use indicators to aid in your trading. The superior bar type would need to respond to both.

    An error correcting method to help avoid tiny end of session bars could be employed as well. It would be a statement something along these lines; if there is less than X amount of time left before the end of the session (value of which is determined by the user) do not print current bar until the end of the session, even if the range threshold is exceeded.

    A tool I've already theorized using this new bar type is a volatility trigger that will go off if the time taken for that bar to close is is less than X percent of the time threshold. That volatility trigger condition will remain true until the time taken for a bar to close is greater than Y percent of that threshold (unless it's the final bar of the day as that close is artificial. The volatility trigger would reset at the end of each trading day if it was active going into the close) This simple condition would allow for the creation of dynamic strategies that are Volatility dependent in a way exclusive to this bar type.
    Attached Files

    #2
    Hello StoneMan78,

    Thank you for the post.

    Without trying to build what you described it would be difficult to say if that is all possible or not. From what I can gather there is nothing that directly sticks out as not possible however there are a lot of details in your post so its possible some of your ideas may or may not work. If you have tried to build this and are having some difficulty I would suggest to create individual posts for those individual questions so we can try to focus on one concept at a time. You would otherwise likely need to find an existing bars type which does some of what you wanted or works similar and use that as a starting point You can view the existing bars types in the NinjaScript editor or view the user provided ones as well.


    Please let me know if I may be of additional assistance.






    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      I have not begun to build it yet, just finished the planning phase. There's a lot going on in the post so I'll get more specific with some follow up questions.

      1.) To your knowledge, could ninjatrader handle a new bar type that functions based off of either range or time? I'm a bit confused as to how the concept of Candlestick type ties into this and am wondering if it would get in the way of the design.

      2.) Could bar width be tied to a clock? And if so would that function apply to the width of a live bar or just historical bars (or could I manipulate both)?

      3.) How exactly does the ninjatrader engine handle bar generation, particularly for range bars, is it sequencial or more of an all at once approach? I was thinking of using this as my base and trying to add the internal timer to a range bar rather than add range capabilities to taditional candles.

      Thank you for your support. I have done some strategy and indicator development in ninja before but never a bar type. Trying to learn all that I can and get a game plan before I plow into this project.

      Comment


        #4
        Hello StoneMan78,

        1 the platform has both range and time based bars types, you can review the Range type or Minute for examples of range or time based bars types.

        2 The bars would need to be based on the historical/live data. I am not certain what you mean by a clock, if you mean can you build time based bars then yes, please see one of the existing time based bar series like Minute.
        The width of a bar would be controlled outside of the bars type in a chart style or with custom rednering. A bars type has nothing to do with rendering or displaying the bars but only making bars of data which other items like chart style or chart would use.

        3 All bars types work the same for how they process data, the OnDataPoint override is called for each datapoint of data. Depending on how the logic is coded for the bars type would determine how new bars are generated from that data. It would be difficult to explain the logic of a bars type in text, looking at how the logic works is a better approach to explore how each bar is built for a given type.

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


        Please let me know if I may be of additional assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          Thank you for your reply. I've layed out a work flow plan with some pre planned iterations to try to make the project more manageable. I've also identified a potential issue with the display idea which I'll outline first.

          Potential issue: when a candle starts its width will be so small you will not be able to see it. Perhaps I could give live candles a minimum thickness and the historical data can be displayed in the actual thickness regardless of how thin they end up being

          I guess the basic premise of this candle type is it prints a new candle based on 1.) A time threshold OR 2.) A range threshold OR 3.) At the end of the trading day

          The iterations begin with the most basic functionality then are built out from there.

          Iteration 1: would just focus on the time or range functionality, we will ignore the end of day print and the candle width.

          Iteration 2: would add the candle width functionality. You mentioned above that this is done with chart styling. Would this feature therefore need to be built using a separate script?

          Iteration 3: would add the end of day print.

          Iteration 4: would add the error correcting method I outline. Differentiate between live and historical candles to increase usability (fix potential issue). Fix any other issues that crop up.

          Iteration 1 will be where I begin to dive into the code and serve as the proof of concept. Any advice or resources you could give me for how to get that done? Thank you.


          Comment


            #6
            Hello StoneMan78,

            Potential issue: when a candle starts its width will be so small you will not be able to see it. Perhaps I could give live candles a minimum thickness and the historical data can be displayed in the actual thickness regardless of how thin they end up being
            If you wanted to render bars in a different way you would need to use a custom chart style. The chartStyle would work how you program it so if the bars are too small to see you would have to work around that by not making them too small to see initially.


            From your iterations the candle width would not be something involved in the bars type, you could use the bars type to generate bars of data and then a chart style to render that data in a way you like. Any calculations that are required to generate bars would need to go in the bars type and anything you are doing to display the bars would go in the chart style.


            Please let me know if I may be of additional assistance.



            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you for your reply that clears things up a lot for me. I'll continue to ask questions here on this thread as needed as I begin development on the project.

              Comment


                #8
                Hello Jesse,

                I have begun development on the project and started by combining the component parts of the minute and the range bar scripts together. It's a bit messy and I'm getting some errors I am hoping you could help me work through. My code and a screen shot of those errors will be attached below.

                Updated Task Log

                I have further split up the project into more manageable tasks. 1, 2, and 3 would each be separate scripts with 1 being a candle stick, 2 being a chart style and 3 being an indicator. I'll use this log as reference when asking future questions.

                Links to the Dvalue and bar timer indicator mentioned in the task log are pasted below.

                1a.) Create a candle type that prints on either range OR time based threshold

                1b.) Update that candle to be able to force a print at the end of a trading day, this would be done by selecting the session length and session start time. Give the user the option to also force a print at the start of the regular session. The Dvalue indicator does exactly this with its histograms. I will be able to use this code as reference. Should be able to copy significant parts of it.

                1c.) Implement option for an insignificant candle correcting method that prevents the range based threshold from printing a new candle if that candle is less than a set amount of time away from a forced print (discussed above)

                1d.) Create a clone where the data set is built from either minute or second bars (instead of tick) to improve performance on larger time scales

                2a.) Create a chart style that ties bar width to the bar timer indicator. I could use this on normal range/renko bars to test its functionality. The premise is any bar lasting longer than X time is 100% (Y) width. Any bar lasting a fraction of X time is that fraction of Y width. This style would put the bars directly next to each other like the equivolume bar style.

                2b.)Make it so the style can account for when the current candle is new by giving it a minimum width before it prints to ensure visibility.

                3a.) Build my volatility trigger off of the bar timer indicator. This could be implemented with for testing with range/renko bars. This gets some sort of time based measure involved with the range bars which is what the volatility trigger boils down to. The volatility trigger goes off if a candle prints in less than a set period of time. It stays active until a candle prints in greater than a set period of time.

                Bar timer indicator
                https://ninjatraderecosystem.com/use.../nt8-bartimes/

                Dvalue Indicator
                https://ninjatraderecosystem.com/use...ad/dvaluearea/
                Attached Files

                Comment


                  #9
                  Hello StoneMan78,

                  The image you attached is saying that there is a problem in the RangeTimeHybrid file. The files you attached are RangeTimeHybrid1 and compiled on my end. You may need to check if you have a duplicate file, the error specifically relates to the file which contains the class RangeTimeHybrid.


                  Please let me know if I may be of additional assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hello Jesse,

                    I fixed the file issue and did some additional work to try to give the bar type functionality. I realized I need to add in a way to allow for the selection of time and range into the data series portal. Not sure how exactly to accomplish this and weave it into the existing code. I wish I had other more pointed questions but as of now I'm just not sure how exactly the logic from the range and minute bars are meshing. I've left many comments in my code laying out some of the stuff I have done but I just can't figure out how to get the functionality I am looking for. Any guidance here would be greatly appreciated. The code is attached below.
                    Attached Files

                    Comment


                      #11
                      Hello StoneMan78,

                      To add user inputs you can use the Value and Value 2 properties. To give them custom names you can use SetPropertyName. If you take a look at the Range script on line 530 you will see how that is used. You can also see the Renko for examples of other properties which can be removed/renamed for use in your script. To use the property in your code you would use Value or Value2 or the property that you had renamed.

                      I otherwise didn't see any specific questions in the comments left in the file to clarify anything else. If you had other questions please feel free to post those.


                      Please let me know if I may be of additional assistance.
                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by aelagha, Today, 12:21 AM
                      0 responses
                      18 views
                      0 likes
                      Last Post aelagha
                      by aelagha
                       
                      Started by rcrook23, Today, 03:06 AM
                      1 response
                      11 views
                      0 likes
                      Last Post rcrook23  
                      Started by timekiller1985, Today, 02:46 AM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Jason  
                      Started by sidlercom80, Today, 01:19 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post sidlercom80  
                      Started by xxzbill, Yesterday, 04:07 PM
                      3 responses
                      14 views
                      0 likes
                      Last Post xxzbill
                      by xxzbill
                       
                      Working...
                      X