Say, I make my own wighted moving average.
I have sets of coefficient ( k[2,Period] ).
On each bar I multiplicate Period last Closes prices at appropriate coefficient.
I made 3 almost same algorithms:
Variant = "Variant 1";
for( int i = 0; i < Period; i++ )
{
sum_0 += Close[i] * K[0][i];
sum_1 += Close[i] * K[1][i];
}
Variant = "Variant 2";
for( int i = 0; i < Period; i++ )
{
double close = Close[i];
sum_0 += close * K[0][i];
sum_1 += close * K[1][i];
}
Variant = "Variant 3";
for( int i = 0; i < Period; i++ )
{
double close = Close[i];
sum_0 += K[0][i];
sum_1 += K[1][i];
}
Variant 1: 0.38 ms \ bar
Variant 1: 0.33 ms \ bar
Variant 1: 0.33 ms \ bar
I want pay attention that "Variant 3" have no multiplication at all - all time spend for data access only.
My conclusion: calculations take almost no time. All time spend at data access.
My question: how can we decrease data access time using safe code?

Comment