period1 = Optimize("period1", 25, 10, 50, 5);
period2= Optimize("period2", 840, 800, 900, 10);
fast [0] = C[0];
slow [0] = C[0];
for(
bar = 1; bar
< BarCount; bar++ )
{
fast[ bar ] =fast[bar-1]+(Close[bar]-fast[bar-1])*2/(period1+1);
slow[ bar ] =slow[bar-1]+(Close[bar]-slow[bar-1])*2/(period2+1);
}
Plot(fast, "" ,colorGreen);
Plot(slow,
"", colorRed);
Buy
= Cross(fast,
slow);
Sell
= Cross(slow,fast);
On 2/1/2010 1:26 PM, Markus Witzler wrote:
Hello,
I have loops built into my code
and thus suppose that it´s running too slow.
I use a EMA crossover system
(long side only at this point):
Buy= Cum(1)>=25 AND Cross(Fast_EMA(period1),
Slow_EMA(period2))AND period1 < period2;
Sell= Cross(Slow_EMA(period2), Fast_EMA(period1));
I coded
Fast_EMA and Slow_EMA instead of using AB´s built-in EMA function to be
able to use my own seed values.
Anyways, the
code for both follows further below.
Would the rode run faster, if I
stored the values for fast_MA and slow_EMA in a separate composite and
then used these in the buy and sell rules?
Or is there another way to make my
code faster? Are there some clues how to "pimp" my code when I "have"
to use loops (for instance when coding proprietary stops instead of
applystop etc.)???
Some other general guidelines what
to look out for when trying to keep the code as fast as possible (or
better: the execution thereof)??
Thanks
Markus
function Fast_EMA( period1 )
{ local
bar;
for( bar = 0; bar < BarCount; bar++ )
{ if
(bar < 1)
EMA_fast[ bar ] = Close[
0 ];
else
EMA_fast[ bar ] =EMA_fast[bar-1]+(Close[bar]-EMA_fast[bar-1])*2/(period1+1);
}
return EMA_fast;
}
period1 = Optimize("period1",
25, 10, 50, 5);
Exp_MA_fast = Fast_EMA (
Period1 );
function Slow_EMA( period2 )
{ local
bar;
for( bar = 0; bar < BarCount; bar++ )
{ if
(bar < 1)
EMA_slow[ bar ] = Close[
0 ];
else
EMA_slow[ bar ] =EMA_slow[bar-1]+(Close[bar]-EMA_slow[bar-1])*2/(period2+1);
}
return EMA_slow;
}
period2 = Optimize("period2",
840, 800, 900, 10);
Exp_MA_slow = Fast_EMA (
Period2 );
__________ Information from ESET Smart Security, version of virus
signature database 4668 (20091207) __________
The message was checked by ESET Smart Security.
http://www.eset.com