C - D

Disclaimer: The information provided on this page is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security. Please see our Risk Disclosure and Performance Disclaimer Statement.

How to access the studies in MotiveWave:

Go to the top menu, choose Study>Study Group>Study Name

or Go to the top menu, choose Study>All Studies> Start typing in the study name until you see it appear in the list> Click on the study name> Click OK.

Calmar Ratio

The Calmar Ratio was authored by Terry W. Young in 1991. The higher the Calmar Ratio the better the instrument’s performance. The Calmar Ratio is the annual return divided by the maximum peak-to-trough negative return. The user must select linear bars but may change the input (close) and period length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

See Calmar Ratio

How To Trade Using the Calmar Ratio

The Calmar Ratio may be used to evaluate an instrument’s performance. No trading signals are calculated.

Calculation

//input = price, user defined, default is close //period = p1, user defined, default is 30 //abs = absolute value, pow = power //index = current bar number

BarSize bar = getBarSize();
if (bar.getType() == BarSizeType.LINEAR) barMin = bar.getInterval();
else return;
minPerYr = 60*24*30*12;
barsPerYr = minPerYr/barMin;
priorP = price[index-p1];
maxDn = highest(index, p1, input);
dd = (price - maxDn) / maxDn;
ret = (price/priorP) - 1;  //returns for the period
power = barsPerYr/p1;
anualRet = Math.pow((1 + ret), power) - 1; //convert to annual return
maxDd = lowest(index, p1, DD); //largest negative value 
Plot: calmar = anualRet / Math.abs(maxDd);

Center Of Gravity

The Center Of Gravity (COG) is calculated from the sum of prices over a user-defined period. A signal line which is a moving average of the COG is also plotted. Adjustable guides are shown to fine-tune the signals. The user may change the input (close), method (EMA), period lengths and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Center Of Gravity

Adjust the top and bottom guides to control the quantity and quality of the trading signals. If the COG is above the top guide and crosses below the signal line a sell signal is generated. Conversely, if the COG is below the bottom guide and crosses above the signal line a buy signal will be given.

Calculation

//input = price, user defined, default is closing price //method = moving average, user defined, default is EMA //cogPeriod = user defined default is 10 //sigPeriod = user defined default is 5 //sumNum = sumNumerator //sumDen = sumDenomator //MT = moreThan, LT = lessThan //index = current bar number

x = 0;
for (i = index-cogPeriod+1; i++)
    iprice = price[i];
    sumNum = sumNum + (iprice * (x + 1));
    sumDen = sumDen + iprice;
    x++;
end;
cog = 100 * sumNum / sumDen;
sig = ma(index, method, sigPeriod, cog);
//Signals
sell = crossedBelow(cog, sig) AND cog MT topGuide  AND (cog MT highSell);
buy = crossedAbove(cog, sig) AND cog LT bottGuide  AND (cog LT lowBuy);

Chaikin Oscillator

The Chaikin Oscillator is formed by subtracting X-day exponential moving average from a Y-day exponential moving average of the accumulation/distribution line. Typical values of X and Y are (10, 3). The user may change the periods lengths. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using the Chaikin Oscillator

No trading signals are calculated for this indicator

Calculation

//period1 = user defined, default = 3 //period2 = user defined, default = 10 //index = current bar number

prev = ifNull(0, ADL[index-1]);
adl = prev + getVolume(index)*mfm(index);
ema1 = ema(index, period1, ADL);
ema2 = ema(index, period2, ADL);
Plot: co = ema1 - ema2;

Chaikin Money Flow Index

The Chaikin Money Flow Index (CMF) was authored by Marc Chaikin. The CMF is an oscillator derived from the Accumulation/Distribution Line. CMF values are calculated by adding all of the A/D line values for the period and dividing this by the total volume for the period. The user may change only the period length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Chaikin Money Flow (CMF)

No trading signals are calculated for this indicator.

Calculation

//period = user defined, default is 20 //LT = less than, LOR= = less or equal //index = current bar number

adTotal = 0;
volumeTotal = 0;
for(i = index-period+1; i LOR= index; i++)
    adTotal += getVolume(i)*mfm(i);
    volumeTotal += getVolume(i);
endFor
Plot: adTotal / volumeTotal;

Chaikin Volatility Indicator

Chaikin Volatility Indicator by Marc Chaikin is a volatility indicator that includes high-low differences and Rate of Change in its construction. The user may change the method (EMA) and period lengths. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Chaikin Volatility Indicator

The Chaikin Volatility Indicator is meant to be used in conjunction with other indicators. No trading signals are given.

Calculation

//method = moving average (ma) (user defined, default is EMA) //maPeriod = user defined, default is 10 //rocPeriod = user defined, default is 12 //roc = rate of change

hl = high - low;
ma = ma(method, maPeriod, hl);
Plot: cvi = 100 * roc( rocPeriod, ma);

Chande Momentum Oscillator

The Chande Momentum Oscillator (CMO) was authored, not surprisingly, by Tushar Chande. The CMO is the difference between, the sum of all recent gains and the sum of all recent losses, and dividing the result by the sum of all price movements of the given period. It is bounded between the range +100 and -100. The user may change the input (close) and period length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Chande Momentum Oscillator (CMO)

Adjust the top and bottom guides to control the quantity and quality of the trading signals. CMO values above 50 are considered to be overbought and therefore offer an opportunity to sell. CMO values below minus 50 are considered oversold and present an opportunity to buy. If the CMO crosses above the top guide a sell signal will be generated. Conversely, if the CMO crosses below the bottom guide a buy signal will be given. The 0 line divides the bulls above from the bears below.

Calculation

//input = price, user defined, default is closing price //period = user defined, default is 14 //MT = more than //LT = less than //prev = previous, diff = difference //index = current bar number

prevPrice = price[index-1];
diff = price - prevPrice;
cmo1=0,
cmo2=0;
if (diff MT 0) cmo1 = diff;
if (diff LT 0) cmo2 = -diff;
sum1 = sum(index, period, CMO1);
sum2 = sum(index, period, CMO2);
cmo = ((sum1-sum2)/(sum1+sum2)) * 100;
//Signals
buy = crossedAbove(CMO, topGuide);
sell = crossedBelow(CMO, bottomGuide);

Chandelier Exits

Chandelier Exits (CE) was authored, by Chuck LeBeau. CE identifies stop-loss exit points for long or short positions. Optional entry points are also displayed. CE uses an exponential moving average to determine the current trend; then the average true range times a user-defined factor is either, depending upon the trend, added or subtracted from the highest high or lowest low. The user may change the position (long), input (close), method (EMA), period lengths, look back, factor and show entry option. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Chandelier Exits

Chandelier Exits are designed to aid in stop-loss exit decisions. However, entry points are optionally provided. These are based on five consecutive increases in an uptrend (buy) or five consecutive decreases in a downtrend (sell).

Calculation

//position = pos, user defined, default is long //input = price, user defined, default is close //method = moving average (ma), user defined, default is EMA //period1 = maP, user defined, default is 63 //period2 = upP, user defined, default is 22 //period3 = dnP, user defined, default is 22 //look back = lb, user defined, default is 5 //factor = fac, user defined, default is 3 //show entry = showE, user defined boolean, default is false //index = current bar number, prev = previous //shortP = short position, longP = long position //index = current bar number

ma = ma(method, index, maP, key);
prevP = price[index-1];
upTrend = price moreThan ma;
dnTrend = price lessThan ma;
if (upTrend)
    atrUp = atr(index, upP);
    highest = highest(index, upP, HIGH);
    chand = highest - fac * atrUp;
endIf
if (dnTrend)
    atrDn = atr(index, dnP);
    lowest = lowest(index, dnP, LOW);
    chand = lowest + fac * atrDn;
