Visual basic coding for indicator

#1
Hello, I was wondering if anyone here could help me with some simple coding in Visual Basic.net.
I would like to get the formulation of Larry Williams A/D indicator in VB.net.
Right below I will give you a description of what the indicator is and will also include the code for Amibroker.
If some one could please get this translated to VB.net or preferebly RealCode I would greatly appreciate it.
Thanks

----------------------------------------------------------

This is the formula for it:

To calculate the Williams' Accumulation/Distribution indicator,
determine:

True Range High (TRH) = Yesterday's close or today's high whichever
is greater

True Range Low (TRL) = Yesterday's close or today's low whichever is
less

The day's accumulation/distribution is then calculated by comparing
today's closing price to yesterday's closing price.

If today's close is greater than yesterday's close: Today's A/D =
today's close - TRL

If today's close is less than yesterday's close: Today's A/D =
today's close - TRH

If today's close is the same as yesterday's close then the A/D is
zero.

The Williams' Accumulation/Distribution indicator is a cumulative
total of the daily values:

Williams A/D = Today's A/D + Yesterday's Williams A/D

Thus, the Williams' Accumulation/ Distribution indicator is used to
determine if the Forex market is controlled by buyers (accumulation)
or by sellers (distribution); and trading when there is divergence
between price and the A/D indicator.

The Williams A/D indicator recommends buying when prices fall to a
new low, yet the A/D indicator fails to reach a new low. Likewise,
sell when the price makes a new high and the indicator fails to
follow suit.

The code follows:

Barry

// Larry Williams' Accumulation/Distribution indicator

/*To calculate the Williams' Accumulation/Distribution indicator,
determine:
True Range High (TRH) = Yesterday's Close OR today's High whichever
is greater
True Range Low (TRL) = Yesterday's Close OR today's Low whichever is
less
The Day's accumulation/distribution is then calculated by comparing
today's closing price to yesterday's closing price.
if today's Close is greater than yesterday's Close: Today's A/D =
today's Close - TRL
if today's Close is less than yesterday's Close: Today's A/D =
today's Close - TRH
if today's Close is the same as yesterday's Close then the A/D is
zero.
The Williams' Accumulation/Distribution indicator is a cumulative
total of the daily values:
Williams A/D = Today's A/D + Yesterday's Williams A/D
*/

TRH = IIf(Ref(C, -1) > H, Ref(C, -1), H);
TRL = IIf(Ref(C, -1) < L, Ref(C, -1), L);
ad = IIf(C > Ref(C, -1), C - TRL, IIf(C < Ref(C, -1), C - TRH, 0));
WAD = Cum(ad);
Plot(WAD, "Williams AD", colorBlue);
Plot(ad, "AD daily", colorRed, styleOwnScale | styleNoLine |
styleNoLabel );

AddColumn(ad, "AD");
AddColumn(wad, "WAD");
Buy = Sell = C;
Filter = Buy OR Sell;

"Williams' Accumulation/ Distribution indicator is used to determine
if the Forex market is controlled by buyers (accumulation) OR by
sellers (distribution). \n\nTrade when there is Divergence between
price AND the A/D indicator.\n\nThe Williams A/D indicator recommends
buying when prices fall to a new Low, yet the A/D indicator fails to
reach a new Low. \n\nLikewise, Sell when the price makes a new High
AND the indicator fails to follow suit.";
 
#2
What is the data structure(s) for holding the price and volume ?
This code is going to be running in a platform, which manages the data structure for price and volume. So you would not have to worry about that.
The tranlation of the Williams A/D indicator ask above has been already coded and I will show you what it looks like.

'# Cumulative
Static williamsAD As Single
If isFirstBar Then
williamsAD = 0
Else If Price.Last > Price.Last(1) Then
williamsAD += (Price.Last - system.Math.Min(Price.Last(1), Price.Low))
Else If Price.Last < Price.Last(1) Then
williamsAD += (Price.Last - System.Math.Max(Price.Last(1), Price.High))
End If
Plot = williamsAD

As you see it is very simple - the RealCode language allows for it.
What I have in store to code is a little more extensive, but if you really understand the RealCode language it shouldn't be too difficult.

For example the following formula translated to RealCode is the beginning.
Could you code this:

If close <> close[-1] then
AD = AD[-1] + (close - min(low, close[-1]) +0.01) /(max(high, close[-1] -low)+0.01)

if close = close[-1] then
AD = AD[-1}


Thanks
 

Similar threads