Hey folks, here's a simple Gap up / Gap Down label with some of the TOS boiler plate code for opening and closing prices.
Color coded red /green and shows the gap amount. Cool right? Basic stuff, but helpful.
Color coded red /green and shows the gap amount. Cool right? Basic stuff, but helpful.
Ruby:
plot data = close; ##need one plot###
data.hide();
#open#
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
def PrevDayClose;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) { PrevDayClose = Double.NaN;
} else { PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}
#close#
def prevPrice = open(period = aggregationPeriod)[-1];
def price = open(period = aggregationPeriod);
def DailyOpen = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price;
#defintions#
def gapup = dailyopen>prevDayClose;
def gapdown = dailyopen<prevDayClose;
def upgap = dailyopen-prevDayClose;
def downgap= prevDayClose-dailyOpen;
addlabel(yes, if gapup then " Gapup: +" + upgap + " " else " Gapdown: -" + downgap+ " ", if gapup then createcolor(55,155,55) else createcolor(155,55,55));
Last edited by a moderator: