I am wanting to add instruction to a script to only color the first candle in a series.
Below you will see BULL condition will color the candles green and BEAR condition will color red. But...for example in an uptrend there will be many green candles painted and then change to red candles when trend changes. I am looking to color only the first candle (GREEN) that meets the BULL condition and only the first (RED) that meets BEAR condition. I hope I explained this sufficiently.
Below you will see BULL condition will color the candles green and BEAR condition will color red. But...for example in an uptrend there will be many green candles painted and then change to red candles when trend changes. I am looking to color only the first candle (GREEN) that meets the BULL condition and only the first (RED) that meets BEAR condition. I hope I explained this sufficiently.
Code:
declare upper;
input price = close;
input TF1 = AggregationPeriod.MIN;
input TF2 = AggregationPeriod.FIVE_MIN;
input TF3 = AggregationPeriod.FIFTEEN_MIN;
input TF4 = AggregationPeriod.HOUR;
def o1 = open(period = TF1);
def c1 = close(period = TF1);
def o2 = open(period = TF2);
def c2 = close(period = TF2);
def o3 = open(period = TF3);
def c3 = close(period = TF3);
def o4 = open(period = TF4);
def c4 = close(period = TF4);
def BULL = (o1 < c1) and (o2 < c2) and (o3 < c3) and (o4 < c4);
def BEAR = (o1 > c1) and (o2 > c2) and (o3 > c3) and (o4 > c4);
DefineGlobalColor("BULL", Color.GREEN);
DefineGlobalColor("BEAR", Color.RED);
DefineGlobalColor( "default", Color.GRAY );
AssignPriceColor( if BULL then globalColor( "BULL" ) else if BEAR then globalColor( "BEAR" ) else globalColor( "default" ) );
hen globalColor( "BULL" ) else if BEAR then globalColor( "BEAR" ) else globalColor( "default" ) );