double HeikenAshi(int tf,int price,int bar)
{ 
   //if(bar == iBars(NULL,TimeFrame)- 1) 
//if(bar == chartbars[displayedfile]- 1) 
if(bar == 666- 1) 
   {
   haClose[bar] = iclose(tf,bar);
   haOpen[bar]  = iopen(tf,bar);
   haHigh[bar]  = ihigh(tf,bar);
   haLow[bar]   = ilow(tf,bar);
   }
   else
   {
   haClose[bar] = (iopen(tf,bar)+ihigh(tf,bar)+ilow(tf,bar)+iclose(tf,bar))/4;
   haOpen[bar]  = (haOpen[bar+1]+haClose[bar+1])/2;
   haHigh[bar]  = mathmax(ihigh(tf,bar),mathmax(haOpen[bar], haClose[bar]));
   haLow[bar]   = mathmin(ilow(tf,bar),mathmin(haOpen[bar], haClose[bar]));
   }
   
   switch(price)
   {
   case 0: return(haClose[bar]);break;
   case 1: return(haOpen[bar]);break;
   case 2: return(haHigh[bar]);break;
   case 3: return(haLow[bar]);break;
   }
}     
示例#2
0
QIntMatrix basicSegmentation::find(QBitmap mask, int minsize)
{
  int y, x, a, l, t, eqI, eqTI, eqV, w, h, eqMaxI=1, newID = 2;
  bool done;
  QIntMatrix r(mask.width(), mask.height());
  QImage im = mask.toImage();
  QVector<int> u, eq, counts;
  w = mask.width();
  h = mask.height();
     
  for(y = 0; y < h; y++) {
    for(x = 0; x < w; x++) {
      a = qRed(im.pixel(x, y));
      if(a == 0) {
        r.set(x, y, 1);      	
      } else {
      	r.set(x, y, 0);
      }
    }
  }


  eq =  QVector<int>(2);
  counts =  QVector<int>(2);
  for(y = 1; y < (h - 1); y++) {
    for(x = 1; x < (w - 1); x++) {
      a = r.at(x, y-1);
      l = r.at(x-1, y);
      t = r.at(x, y);
      if (t == 1) {
        if (a == l && a > 1) {
          r.set(x, y, a);
          if(a > (counts.size()-1)) {
          	counts.resize(a+1);
          }
          counts[a]++;
        } else if (a != l && a > 1 && l > 1) {
          r.set(x, y, mathmin(a, l));
          if(mathmin(a, l) > (counts.size()-1)) {
          	counts.resize(mathmin(a, l)+1);
          }
          counts[mathmin(a, l)]++;
          eqI = mathmax(a,l);
          eqV = mathmin(a,l);
          done = false;
          while (!done) {
            if (eqI > eqMaxI) {
              eq.resize(eqI+1);
              eqMaxI = eqI;
            }
            if ((eq.at(eqI) > 1)) {
              if (eqV != eq.at(eqI)) {
                eqTI = eqI;
                eqI = mathmax(eqV, eq.at(eqTI));
                eqV = mathmin(eqV, eq.at(eqTI));
                eq[eqTI] = eqV;
              } else {
                eq[eqI] = eqV;
                done = true;
              }
            } else {
              eq[eqI] = eqV;
              done = true;
            }
          }
        } else if (mathmax(a,l) > 1) {
            r.set(x, y, mathmax(a, l)); 
            if(mathmax(a, l) > (counts.size()-1)) {
            	counts.resize(mathmax(a, l)+1);
            }
            counts[mathmax(a, l)]++;
        } else  {
           r.set(x, y, newID++);
           counts.resize(newID+1);
           counts[newID]=1;
        }
      } else {
      	 r.set(x, y, 0);
      }
    }
  }

  //clean up edges 

  r.replace(1, 0);

  //resolve equivalent ids

  
  if(eqMaxI > 1) 
  {
    resolveEq(&r, eq, counts, minsize);
  }

   return(r);
}