# Move bubbles ToS Variable MA

#### Rags

##### New member
I have been using an indicator which provides bubble when the market transitions from one phase to the other. However, the bubbles are positioned right on the candles hence the chart is not crisp. Is there a way to move the bubbles about five candles to the right?

Here is the current Code:

input ChartBubblesOn = no;

input price = close;

input length = 8;

def tmp1 = if price > price[1] then price - price[1] else 0;

def tmp2 = if price[1] > price then price[1] - price else 0;

def d2 = sum(tmp1, length);

def d4 = sum(tmp2, length);

def cond = d2 + d4 == 0;

def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;

def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;

def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price

);

plot VMA = asd;

VMA.setDefaultColor(GetColor(0));

def vwma8 = sum(volume * close, 8) / sum(volume, 8);

def vwma21 = sum(volume * close, 21) / sum(volume, 21);

def vwma34 = sum(volume * close, 34) / sum(volume, 34);

def bullish = if vwma8 > vwma21 and vwma21 > vwma34 then 1 else 0;

def bearish = if vwma8 < vwma21 and vwma21 < vwma34 then 1 else 0;

def distribution = if !bullish and !bearish then 1 else 0;

AddLabel(yes, if bullish and close >= VMA then "Stage: Acceleration" else if bearish and close <= VMA then "Stage: Deceleration" else if close>=VMA then "Stage: Accumulation" else "Stage: Distribution", if bullish and close >= VMA then color.green else if bearish and close <= VMA then color.red else if close >=VMA then color.yellow else color.orange);

VMA.AssignValueColor(if bearish and close<= VMA then color.red

else if bullish and close >= VMA then color.green

else color.gray);

def accumulationToAcceleration = if (bullish and close>=VMA) then 1 else 0;

AddChartBubble(ChartBubblesOn and accumulationToAcceleration and !accumulationToAcceleration[1], close, "Entering Acceleration", color.green);

def distributionToDeceleration = if (bearish and close <= VMA) then 1 else 0;

AddChartBubble(ChartBubblesOn and distributionToDeceleration and !distributionToDeceleration[1], close, "Entering Deceleration", color.red);

#### halcyonguy

##### Well-known member
VIP
I have been using an indicator which provides bubble when the market transitions from one phase to the other. However, the bubbles are positioned right on the candles hence the chart is not crisp. Is there a way to move the bubbles about five candles to the right?

Here is the current Code:

input ChartBubblesOn = no;

input price = close;

input length = 8;

def tmp1 = if price > price[1] then price - price[1] else 0;

def tmp2 = if price[1] > price then price[1] - price else 0;

def d2 = sum(tmp1, length);

def d4 = sum(tmp2, length);

def cond = d2 + d4 == 0;

def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;

def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;

def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price

);

plot VMA = asd;

VMA.setDefaultColor(GetColor(0));

def vwma8 = sum(volume * close, 8) / sum(volume, 8);

def vwma21 = sum(volume * close, 21) / sum(volume, 21);

def vwma34 = sum(volume * close, 34) / sum(volume, 34);

def bullish = if vwma8 > vwma21 and vwma21 > vwma34 then 1 else 0;

def bearish = if vwma8 < vwma21 and vwma21 < vwma34 then 1 else 0;

def distribution = if !bullish and !bearish then 1 else 0;

AddLabel(yes, if bullish and close >= VMA then "Stage: Acceleration" else if bearish and close <= VMA then "Stage: Deceleration" else if close>=VMA then "Stage: Accumulation" else "Stage: Distribution", if bullish and close >= VMA then color.green else if bearish and close <= VMA then color.red else if close >=VMA then color.yellow else color.orange);

VMA.AssignValueColor(if bearish and close<= VMA then color.red

else if bullish and close >= VMA then color.green

else color.gray);

def accumulationToAcceleration = if (bullish and close>=VMA) then 1 else 0;

AddChartBubble(ChartBubblesOn and accumulationToAcceleration and !accumulationToAcceleration[1], close, "Entering Acceleration", color.green);

def distributionToDeceleration = if (bearish and close <= VMA) then 1 else 0;

AddChartBubble(ChartBubblesOn and distributionToDeceleration and !distributionToDeceleration[1], close, "Entering Deceleration", color.red);

yes , bubbles can be placed anywhere on a chart.
the trick is reading valid price data if it is to be to the right of the last bar.
you can define a 'bar' location after the last bar, by using 2 variables with offsets.
one looks back at the last price and another looks back at the bar after the last bar (which will have an error for price)

def x = !isNaN(close[4]) and isNaN(close[3]) ;

this looks back at the last bar and reads the close price

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?