예제 #1
0
void
RangeSlider::calculatePositions(int& left, int& right) const
{
    int w = getSize().x;
    int hw = lHandle_->getSize().x;
    left = round_pos(lValue_ * (w - hw - 2)) + 1;
    right = round_pos(rValue_ * (w - hw - 2)) + 1;
}
예제 #2
0
const Point&
RangeSlider::setSize(float width, float height)
{
    const Point& newSize = AbstractSliderBase::setSize(width, height);

    float hdlW = std::max(round_pos(newSize.x * .05f), handleSize_);

    lHandle_->setSize(hdlW, newSize.y - 2);
    rHandle_->setSize(hdlW, newSize.y - 2);

    int lx, rx;
    calculatePositions(lx, rx);
    lHandle_->setPos(lx, 1);
    rHandle_->setPos(rx, 1);

    updateRangeBar();

    return newSize;
}
예제 #3
0
RangeSlider::RangeSlider(
    const Point& pos,
    const Point& size,
    const float range[2],
    MapType mapType,
    const char* colorScheme)
:   AbstractSliderBase(pos, size, range, mapType, colorScheme),
    handleSize_(3)
{
    lValue_ = 0.f;
    rValue_ = 1.f;

    float hdlW = std::max(round_pos(size.x * .05f), handleSize_);
    Point hdlSize(hdlW, size.y - 2);

    lHandle_ = new WiBox(Point(1, 1), hdlSize);
    rHandle_ = new WiBox(Point(size.x - 1 - hdlSize.x, 1), hdlSize);

    GuiObject* obj[] = { lHandle_, rHandle_ };
    for (int i = 0; i != 2; ++i)
    {
        obj[i]->addDraggedListener(this);
        obj[i]->setDraggable();
        obj[i]->setDraggableArea(0, Point(1, 1));
    }

    rangeBar_ = new WiBox(Point(), Point());

    GuiObject* obj2[] = { rangeBar_, lHandle_, rHandle_ };
    for (int i = 0; i != 3; ++i)
    {
        addSubObject(obj2[i]);
        obj2[i]->setEmbedded();
        obj2[i]->addMouseListener(this);
    }

    addMouseListener(this);

    updateRangeBar();
    setColors(colorScheme);
}
예제 #4
0
TA_RetCode TA_ADX( TA_Libc      *libHandle,
                   TA_Integer    startIdx,
                   TA_Integer    endIdx,
                   const TA_Real inHigh_0[],
                   const TA_Real inLow_0[],
                   const TA_Real inClose_0[],
                   TA_Integer    optInTimePeriod_0, /* From 1 to TA_INTEGER_MAX */
                   TA_Integer   *outBegIdx,
                   TA_Integer   *outNbElement,
                   TA_Real       outReal_0[] )
/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
{
	/* insert local variable here */
   TA_Integer today, lookbackTotal, outIdx;
   TA_Real prevHigh, prevLow, prevClose;
   TA_Real prevMinusDM, prevPlusDM, prevTR;
   TA_Real tempReal, tempReal2, diffP, diffM;
   TA_Real minusDI, plusDI, sumDX, prevADX;

   int i;

   #define TRUE_RANGE(TH,TL,YC,OUT) {\
      OUT = TH-TL; \
      tempReal2 = fabs(TH-YC); \
      if( tempReal2 > OUT ) \
         OUT = tempReal2; \
      tempReal2 = fabs(TL-YC); \
      if( tempReal2 > OUT ) \
         OUT = tempReal2; \
   }

/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

   (void)libHandle; /* Get ride of warning if unused. */

#ifndef TA_FUNC_NO_RANGE_CHECK

   /* Validate the requested output range. */
   if( startIdx < 0 )
      return TA_OUT_OF_RANGE_START_INDEX;
   if( (endIdx < 0) || (endIdx < startIdx))
      return TA_OUT_OF_RANGE_END_INDEX;

   /* Validate the parameters. */
   /* Verify required price component. */
   if(!inHigh_0||!inLow_0||!inClose_0)
      return TA_BAD_PARAM;

   /* min/max are checked for optInTimePeriod_0. */
   if( optInTimePeriod_0 == TA_INTEGER_DEFAULT )
      optInTimePeriod_0 = 14;
   else if( (optInTimePeriod_0 < 1) || (optInTimePeriod_0 > 2147483647) )
      return TA_BAD_PARAM;

   if( outReal_0 == NULL )
      return TA_BAD_PARAM;

#endif /* TA_FUNC_NO_RANGE_CHECK */

