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

Re: [amibroker] Re: Help with code bringing Ami to a grinding halt



PureBytes Links

Trading Reference Links

Brian --
I believe you are having some of the same problems I had when I first started using AmiBroker (even though, or maybe because, I had been programming in C since before  either M$ or Borland had C compilers).  The two most troublesome for me were:

1.   AB uses 'arrays' without declaring them as such (except inside of loop structures such as for(){} where you must use [] for all arrays.  In your code below, you used [] to define the elements for the HiVal array.  However, you did not use set[], so AB did not treat set as an array but only as a variable (and therefore the same goes for
maxDegreesZero).

2.  AB only makes a single pass through the code.  Read Fred's contribution 1/30/2006 at 11:49pm.  I quote:
"
AmiBroker AFL is processed from top to bottom with each statement being executed ONCE and ONLY ONCE ... NOT ONCE PER BAR ...
Unless you build your own Do / While / For Loops and subscript the
ARRAYS then typically each statement works on the entire ARRAY ..."

BTW, you don't need loops in your code at all.  For example, your for(){} loop could (and should) be written as such:
set = IIf(HiVal2>1 AND  HiVal2<=25, 30,
      IIf(HiVal2>25 AND  HiVal2<=50, 55,
      IIf(HiVal2>50 AND  HiVal2<=100, 120,
      IIf(HiVal2>100 AND  HiVal2<=200, 220,
      IIf(HiVal2>200 AND  HiVal2<=500, 510,
      IIf(HiVal2>500 AND  HiVal2<=900, 920, 1300))))));
// I assume you meant 9000 and not 9000 and 13000

-- Keith




coba702002 wrote:
HI Tomasz

Ok I have revised my incorrect code and removed other code to try
and pinpoint the problem, but I still get weird things happening
even without datafeed, which Im sure tomorrow when I have data will
make the AMI unusable. Right now when I insert that code below into
a new window switching between that window and others is ALOT slower
ALSO when I select>>view and open say charts it will not open the
pane until I minimize ami and restore ami then it shows up... If I
try and close that pane it will not close until I Minimize ami and
then restore , then its gone.  This Problem Does not show up without
this code in any windows???

Thanks for any thoughts or ideas to fix this

Brian

range2=95;
LastBar = BarCount-1;
HiVal2 = HHV(H,range2);
LoVal2 = LLV(L,range2);

step = 8;
for( i = 0; i < BarCount; i++ )
{
      if(HiVal2[i] >1.0 AND  HiVal2[i]<=25 )
            set = 30;
      else if (HiVal2[i]>25 AND  HiVal2[i]<=50 )
            set = 55;
      else if (HiVal2[i]>50 AND  HiVal2[i]<=100 )
            set = 120;
      else if (HiVal2[i]>100 AND  HiVal2[i]<=200 )
            set = 220;
      else if (HiVal2[i]>200 AND  HiVal2[i]<=500 )
            set = 510; 
      else if (HiVal2[i]>500 AND  HiVal2[i]<=900 )
            set = 920;
      else if (HiVal2[i]>9000 AND  HiVal2[i]<=13000 )
            set = 13000;
      else       set = 13000;
           
}

maxDegreesZero = set;
degreesZero = 1;
increment = 1;
degreesValueInt = 0;
angleFactor = 0;
sqrtDegreesZero = 0;
degreesValue = 0;


     
        // Iterate through the set of squares
        while (degreesZero < maxDegreesZero)
        {
           sqrtDegreesZero = sqrt(degreesZero);
                      
            // Iterate through the circle for this square, in 11.25
degree increments
            for (angle = 0; angle < 360; angle = angle + 11.25)
            {
                angleFactor = (angle / 360.0) * 2.0;
                            degreesValue = (sqrtDegreesZero +
angleFactor) ^ 2;

                          roundedValue = round(degreesValue);
                             
           
                        HHVBarsSince = HHV(H, 30) ;
                        LLVBarsSince = LLV(L, 30) ;

                 
              if (roundedValue[LastBar]< (HHVBarsSince[Lastbar])
AND roundedValue[LastBar]>(LLVBarsSince[Lastbar]) ){     
              Plot(Prec(roundedValue,2), "",
colorGrey40|styleLine, -(LLVBarsSince[Lastbar]),(HHVBarsSince
[Lastbar]));
                   
              }
             
            }

            // Find the next 0 degree value
            degreesZero = degreesZero + increment;
            increment = increment + step;
        }

// End Square Of Nine  ************

PlotOHLC(Open,High,Low,Close,"",colorBlack, styleCandle);

TitleStr= Interval(2) ;


Title = TitleStr;

--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxx>
wrote:
>
> Hello,
>
> No, I am referring to IIFs at the beginning that are written
incorrectly. I did not even
> check further since the beginning of the code is wrong.
> You are mixing up if (statement) with iif (function)
>
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message -----
> From: "coba702002" <coba702002@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Saturday, February 04, 2006 9:05 PM
> Subject: [amibroker] Re: Help with code bringing Ami to a grinding
halt
>
>
> > Thanks for your fast response... I can't test it today, no
datafeed 
> > But just glancing at it, are you referring to the rounding
section
> > of the code?  If so Im pretty sure that didn't make any
difference
> > when it wasn't in there.
> >
> > So what your saying is this code once correct shouldn't be a
problem
> > working in an indicator VS a plain jane price chart in real
time? 
> > My test comparison of the two was a MAJOR slowdown with my code
> > added.
> >
> > Thanks again for any thoughts
> > Brian
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@>
> > wrote:
> >>
> >> The code contains numerous errors listed in "common coding
> > mistakes" in the User's Guide:
> >>
> >> http://www.amibroker.com/guide/a_mistakes.html
> >>
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >> ----- Original Message -----
> >> From: "coba702002" <coba702002@>
> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> Sent: Saturday, February 04, 2006 8:10 PM
> >> Subject: [amibroker] Help with code bringing Ami to a grinding
halt
> >>
> >>
> >> > Can anyone help me figure out why when I add a window with
this
> > code
> >> > in it.. Ami (ver-4.76, windows xp, Ib tws 1.51) slows down to
> >> > unusable levels. ie switching windows takes forever...
candles
> > seem
> >> > stuck then suddenly change price.
> >> >
> >> > Is there a way to make this code work???
> >> >
> >> > any help or ideas would be greatly appreciated
> >> >
> >> > Thanks
> >> > Brian
> >> >
> >> > // Begin Square Of Nine  ************  
> >> >
> >> > range2=95;
> >> > LastBar = BarCount-1;
> >> > HiVal2 = HHV(H,range2);
> >> > LoVal2 = LLV(L,range2);
> >> >
> >> > step = 8;
> >> > IIf(HiVal2>1.0 AND  HiVal2<=25 ,set = 30,0);
> >> > IIf(HiVal2>25 AND  HiVal2<=50 ,set = 55,0);
> >> > IIf( (HiVal2>50 AND  HiVal2<=100 ),set = 120,0);
> >> > IIf( (HiVal2>100 AND  HiVal2<=200 ),set = 220,0);
> >> > IIf( (HiVal2>200 AND  HiVal2<=500 ),set = 510,0);
> >> > IIf( (HiVal2>500 AND  HiVal2<=900 ),set = 920,0);
> >> > IIf( (HiVal2>9000 ),set = 13000,0);
> >> > maxDegreesZero = set;
> >> > degreesZero = 1;
> >> > increment = 1;
> >> > degreesValueInt = 0;
> >> > angleFactor = 0;
> >> > sqrtDegreesZero = 0;
> >> > degreesValue = 0;
> >> >
> >> >
> >> >
> >> >        // Iterate through the set of squares
> >> >        while (degreesZero < maxDegreesZero)
> >> >        {
> >> >      sqrtDegreesZero = sqrt(degreesZero);
> >> >                 
> >> >            // Iterate through the circle for this square, in
> > 11.25
> >> > degree increments
> >> >            for (angle = 0; angle < 360; angle = angle + 11.25)
> >> >            {
> >> >                angleFactor = (angle / 360.0) * 2.0;
> >> >     degreesValue = (sqrtDegreesZero +
> >> > angleFactor) ^ 2;
> >> >
> >> >   // round either to tenths, quarters, OR wholes
> >> >    if (degreesValue <= 450)
> >> >    {
> >> > degreesValue = degreesValue
> >> > * 10;
> >> >        roundedValue = Prec
> >> > (degreesValue,2) / 10;
> >> >    }
> >> >    else if (degreesValue > 450 AND degreesValue
> >> > < 5000)
> >> >    {
> >> >        remainder = frac(degreesValue);
> >> >         intValue = degreesValue - remainder;
> >> >        if (remainder > 0 AND remainder
> >> > <= .25)
> >> >            remainder = .25;
> >> >        else if (remainder > .25 AND
> >> > remainder <= .5)
> >> >            remainder = .5;
> >> >        else if (remainder > .5 AND
> >> > remainder <= .75)
> >> >            remainder = .75;
> >> >        else
> >> >            remainder = 1;
> >> >        roundedValue = intValue +
> >> > remainder;
> >> >    }
> >> >    else
> >> >    {
> >> >        roundedValue = round(degreesValue);
> >> >
> >> >    }
> >> >
> >> >
> >> > HHVBarsSince = HHV(H, 30) ;
> >> > LLVBarsSince = LLV(L, 30) ;
> >> >
> >> >
> >> >   //if (roundedValue[LastBar]<(45) AND roundedValue
> >> > [LastBar]>(30) ){
> >> >   if (roundedValue[LastBar]< (HHVBarsSince[Lastbar])
> >> > AND roundedValue[LastBar]>(LLVBarsSince[Lastbar]) ){
> >> >   Plot(Prec(roundedValue,2), "",
> >> > colorGrey40|styleLine, -(LLVBarsSince[Lastbar]),(HHVBarsSince
> >> > [Lastbar]));
> >> >  
> >> >   }
> >> >  
> >> >            }
> >> >
> >> >            // Find the next 0 degree value
> >> >            degreesZero = degreesZero + increment;
> >> >            increment = increment + step;
> >> >        }
> >> >
> >> > // End Square Of Nine  ************
> >> >
> >> > PlotOHLC(Open,High,Low,Close,"",colorBlack, styleCandle);
> >> >
> >> > TitleStr= Interval(2) ;
> >> >
> >> >
> >> > Title = TitleStr;
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > 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
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> >
> >
> >
> >
> > 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
> >
> >
> >
> >
> >
> >
> >
>






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