endIf
Plot: chand;
//Signals
lowFive = false;
for (i = -(lb-1); i lessOr=0; i++) 
    cP = price[index+i];
    prevP = price[index+i-1];
    cMa = MA[index+i];
    pMa = MA[index+i-1];
    lowFive =  (cP lessThan prevP AND cP lessThan cMa AND prevP lessThan pMa);
    if (!lowFive) break;
endFor
highFive = false;
for (i = -(lb-1); i lessOr=0; i++)
    cP = price[index+i];
    prevP = price[index+i-1];
    cMa = MA[index+i];
    pMa = MA[index+i-1];
    highFive =  (cP moreThan prevP AND cP moreThan cMa AND prevP moreThan pMa);
    if (!highFive) break;
endFor
sell = false, buy = false;
if (chand != 0)
    if (longP AND upTrend)
        sell = prevP moreThan chand AND price lessThan chand;  //sell to exit
        buy = highFive AND showE; //buy
    endif
    if (shortP AND dnTrend)
        sell = lowFive AND showE; //sell short
        buy = prevP lessThan chand AND price moreThan chand; //buy to cover
    endIf
endIf

Chartmill Value Indicator

The Chartmill Value Indicator (CMVI) was authored by Dirk Vandycke in the Stocks and Commodities Magazine, January 2013. The CMVI uses Moving Averages of True Range and the Midpoint price to calculate adjusted open, high, low and closing prices. These adjusted values are displayed as price bars on a separate graph. The user may change the method (SMA), period length and price bar type. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using The Chartmill Value Indicator

No trading signals are calculated for this indicator.

Calculation

//method = moving average, user defined, default is SMA //x = period, user defined, default is 5 //type = price bar type, default is Candlesticks //index = current bar number

f = ma(method, index, x, MIDPOINT);//MIDPOINT=(high+low)/2
v = ma(method, index, x, TR);//TR=True Range
cmvC = (close - f) / v;
cmvH = (high - f) / v;
cmvL = (low - f) / v;
cmvO = (open - f) / v;
prevCmvO = cmvO[index-1];
prevCmvH = cmvH[index-1];
prevCmvL = cmvL[index-1];
prevCmvC = cmvC[index-1];
Figure fig = new PriceBar(ctx, index, type, cmvO, cmvH, cmvL, cmvC, prevCmvO, prevCmvH, prevCmvL, prevCmvC);
addFigure(fig);

Choppiness Index

The Choppiness Index (CI) was authored by Australian commodity trader E.W. Dreiss. The CI may be used to determine if the market is consolidating or trending. The user may change the period length and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using the Choppiness Index

The Choppiness Index is a directionless indicator. Values above the top guide (61.8) indicate that the market is moving sideways in a ranging or choppy manner. Values below the bottom guide (38.2) indicate the market is trending. The Choppiness Index is best used in conjunction with other studies. No trading signals are calculated for this indicator.

Calculation

//period = user defined, default is 14 //top guide = user defined, default is (fibonacci number) 61.8 //bottom guide = user defined, default is (fibonacci number) 38.2 //index = current bar number

   atr = atr(index, period);
   total = sum(index, period, ATR);
   lowest = lowest(index, period, LOW);
   highest = highest(index, period, HIGH);
   diff = highest - lowest;
   temp = (total/diff);
   Plot: chop = 100 * Math.log10(temp) / Math.log10(period);

CMO Abs

The CMO Abs was authored by Chande and Kroll for Omega Research 1997. The CMO Abs is a momentum indicator somewhat similar to the Relative Strength Index (RSI). It uses the sum of the absolute difference between the current price and the last price, and also a prior price, to create an oscillator with a range of 0 to 100. Adjustable guides are given to fine-tune the trading signals. The user may change the input (close), period and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using CMO Abs

Adjust the top and bottom guides to control the quantity and quality of the trading signals. CMOF values above 70 to 80 are considered to be overbought and therefore offer an opportunity to sell. CMOF values below 30 to 20 are considered oversold and present an opportunity to buy. If the CMOF peaks above the top guide a sell signal will be generated. Conversely, if the CMOF troughs below the bottom guide a buy signal will be given. The 50 line divides the bulls (above) from the bears (below).

Calculation

//input = price, user defined, default is closing price //period = user defined, default is 9 //num = numerator, den = denomator //abs = absolute value, prev = previous //index = current bar number

lastV = price[index-1];
absDiff = abs(price-lastV)
priorV = price[index-period];
num = abs(100 * (price - priorV));
den = sum(index, period, absDiff);
Plot: cmoabs = num / den;
//Signals
prevC = cmoabs[index-1];
highSell = cmoabs for last sell signal, reset to max_negative at each  buy signal;
lowBuy = cmoabs for last buy signal, reset to max_positive at each sell signal;
sell = (cmoabs moreThan topGuide) AND (prevC moreThan cmoabs) AND (cmoabs moreThan highSell);
buy = (cmoabs lessThan bottomGuide AND prevC lessThan cmoabs) AND (cmoabs lessThan lowBuy);

CMO ABS Average

The CMO ABS Average, by Chande and Kroll for Omega Research 1997, uses the average of the absolute difference between the current price and the last price over 3 periods to create an oscillator with a range of 0 to 100. Adjustable guides are given to fine-tune the trading signals. The user may also change the input (close) and period values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using CMO ABS Average

Adjust the top and bottom guides to control the quantity and quality of the trading signals. CMOABSAV values above 70 to 80 are considered to be overbought and therefore offer an opportunity to sell. CMOABSAV values below 30 to 20 are considered oversold and present an opportunity to buy. If the CMOABSAV peaks above the top guide, a sell signal will be generated. Conversely, if the CMOABSAV troughs below the bottom guide, a buy signal will be given. The 50 line divides the bulls (above) from the bears (below).

Calculation

//input = price (user defined, default is closing price) //period1 = user defined, default is 5 //period2 = user defined, default is 10 //period3 = user defined, default is 20 //abs = absolute value, diff = difference //index = current bar number

lastV = price[index-1];
diff = price - lastV;
absDiff = abs(diff);
diffSum1 = sum(index, period1, diff);
absSum1 = sum(index, period1, absDiff);
diffSum2 = sum(index, period2, diff);
absSum2 = sum(index, period2, absDiff);
diffSum3 = sum(index, period3, diff);
absSum3 = sum(index, period3, absDiff);
temp1 = diffSum1/absSum1;
temp2 = diffSum2/absSum2;
temp3 = diffSum3/absSum3;
Plot: cmoAbsAv = abs(100 * (temp1 + temp2 + temp3) / 3);
 //Signals
prevC = cmoAbsAv[index-1];
highSell = cmoAbsAv for last sell signal, reset to max_negative at each  buy signal;
lowBuy = cmoAbsAv for last buy signal, reset to max_positive at each sell signal;
sell = cmoAbsAv moreThan topGuide AND prevC moreThan cmoAbsAv AND cmoAbsAv moreThan highSell;
buy = cmoAbsAv lessThan bottGuide AND prevC lessThan cmoAbsAv AND cmoAbsAv lessThan lowBuy;

CMO And WMA

CMO And WMA was authored by Chande and Kroll for Omega Research 1997. The CMO uses the absolute difference between price and previous price with sums and averages to arrive at its value. A signal line which is a Weighted Moving Average (WMA) of the CMO is also plotted. Adjustable guides are given to fine tune the trading signals. The user may change the input (close), method (WMA), period lengths and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using CMO And WMA

Adjust the top and bottom guides to control the quantity and quality of the trading signals. CMO values above 50 are considered to be overbought and therefore offer an opportunity to sell. CMO values below minus 50 are considered oversold and present an opportunity to buy. If the CMO is above the top guide and crosses below the CMOWMA a sell signal will be generated. Conversely, if the CMO is below the bottom guide and crosses above the CMOWMA a buy signal will be given. The 0 line divides the bulls above from the bears below.

Calculation

//input = price, user defined, default is closing price //period1 = user defined, default is 9 //period2 = user defined, default is 9 //method = moving average (ma), user defined, default is WMA //abs = absolute value, prev = previous //index = current bar number

cmo = cmo(index, period1, input);
Plot: cmowma = ma(method, index, period2, CMO);
//Signals
highSell = rmaix for last sell signal, reset to max_negative at each  buy signal;
lowBuy = rmaix for last buy signal, reset to max_positive at each sell signal;
sell = crossedBelow(CMO, CMOWMA) AND cmo moreThan topGuide AND (cmo moreThan highSell);
buy = crossedAbove(CMO, CMOWMA)  AND cmo lessThan bottGuide AND (cmo lessThan lowBuy);
....
Method cmo(index, period, input)
sumD = 0;
for (i = index-period+1; i lessOr= index; i++)
    iprice = price[i];
    prevP = price[i-1];
    sumD = sumD + (Math.abs(price - prevP));
endFor
priorP = price[index-period];
cmo = 100 * (price - priorP) / sumD;
return cmo;
endMethod
....

CMO Average

CMO Average (cmoAv) by Chande and Kroll for Omega Research 1997 is a momentum indicator. It uses data from up and down days, averages 3 summation periods and has a range of 100 to -100. Adjustable guides are given to fine-tune the signals. The user may change the input (close), period lengths and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using cmoAv

Adjust the top and bottom guides to control the quantity and quality of the trading signals. CmoAv values above 50 are considered to be overbought and therefore offer an opportunity to sell. CmoAv values below -50 are considered oversold and present an opportunity to buy. If the cmoAv peaks above the top guide a sell signal will be generated. Conversely, if the cmoAv troughs below the bottom guide a buy signal will be given. The 0 line divides the bulls (above) from the bears (below).

Calculation

//input = price (user defined, default is closing price) //period1 = user defined, default is 5 //period2 = user defined, default is 10 //period3 = user defined, default is 20 //prev = previous, index = current bar number //abs = absolute value //MT = more than, LT = less than

prevValue1 = price[index-1];
minusC1 = price - prevValue1;
absMinusC1 = abs(minusC1);
sumP1 = sum(index, period1, minusC1);
absSumP1 = sum(index, period1, absMinusC1);
sumP2 = sum(index, period2, minusC1);
absSumP2 = sum(index, period2, absMinusC1);
sumP3 = sum(index, period3, minusC1);
absSumP3 = sum(index, period3, absMinusC1);
Plot: cmoAv = 100 * (((sumP1/absSumP1) + (sumP2/absSumP2) + (sumP3/absSumP3)) / 3);
//Signals
prevCmo = cmoAv[index-1];
highSell = cmoAv for last sell signal, reset to max_negative at each  buy signal;
lowBuy = cmoAv for last buy signal, reset to max_positive at each sell signal;
sell = (cmoAv MT topGuide) AND (prevCmo MT cmoAv) AND (cmoAv MT highSell);
buy = (cmoAv LT bottomGuide AND prevCmo LT cmoAv)  AND (cmoAv LT lowBuy);

CMO Filter

The CMO Filter was authored by Chande and Kroll for Omega Research 1997. A user-defined filter is applied to the real and absolute sum of the difference between the current price and last price. The quotient is oversized to create an oscillator with a range of 100 to -100. Adjustable guides are given to fine-tune the trading signals. The user may change the input (close), period, filter and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using CMO Filter

Fine-tune the top and bottom guides to control the quantity and quality of the trading signals. CMOF values above 70 are considered to be overbought and therefore offer an opportunity to sell. CMOF values below -70 are considered oversold and present an opportunity to buy. If the CMOF peaks above the top guide a sell signal will be generated. Conversely, if the CMOF troughs below the bottom guide a buy signal will be given. The 0 line divides the bulls (above) from the bears (below).

Calculation

//input = price (user defined, default is closing price) //period = user defined, default is 9 //filter = user defined, default is 3 //prev = previous, index = current bar number //abs = absolute value, diff = difference //MT = more than, LT = less than

prevValue = price[index-1];
diffV = price - prevValue;
absV = abs(diffV);
if (absV MT filter) diffV = 0; absV = 0;
temp1 = sum(index, period, diffV);
temp2 = sum(index, period, absV);
Plot: cmof = 100 * temp1 / temp2;
//Signals
prevC = cmof[1];
highSell = cmof for last sell signal, reset to max_negative at each  buy signal;
lowBuy = cmof for last buy signal, reset to max_positive at each sell signal;
sell = (cmof MT topGuide) AND (prevC MT cmof)  AND (cmof MT highSell);;
buy = (cmof LT bottGuide AND prevC LT cmof) AND (cmof LT lowBuy); 

Commodity Channel Index (CCI)

Donald Lambert introduced the Commodity Channel Index (CCI) in 1980. It is designed to identify cyclical turns in commodities. The assumption is that commodities move in cycles, with highs and lows at periodic intervals. It is recommended to use 1/3 of a complete cycle as a time frame (IE: for a 60-day cycle, use a 20-day CCI). The user may change only the period length. The CCI is a momentum oscillator that measures the deviation of the current price from its historical mean, which helps gauge the distance of the price from its average. The CCI line oscillates around the zero line with thresholds of +100 and -100. This indicator signals overbought/oversold conditions, trend direction and potential reversals. Click here for more information.

How To Trade Using Commodity Channel Index

If the CCI value is above +100, it indicates an overbought condition, and therefore, a potential reversal might happen from up to a downtrend. The condition when the CCI value reaches above +100 also shows a strong price movement and might be an uptrend. In contrast, if the CCI value falls below the -100 level, it implies the price is relatively low and the market is in an oversold condition. This means a potential reversal to an uptrend might occur.

Adjust the top and bottom guides to control the quantity and quality of the trading signals. If the CCI crosses above the top guide (+100) from below, this might be a sign for buying. Conversely, if the CCI crosses below the bottom guide (-100) from above, it might signal selling opportunities.

When the price makes higher highs but the CCI line makes lower highs, it suggests a potential downward reversal and the momentum is weakening. When the price makes lower lows but the CCI line makes higher lows, it signals a potential uptrend reversal.

Calculation

This indicator’s definition is further expressed in the condensed code given in the calculation below:

//period = user defined, default is 20 //LT = less than, LOR= = less or equal //index = current bar number

TP[] = new [period];
j = 0;
sum = 0;
for(int i = index-period+1; i LOR= index; i++)
      TP[j] = getTypicalPrice(i);
      sum += TP[j];
      j++;
endFor
SMATP = sum / period;      
// Calculate the Mean Deviation
sum = 0;
for(int i = 0; i LT TP.length; i++) 
      sum += Math.abs(TP[i]-SMATP);
endFor
MD = sum / period;
Plot: CCI = (TP[period-1] - SMATP) / (.015*MD);
//Signals
buy = crossedAbove(CCI, topGuide);
sell = crossedBelow(CCI, bottomGuide);

Conditional Accumulator

Conditional Accumulator, by Omega Research 1996, accumulates a valve based on a condition. The user may change the condition, increment and start value. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Conditional Accumulator

No trading signals are given.

Calculation

//condition = default is (low moreThan prevHigh) //increment = user defined, default is 1 //startValue = user defined, default is 0 //index = current bar number, LOE = less or equal

