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

RE: [amibroker] Still confused



PureBytes Links

Trading Reference Links

Title: Simple code problem

Getting the moving average result outside the loop does my head in because it doesn’t look like it will work.  I tried it and it is also very slow.  I tried your first example, which works perfectly.

 

Thank you very much,

 

Rush

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of emp62
Sent: 01 April 2006 13:24
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Still confused

 

Rush,

 

these type of calculations can be done using arrays only, like

 

Periods = Param("Periods", 5, 2, 200, 1, 1 );

mo =
MA( Open, Periods);
mh =
MA( High, Periods);  
mc =
MA( Close, Periods);

TheDiff =
IIf(mo < mc,mh - mc,IIf(mo > mc,mh - mo, 0));
Color =
IIf(mo < mc,colorBlue,IIf(mo > mc,colorRed, colorGreen));

Plot( TheDiff, "SC Plus", Color, styleHistogram);

 

 

 

You can also do it using loops. However you can take

 

           mo = MA( Open, Periods);

           mh = MA( High, Periods); 

           mc = MA( Close, Periods);

 

outside of the loop like (then it goes much faster):

 

 

Periods = Param("Periods", 5, 2, 200, 1, 1 );

 

     Color = Null;

     TheDiff = Null;

 

 

    mo = MA( Open, Periods);

     mh = MA( High, Periods); 

     mc = MA( Close, Periods);

 

     for( i = 0; i < BarCount; i++ ) {

 

 

          if(mo[i] < mc[i]){

                TheDiff[i] = mh[i] - mc[i];

                Color[i] = colorBlue;

           }else if(mo[i] > mc[i]){

                TheDiff[i] = mh[i] - mo[i];

                Color[i] = colorRed;

           }else{

                TheDiff[i] = 0;

                Color[i] = colorGreen;

           }

 

     }

 

Plot( TheDiff, "SC Plus", Color, styleHistogram);

 

 

 

 

 

----- Original Message -----

From: Rush

Sent: Saturday, April 01, 2006 12:59 PM

Subject: [amibroker] Still confused

 

Hi,

 

I’m still confused on how to use the variables.  The code below seems to work but slows AmiBroker down.  It seems that the “if” statement doesn’t like to see the variables mo, mh, mc without the square brackets.  All I’m trying to do here is plot the difference between the average high and average open/close in a colour depending of the result as a histogram.

 

Question: is it possible to define a variable that is not an array?

 

Periods = Param("Periods", 5, 2, 200, 1, 1 );

 

     Color = Null;

     TheDiff = Null;

 

     for( i = 0; i < BarCount; i++ ) {

 

           mo = MA( Open, Periods);

           mh = MA( High, Periods); 

           mc = MA( Close, Periods);

 

          if(mo[i] < mc[i]){

                TheDiff[i] = mh[i] - mc[i];

                Color[i] = colorBlue;

           }else if(mo[i] > mc[i]){

                TheDiff[i] = mh[i] - mo[i];

                Color[i] = colorRed;

           }else{

                TheDiff[i] = 0;

                Color[i] = colorGreen;

           }

 

     }

 

Plot( TheDiff, "SC Plus", Color, styleHistogram);

 

 





Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





YAHOO! GROUPS LINKS