Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

heiken ashi close

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

    heiken ashi close

    on a live chart the heiken ashi close does not compute correctly. per the HA bar script:

    Code:
    haClose        = bars.Instrument.MasterInstrument.RoundToTickSize((open + high + low + close) / 4.0);
    the attached pic shows a 154'06 open, 154'06 high, 154'01 low and 154'01 close. 154'01 was the bar's actual close. the HA close should be 154'03.

    why doesn't the heiken ashi bar type build in a live environment as it is programed to?
    Attached Files

    #2
    Hello jcash,

    Thank you for your post.

    Are you stating the 233 Tick bar's Open, High, Low, and Close were these values or the Heiken Ashi Bars Open, High, Low, and Close were these values?

    I would recommend you review the details on Heiken Ashi at the following link in our Help Guide: http://ninjatrader.com/support/helpG...HeikenAshiBars

    Comment


      #3
      the open is the haOpen (previous bar pic is attached), the high is the haHigh and the low is the haLow. the close is what is incorrect.

      so on live data the close is not the haClose, but the actual close. why?
      Attached Files

      Comment


        #4
        this issue with the close calculation on heiken ashi bars was brought up by user EURLSD back in August:



        what was the result of investigation?

        Comment


          #5
          Hello jcash,

          Thank you for your patience.

          Calculated values will be rounded to the instrument's nearest tick size. This is done to ensure accuracy in order submission and execution during backtesting. So the Close is rounded to the nearest Tick, this is in fact different from NinjaTrader 7.

          Comment


            #6
            In short, for the future readers, the Heikin-Ashi candle Close in NT8 is currently not calculated as olhc/4 , but is something closer to equal to the regular candle close.
            This makes is quite unreliable for standard purpose use, so be careful.

            If you need more assistance send me a direct message.
            Last edited by regular_guy; 10-08-2021, 12:28 PM.

            Comment


              #7
              Hello regular_guy,

              Thank you for your reply.

              The calculation for the Close value of the Heikin Ashi bars is below;

              haClose = bars.Instrument.MasterInstrument.RoundToTickSize(( open + high + low + close) / 4.0);

              It is indeed calculated by adding the sum of the OHLC and dividing by 4. However, it is rounded to the nearest tick, as my colleague has previously stated. This is most definitely a different calculation than a standard candlestick.
              Zachary S.NinjaTrader Customer Service

              Comment


                #8
                Yes, I checked the code. But seeing that something is written in the code correctly doesn't mean that the script reaches it or that it isn't overwritten later

                NT8 is great and I like it. But the Heikin-Ashi minute candles close is wrong. Just open your program, Zachary. Make some calcs.

                Click image for larger version