endIndex = getEndIndex() -1;
value = startValue;
for (i = 1; i LOE endIndex; i++)
    if (trendUp)
        prevHigh = high[i - 1];
        low = low[i];
        if (low moreOr= prevHigh) value = value + increment;
    else
        prevLow = low[i - 1];
        high= high[i];
        if (high lessOr= prevLow) value = value - increment;
    endIf
    Plot: value;
endFor

Contract Hi Low

Contract Hi Low was authored by Omega Research 1995. It displays the highest high and the lowest low. No user input is required. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Contract Hi Low

No trading signals are given for this indicator.

Calculation

//con = contract //index = current bar number

conHi = ifNull(high, conHi[index-1]);
conLow = ifNull(low, conLow[index-1]);
if (high moreThan conHi) conHi = hi;
if (low lessThan conLow) conLow = low;
Plot1: conHi;
Plot2: conLow

Coppock Curve

The Coppock Curve (originally named Trendex Model) was authored by E.S.C. Coppock. It is a trend following indicator tallied from the smoothed sum of 2 rates of change periods. The original purpose was for market entries and sell signals were not considered. Both buy and sell signals are generated in this version. Adjustable guides are also given to fine-tune the signals. The user may change the input (close), method (WMA), and period lengths. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using The Coppock Curve

Coppock is not well suited for commodity markets and was originally designed for the S&P 500. It was also designed for monthly trading with periods of 14 (roc1), 11 (roc2) and 10 (wma). If using daily trading change periods to 294, 231 and 210. Adjust the top and bottom guides to control the quantity and quality of the trading signals. Buy signals are given after the coppock troughs below the bottom guide. Conversely, sell signals are given after it peaks above the top guide.

Calculation

//input = price user defined, default is close //period1 = user defined, default is 14 //period2 = user defined, default is 11 //period3 = user defined, default is 10 //method = ma, default is WMA //roc = rate of change //ma = moving average, index = current bar number //MT = more than //LT = less than

roc1 = roc(index, period1, input);
roc2 = roc(index, periodc2, input);
rocSum = roc1 + roc2;
Plot: coppock = ma(method, index, period3, rocSum);
//Signals
highSell = coppock for last sell signal, reset to max_negative on each  buy signal;
lowBuy = coppock for last buy signal, reset to max_positive on each sell signal;
sell = (coppock MT topGuide) AND (prevCoppock MT coppoch) AND (coppock MT highSell);
buy = (coppock LT bottomGuide AND prevCoppock LT coppoch) AND (coppock LT lowBuy);

Correlation Coefficient

Correlation Coefficient in the trading world is a useful measure to identify the strength of relationships between two instruments in price.

The formula for the Correlation Coefficient is as follows:

where: Covar=avgV1V2 − (avgV1 x avgV2) ;

avgV1 = average price of instrument 1 for the period;

avgV2 = average price of instrument 2 for the period;

avgV1V2 = Average of prices of instrument 1 multiplied by prices of instrument 2 for the period'

Var1 = avgV1Sq − (avgV1 × avgV1);

avgV1Sq = Average of the square of prices of instrument 1 (V1 x V1) for the period.

Var2=avgV2Sq−(avgV2×avgV2)

avgV2Sq = Average of the square of prices of instrument 2 (V2 x V2) for the period.

How to trade using Correlation Coefficient

The range of CC is from -1 to +1. If the value of CC is positive, it indicates that the two instruments have the same direction in terms of price. Meanwhile, if CC is negative, it suggests opposite directions of the two instruments. In case the CC is close or equal to 0, the two instruments have little to no relation. Understanding the relationship between two instruments can help traders identify the trend of one instrument based on the other.

Some examples of positive and negative CCs are between Google and Microsoft, and eBay and Amazon.

In the case of Google and Microsoft, the CC value is positive, as demonstrated by the predominantly green area on the chart. This indicates a strong positive relationship between Google and Microsoft, therefore, traders may expect similar price movements for both companies.

On the other hand, eBay and Amazon exhibits an inverse relationship, as illustrated by the largely red area on the second chart below. This suggests that the price actions of this pair often move in opposite directions.

Cumulative Delta

Displays a running total of the delta volume as price bars in a separate plot. The running total is reset daily (using the trading hours).

For details on how to use this study, see our Volume and Order Flow Analysis Guide

Daily Volume Profile

The Daily Volume Profile displays a vertical representation of the volume distribution over the price range for the visible bars. Select intraday bars only. The user may change the number of bars, width, align, range percent and show range option. This indicator’s default values are given in the calculation below.

How To Trade Using the Daily Volume Profile

No trading signals are calculated for this indicator.

Calculation

//Bars = user defined, default is 20 //Width = user defined, default is 100 //Align = user defined, default is right //Range Percent = user defined, default is 70 //Show Range = user defined, default is true

Code may be available on request.

Darvas Box

The Darvas Box (DB) was authored by Nicholas Darvas. The DB system uses highs, lows and a series of logical states to draw boxes around specific groups of price bars. Signals are given when the price breaks through the box. State 1 can start with any bar, and establish the high. State 2 is when the period high is lower than the State 1 period, otherwise it remains in State 1 and forms a new box top. State 3 when the period high is lower than the State 2 period, otherwise it returns to State 1 and forms a new box top. In State 3 a box bottom is formed. This may or may not be the same bar that formed the box top. State 4 is when the period low is higher than the State 3 period, otherwise it remains in State 3 and forms a new box bottom. (If the period high is higher than the box top, form a new box top and return to State 1.) State 5 when the period low is higher than the State 4 period, otherwise it returns to State 3 and forms a new box bottom. (If the period high is higher than the box top, form a new box top and return to State 1.) Only after State 5 is reached is a complete box formed on the chart.

How To Trade Using Darvas Box

Experiment with different time scales, some say weekly charts are best. Once a box is completed, if a high moves above the box top a sell signal will be generated. Conversely, if a low goes below the box bottom a buy signal will be given.

Calculation

//period = user defined, default is 4 //LOE = less or equal, MOE = more or equal

state = 0;
hPrice = 0;
lPrice = 0;
boxTop = 0;
boxBott = 0;
startX = 0;
countTop = 0;
countBott = 0;
endIndex = getEndIndex()-1;
for (i = 0; (i LOE endIndex); i++)
    hPrice = getHigh(i);
    lPrice = getLow(i);
    countTop++;
    if (countTop MOE period) state = 2;
    if (countTop MOE (period*2)) state = 3; countBott++;
    if (countTop MOE (period*2) AND countBott MOE period) state = 4;
    if (countTop MOE (period*2) AND countBott MOE (period*2)) state = 5;
    if (hPrice moreThan boxTop)
        if (state == 5)
            plotBox(startX, boxTop, i, boxBott);
            signal(true);  //Sell signal
            state = 1;
            boxTop = 0;
            countTop = 0;
            countBott = 0;
            continue;
        endIf
        boxTop = hPrice;
        boxBott = lPrice;
        startX = i;
        state = 1;
        countTop = 0;
        countBott = 0;
        continue;
    endIf
    if (lPrice lessThan boxBott)
        if (state == 5)
            plotBox(startX, boxTop, i, boxBott);
            signal(false); //Buy signal
            state = 1;
            boxTop = 0;
            countTop = 0;
            countBott = 0;
            continue;
        endIf
        boxBott = lPrice;
        countBott = 0;
    endIf
    if (state == 2) plotTop(startX, i, boxTop);
    if (state == 3) plotTop(startX, i, boxTop);
    if (state == 3) plotBott(startX, i, boxBott);
    if (state == 4) plotBott(startX, i, boxBott);
