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

Williams Accumulation Distribution

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

    Williams Accumulation Distribution

    Hi,
    i am trying to contruct this indicator since i see it isn't available. i was wondering if you could help, or at least give me some clues to get started. The formula can be found here at the bottom of this webpage:

    Williams Accumulation Distribution is traded on divergences. When price makes a new high and the indicator fails to exceed its previous high, distribution is taking place.

    #2
    Hi there,
    I gave this a shot, here's what I ended up with. Seems to be correct from what I can tell. You can just plug this code into an empty indicator template.

    Add an array double[] williamsADs to your class variables somewhere and make your OnBarUpdate look like this:
    Code:
    protected override void OnBarUpdate()
    {
    	if(CurrentBar < 2)
    		return;
    
    	double trueRangeHigh, trueRangeLow;	
    	double priceMove, AD, williamsAD;
    	
    	priceMove = 0d;
    	// calculate true range high and low
    	trueRangeHigh = (High[0] > Close[1] ? High[0] : Close[1]);
    	trueRangeLow = (Low[0] < Close[1] ? Low[0] : Close[1]);
    
    	// compare closing price to yesterdays
    	if(Close[0] > Close[1])
    		priceMove = Close[0] - trueRangeLow;
    	else if(Close[0] < Close[1])
    		priceMove = Close[0] - trueRangeHigh;
    	else if(Close[0] == Close[1])
    		priceMove = 0d;
    	
    	AD = priceMove * Volume[0];
    	
    	williamsAD = AD + williamsADs[CurrentBar-1];
    	williamsADs[CurrentBar] = williamsAD;
    	Plot0.Set(williamsAD);
    	Print(String.Format("CurrentBar = {0}, williamsAD = {1}, williamsADs = {2}",
     CurrentBar, williamsAD, williamsADs[CurrentBar-1]));
    }
    does this look correct?

    Last edited by Dexter; 02-26-2011, 02:12 AM.

    Comment


      #3
      Thank you! It looks pretty good but i can't verify for sure yet.

      I'm not quite sure what you mean by "adding an array double williamsADs"

      The only thing i came up with was: double williamsADs = 1;
      But this is giving me a bunch of error messages & i don't really have any reason for putting the 1 in there b/c i dont think this indicator has any variables to plug in....

      Thanks

      Comment


        #4
        Sorry i dont really understand programming language : )

        Comment


          #5
          No worries, add this to your variables section to create an array:

          double[] williamsADs = new double[256];

          it should work after that, I can post it in entirety if you like

          Comment


            #6
            Not to take away from what is being discussed, isnt this the ADL indicator included in the NT7 distribution? NOT the same exact code, just the basics. OR I am on wrong track and apologize in advance

            "The Accumulation/Distribution (AD) study attempts to quantify the amount of volume flowing into or out of an instrument by identifying the position of the close of the period in relation to that periods high/low range."

            Comment


              #7
              Yeah, I just took a look at it and it appears to be very similiar, only lacking the running addition of previous day.

              look at this one liner
              AD.Set((CurrentBar == 0 ? 0 : AD[1]) + (High[0] != Low[0] ? (((Close[0] - Low[0]) - (High[0] - Close[0])) / (High[0] - Low[0])) * Volume[0] : 0));

              Comment


                #8
                Thanks again for your help Dexter, i added that in however i am getting 2 error messages:

                cannot implicitly convert type 'double[]' to 'double'
                cannot implicitly convert type 'double' to 'double[]'

                Comment


                  #9
                  here is everything together, you should be able to copy paste it:
                  Code:
                  double[] williamsADs = new double[256];
                  protected override void OnBarUpdate()
                  {
                  	if(CurrentBar < 2)
                  		return;
                  	double trueRangeHigh, trueRangeLow;	
                  	double priceMove, AD, williamsAD;
                  	
                  	priceMove = 0d;
                  	// calculate true range high and low
                  	trueRangeHigh = (High[0] > Close[1] ? High[0] : Close[1]);
                  	trueRangeLow = (Low[0] < Close[1] ? Low[0] : Close[1]);
                  
                  	// compare closing price to yesterdays
                  	if(Close[0] > Close[1])
                  		priceMove = Close[0] - trueRangeLow;
                  	else if(Close[0] < Close[1])
                  		priceMove = Close[0] - trueRangeHigh;
                  	else if(Close[0] == Close[1])
                  		priceMove = 0d;
                  	
                  	AD = priceMove * Volume[0];
                  	
                  	williamsAD = AD + williamsADs[CurrentBar-1];
                  	williamsADs[CurrentBar] = williamsAD;
                  	
                  	Plot0.Set(williamsAD);
                  }
                  I could actually rewrite it to be much more simple since the existing ADL indicator already does 90% of the math

                  Comment


                    #10
                    can you post all the collasped lines below that too? lines 83 & 84 on my page are what is where that error needs to be corrected. Here is what i have just below what you just posted...

                    #region Properties
                    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                    public DataSeries WillAD
                    {
                    get { return Values[0]; }
                    }

                    [Description("")]
                    [GridCategory("Parameters")]
                    public double WilliamsADs
                    {
                    LINE 83 get { return williamsADs; }
                    LINE 84 set { williamsADs = Math.Max(1, value); }
                    }
                    #endregion
                    }
                    }

                    Comment


                      #11
                      deleting the WilliamsADs property should fix it, just delete all of below:


                      [Description("")]
                      [GridCategory("Parameters")]
                      public double WilliamsADs
                      {
                      LINE 83 get { return williamsADs; }
                      LINE 84 set { williamsADs = Math.Max(1, value); }
                      }

                      Comment


                        #12
                        thanks so much for your help. i've compared it to what it looks like in another software & it looks to be very close. can i ask what the 256 is for?

                        Comment


                          #13
                          256 is how many elements the array used to store previous days AD hold, since the formula takes a running total of current day AD + yesterdays this was a simple way to store all the days ADs. Arrays are a type of data structure which contain several variables of the same type, in this case doubles of market data. You create them in C# using the [] brackets

                          Comment


                            #14
                            Thank you so much. You're the best!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Skifree, Today, 03:41 AM
                            1 response
                            4 views
                            0 likes
                            Last Post Skifree
                            by Skifree
                             
                            Started by usazencort, Today, 01:16 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post usazencort  
                            Started by kaywai, 09-01-2023, 08:44 PM
                            5 responses
                            603 views
                            0 likes
                            Last Post NinjaTrader_Jason  
                            Started by xiinteractive, 04-09-2024, 08:08 AM
                            6 responses
                            23 views
                            0 likes
                            Last Post xiinteractive  
                            Started by Pattontje, Yesterday, 02:10 PM
                            2 responses
                            23 views
                            0 likes
                            Last Post Pattontje  
                            Working...
                            X