6.1 Basis of candle stick

Candle Sticks make uses of all four daily prices series: high, low, open, close

For a candle sticks, its two ends are high and low prices while two ends of its (real ) body are close and open prices.

Color is important for a candle stick. A candle is a bullish candle if the close > open. A bullish candle is either green or white. A candel is a bearish candle if close < open. A bearish candel is either red or black.

The median of a candle stick is average of closign and opening price:

\[M(t) = \frac{Op(t)+Cl(t)}{2}\]

M <- c()
for (t in 1:N){
  M[t] <- (OP[t]+CL[t])/2
}

There are four important lengths for a candle stick:

  1. upper shadow
  2. lower shadow
  3. whole candle length
  4. body length

The upper shadow is line between high and real body while the lower shadow is line between low and real body. Hence, upper shadow length is

\[US(t)=Hi(t)-\max\{Op(t),Cl(t)\}\]

US <- c()
for (t in 1:N){
  US[t] <- HI[t] - max(OP[t],CL[t])
}

Similarly, lower shadow length is

\[LS(t)=\min\{Op(t),Cl(t)\}-Lo(t)\]

LS <- c()
for (t in 1:N){
  LS[t] <- min(OP[t],CL[t]) - LO[t]
}

Whole candle length is

\[WC(t)=Hi(t)-Lo(t)\]

WC <- c()
for (t in 1:N){
  WC[t] <- HI[t] - LO[t]
}

Body length is

\[BL(t)= |Op(t)-Cl(t)|\]

BL <- c()
for (t in 1:N){
  BL[t] <- abs(OP[t] - CL[t])
}

6.1.1 Remark: More compact code

We have used for loop to do the job but it can be done more elegant way through vector operations:

M <-(OP+CL)/2
US <- HI - pmax(OP,CL)
LS <- pmin(OP,CL) - LO
WC <- HI - LO
BL <- abs(OP - CL)

Note that this vectorized operation would inherit the time series property (i.e., with timestamp). Note that pmax() is to return a vector that gives maximum number for each element in a vector. It is similar for pmin().