endFor
....
Method plotBox(startX,  boxTop, endX, boxBott)
    if (getSettings().getPath(Inputs.PATH).isEnabled())
        if (topLine != null) removeFigure(topLine);
        if (bottLine != null) removeFigure(bottLine);
        PathInfo lineInfo = getSettings().getPath(Inputs.PATH);
        Coordinate start = new Coordinate(getStartTime(startX), boxTop);
        Coordinate end = new Coordinate(getStartTime(endX), boxTop);
        Line line = new Line(start, end, lineInfo);
        addFigure(line);
        start = new Coordinate(getStartTime(endX), boxTop);
        end = new Coordinate(getStartTime(endX), boxBott);
        line = new Line(start, end, lineInfo);
        addFigure(line);
        start = new Coordinate(getStartTime(endX), boxBott);
        end = new Coordinate(getStartTime(startX), boxBott);
        line = new Line(start, end, lineInfo);
        addFigure(line);
        start = new Coordinate(getStartTime(startX), boxBott);
        end = new Coordinate(getStartTime(startX), boxTop);
        line = new Line(start, end, lineInfo);
        addFigure(line);
    endIf
endMethod
....
Method plotTop(startX, endX, boxTop)
if (getSettings().getPath(Inputs.PATH).isEnabled())
        PathInfo lineInfo = getSettings().getPath(Inputs.PATH);
        Coordinate start = new Coordinate(getStartTime(startX), boxTop);
        Coordinate end = new Coordinate(getStartTime(endX), boxTop);
        if (topLine != null) removeFigure(topLine);
        Line line = new Line(start, end, lineInfo);
        topLine = line;
        addFigure(line);
    endIf
endMethod
....
Method plotBott(startX, endX, boxBott)
    if (getSettings().getPath(Inputs.PATH).isEnabled()){
        PathInfo lineInfo = getSettings().getPath(Inputs.PATH);
        Coordinate start = new Coordinate(getStartTime(startX), boxBott);
        Coordinate end = new Coordinate(getStartTime(endX), boxBott);
        if (bottLine != null) removeFigure(bottLine);
        Line line = new Line(start, end, lineInfo);
        bottLine = line;
        addFigure(line);
    endIf
endMethod
....

DecisionPoint Momentum Oscillator (PMO)

DecisionPoint Momentum Oscillator (PMO) was authored by Carl and Erin Swenlin, based on Rate of Change (ROC) study. PMO measures the momentum of the price actions, similar to other momentum oscillators, such as RSI or MACD. The difference between PMO and the other momentum indicators is that PMO employs a dual-smoothing process with a custom exponential moving average (EMA) method. Therefore, PMO provides smoother, more consistent signals and is more responsive to price changes.

There are two lines in a PMO chart: the PMO path and the Signal path. The PMO path illustrates the price momentum. Meanwhile, the Signal path is a 10-period MA of the PMO path that provides signals when it crosses the PMO path.

The following is the PMO's formula: PMO = shortPeriod MA of (10xlongPeriod MA of (((Today's Price/Yesterday's Price) x 100) - 100))

Signal = signalPeriod MA of PMO

Click here for more information.

How to trade using PMO

There are several ways to trade with PMO. Users can look at buy/sell signals on the chart or the overbought/oversold conditions to make decisions.

In terms of buy/sell signals, a buy signal will be generated if the PMO path crosses above the Signal path. This condition indicates a bullish crossover where the price might start to rise. In case the PMO is also below the 0 line, it is even more reliable to buy. Conversely, a sell signal will be given when the PMO path crosses below the Signal path. This condition indicates a bearish crossover where the price might start to fall. In case the PMO is also above the 0 line, it is even more reliable to sell.

In terms of overbought/oversold conditions, consider selling when the PMO path reaches abnormally high levels as it might present an overbought situation. In contrast, if the PMO path approaches abnormally low levels, traders should consider buying since it indicates an oversold situation.

Delta MA

The Delta MA Displays a moving average of the difference between the two given inputs over a given range of bars (Delta Range). The formula for this is as follows: Moving Average(input1 – input2[d], n) where input[d] is the input value of a bar d bars ago. The user may change the inputs, method (WMA), period and delta range length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Delta MA

No trading signals are calculated for this indicator.

Calculation

//input1 = price, user defined, default is close //input2 = price, user defined, default is open //method = moving average (ma), user defined, default is SMA //period = user defined, default is 10 //deltaRange = user defined, default is 5 //index = current bar number

price1 = getPrice(index, input1);
price2 = getPrice(index-deltaRange, input2);
DELTA =  price1 - price2;   
ma = ma(method, index, period, DELTA);
setColor(ma);
PlotHist: DELTA;

Delta Volume

Displays the Delta Volume (Ask Volume - Bid Volume) on a separate plot.

For details on how to use this study, see our Volume and Order Flow Analysis Guide

DEMA 2Lines

DEMA 2Lines by Bill Mars displays two doubly smoothed, exponential moving averages. When the two averages cross trading signals are triggered. The user may change the method (EMA) and period lengths. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using DEMA 2Lines

Trading signals are generated when the DEMA1 and the DEMA2 cross. If the DEMA1 crosses above (upward movement) a buy signal is generated. Conversely, if the DEMA1 crosses below (downward movement) a sell signal is given.

Calculation

//method = moving average(ma), user defined, default is EMA //period1 = user defined, default = 10 //period2 = user defined, default = 40 //ema = expotential moving average

price = (high + low) / 2;
ema1 = ma(method, period1, price);
ema2 = ma(method, period2, price);
Plot1: dema1 = ma(method, period1, ema1);
Plot2: dema2 = ma(method, period2, ema2);
//Signals
buy = crossedAbove(DEMA1, DEMA2);
sell = crossedBelow(DEMA1, DEMA2);

DeMarker

The DeMarker (DM) compares the most recent price action to the previous period’s price in an attempt to measure the demand of the underlying asset. DM is generally used to identify price exhaustion and market tops/bottoms. The user may change only the period length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using DeMarker

Adjust the top and bottom guides to control the quantity and quality of the trading signals. If the DM crosses above the top guide a sell signal will be generated, Conversely, if the DM crosses below the bottom guide a buy signal will be given.

Calculation

//period = user defined, default is 20 //LT = less than, MT= = more than //index = current bar number

dmax = 0;
dmin = 0;
prevH = high[index-1];
prevL = low[index-1];
if (high MT prevH ) dmax = high - prevH;
if (low LT prevL) dmin = prevL - low;
maxMA = sma(index,  period, DMAX);
minMA= sma(index,  period, DMIN);
Plot: DM = (maxMA / (maxMA + minMA))*100;
// Signals
buy =  crossedAbove(DM, topGuide);
sell = crossedBelow(DM, bottGuide);

Detrended Ehlers Leading Indicator

The Detrended Ehlers Leading Indicator(DELI) was authored by Jon Ehlers (See “MESA and Trading Market Cycles” by John Ehlers). The DELI uses highs, previous highs, lows, previous lows and feedback to create two exponential moving averages. First, Detrended Synthetic Price (DSP) is plotted as their difference. Then a third exponential moving average is created from the DSP and the DELI is plotted as their difference. The period length is used but in a non-traditional way. The user may change only this period length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using The Detrended Ehlers Leading Indicator

Detrended Ehlers Leading Indicator may be used in conjunction with other indicators. No trading signals are given.

Calculation

//period = user defined, default is 14 //prev = previous, index = current bar number

prevHigh = high[index-1];
prevLow = low[index-1];
if (prevHigh moreThan high) high = prevHigh;
if (prevLow lessThan low) low = prevLow;
price = (high + low) / 2;
alpha = .67;
if (period moreThan 2) alpha = 2 / (period + 1);
prevEma1 = ifNull(price, ema1[index-1]);  //returns price on first try
ema1 = (alpha * price) + ((1 - alpha) * prevEma1);
prevEma2 = ifNull(price, ema2[index-1]);
ema2 = ((alpha/2) * price) + ((1 - (alpha/2)) * prevEma2);
Plot1: dsp = ema1 - ema2;
prevTemp = ifNull(0,temp[index-1]);
temp = (alpha * dsnp) + ((1 - alpha) * prevTemp);
Plot2: deli = dsp - temp;

Detrended Synthetic Price

Detrended Synthetic Price (DSP) was authored by Bill Mars. The DSP uses highs, previous highs, lows, previous lows and feedback to create two exponential moving averages. The DSP is plotted as their difference. The period length is used but in a non-traditional way. The user may change only this period length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using The Detrended Synthetic Price

Detrended Synthetic Price may be used in conjunction with other indicators. No trading signals are given.

Calculation

//period = user defined, default is 14 //prev = previous, index = current bar number

prevHigh = high[index-1];
prevLow = low[index-1];
if (prevHigh moreThan high) high = prevHigh;
if (prevLow lessThan low) low = prevLow;
price = (high + low) / 2;
alpha = .67;
if (period moreThan 2) alpha = 2 / (period + 1);
prevEma1 = ifNull(price, ema1[index-1]); //returns price on first try
ema1 = (alpha * price) + ((1 - alpha) * prevEma1);
prevEma2 = ifNull(price, ema2[index-1]);
ema2 = ((alpha/2) * price) + ((1 - (alpha/2)) * prevEma2);
Plot: dsp = ema1 - ema2;

Detrended Price Oscillator (DPO)

The Detrended Price Oscillator (DP0) was created by William Blau in 1991. DPO is a lagging oscillating cycle indicator. This means the oscillator generates signals based on historical price data, and might not react timely to the current price actions. Long-term price fluctuations are filtered out by applying a displaced moving average which will shift the latest price movements away. So instead of following the overall trend, the DPO emphasizes smaller cyclical movements, making it easier to identify short-term buy and sell points.

How to trade using DPO

The DPO calculates the cycles by comparing a previous price to a displaced moving average. The result is an oscillator that moves above and below the 0 line. A buy signal is generated when the DPO crosses above the 0 line. Conversely, a sell signal is given when the DPO crosses below the 0 line.

Traders can also use the DPO to identify the short-term overbought/oversold conditions. If the DPO rises from a negative area, it indicates an opportunity to buy. Meanwhile, if the DPO falls from a positive area, it presents an opportunity to sell.

Directional Movement Indicator (DMI)

The Directional Movement Indicator/Index (DMI) was authored by J. Welles Wilder in 1978. DMI is a valuable tool for assessing price direction and strength. It is composed of two indicators, the positive directional indicator (+DMI) and the negative directional indicator (-DMI). The user may change only the period length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

See also Average DMI.

How To Trade Using Directional Movement Indicator (DMI)

The Directional Movement Indicator (DMI) may be used in conjunction with other studies. No signals are calculated for this indicator.

Calculation

//period = user defined, default is 14 //index = current bar number //smma = smoothed moving average //abs = absolute value

// Calculate the +DM, -DM and TR
pDM = getPositiveDM(index);
nDM = getNegativeDM(index);
tr = getTrueRange(index);
// Calculate the Average +DM, -DM and TR
PDMa = smma(index, period, PDM);
NDMa = smma(index, period, NDM);
TRa = smma(index, period, TR);
// Determine the +DI, -DI and DX
Plot1: pDI = PDMa / TRa * 100;
Plot2: nDI = NDMa / TRa * 100;
DX = Math.abs((PDMa - NDMa)) / (PDMa + NDMa) * 100;

Divergent Bars

Divergent Bars by Bill Williams, is an overlay displaying up and down arrows on certain price bars. Divergent Bars (Bullish-green; the current bar must have a lower low than the previous bar AND the current bar must close in the upper half) (Bearish-red; The current bar must have a higher high than the previous bar AND current bar must close in the lower half). This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Divergent Bars

Buy signals are generated if the current low is less than the previous low and the close is more than the midpoint price. Sell signals are generated if the current high is more than the previous high and the close is less than the midpoint price.

Calculation

//currentAverage = midpoint = (high+low)/2previous //prev = previous //LT = lessThan, index = current bar number //MT = moreThan

prevLow = Low[index-1]);
prevHigh = High[index-1];
currentAverage = (High + Low) / 2;
//Signals
buy = (Low LT prevLow AND Close MT currentAverage);
sell = (High MT prevHigh AND Close LT currentAverage);

