Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Heiken Ashi[int BarsAgo]

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

    Heiken Ashi[int BarsAgo]

    Hello,

    my simple indicator works with

    if (BarsInProgress !=0) return;
    if(HeikenAshi().HAClose[0]<=HeikenAshi().HAOpen[0]) Backcolor=....;

    but there is no backcoloring with

    if (BarsInProgress !=0) return;
    if(HeikenAshi().HAClose[1]>HeikenAshi().HAOpen[1]
    && HeikenAshi().HAClose[0]<=HeikenAshi().HAOpen[0])
    Backcolor=....;

    What is the problem with BarsAgo here (as this works for Minute, Range....)

    Thanks
    Tony

    #2
    Originally posted by tonynt View Post
    Hello,

    my simple indicator works with

    if (BarsInProgress !=0) return;
    if(HeikenAshi().HAClose[0]<=HeikenAshi().HAOpen[0]) Backcolor=....;

    but there is no backcoloring with

    if (BarsInProgress !=0) return;
    if(HeikenAshi().HAClose[1]>HeikenAshi().HAOpen[1]
    && HeikenAshi().HAClose[0]<=HeikenAshi().HAOpen[0])
    Backcolor=....;

    What is the problem with BarsAgo here (as this works for Minute, Range....)

    Thanks
    Tony
    What is the error in your log?

    I expect it to say: "You are accessing an index with a value that is invalid since its out of range", in which case you need to escape your first bar.

    In which case, I would suggest that you look at my response in this tread.

    ref: http://www.ninjatrader.com/support/f...ad.php?t=41781
    Last edited by koganam; 09-18-2016, 09:47 AM.

    Comment


      #3
      Will there be an entry with close of downbar when COBC==true with this

      if(HeikenAshi().HAClose[1]>=HeikenAshi().HAOpen[1]
      && HeikenAshi().HAClose[0]<=HeikenAshi().HAOpen[0])

      or do I have to add "&& FirstTickOfBar"

      And how can one refer to HeikinAshi of another dataseries please?
      Same as "normal" and write "HeikenAshi().HACloses[2][0]..." to refer to 2nd added dataseries?

      Thanks
      Tony

      Comment


        #4
        Hello,
        The condition you provided would cause an order to be submitted after the close of the current bar when the previous bar is an up bar and the current bar is a down bar.

        To get the HeikenAshi of a secondary data series you would use HeikenAshi(IDataSeries input)
        For example if you wanted to get the current bar close of the secondary series heiken ashi you would use HeikenAshi(BarsArray[1]).HAClose[0]
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          thank you for your reply. When the entry is done at the close of the HeikenAshi bar then this is not the "real" price that moment, correct?

          And last question referring HeikenAshi please:

          When I add the HeikenAshi Indicator eg to a 5 Range-Bar-Chart then the Open and Close of the HeikenAshi Bar in the chart is different from the Open and Close of the 5 RangeBar. But what about High and Low, should they be the same? Or is it calculated in a different way and so not the "real" High and Low?

          Thanks
          Tony
          Last edited by tonynt; 09-23-2016, 07:27 AM. Reason: clearifying, translation error

          Comment


            #6
            Originally posted by tonynt View Post
            Hello,

            thank you for your reply. When the entry is done at the close of the HeikenAshi bar then this is not the "real" price that moment, correct?

            And last question referring HeikenAshi please:

            When I add the HeikenAshi Indicator eg to a 5 Range-Bar-Chart then the Open and Close of the HeikenAshi Bar in the chart is different from the Open and Close of the 5 RangeBar. But what about High and Low, should they be the same? Or is it calculated in a different way and so not the "real" High and Low?

            Thanks
            Tony
            Code:
                        HAClose.Set((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close
                        HAOpen.Set((HAOpen[1] + HAClose[1]) * 0.5); // Calculate the open
                        HAHigh.Set(Math.Max(High[0], HAOpen[0])); // Calculate the high
                        HALow.Set(Math.Min(Low[0], HAOpen[0])); // Calculate the low
            • So, other than for a balanced doji, the HAOpen and HAClose are never the same as the the Open and Close for the period.
            • The HAHigh and/or HALow may be the same as the High and/or Low for the period.
            Last edited by koganam; 09-23-2016, 07:43 AM.

            Comment


              #7
              I have a question about something very similar. It looks like these posts relate to Heiken Ashi changing from up to down or from green to red. I am using the same logic, except that instead of using 1 bar ago or 5 bars ago, I need code to determine if this has occurred within the last 5 bars. In other words, how do I use bars ago to be a range of closes rather than a specific number? Please advise.

              Comment


                #8
                Hello Birdjaguar,

                To do this you could use Most Recent Occurrence. The way this works is if the Close is greater than the open, in the last 5 bars, it’ll return the bars ago this was true. If the most recent was the current bar, a value of 0 will be set to xHappen. If there was never an occurrence, xHappen will be set to -1. If it happened three bars ago, xHappen will be set to 3.

                From the example I describe above,

                int xHappen = MRO(() => Close[0]> Open[0]==true,1,5);

                Please see Most Recent Occurrence section of our helpguide:


                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks. I checked the help guide and I tried similar code. But what I was really looking for was something that recognized any instance within the last five bars, not just one particular instance. So I went with a "lookback" statement instead of the MRO.
                  "CrossAbove(HeikenAshi().HAClose, HeikenAshi().HAOpen, 5)"

                  However, It is still not catching every instance. Any feedback will be appreciated.

                  Comment


                    #10
                    Hello birdjaguar,

                    I would suggest adding prints to confirm that these conditions indeed true at the times you suspect they’re being missed. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:

                    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


                    I’ve provided a link covering debugging which you may find helpful.

                    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

                    If you’d like to send a copy of the strategy you’re running, I can take a look and see if anything jumps out.

                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by alifarahani, Today, 09:40 AM
                    6 responses
                    39 views
                    0 likes
                    Last Post alifarahani  
                    Started by Waxavi, Today, 02:10 AM
                    1 response
                    18 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by Kaledus, Today, 01:29 PM
                    5 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Waxavi, Today, 02:00 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by gentlebenthebear, Today, 01:30 AM
                    3 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X