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

[amibroker] Re: Relative Volume by time



PureBytes Links

Trading Reference Links

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@xxxxxxxxxxxxxxx, "etoketrader" <etoke420@xxx> 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@xxxxxxxxxxxxxxx, "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
> >
>




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

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

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/