Divergent Bars Alligator Filter

The Divergent Bars Alligator Filter is a combination of the Divergent Bars and Alligator studies, authored by Bill Williams. The user may change the input (midpoint), method (SMMA), period lengths, shift lengths and percent factor. This indicator’s definition is further expressed in the condensed code given in the calculation below.

See Divergent Bars. See Alligator.

How To Trade Using Divergent Bars Alligator Filter

If the current low is less than the previous low and the close is more than the current average and the current low is less than the minimum low a buy signal will be generated. Conversely, if the current high is more than the previous high and the current close is less than the current average and the current high is more than the maximum high a sell signal will be given.

Calculation

//input = price, user defined, default is midpoint //method = moving average (ma), user defined, default is SMMA //jaw period = jawP = user defined, default is 13 //jaw shift = jawS = user defined, default is 8 //teeth period = teethP = user defined, default is 8 //teeth shift = teethS = user defined, default is 5 //lips period = lipsP = user defined, default is 5 //lips shift = lipsS = user defined, default is 3 //percent factor = fac = user defined, default is 1 //index = current bar number

prevLow = getLow(index - 1);
prevHigh = getHigh(index - 1);
currentAverage = (high + low) / 2;
jaw = ma(method, index, jawP, input);
Plot1: cJaw = jaw[index];
teeth = ma(method, index, teethP, input);
teeth[index+teethS] = teeth;
Plot2: cTeeth = teeth[index];
lips = ma(method, index, lipsP, input);
lips[index+lipsS] = lips;
Plot3: cLips = lips[index];
min = Math.min(Math.min(cJaw, cTeeth),cLips);
max = Math.max(Math.max(cJaw, cTeeth),cLips);
mid = (max + min) * .5;
minL = min - (fac * min/100);
if (minL moreThan mid) minL = mid;
maxH = max + (fac * max/100);
if (maxH lessThan mid) maxH = mid;
Plot4: maxH;;
Plot5: minL;
//Signals
boolean buy = (low lessThan prevLow AND close moreThan currentAverage AND low lessThan minL);
boolean sell = (high moreThan prevHigh AND close lessThan currentAverage AND high moreThan maxH);

Directional Trend Index

The Directional Trend Index by William Blau may be used to determine if a stock is trending and also identifies overbought and undersold conditions. Adjustable guides are given to fine-tune the signals. The user may change the method (EMA), period lengths and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Directional Trend Index

Adjust the top and bottom guides to control the quantity and quality of the trading signals. DTI values above 25 are considered to be overbought and therefore offer an opportunity to sell. DTI values below -25 are considered oversold and present an opportunity to buy. If the DTI peaks above the top guide a sell signal will be generated. Conversely, if the DTI troughs below the bottom guide a buy signal will be given. The 0 line divides the bulls (above) from the bears (below).

Calculation

//method = moving average (ma) user defined, default is EMA //rPeriod = user defined, default is 14 //sPeriod = user defined, default is 10 //uPeriod = user defined, default is 5 //prev = previous //LT = less than, MT = more than //abs = absolute value, index = current bar number

