• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Bollinger bands inside keltner channels candles

arod49

New member
hello I'm looking for candle to be painted blue if the Bollinger bands 20 period are inside of the keltner channel 20 period if anyone can help me out thank you
 

generic

Active member
@arod49

Code:
declare upper;
declare weak_volume_dependency;

input price = close;
input bb_averageType = AverageType.Simple;
input bb_length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

def sDev = stdev(data = price, length = bb_length);

def MidLine = MovingAverage(bb_averageType, data = price, length = bb_length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

input kc_averageType = AverageType.Simple;
input trueRangeAverageType = AverageType.SIMPLE;
input kc_length = 20;
input factor = 1.5;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), kc_length);

def average = MovingAverage(kc_averageType, price, kc_length);
def UpperChannel = average + shift;
def LowerChannel = average - shift;

AssignPriceColor(if UpperBand < UpperChannel and LowerBand > LowerChannel then color.BLUE else color.CURRENT);
 

arod49

New member
@generic hey man I would really appreciate it you can help me out with another code , im looking for candle to be painted yellow IF the LOW of a candle is below keltner channels and Bollinger bands LOWERBAND but CLOSES above the keltner channel/bollingerband LOWERBAND
 

generic

Active member
@arod49 Add this to the bottom of the code. Note that this will overlap with the blue bars if it's also in a squeeze.

Code:
AssignPriceColor(if low < LowerBand and low < LowerChannel and close > LowerBand and close > LowerChannel then color.YELLOW else color.CURRENT);
 

Similar threads

Top