Hello Mike, I somewhat overlooked your post.
Thanks for these insights. They´ll definitely help me to make my coding faster and give me guidelines when speed is an issue! Thanks loads Markus ----- Original Message ----- From: Mike To: [email protected] Sent: Tuesday, February 02, 2010 3:28 AM Subject: [amibroker] Re: "Pimping" my code No chance for what? The primary issues with your original code were: 1. Redundant calls to the same function. You have called each of Fast_EMA and Slow_EMA twice. It would have been better instead to call each once and hold the result e.g. fast = Fast_EMA(period1); slow = Slow_EMA(period2); Buy = Cum(1)>=25 AND Cross(fast, slow) AND period1 < period2; Sell= Cross(slow, fast); 2. You have two functions with identical logic. The only difference is the global variable in which the result is stored. There is a cost for AmiBroker to have to parse each function. It would have been better to instead have a single function that returned the result generically, rather than writing directly to a global variable. e.g. function My_EMA(period) { local result; ... return result; } 3. It is wasteful to have to check an "if" condition at every iteration of the loop. Set the 0th element of the array first, then loop from 1 to BarCount - 1 without the unnecessary if. e.g. result[0] = ...; for (bar = 1; bar < BarCount; bar++) { ... } And, of course, any time you can combine multiple calculations within a single loop (as opposed to looping through all bars for each calculation), that will be the fastest. Aron's solution addressed all those issues. I don't see how adding to composite would help you. Mike --- In [email protected], "Markus Witzler" <funny...@...> wrote: > > So, there seems to be no chance... > > Thanks though, Aron! > > Markus > > ----- Original Message ----- > From: Aron > To: [email protected] > Sent: Monday, February 01, 2010 2:46 PM > Subject: Re: [amibroker] "Pimping" my code > > > > You would still have to use Foreign() . > > As far as I know for best execution times you need to use: > > No Incudes > No user functions/procedures > No loops > No Foreign() > > > > On 2/1/2010 2:33 PM, Markus Witzler wrote: > > Hello Aron, > > right, I was thinking too complicated. ;-) > > Still, would storing the results of the loop into an addtocomposite ticker make sense that my code could access every time it checked for a MY crossover instead of running the loop? > > Thanks for your clue! > > Markus > ----- Original Message ----- > From: Aron > To: [email protected] > Sent: Monday, February 01, 2010 1:52 PM > Subject: Re: [amibroker] "Pimping" my code > > > > 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 > > > > > > __________ Information from ESET Smart Security, version of virus signature database 4668 (20091207) __________ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > > __________ Information from ESET Smart Security, version of virus signature database 4668 (20091207) __________ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > > > > > __________ Information from ESET Smart Security, version of virus signature database 4668 (20091207) __________ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > > > __________ Information from ESET Smart Security, version of virus signature database 4668 (20091207) __________ > > The message was checked by ESET Smart Security. > > http://www.eset.com > __________ Information from ESET Smart Security, version of virus signature database 4668 (20091207) __________ The message was checked by ESET Smart Security. http://www.eset.com
