Momentum Candles Indicator

barbaros

Administrator
Staff member
Platform
  1. Thinkorswim
GwXHyDX.png


Code:
# Momentum Candles
# b4indicators.com
# Free for use. Header credits must be included when any form of the code included in this package is used.
# Any indicator built on this indicator needs to attribute the original author's work

# Define the conditions for green candles
def GreenCandle = close > open;
def HigherClose = close > close[1];
def isMomentumGreen = GreenCandle and HigherClose and GreenCandle[1] and HigherClose[1] and GreenCandle[2] and HigherClose[2];

# Define the conditions for red candles
def RedCandle = close < open;
def LowerClose = close < close[1];
def isMomentumRed = RedCandle and LowerClose and RedCandle[1] and LowerClose[1] and RedCandle[2] and LowerClose[2];

# Suppress arrows for the next five candles after the signal
rec isMomentumPrev = if isMomentumGreen[1] and !isMomentumGreen[2] or isMomentumRed[1] and !isMomentumRed[2] then 5 else if isMomentumPrev[1] > 0 then isMomentumPrev[1] - 1 else 0;

# Generate the signal for both green and red momentum
def signalGreen = isMomentumGreen and isMomentumPrev == 0;
def signalRed = isMomentumRed and isMomentumPrev == 0;

# Add a single label to display the momentum signal
AddLabel(yes, "isMomentum:   " + if signalGreen then "BUY     " else if signalRed then "SELL     " else "NONE   ", if signalGreen then Color.GREEN else if signalRed then Color.RED else Color.WHITE);

# Plot an arrow at the close of the three green or red candles
plot ArrowUp = if signalGreen then low - TickSize() else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetLineWeight(3);
ArrowUp.SetDefaultColor(Color.GREEN);

plot ArrowDown = if signalRed then high + TickSize() else Double.NaN;
ArrowDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDown.SetLineWeight(3);
ArrowDown.SetDefaultColor(Color.RED);
 
Top