Title: Simple code problem
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





SPONSORED LINKS
Investment management software Real estate investment software Investment property software
Software support Real estate investment analysis software Investment software


YAHOO! GROUPS LINKS




Reply via email to