[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [amibroker] Re: Relative Volume by time



PureBytes Links

Trading Reference Links



This is what I use
I modified Bill Schmidt's code

z is the z score
Rajiv
 
 
H1=V;
Avgvol=0;
sqsum=0;
relsd=0;
if (Interval()<inDaily) {
n = round(3600*6.75/Interval());  //number of bars in the day
barnum = BarsSince(Day()!=Ref(Day(),-1)); //bar number from start of the day
for (i=0; i<n; i++) {
VarSet("vol"+i,IIf(i==barnum,H1,0));
VarSet("vols"+i,IIf(i==barnum,H1*H1,0));
}

for (i=0; i<n; i++) {
Avgvol=IIf(barnum==i,Sum(VarGet("vol"+i),n*d)/d,Avgvol);
sqsum=IIf(barnum==i,Sum(VarGet("vols"+i),n*d)/d,sqsum);
}

relsd=sqrt(sqsum-(Avgvol*Avgvol));
}
// Z-Score
z=100*((H1-Avgvol)/relsd);
 

To: amibroker@xxxxxxxxxxxxxxx
From: angus@xxxxxxxxxxxxx
Date: Tue, 5 May 2009 18:39:22 +0000
Subject: [amibroker] Re: Relative Volume by time



Hi Etoke,

I tried to code this formula some time ago and run into the same problem. I didn't manage to fix it as my programming skills are a little lacking, however I believe the problem is that the AvgVol referenced for the StDev calculation is not the last calculated value.

As I understand it (in other words this could be wrong), if the last bar is todays time 09:15, the AvgVol for the last 5 days is caculated. Then the loop subtracts Vol[0] of now - AvgVol[0] of now, Vol[0] of yesterday - AvgVol[0] of yesterday (thus not the AvgVol calculated now but from yesterday) and so on. The AvgVol variable is changing in the loop instead of remaining static with the final calculated value.

I hope this makes sense / helps.

Could you post a copy of the code when you have it figured out?

Thanks.

Tip2012

--- In amibroker@xxxxxxxxxps.com, "etoketrader" <etoke420@xx.> wrote:
>
> Hi all once again.
>
> I have been able to create the indicator I was after with one issue,
> which maybe somebody with better math skills than me could help me with
> [:)] . Basically it is a variation on a standard formula already in the
> library and does the following:
>
> The code below works for sub 15 minute charts, and will show volume in
> 15 minute segments.
>
> 1. It plots current volume over the average volume for a specific 15
> minute timeframe.
> 2. If plots standard deviation bands above and below the average volume
> in order to put the current volume relative to the average volume in
> better context.
>
> My problem is with the standard deviation : It shows something close,
> but not the same, as the standard deviation I calculate manually in
> Excel. Like the average volume, the standard deviation is also per 15
> minute timeperiod.
>
> Below is the code. Can anybody spot anything wrong with the standard
> deviation calculation??
>
> eToke.
>
> TimeFrame = 900; //15 minute
> n = (3600*6.5)/timeframe;// number of bars in day
>
> TimeFrameSet(timeframe);
> Avgvol=0;
> StdDev=0;
> d = 5;
> barnum = BarsSince(Day()!=Ref(Day(),-1)); //bar number from start of the
> day
> for (i=0; i<n; i++) {
> VarSet("vol"+i,IIf(i==barnum,V,0));
> }
> for (i=0; i<n; i++) {
> Avgvol=IIf(barnum==i,Sum(VarGet("vol"+i),n*d)/d,Avgvol);
> VarSet("AvgVol"+i,IIf(i==barnum,Avgvol,0));
> }
> for (i=0; i<n; i++) {
>
> StdDev=IIf(barnum==i,sqrt(Sum((VarGet("vol"+i)-VarGet("AvgVol"+i))*VarGe\
> t("vol"+i)-VarGet("AvgVol"+i)),n*d)/d),StdDev);
> }
>
> CurrentVolume = Ref(V,1);
> AvgVol = Ref(AvgVol,1);
> VolStdDev = Ref(StdDev,1);
>
> TimeFrameRestore();
>
> AvgVol = TimeFrameExpand(AvgVol,timeframe);
> VolStdDev = TimeFrameExpand(VolStdDev,timeframe);
> CurrentVolume = TimeFrameExpand(CurrentVolume,timeframe);
>
> Plot(CurrentVolume,"Volume",colorGreen,styleHistogram);
> Plot(Avgvol-VolStdDev,"Lower",colorDarkRed,styleHistogram|styleThick);
> Plot(Avgvol,"Avg Vol",colorRed,styleHistogram|styleThick);
> Plot(Avgvol+VolStdDev,"Upper",colorPink,styleHistogram|styleThick);
> Plot(0,"ZeroLine",colorBlack,styleNoTitle|styleNoLabel);
>
>
> --- In amibroker@xxxxxxxxxps.com, "etoketrader" <etoke420@> wrote:
> >
> > Hi everybody,
> >
> > I am trying to create a relative volume indicator which would plot a
> volume bar relative to it's moving average by timeframe.
> >
> > If this is done across all timeframes, then the code would be very
> simple.. for example :
> >
> > RelativeVol = V - MA(V,20)
> >
> > However what I am looking for is to be able to compare the current
> volume with the MA of the equivalent bar of the same time, so for
> example the Volume of the 9:30 bar is compared to the moving average of
> the 9:30 bars of the previous 20 days.
> >
> > Is there a straightforward method of coding this?
> >
> > thanks!
> > etoke
> >
>




Hotmail® has ever-growing storage! Don’t worry about storage limits. Check it out.

__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___