Hi, 
I'm trying to write an AFL to draw support trendline (PS. I'm aware that there 
is existing trendline AFLs in the library).  There is a section where I can't 
think of other ways but to use loop (probably should be defined as a loop in 
another loop).  This slows down the AFL speed tremendously.  Would anyone be 
able to think of a better way to improve the following ?

The logic of the code is this:  The first point of the support/trend line has 
been identified as (SupportX1, SupportY1).  The following code then attempts to 
find the next point (SupportX2, SupportY2) of the trendline.  A bar-by-bar 
search approach is adopted (hence the loop).  The bar with the Low that forms 
the lowest gradient line is the target here (assigned SupportX2). 

Any help is appreciated.
Kevin


gradient0 = ( Ref(L, -1) - SupportY1) / (-1 + SupportX1);

for (i=1; i<BarCount; i++)
{
   loopstartX = 1;
   while(loopstartX < (SupportX1[i]))
   {
   gradient = ( Ref(L,-loopstartX) - SupportY1 )/(-loopstartX + SupportX1);
   if ((gradient[i]) < (gradient0[i]))
      {
      gradient0[i] = gradient[i];
      SupportX2[i]= loopstartX;
      }
   nxsup00 = nxsup00 + 1;
   }
}


Reply via email to