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

[amibroker] Re: my vwap + standard deviation bands - very slow



PureBytes Links

Trading Reference Links

I have been following this as an AFL study piece and I was going to comment/ask some questions this weekend  ... since Bruce has started the ball rolling.

If anyone can help shed some light on the following it would be appreciated:

> Also, I noticed that if I DO NOT USE:
> SetBarsRequired( 1000, 0 );
> The bands show up incorrect...(sometimes expanding/shrinkking as I >scroll on the 1 minute chart)

I recently had an incidence of plots that were behaving 'other than my expectations' when scrolling ... as I scrolled forward in time the visual cues I had on the chart didn't appear until half way across the chart ..... this was annoying because I wanted to look forward in the charts from the 'markers' as the bar they highlighted became the first bar in the chart (counting from the left).

I am not certain exactly what I was doing at the time ... unforunately I didn't stop for the learning experience ... I think it was the case shown below and I got around it by subsituting Cum(1) for BarIndex().

At the time I assumed it was something to do with QuickAFL and how it sets the range in charts?

The code is a quick and dirty attempt to mark the intraday sessions in an eSignal 24 hour RT database ... I live outside the US and because eSignal uses GMT as their basetime any RT databases I save, have a one hour timeshift in them if the history crosses US daylight saving time start/end dates (sometimes this can be more than once in a database) ..... for a quick fix, when I want to visual the charts, I place a horizontal marker at the start and end of the daily session .... it works most of the time.

In the code I commented out the first ES variable statement and replaced it with the line below (Cum replaces BarIndex) .... obviously I had a good reason (wouldn't do it if the first attempt was doing what I expected it would do).

Vol = Foreign("$INDU","V");
SS = Vol > 3 * Ref(Vol,-1) AND TimeNum() >= 093000 AND TimeNum() <= 103000;//StartSession
SB = (6.5 * 60)/(Interval()/60);//SessionBars
//ES = BarIndex() == ValueWhen(SS == 1, BarIndex(),1) + SB;
ES = Cum(1) == ValueWhen(SS == 1, Cum(1),1) + SB;

Plot(SS,"StartSession",colorBrightGreen,styleHistogram|styleOwnScale);
Plot(ES,"EndSession",colorRed,styleHistogram|styleOwnScale);

--- In amibroker@xxxxxxxxxxxxxxx, "shakerlr" <ljr500@xxx> wrote:
>
> I just created the following code to calculate the VWAP + std deviation bands, but have found that it is extrememly slow.  I posted the original code to the amibroker study site and was wondering if anyone has any suggestions to speed it up for display on 1 minute charts.  
> 
> Also, I noticed that if I DO NOT USE:
> SetBarsRequired( 1000, 0 );
> 
> The bands show up incorrect...(sometimes expanding/shrinkking as I scroll on the 1 minute chart)
> 
> Note that I have about 100000 bars in my stock/ticker being studied...so that may be the reason it is slow...
> 
> ----
> /// VWAP code that also plots standard deviations...if you want a 3rd...it
> should be fairly simple to add 
> //
> // NOTE: the code is SLOOOOWWWW...can someone help speed it up?  
> // I tried my best, but can't really do much with the two for-loops...
> //
> // LarryJR
> 
> 
> SetBarsRequired( 1000, 0 );
> 
> // this stores true/false based on a new day...
> newday=Day() != Ref(Day(), -1);
> 
> SumPriceVolume=0;
> totVolume=0;
> Vwap2=0;
> stddev=0;
> newdayindex=0;
> Variance =0;
> 
> // we must use a loop here because we need to save the vwap for each bar to
> calc the variance later
> for( i= 0; i < BarCount; i++ ) 
> { 
> 	// only want to reset our values at the start of a new day
> 	if (newday[i]==True)
> 	{
> 		SumPriceVolume=0;
> 		totVolume=0;
> 		newdayindex=i;	// this is the index at the start of a new day
> 		Variance=0;
> 		//Vwap2=0;
> 	}
> 	AvgPrice=(O[i] + H[i] + L[i] + C[i])/4;
> 
> 	// Sum of Volume*price for each bar
> 	sumPriceVolume += AvgPrice * (Volume[i]);
> 		
> 	// running total of volume each bar
> 	totVolume += (Volume[i]);		
> 
> 	if (totVolume[i] >0)
> 	{	
> 		Vwap2[i]=Sumpricevolume / totVolume ;
> 		Vwap2temp=Vwap2[i];
> 	}
> 
> 	// now the hard part...calculate the variance...
> 	// a separate calc from the start of each day - note it requires the vwap from
> above
> 	// also note, we calculate starting at the first bar in the new day to today
> to the curent bar
> 	Variance=0;
> 	for (j=newdayindex; j < i; j++)
> 	{
> 		AvgPrice=(O[j] + H[j] + L[j] + C[j])/4;
> 		Variance += (Volume[j]/totVolume) *
> (Avgprice-Vwap2temp)*(Avgprice-Vwap2temp);
> 	}
> 	stddev_1_pos[i]=Vwap2temp + sqrt(Variance);
> 	stddev_1_neg[i]=Vwap2temp - sqrt(Variance);
> 
> 	stddev_2_pos[i]=Vwap2temp + 2*sqrt(Variance);
> 	stddev_2_neg[i]=Vwap2temp - 2*sqrt(Variance);
> } 
> Plot (Vwap2,"VWAP2",colorDarkGrey, styleLine);
> Plot (stddev_1_pos,"VWAP_std+1",colorGrey50, styleDashed);
> Plot (stddev_1_neg,"VWAP_std-1",colorGrey50, styleDashed);
> Plot (stddev_2_pos,"VWAP_std+2",colorGrey40, styleDashed);
> Plot (stddev_2_neg,"VWAP_std-2",colorGrey40, styleDashed);
>




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

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