Convert a Label to a Bubble

Branch

Member
VIP
I would like to have this Label code also be a AddBubble on the CCI line and have the bubble if possible on the left side of the line so that it does not cover the current data.
AddLabel(1, " CCI : " + Round(CCI, 1) + (if CUP then " RISING " + "" else if CDN then " FALLING " + "" else " --NEUTRAL"),
if CUP then Color.green else if CDN then color.RED else Color.YELLOW);


Code:
#COMPLETE CODE---------------------
declare lower;
input shortLength = 6;
input longLength = 14;
input lowerSideWinderLimit = 30.0;
input upperSideWinderLimit = 100.0;
input hideSideWinder = No;

def LinearReg = Inertia(close, 25);
def expAvg = ExpAverage(close, 34);
def diff = close - expAvg;
def yyyyMmDd = getYyyyMmDd();
def session_duration_minutes = (regularTradingEnd(yyyyMmDd) - regularTradingStart(yyyyMmDd)) / AggregationPeriod.MIN;
def interval_size_raw;
def aggregation = getAggregationPeriod();
if (aggregation == AggregationPeriod.DAY) {
    interval_size_raw = session_duration_minutes * 60;
} else if (aggregation == AggregationPeriod.TWO_DAYS) {
    interval_size_raw = session_duration_minutes * 60 * 2;
} else if (aggregation == AggregationPeriod.THREE_DAYS) {
    interval_size_raw = session_duration_minutes * 60 * 3;
} else if (aggregation == AggregationPeriod.FOUR_DAYS) {
    interval_size_raw = session_duration_minutes * 60 * 4;
} else if (aggregation == AggregationPeriod.WEEK) {
    interval_size_raw = session_duration_minutes * 60 * 5;
} else if (aggregation == AggregationPeriod.MONTH or aggregation == AggregationPeriod.OPT_EXP) {
    interval_size_raw = session_duration_minutes * 60 * 22;
} else if (aggregation >= AggregationPeriod.MIN) {
    interval_size_raw = aggregation / AggregationPeriod.MIN;
} else {
    interval_size_raw = aggregation;
}

def ema_angle_factor = Sqrt(interval_size_raw / 180);
def avg_ema = (expAvg[2] + expAvg[1]) / 2;
def avg_lsma = (LinearReg[2] + LinearReg[1]) / 2;
def lsma_slope = (LinearReg - avg_lsma) / tickSize();
def lsma_angle = ATan(lsma_slope / ema_angle_factor) / Double.Pi * 180;
def ema_slope = (expAvg - avg_ema) / tickSize();
def ema_angle = ATan(ema_slope / ema_angle_factor) / Double.Pi * 180;
def sw = lsma_angle + ema_angle;
def swabs = AbsValue(sw);

plot CCI = cci(length = longLength);
plot "SW +200" = if IsNaN(close) then Double.NaN else 200;
plot "SW -200" = if IsNaN(close) then Double.NaN else -200;
plot ZeroLine = if IsNaN(close) then Double.NaN else 0;

CCI.SetDefaultColor(GetColor(1));
CCI.SetLineWeight(1);

"SW +200".SetDefaultColor(GetColor(1));
"SW +200".SetLineWeight(2);
"SW +200".SetPaintingStrategy(PaintingStrategy.DASHES);
"SW +200".HideTitle();
"SW +200".HideBubble();
"SW +200".DefineColor("Trending", Color.GREEN);
"SW +200".DefineColor("Normal", Color.YELLOW);
"SW +200".DefineColor("Flat", Color.RED);
"SW +200".AssignValueColor(
    if swabs >= upperSideWinderLimit then "SW +200".color("Trending")
    else if swabs >  lowerSideWinderLimit then "SW +200".color("Normal")
    else "SW +200".color("Flat"));

"SW -200".AssignValueColor("SW +200".TakeValueColor());
"SW -200".SetDefaultColor(GetColor(1));
"SW -200".SetLineWeight(2);
"SW -200".SetPaintingStrategy(PaintingStrategy.DASHES);
"SW -200".HideTitle();
"SW -200".HideBubble();

ZeroLine.SetDefaultColor(GetColor(9));
ZeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);
ZeroLine.SetLineWeight(1);
ZeroLine.HideTitle();

AddLabel (yes,if close then " CCI " else "", Color.GRAY);
#Label Rise and Fall-------------------------------------------------------------------------------------

input n = 1;

def CUP = CCI > CCI[n];
def CDN = CCI < CCI[n];
[B]AddLabel(1, " CCI : " + Round(CCI, 1) + (if CUP then "   RISING " + ""  else if CDN then "   FALLING " + "" else " --NEUTRAL"),
if CUP then Color.green else if CDN then color.RED else Color.YELLOW);[/B]
 
Last edited:

Similar threads

Top