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

Coding Custom Range Bars

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

    Coding Custom Range Bars

    PLEASE can someone help. I have been at this for almost a week now.
    All I want to do is create custom range bars (real time) with the following logic.
    The logic is extremely easy in backtesting...Just the syntax for code in the 'type' directory for live bars.
    * Enter the Bar Height in ticks.
    * Every Close must have actually been traded.
    * The next Open must equal the previous Close...At The Exact Same Tick, Time, and Price.
    * There can Never be a bar < the requested bar height.
    * Never close a bar before the requested bar height is reached.
    Not overnight, Not in a new session, Not over a holiday, etc.
    * As soon as the bar height is reached or exceeded, Close it and put the volume
    in that bar...AND immediately open the next bar On That Exact Same Tick
    with a Volume of 0.
    * If there is a Gap beyond the requested Bar Height, fine, Close that bar on that price & open a new one at that same price...Even is no 2nd trade is made at that price. DO NOT create Dummy/Phantom bars that show bogus/untraded Close values.

    #2
    Originally posted by ChuckAllen View Post
    PLEASE can someone help. I have been at this for almost a week now.
    All I want to do is create custom range bars (real time) with the following logic.
    The logic is extremely easy in backtesting...Just the syntax for code in the 'type' directory for live bars.
    * Enter the Bar Height in ticks.
    * Every Close must have actually been traded.
    * The next Open must equal the previous Close...At The Exact Same Tick, Time, and Price.
    * There can Never be a bar < the requested bar height.
    * Never close a bar before the requested bar height is reached.
    Not overnight, Not in a new session, Not over a holiday, etc.
    * As soon as the bar height is reached or exceeded, Close it and put the volume
    in that bar...AND immediately open the next bar On That Exact Same Tick
    with a Volume of 0.
    * If there is a Gap beyond the requested Bar Height, fine, Close that bar on that price & open a new one at that same price...Even is no 2nd trade is made at that price. DO NOT create Dummy/Phantom bars that show bogus/untraded Close values.
    Hi Chuck,

    I created a chart type a couple years back that does most of what you want.

    Its called RangeNoGap. It does not reset at midnight. There are no price gaps from bar to bar. There is no faux volume or price fill that I'm aware of.

    I give it away for free at my web site.

    http://www.innovative-trading-solutions-online.com/new/ninjatrader-charts/

    Help yourself,

    RJay

    PS: I offer free trials on all purchase products should you want to try them out.
    Last edited by RJay; 01-11-2013, 05:47 PM.
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      Originally posted by ChuckAllen View Post
      PLEASE can someone help. I have been at this for almost a week now.
      All I want to do is create custom range bars (real time) with the following logic.
      The logic is extremely easy in backtesting...Just the syntax for code in the 'type' directory for live bars.
      1 * Enter the Bar Height in ticks.
      2 * Every Close must have actually been traded.
      3 * The next Open must equal the previous Close...At The Exact Same Tick, Time, and Price.
      4 * There can Never be a bar < the requested bar height.
      5 * Never close a bar before the requested bar height is reached.
      Not overnight, Not in a new session, Not over a holiday, etc.
      6 * As soon as the bar height is reached or exceeded, Close it and put the volume
      in that bar...AND immediately open the next bar On That Exact Same Tick
      with a Volume of 0.
      7 * If there is a Gap beyond the requested Bar Height, fine, Close that bar on that price & open a new one at that same price...Even is no 2nd trade is made at that price. DO NOT create Dummy/Phantom bars that show bogus/untraded Close values.
      Lines in red sound contradictory. Assume an unclosed bar (height not reached) on close of day. Next session opens with a gap.

      According to these directions, do not open a new bar because there were no trades on the prices in between the close and next open (#7), and the last bar on close was not completed in height (#4, 5, 6). Normal Range Bars would fill the gap with dummy bars for continuity.

      Range bars can never close and open next at the same price, because the completion of one bar requires a tick beyond the bar range. If you opened the new bar as soon as the range is met, what happens if the price retreats? Do you delete the new bar and come back to the old, or do you let the 2 bars completely overlap?(#3) If they are to completely overlap, the advantage of range bars being time independent is lost, as you can then have multiple overlapping bars showing no range change, instead of a single bar showing that a range has not been completely traversed.
      Last edited by koganam; 01-11-2013, 06:06 PM.

      Comment


        #4
        The spec is perfect! Several types of range bars have Fake bars that show trades that were never made. These bars show EXACTLY what they are intended to show.
        Almost All logic performs trades at the Close of a bar...These bars do that perfectly.
        If a price retreats...so be it. That's what slippage is for. Their design will dramatically improve almost any trading system. I have worked with several people who have created their flavor of Range Bars, but almost all have several flaws...all bars do, but these are extremely close to being perfect in my opinion. Why wait for price to Exceed the bar...You can't make a trade at the Close when its already past! Several bars try to show good backtesting results by taking trades at the Close on these bogus bars! You automatically have to add at least 1 tick to all trades and backtest calculations. When I trade these bars, I get over 95% of my trades Exactly at the Close. The only problems are during extremely fast trading and very thin markets at night. Please consider trying them in real trading & see for yourself.

        Comment


          #5
          Originally posted by ChuckAllen View Post
          The spec is perfect! Several types of range bars have Fake bars that show trades that were never made. These bars show EXACTLY what they are intended to show.
          Almost All logic performs trades at the Close of a bar...These bars do that perfectly.
          If a price retreats...so be it. That's what slippage is for. Their design will dramatically improve almost any trading system. I have worked with several people who have created their flavor of Range Bars, but almost all have several flaws...all bars do, but these are extremely close to being perfect in my opinion. Why wait for price to Exceed the bar...You can't make a trade at the Close when its already past! Several bars try to show good backtesting results by taking trades at the Close on these bogus bars! You automatically have to add at least 1 tick to all trades and backtest calculations. When I trade these bars, I get over 95% of my trades Exactly at the Close. The only problems are during extremely fast trading and very thin markets at night. Please consider trying them in real trading & see for yourself.
          I agree with you. The specs are certainly perfect if that is the way that you want to think about trading. I am sure all those who have custom range types think that their solutions are perfect too, and they are: for them. I notice though that you never did answer my question as to how you handle session gaps after an incomplete bar on the close, when your spec specifically says that no bar can be less than the defined height.

          I was not saying that your spec is not perfect. I was saying that some of the conditions are impossible to meet in an absolute sense. If a bar is incomplete and the next one starts after a gap, and only traded prices can be marked, then it is impossible to have those 2 bars with one closing at a price and the next one opening at the same price, because nothing traded in the gap. Maybe if you care to sketch out the gap situation. it might be clearer what I mean. OTOH, if you want to say that the last bar of the session need not be complete, and the next session bar should start at the opening price, that takes care of the gap neatly. It is just impossible to have both compete bars where there is no trade, and also handle gaps if the spec says that there are to be no gaps.

          All the best in your quest.

          Comment


            #6
            Range Bars With Accurate Closing Values

            Time is completely ignored!
            If you request 3 point bars and the Last bar of the day/session/holiday, etc. is from 100-101, you have a 1 point bar that is incomplete at the end of that period.
            If you have the exact same condition just before a big report...Same thing. You have an incomplete 1 point bar at that time.
            When the session/next day/after report/etc. opens at 110 with No Trades between 101 and 110, the bar finally closes at 110. The next bar Immediately is opened at 110, with a 0 volume. Any trades from that point on are reflected in that next bar. So that previous bar goes from 100-110. This shows Valid Closing Prices and the exact gap. It is extremely easy to see the actual market movements. Whenever there is a bar > the requested size, you have a Gap and can work it into your Gap Logic. Its very easy to know that the gap was between the request bar height and the actual bar height.
            Now, all Closes are valid, and can be traded/analyzed as such.
            We also have a continuous flow of data and the indicators run against them are always valid. You don't have to guess why your trade @ 105, 106, 107,... wasn't taken.
            This was especially painful AND cost me a bunch of money when I backtested with other products that did not have valid Closes. They showed bogus trades at prices that never could be taken. Some platforms Actually Cannot Tell where the Close was and take a valid trade in backtesting! This is the same basic reason that several bar types cannot actually be traded automatically!!
            * The Main Problem I am having with Ninja and creating these bars is when one or more bars exist in a row with 1 price per tick bar. My code/Ninja tends to lump these prices into 1 bar instead of 3, 4, 5, etc. separate bars that are the correct bar height. I started with Ninja's released Range Bar code & their "time, open, high, low, close" variables are right on! But, if you compare the "bar.Time, bar.Open, bar.High...", they are at least 1 bar off. The date/time reflects the previous bar. The price values are way off. The prices seem to be the highest & lowest values for some type of period. The guts of the code is contained in basically 3-5 lines, and I just can't seem to figure out what is going on behind the scenes!
            *
            If high - low >= RequestedBarHeight
            Close the current bar
            Open the next bar where the O,H,L,C all use that Closing Value & 0 Volume
            else
            Update the incomplete bar.
            * THAT's IT!
            * Any Help Would Be Dramatically Appreciated!!!
            * Thanks for the discussion

            Comment


              #7
              Also interested in this Range bar type

              ChuckAllen

              Have you had any luck with getting this bar type? I am also interested in a range bar that will close the current candle on touch instead of having to trade through the price.

              Thanks

              Steve

              Comment


                #8
                Range Bars, No Gap, Close When Price &gt;= Range

                Yes, finally. Ninja does some crazy things behind the scene. The logic is extremely simple, but getting it to work is very difficult. I went through 4 contractors and just over 2 weeks of development. It seems that Ninja also keeps bars someplace and Does Not Rebuild Them when you back test or reload the chart. The only logic is really...When the price Touches the requested range, Close the current bar, Put that volume in the current (just Closed) bar, Open the next bar at that exact same price, volume = 0. There is Never a gap. Never Close a bar otherwise.

                Comment


                  #9
                  Are you able to share or is it proprietary?

                  Are you able to share or is it proprietary? Or can you give a little guidance on the starting point?

                  Thanks

                  Comment


                    #10
                    I own the rights to the logic and code/bars on Ninja. I am the CIO of a new future's fund. I cannot give the right away directly. Mark Jurik and I worked on the logic for over a month. He owns some similar, but not exactly the same, logic and code on Trade Station. I am interested in several improvements to my systems and/or indicators. If you have something that may be of interest, we should be able to work something out. I will need a non disclosure agreement. One of my problems is back testing. If you have a way to get around the drastic import limitation of OHLC bars that won't accept anything less than HHMM...I would be extremely interested. Please feel free to contact me on these bars or anything else.I will try to send a personal message later.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by kevinenergy, 02-17-2023, 12:42 PM
                    117 responses
                    2,766 views
                    1 like
                    Last Post jculp
                    by jculp
                     
                    Started by Mongo, Today, 11:05 AM
                    5 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by traderqz, Today, 12:06 AM
                    8 responses
                    16 views
                    0 likes
                    Last Post traderqz  
                    Started by SightCareAubetter, Today, 12:50 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post SightCareAubetter  
                    Started by Skifree, Today, 03:41 AM
                    5 responses
                    14 views
                    0 likes
                    Last Post Skifree
                    by Skifree
                     
                    Working...
                    X