Name:	ha NT.png
Views:	369
Size:	81.3 KB
ID:	1174419

                As it's unlikely for the support to admit this, as I said, contact me via private message if you need a workaround.

                Comment


                  #9
                  Hello regular_guy,

                  Thank you for your reply.

                  So far, in calculating the close of a bar across a number of different instruments using Minute bars and the corresponding Heikin Ashi bars, I have gotten the values that I would expect using the formula that I had previously provided.

                  So that I may try to create the issue that you are experiencing, please let me know what data provider you are using (For example, Kinetick, NinjaTrader Continuum, Rithmic, etc.).

                  Additionally, please tell your local time zone.

                  I look forward to your response.
                  Zachary S.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Zachary,

                    In order to replicate the issue you need to use >1 unit Heikin-Ashi bars. Calculate it with 30min for example, or with 5day.
                    You can follow the problem specifications as follows.

                    1. As HA bars are custom bars, they are based on a base dataset used to build the custom bars type. More info here:

                    On the same page, at the bottom with the examples, we also read the following:
                    BuiltFrom = BarsPeriodType.Minute; // update OnDataPoint() every minute on historical data
                    2. The code you provided above is correctly the responsible script for the HA calculation.
                    Code:
                    haClose = bars.Instrument.MasterInstrument.RoundToTickSize(( open + high + low + close) / 4.0);
                    Note, that this code is located within the OnDataPoint class method and with this it is subject to updating every 1 unit (every 1 tick, minute or day).

                    Thus, the parameters passed to the OnDataPoint method (amongst them open, high, low, close) are provided every minute. This isn't a problem with the ha-Open, and the High and Low are coded correctly with this snippet
                    Code:
                    Math.Max(high, bars.GetOpen(bars.Count - 1))
                    But the code for the ha-Close calculates the value based on the OLHC/4 values for the last 1 minute of the period - for example for the 1:59:00 - 2:00:00 time interval of a chart that could be with 60-minute candles (correct interval 1:00:00 - 2:00:00).

                    Comment


                      #11
                      Hello regular_guy,

                      Thanks for sharing what you have found.

                      That put me on a different path for understanding the issue with realtime bar formations in our BarsType, and I have drafted some changes that appear to show the results we should expect.

                      I am discussing with Quality Assurance and Development if these changes would be acceptable for merging into NinjaTrader's BarsType.

                      If the changes are accepted, I'll share what I have put together for a midterm fix as we will have to wait until a new release of NinjaTrader to update the BarsType.

                      I will keep you posted as this develops.



                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        Hello Jim, can you share the solution that you have drafted? I created a new Heikin-Ashi bars type that is working for me locally, but I guess your update will be far more elegant.
                        I was hoping to see it in the new version update 8.0.25, but to no avail

                        Comment


                          #13
                          Hello regular_guy,

                          My changes improve the situation, but there were some discrepancies I found with historical data that I have not yet solved. The changes are also not exactly more elegant, but the idea was to update private "actualHigh" and "actualLow" variables before UpdateBar, and to reset them after AddBar.

                          I have attached the source code for the modified BarsType, and I have attached indicator source code for HeikenAshi8Rounded, and HeikenAshiChecker. HeikenAshiChecker can be added to the modified HeikenAshi chart and will print out what bars do not match the rounded indicator calculation.

                          If you have better results testing your BarsType with the HeikenAshiChecker indicator, I would like to see what you are doing so we can see about incorporating changes to our BarsType that make it 100% accurate.
                          Attached Files
                          JimNinjaTrader Customer Service

                          Comment


                            #14
                            I see we used the same approach. Here is what works for me (this is only for the minute bars, I didn't update it for the other timeframes). Hope it helps for future releases.

                            Code:
                            private double candleOpen;
                            private double candleHigh = -99999999.99;
                            private double candleLow = 99999999.99;
                            
                            ...
                            
                            if (bars.Count == 0)
                            AddBar(bars, open, high, low, close, TimeToBarTime(bars, time, isBar), volume);
                            else if (!isBar && time < bars.LastBarTime)
                            {
                            //Real-time updating, OLHC are all last tick price
                            candleHigh = Math.Max(high, candleHigh);
                            candleLow = Math.Min(low, candleLow);
                            
                            haClose = bars.Instrument.MasterInstrument.RoundToTickSize(( candleOpen + candleHigh + candleLow + close) / 4.0);
                            haHigh = bars.Instrument.MasterInstrument.RoundToTickSize(Math.Max(high, bars.GetOpen(bars.Count - 1)));
                            haLow = bars.Instrument.MasterInstrument.RoundToTickSize(Math.Min(low, bars.GetOpen(bars.Count - 1)));
                            UpdateBar(bars, haHigh, haLow, haClose, bars.LastBarTime, volume);
                            bars.LastPrice = close; //used to show real last price on chart and not calculated ha-close
                            }
                            else if (isBar && time <= bars.LastBarTime)
                            {
                            //Historical updating on each 1 unit (tick, minute or day). In my case - each minute
                            candleHigh = Math.Max(high, candleHigh);
                            candleLow = Math.Min(low, candleLow);
                            
                            haClose = bars.Instrument.MasterInstrument.RoundToTickSize(( candleOpen + candleHigh + candleLow + close) / 4.0);
                            haHigh = bars.Instrument.MasterInstrument.RoundToTickSize(Math.Max(high, bars.GetOpen(bars.Count - 1)));
                            haLow = bars.Instrument.MasterInstrument.RoundToTickSize(Math.Min(low, bars.GetOpen(bars.Count - 1)));
                            UpdateBar(bars, haHigh, haLow, haClose, bars.LastBarTime, volume);
                            }
                            else
                            {
                            //New bar creation - both historical and real-time
                            haOpen = bars.Instrument.MasterInstrument.RoundToTickSize(( bars.GetOpen(bars.Count - 1) + bars.GetClose(bars.Count - 1)) / 2.0);
                            haClose = bars.Instrument.MasterInstrument.RoundToTickSize(( open + high + low + close) / 4.0);
                            haHigh = bars.Instrument.MasterInstrument.RoundToTickSize(Math.Max(high, haOpen));
                            haLow = bars.Instrument.MasterInstrument.RoundToTickSize(Math.Min(low, haOpen));
                            time = TimeToBarTime(bars, time, isBar);
                            AddBar(bars, haOpen, haHigh, haLow, haClose, time, volume);
                            
                            candleHigh = -99999999.99;
                            candleLow = 99999999.99;
                            candleOpen = open;
                            }

                            Comment


                              #15
                              Hello regular_guy,

                              Thanks for sharing your perspective.

                              Code:
                              candleHigh = -99999999.99;
                              candleLow = 99999999.99;
                              candleOpen = open;
                              I wouldn't recommend this but would instead recommend assigning low and high to candleLow and candleHigh after AddBar. I get different results if I do what you do in my modification, and the results do not match the rounded indicator.

                              I discovered my discrepancy with historical data. The original bars type was calculating HeikenAshi values for the first bar, and I changed this so the first bar is always the original bar. This helps ensure the bars will match the indicator plots.

                              I'm having some colleagues check my work before I send it back to Quality Assurance and Development. I'm also attaching my latest changes here if you would like to test. I was able to test historical formations for all base barstypes (with BaseBarPeriodValues of 1 and greater than 1) I did not get to test realtime formations today. Please be sure to clear your bar cache (Documents\NinjaTrader 8\db\cache\) before testing this barstype.

                              Update:

                              We have reviewed the changes made, but will not be including with production releases of NinjaTrader since any scripts built using the legacy BarsType will have different results if these changes are included by default. I submitted my changes to the User App Share so the BarsType may be downloaded from there.

                              When the script is live on the User App Share, the submission thread will be updated with a link to the file.

                              Attached Files
                              Last edited by NinjaTrader_Jim; 02-01-2022, 02:48 PM.
                              JimNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderBCL, Today, 04:38 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post TraderBCL  
                              Started by martin70, 03-24-2023, 04:58 AM
                              14 responses
                              106 views
                              0 likes
                              Last Post martin70  
                              Started by Radano, 06-10-2021, 01:40 AM
                              19 responses
                              609 views
                              0 likes
                              Last Post Radano
                              by Radano
                               
                              Started by KenneGaray, Today, 03:48 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post KenneGaray  
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              471 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Working...
                              X