/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

   /* Insert TA function code here. */

   /* 
    * The DM1 (one period) is base on the largest part of
    * today's range that is outside of yesterdays range.
    * 
    * The following 7 cases explain how the +DM and -DM are
    * calculated on one period:
    *
    * Case 1:                       Case 2:
    *    C|                        A|
    *     |                         | C|
    *     | +DM1 = (C-A)           B|  | +DM1 = 0
    *     | -DM1 = 0                   | -DM1 = (B-D)
    * A|  |                           D| 
    *  | D|                    
    * B|
    *
    * Case 3:                       Case 4:
    *    C|                           C|
    *     |                        A|  |
    *     | +DM1 = (C-A)            |  | +DM1 = 0
    *     | -DM1 = 0               B|  | -DM1 = (B-D)
    * A|  |                            | 
    *  |  |                           D|
    * B|  |
    *    D|
    * 
    * Case 5:                      Case 6:
    * A|                           A| C|
    *  | C| +DM1 = 0                |  |  +DM1 = 0
    *  |  | -DM1 = 0                |  |  -DM1 = 0
    *  | D|                         |  |
    * B|                           B| D|
    *
    *
    * Case 7:
    * 
    *    C|
    * A|  |
    *  |  | +DM=0
    * B|  | -DM=0
    *    D|
    *
    * In case 3 and 4, the rule is that the smallest delta between
    * (C-A) and (B-D) determine which of +DM or -DM is zero.
    *
    * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are
    * zero.
    *
    * The rules remain the same when A=B and C=D (when the highs
    * equal the lows).
    *
    * When calculating the DM over a period > 1, the one-period DM
    * for the desired period are initialy sum. In other word, 
    * for a -DM14, sum the -DM1 for the first 14 days (that's 
    * 13 values because there is no DM for the first day!)
    * Subsequent DM are calculated using the Wilder's
    * smoothing approach:
    * 
    *                                    Previous -DM14
    *  Today's -DM14 = Previous -DM14 -  -------------- + Today's -DM1
    *                                         14
    *
    * (Same thing for +DM14)
    *
    * Calculation of a -DI14 is as follow:
    * 
    *               -DM14
    *     -DI14 =  --------
    *                TR14
    *
    * (Same thing for +DI14)
    *
    * Calculation of the TR14 is:
    *
    *                                   Previous TR14
    *    Today's TR14 = Previous TR14 - -------------- + Today's TR1
    *                                         14
    *
    *    The first TR14 is the summation of the first 14 TR1. See the
    *    TA_TRANGE function on how to calculate the true range.
    *
    * Calculation of the DX14 is:
    *    
    *    diffDI = ABS( (-DI14) - (+DI14) )
    *    sumDI  = (-DI14) + (+DI14)
    *
    *    DX14 = 100 * (diffDI / sumDI)
    *
    *    (Note: The DX is rounded)
    *
    * Calculation of the first ADX:
    *
    *    ADX14 = SUM of the first 14 DX
    *
    * Calculation of subsequent ADX:
    *
    *            ((Previous ADX14)*(14-1))+ Today's DX
    *    ADX14 = -------------------------------------
    *                             14
    *
    *   (Note: The ADX is rounded)
    *
    * Reference:
    *    New Concepts In Technical Trading Systems, J. Welles Wilder Jr
    */

   if( optInTimePeriod_0 > 1 )
      lookbackTotal = (2*optInTimePeriod_0) + TA_UnstablePeriodTable[TA_FUNC_UNST_ADX] - 1;
   else
      lookbackTotal = 2;

   /* Adjust startIdx to account for the lookback period. */
   if( startIdx < lookbackTotal )
      startIdx = lookbackTotal;

   /* Make sure there is still something to evaluate. */
   if( startIdx > endIdx )
   {
      *outBegIdx    = 0;
      *outNbElement = 0;
      return TA_SUCCESS;
   }

   /* Indicate where the next output should be put
    * in the outReal_0.
    */
   outIdx = 0;

   /* Process the initial DM and TR */
   *outBegIdx = today = startIdx;

   prevMinusDM = 0.0;
   prevPlusDM  = 0.0;
   prevTR      = 0.0;
   today       = startIdx - lookbackTotal;
   prevHigh    = inHigh_0[today];
   prevLow     = inLow_0[today];
   prevClose   = inClose_0[today];
   i           = optInTimePeriod_0-1;
   while( i-- > 0 )
   {
      /* Calculate the prevMinusDM and prevPlusDM */
      today++;
      tempReal = inHigh_0[today];
      diffP    = tempReal-prevHigh; /* Plus Delta */
      prevHigh = tempReal;

      tempReal = inLow_0[today];
      diffM    = prevLow-tempReal;   /* Minus Delta */
      prevLow  = tempReal;

      if( (diffM > 0) && (diffP < diffM) )
      {
          /* Case 2 and 4: +DM=0,-DM=diffM */
          prevMinusDM += diffM;
      }
      else if( (diffP > 0) && (diffP > diffM) )
      {
          /* Case 1 and 3: +DM=diffP,-DM=0 */
          prevPlusDM += diffP;
      }

      TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal);
      prevTR += tempReal;
      prevClose = inClose_0[today];
   }

   /* Add up all the initial DX. */
   sumDX = 0.0;
   i = optInTimePeriod_0;
   while( i-- > 0 )
   {
      /* Calculate the prevMinusDM and prevPlusDM */
      today++;
      tempReal = inHigh_0[today];
      diffP    = tempReal-prevHigh; /* Plus Delta */
      prevHigh = tempReal;

      tempReal = inLow_0[today];
      diffM    = prevLow-tempReal;   /* Minus Delta */
      prevLow  = tempReal;

      prevMinusDM -= prevMinusDM/optInTimePeriod_0;
      prevPlusDM  -= prevPlusDM/optInTimePeriod_0;

      if( (diffM > 0) && (diffP < diffM) )
      {
         /* Case 2 and 4: +DM=0,-DM=diffM */
         prevMinusDM += diffM;
      }
      else if( (diffP > 0) && (diffP > diffM) )
      {
         /* Case 1 and 3: +DM=diffP,-DM=0 */
         prevPlusDM += diffP;
      }

      /* Calculate the prevTR */
      TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal);
      prevTR = prevTR - (prevTR/optInTimePeriod_0) + tempReal;
      prevClose = inClose_0[today];

      /* Calculate the DX. The value is rounded (see Wilder book). */
      minusDI = round_pos(100.0*(prevMinusDM/prevTR));
      plusDI  = round_pos(100.0*(prevPlusDM/prevTR));

      /* This loop is just to accumulate the initial DX */
      sumDX  += round_pos( 100.0 * (fabs(minusDI-plusDI)/(minusDI+plusDI)) );
   }

   /* Calculate the first ADX */
   prevADX = round_pos( sumDX / optInTimePeriod_0 );

   /* Skip the unstable period */
   i = TA_UnstablePeriodTable[TA_FUNC_UNST_ADX];
   while( i-- > 0 )
   {
      /* Calculate the prevMinusDM and prevPlusDM */
      today++;
      tempReal = inHigh_0[today];
      diffP    = tempReal-prevHigh; /* Plus Delta */
      prevHigh = tempReal;

      tempReal = inLow_0[today];
      diffM    = prevLow-tempReal;   /* Minus Delta */
      prevLow  = tempReal;

      prevMinusDM -= prevMinusDM/optInTimePeriod_0;
      prevPlusDM  -= prevPlusDM/optInTimePeriod_0;

      if( (diffM > 0) && (diffP < diffM) )
      {
         /* Case 2 and 4: +DM=0,-DM=diffM */
         prevMinusDM += diffM;
      }
      else if( (diffP > 0) && (diffP > diffM) )
      {
         /* Case 1 and 3: +DM=diffP,-DM=0 */
         prevPlusDM += diffP;
      }

      /* Calculate the prevTR */
      TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal);
      prevTR = prevTR - (prevTR/optInTimePeriod_0) + tempReal;
      prevClose = inClose_0[today];

      /* Calculate the DX. The value is rounded (see Wilder book). */
      minusDI  = round_pos(100.0*(prevMinusDM/prevTR));
      plusDI   = round_pos(100.0*(prevPlusDM/prevTR));
      tempReal = round_pos(100.0*(fabs(minusDI-plusDI)/(minusDI+plusDI)));

      /* Calculate the ADX */
      prevADX = round_pos(((prevADX*(optInTimePeriod_0-1))+tempReal)/optInTimePeriod_0);     
   }

   /* Output the first ADX */
   outReal_0[0] = prevADX;
   outIdx = 1;

   /* Calculate and output subsequent ADX */
   while( today < endIdx )
   {
      /* Calculate the prevMinusDM and prevPlusDM */
      today++;
      tempReal = inHigh_0[today];
      diffP    = tempReal-prevHigh; /* Plus Delta */
      prevHigh = tempReal;

      tempReal = inLow_0[today];
      diffM    = prevLow-tempReal;   /* Minus Delta */
      prevLow  = tempReal;

      prevMinusDM -= prevMinusDM/optInTimePeriod_0;
      prevPlusDM  -= prevPlusDM/optInTimePeriod_0;

      if( (diffM > 0) && (diffP < diffM) )
      {
         /* Case 2 and 4: +DM=0,-DM=diffM */
         prevMinusDM += diffM;
      }
      else if( (diffP > 0) && (diffP > diffM) )
      {
         /* Case 1 and 3: +DM=diffP,-DM=0 */
         prevPlusDM += diffP;
      }

      /* Calculate the prevTR */
      TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal);
      prevTR = prevTR - (prevTR/optInTimePeriod_0) + tempReal;
      prevClose = inClose_0[today];

      /* Calculate the DX. The value is rounded (see Wilder book). */
      minusDI  = round_pos(100.0*(prevMinusDM/prevTR));
      plusDI   = round_pos(100.0*(prevPlusDM/prevTR));
      tempReal = round_pos(100.0*(fabs(minusDI-plusDI)/(minusDI+plusDI)));

      /* Calculate and output the ADX */
      prevADX = round_pos(((prevADX*(optInTimePeriod_0-1))+tempReal)/optInTimePeriod_0);     
      outReal_0[outIdx++] = prevADX;
   }

   *outNbElement = outIdx;

   return TA_SUCCESS;
}