Thanks guys ... on the weekend I will try performance counter etc on shakers code and then compare the speed to some other version .... I might come back with more questions then.
What I am asking here is .... if I use code: Array1 Array2 Loop1 (references Array 2 and produces Array3) Array 4;// dependent on variable from loop i.e. array3 Array 5;// independent of loop Loop2 Array6;// Array7;//independent of loop Array8;//dependent on Array6,7 and Loop2 Will AB run through the code up until Loop1 and then perform the loop before going on? OR will it calulate all 'standalone' arrays before starting the first loop AND does it matter i.e. does it slow the code down if I put Array5,6 and 7 anywhere in the code when I could put it at the start? --- In [email protected], "brian_z111" <brian_z...@...> wrote: > > People talk about AFL execution, and how important it is to understanding > AFL, but I can't find a reference to it anywhere ... possibly I haven't tried > hard enough. > > > My best understanding so far is: > > - arrays are contiguous in disc memory (AB uses this somehow to effieciently > process the data) > - arrays are 'othoganal' (stacked on top of one another in operating memory > ... so AB gets a performance hit out of this as well?) > - maths operations are fast in array processing because of above? > > > so, my rules of thumb: > > - rearrange the maths to express the maths using basic operands as far as > possible (+- */)? > - code is executed sequentially? > > As you can see there is a lot to learn! > > Looking at shake1r's code I am not certain when the arrays or loops will be > executed. > > If I put AvgPrice=(O[i] + H[i] + L[i] + C[i])/4; > outside the loop will it be executed first (as an array) and then the loop > will reference the array elements thereafter. > > AvgPrice = (O + H + L + C)/4; > > for( i= 0; i < BarCount; i++ ) > > { AvgPrice[i] = 0; > > etc > > } > > Presumably if AvePrice array doesn't come first then when we get to the loop > the syntax will fail (AvePrice not initialized?) > > If I am using the above type of code in an indicator (assuming that arrays > can be created first and referenced in a loop second) what happens when a new > bar arrives in the chart (say I am using RT data) ... now the array has an > extra value ... how does the code know to recalculate (execute?) the AFL and > how often does it do that? > > > Another question: > > When do we have to intialize a variable to zero at the start of the code and > why e.g. > > is there really a need to start with > > SumPriceVolume=0; > totVolume=0; > Vwap2=0; > ddev=0; > newdayindex=0; > Variance =0; > > Thanks, > > brian_z > > > - --- In [email protected], "shakerlr" <ljr500@> 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); > > >