prevHigh = high[index-1];
prevLow = low[index-1];
hmu = 0;
if (high - prevHigh MT 0) hmu = high - prevHigh;
lmd = 0;
if (low - prevLow LT 0) lmd = -(low - prevLow);
diff = hmu - lmd;
absDiff = abs(diff);
ma1 = ma(method, index, rPeriod, diff);
aMa1 = ma(method, index, rPeriod, absDiff);
ma2 = ma(method, index, sPeriod, ma1);
aMa2 = ma(method, index, sPeriod, aMa1);
ma3 = ma(method, index, uPeriod, ma2);
aMa3 = ma(method, , index, uPeriod, aMa2);
Plot: dti = 100 * ma3 /aMa3;
//Signals
prevDti = dti[index-1];
highSell = dti for last sell signal, reset to max_negative at each  buy signal;
lowBuy = dti for last buy signal, reset to max_positive at each sell signal;
sell = (dti MT topGuide) AND (prevDti MT dti) AND (dti MT highSell); //peaked above topGuide
buy = (dti LT bottomGuide AND prevDti LT dti) AND (dti LT lowBuy);  //trough below bottomGuide

Displaced Moving Average

Displaced Moving Average (DMA) displays the previous Moving Average (MA) on the current bar. The MA is also plotted as a signal line for the DMA. The user may change the input (close), method (SMA), period and displace length. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Displaced Moving Averages

Trading signals are generated when the DMA and the MA cross. If the DMA crosses above (upward movement) a buy signal is generated. Conversely, if the DMA crosses below (downward movement) a sell signal is given.

Calculation

//input = price (user defined, default is midpoint price) //method = user defined, default is SMA //period = user defined, default = 13 //displace = user defined, default = 8 //index = current bar number

Plot1: MA = ma(method, index, period, input);
Plot2: DMA = ma(method, index+displace, period, input);
 //Check for signal events
buy = crossedAbove(DMA, MA);
sell = crossedBelow(DMA, MA);

DMI Stochastic

DMI Stochastic was authored by Barbara Star in the Stocks and Commodities Magazine, January 2013. The J. Welles Wilder Directional Movement Plus and Minus Indexes are combined to create an oscillator. These oscillator values are used as input to the familiar Stochastic Oscillator. A moving average of the price is also plotted. The user may change the input (close), methods, period lengths and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

Click here for more information on the Stochastic Oscillator

Click here for more information on the Directional Movement Index

How To Trade Using DMI Stochastic

No trading signals are calculated for this indicator

Calculation

//input = price, user defined, default is closing price //dmiPeriod = user defined, default is 10 //fastKPeriod = user defined, default is 10 //slowKPeriod = user defined, default is 3 //smoothPeriod = user defined, default is 3 //stochasticMethod = moving average, user defined, default is SMA //maPeriod = user defined, default is 50 //maMethod = moving average, user defined, default is SMA //index = current bar number

//Calculate the +DM, -DM and TR 
pDm = series.getPositiveDM(index);
nDm = series.getNegativeDM(index);
tr = series.getTrueRange(index);

//Calculate the Average +DM, -DM and TR 
pdMa = series.smma(index, dmiPd, PDM);
ndMa = series.smma(index, dmiPd, NDM);
tra = series.smma(index, dmiPd, TR);

//Determine the +DI, -DI and DX 
pdi = pdMa / tra * 100;
ndi = ndMa / tra * 100;
Plot: dmiOsc = ndi - pdi;
if (dmiOsc moreThan midGuide) series.setBarColor(index, DMI_OSC, upColor);
else series.setBarColor(index, DMI_OSC, downColor);

//DMI Stochastic
lowest = series.lowest(index, fastkPd, DMI_OSC);
highest = series.highest(index, fastkPd, DMI_OSC);
fastK = (dmiOsc - lowest) / (highest - lowest) * 100.0;
slowK = series.ma(stochMethod, index, slowkPd, FAST_K);
Plot: dmiStoch =series.ma(stochMethod, index, stochSmPd, SLOW_K);

//MA
Plot: ma = series.ma(maMethod, index, maPd, input);

Donchian Channels

Donchian Channels were developed by Richard Donchian. They are displayed as two bands (upper and lower) which are calculated using the highest and lowest prices. These bands are often used as a volatility indicator. The user may change only the period length. This indicator’s definition is further expressed in the condensed code given in the calculation below. Click here for more information.

How To Trade Using Donchian Channel

No trading signals are calculated for this indicator.

Calculation

//period = user defined, default is 20 //index = current bar number

Plot1: top = highest(index, period, HIGH);
Plot2: bottom = lowest(index, period, LOW);

Double Exponential Moving Average (DEMA)

The Double Exponential Moving Average (DEMA) combines a smoothed EMA with a single EMA to provide a diminished amount of delays (than if the two moving averages had been used apart). This is calculated as follows DEMA = 2*EMA – EMA(EMA). The user may change the input (close), period length and shift number. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using the Double Exponential Moving Average

The Double Exponential Moving Average is a lagging trend indicator and may be used in conjuction with other studies. No trading signals are calculated.

Calculation

//input = price, user defined, default is close //period = user defined, default is 20 //shift = user defined, default is 0 //dema = double exponential moving average //index = current bar number

Plot: dema = dema(index+shift, input, period);

Double Smooth Stochastic (DSS)

The Double Smooth Stochastic by William Blau is a version of a stochastic oscillator first promoted by Dr. George Lane in the 1950′s. In this version of stochastics, the numerator (close – period low) and the denominator (period high - period low) are separately, doubly smoothed, with EMA’s and the quotient multiplied by 100. A signal line (SDSS), which is an EMA of the DSS, is plotted to help trigger buy and sell signals. Using EMAs instead of SMAs is the main difference of DSS from Dr.Lane's indicator. The advantage of this approach is that EMAs are more responsive to price movements than SMAs, but also maintain smoothness and reduce noise.

Adjustable guides are also given to fine-tune the signals. The user may change the input (close), method (EMA), period lengths and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

Click here for more information on the Stochastic Oscillator

How to trade using Double Smooth Stochastic

Adjust the top and bottom guides to control the quantity and quality of the trading signals. DSS values above 70 to 80 are considered to be overbought and therefore offer an opportunity to sell. DSS values below 30 to 20 are considered oversold and present an opportunity to buy. In addition to the guides, if the DSS crosses the signal line a change in trend is predicted. If the DSS is above the top guide and crosses below the signal line a sell signal will be generated. Conversely, if the DSS is below the bottom guide and crosses above the signal line a buy signal will be given. The 50 line divides the bulls above from the bears below.

Calculation

//input = price, user defined, default is closing price //method = moving average, user defined, default is EMA //kPeriod = user defined, default is 2 //ssPeriod = user defined, default is 3 //dsPeriod = user defined, default is 15 //sdsPeriod = user defined, default is 3 //num = numerator //den = denomator //ss = single smoothed //ds = double smoothed //dss = double smoothed stochastic //sdss = signal for double smoothed stochastic //index = current bar number

if (HighLow)
    lowest = lowest(index, kPeriod, Low);
    highest = highest(index, kPeriod, High);
else
    lowest = lowest(index, kPeriod, input);
    highest = highest(index, kPeriod, input);
end
num = input - lowest;
den = highest - lowest;
ssNum = ma(method, index, ssPeriod, num);
ssDen = ma(method, index, ssPeriod, den);
dsNum = ma(method, index, dsPeriod, ssNum);
dsDen = ma(method, index, dsPeriod, ssDen);
Plot1: DSS = 100 * dsNum / dsDen;
Plot2: SDSS = ma(method, index, sdsPeriod, DSS);
//Signals
highSell = dss for last sell signal, reset to max_negative at each  buy signal;
lowBuy = dss for last buy signal, reset to max_positive at each sell signal;
sell = crossedBelow(DSS, SDSS) AND dss moreThan topGuide AND dss moreThan highSell;
buy = crossedAbove(DSS, SDSS) AND dss lessThan bottomGuide AND dss lessThan lowBuy;

