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

[amibroker] Re: Relative Volume by time



PureBytes Links

Trading Reference Links



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))*VarGet("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@xxxxxxxxxxxxxxx, "etoketrader" <etoke420@xxx> 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
>


__._,_.___


**** 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

__,_._,___