Double Smooth Stochastic Bressert (DSS Bressert)

The Double Smooth Stochastic Bressert (DSS Bressert) was developed by Walter Bressert. It is a slightly different version of the DSS by William Blau. Similar to the traditional version (which is Dr. Geogre Lane's work), Bressert calculates the K-line using the raw Stochastic first, but this value is not modified at this stage like other versions. Next, an EMA is applied to smooth the K-line. Then the K-line is calculated again using the Stochastic method. Finally, the result is refined the second time with EMA. To summarize, the K-line is computed with the raw Stochastic and the results get double-smoothed by EMA.

How to trade using DSS Bressert

Adjust the top and bottom guides to control the quantity and quality of the trading signals. When the DSS Bressert line crosses the trigger line, a change in trend is predicted. If the DSS line (%K line) crosses below the trigger line, and both lines are above 80 (overbought zone), it indicates a selling opportunity. Conversely, if the DSS line crosses above the trigger line, and both lines are below 20 (oversold zone), it might be a good signal to buy. The 50 line divides the bulls above from the bears below.

DSS Bressert might be used in conjunction with other indicators, especially with long-term trend filters and volume analysis for confirmation.

Drunkard's Walk

The Drunkard’s Walk was authored by Ron Davis in the Stocks And Commodities Mag, December 2011. It is also referred to as a random walk and is an attempt to generate a cycle-free trend identification. Two histograms are given one called an Up Walk, the other a Down Walk. Bollinger Band ranges of the Up and Down Walks determine the color scheme of the histograms. A PercentB path is also shown. The user may change the input (close), Standard Deviation factor, and period lengths. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Drunkard’s Walk

The Drunkard’s Walk may be used with other indicators such as Stochastic Oscillator, Bollinger Bands® and the Commodity Channel Index (CCI). No signals are given for this indicator.

Calculation

//input = price, user defined, default is closing price //period = user defined, default is 80 //pbPeriod = user defined, default is 14 //std = Standard Deviation user defined, default is 2 //index = current bar number

lowArr[] = lowestBar(index, period, LOW); 
highArr[] = highestBar(index, period, HIGH);
lowest = lowArr[0]; //lowest low for the period
highest = highArr[0];  //highest high for the period
maxBar = highArr[1]; //index for highest high
minBar = lowArr[1]; //index for lowest low
dnRun = index - maxBar;
upRun = index - minBar;
//Calculate Average True Range
atrUp = atr(index, upRun);
atrDn = atr(index, dnRun);
den = 0, upWalk = 0, dnWalk = 0;
if (dnRun moreThan 0 AND upRun moreThan 0) 
  den = 1;
  if (atrUp moreThan 0) 
    den = atrUp;
  endIf
  upWalk = (high-lowest) / (Math.sqrt(upRun) * den);
  den = 1;
  if (atrDn moreThan 0) 
     den = atrDn;
  endIf
  dnWalk = (highest-low) / (Math.sqrt(dnRun) * den);
endIf
pcb = perCentB(pbPeriod, index, std, key);
Plot1 upWalk;
Plot2: dnWalk;
Plot3: pcb;
bbUp[] = bollingerBands(index, pbPeriod, std, std, UPWALK);
bbDn[] = bollingerBands(index, pbPeriod, std, std, DNWALK);

setBarColor(index, UPWALK, nUpC);
setBarColor(index, DNWALK, nDnC);

//bbUp[0], bbUp[1]  0 is for top band 1 is for bottom band
if (upWalk lessOrEqual bbUp[1]) 
     setBarColor(index, UPWALK, upBelowC);
endIf
if (dnWalk lessOrEqual bbDn[1])
      setBarColor(index, DNWALK, dnBelowC);
endIf
if (upWalk moreOrEqual bbUp[0])
      setBarColor(index, UPWALK, upAboveC);
endIf
if (dnWalk moreOrEqual bbUp[0])
      setBarColor(index, DNWALK, dnAboveC);
endIf

Dynamic Momentum Index

The Dynamic Momentum Index by Tushar Chande and Stanley Kroll, Stocks and Commodities Mag. 05/1993, is similar to the Relative Strength Index (RSI) except with a variable length period. The user-defined RSI period may be modified (within limits) with the average Standard Deviation value. Signals and adjustable guides are given. The user may change the input (close), period lengths, limits and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using Dynamic Momentum Index

Adjust the top and bottom guides to control the quantity and quality of the trading signals. If the dmi peaks above the top guide a sell signal will be generated. Conversely, if the dmi troughs below the bottom guide a buy signal will be given. The 50 line divides the bulls (above) from the bears (below).

Calculation

//input = price, user defined, default is close //sdPeriod = user defined, default is 5 //avSdPeriod = user defined, default is 10 //rsiPeriod = user defined, default is 14 //upLimit = user defined, default is 30 //loLimit = user defined, default is 5 //stdDev = std = standard deviation //av = average, prev = previous //rsi = Relative Strength Index //sma = simple moving average, index = current bar number

stdDev = std(index, sdPeriod, input);
avSd = sma(index, avSdPeriod, stdDev);
dTime = round(rsiPeriod / avSd); //period dependent on average of stdDev
lenDmi = max(min(dTime, upLimit), loLimit);  //determine period length
Plot: dmi = rsi(lenDmi, input)[0];
 //Signals
prevDmi = dmi[index-1]; 
highSell = dmi for last sell signal, reset to max_negative at each  buy signal;
lowBuy = dmi for last buy signal, reset to max_positive at each sell signal;
sell = (dmi moreThan topGuide) AND (prevDmi moreThan dmi  AND (dmi moreThan highSell); 
buy = (dmi lessThan bottGuide AND prevDmi lessThan dmi AND (dmi lessThan lowBuy);

D Three Ten Oscillator

D Three Ten Oscillator was authored by Bill Mars. The difference in magnitude of a three and ten period moving average maps this oscillator’s path. A signal line, which is an EMA of the D Three Ten, is also plotted to help trigger trading signals. Adjustable guides are added to fine-tune these signals. The user may change the input (close), method (EMA), period lengths and guide values. This indicator’s definition is further expressed in the condensed code given in the calculation below.

How To Trade Using D Three Ten Oscillator

Fine tune the top and bottom guides to control the number and quality of the trading signals. If the D Three Ten (V1) is above the top guide and crosses below the signal line (V2) a sell signal will be generated. Conversely, if the V1 is below the bottom guide and crosses above the signal line (V2) a buy signal will be given. The 0 line divides the bulls (above) from the bears (below).

Calculation

//input = price, user defined, default is midpoint //method = moving average, user defined, default is EMA //period1 = user defined, default is 3 //period2 = user defined, default is 10 //period3 = user defined, default is 16 //ma = moving average, index = current bar number

ma3Day = ma(method, index, period1, key);
ma10Day = ma(method, index, period2, ma3Day);
Plot1: v1 = ma3Day - ma10Day;
Plot2: v2 = ma(method, index, period3, v1);
//Signals
highSell = v1 for last sell signal, reset to max_negative at each  buy signal;
lowBuy = v1 for last buy signal, reset to max_positive at each sell signal;
sell = crossedBelow(v1, v2) AND (v1 moreThan topGuide)  AND (v1 moreThan highSell);
buy = crossedAbove(v1, v2) AND (v1 lessThan bottGuide) AND (v1 lessThan lowBuy);

Last updated