AddChartBubble() doesn't display anything

OptionsMillions

New member
VIP
Dear Users,

I have a script with two conditions. AddChartBubble() works fine on either condition (simply uncomment the AddChartBubble portion in condition 1 or condition2). However, when I combine the two conditions, AddChartBubble() doesn't display anything (see the last 4 lines of the code).

Any tips on how to rectify this problem?

Thank you.



Code:
declare upper;

input MovAvgType = AverageType.EXPONENTIAL;

#######################  CONDITION 1  ##################################
input length = 7;
def na = Double.NaN;
def price0 = (high + low + close * 2) / 4;
def r0 = MovingAverage(MovAvgType, price0, length);
def r1 = stdev(price0, length);
def r2 = (price0 - r0) * 100 / r1;
def r3 = MovingAverage(MovAvgType, r2, length);
def u = MovingAverage(MovAvgType, r3, length);
def d = MovingAverage(MovAvgType, u, length);
def Buy0 = Crosses(u, d, CrossingDirection.ABOVE);
def Sell0 = Crosses(u, d, CrossingDirection.BELOW);
#AddChartBubble(Buy0, low, "LONG0", Color.GREEN, no);
#AddChartBubble(Sell0, high, "SHORT0", Color.MAGENTA, yes);
####################  END OF CONDITION 1  ##############################


#######################  CONDITION 2  ############################
input fastlength = 5;
input slowlength = 35;
input MACDlength=10;

def Value = MACD(fastLength, slowLength, MACDLength, MovAvgType).value;
def Avg = MACD(fastLength, slowLength, MACDLength, MovAvgType).Avg;
def Buy1 = value crosses above avg;
def sell1 = value crosses below avg;
#AddChartBubble(Buy1, low-0.01, "LONG1", Color.GREEN, no);
#AddChartBubble(Sell1, high+0.01, "SHORT1", Color.MAGENTA, yes);
####################  END OF CONDITION 2  ##############################


#################### UNIFY CONDITIONs 1 & 2  ###########################
def Buy  = Buy0  and Buy1;
def Sell = Sell0 and Sell1;
AddChartBubble(Buy, low-0.015, "LONG", Color.GREEN, no);
AddChartBubble(Sell, high+0.015, "SHORT", Color.MAGENTA, yes);
 
Solution
Dear Users,

I have a script with two conditions. AddChartBubble() works fine on either condition (simply uncomment the AddChartBubble portion in condition 1 or condition2). However, when I combine the two conditions, AddChartBubble() doesn't display anything (see the last 4 lines of the code).

Any tips on how to rectify this problem?

Thank you.



Code:
declare upper;

input MovAvgType = AverageType.EXPONENTIAL;

#######################  CONDITION 1  ##################################
input length = 7;
def na = Double.NaN;
def price0 = (high + low + close * 2) / 4;
def r0 = MovingAverage(MovAvgType, price0, length);
def r1 = stdev(price0, length);
def r2 = (price0 - r0) * 100 / r1;
def r3 = MovingAverage(MovAvgType, r2, length)...
Dear Users,

I have a script with two conditions. AddChartBubble() works fine on either condition (simply uncomment the AddChartBubble portion in condition 1 or condition2). However, when I combine the two conditions, AddChartBubble() doesn't display anything (see the last 4 lines of the code).

Any tips on how to rectify this problem?

Thank you.



Code:
declare upper;

input MovAvgType = AverageType.EXPONENTIAL;

#######################  CONDITION 1  ##################################
input length = 7;
def na = Double.NaN;
def price0 = (high + low + close * 2) / 4;
def r0 = MovingAverage(MovAvgType, price0, length);
def r1 = stdev(price0, length);
def r2 = (price0 - r0) * 100 / r1;
def r3 = MovingAverage(MovAvgType, r2, length);
def u = MovingAverage(MovAvgType, r3, length);
def d = MovingAverage(MovAvgType, u, length);
def Buy0 = Crosses(u, d, CrossingDirection.ABOVE);
def Sell0 = Crosses(u, d, CrossingDirection.BELOW);
#AddChartBubble(Buy0, low, "LONG0", Color.GREEN, no);
#AddChartBubble(Sell0, high, "SHORT0", Color.MAGENTA, yes);
####################  END OF CONDITION 1  ##############################


#######################  CONDITION 2  ############################
input fastlength = 5;
input slowlength = 35;
input MACDlength=10;

def Value = MACD(fastLength, slowLength, MACDLength, MovAvgType).value;
def Avg = MACD(fastLength, slowLength, MACDLength, MovAvgType).Avg;
def Buy1 = value crosses above avg;
def sell1 = value crosses below avg;
#AddChartBubble(Buy1, low-0.01, "LONG1", Color.GREEN, no);
#AddChartBubble(Sell1, high+0.01, "SHORT1", Color.MAGENTA, yes);
####################  END OF CONDITION 2  ##############################


#################### UNIFY CONDITIONs 1 & 2  ###########################
def Buy  = Buy0  and Buy1;
def Sell = Sell0 and Sell1;
AddChartBubble(Buy, low-0.015, "LONG", Color.GREEN, no);
AddChartBubble(Sell, high+0.015, "SHORT", Color.MAGENTA, yes);

the very first symbol i looked at, had bubbles.
CL 15min
so, i have no answer, except to say, look at more symbols and timeframes, when debugging.

i added a bubble to the end of your code. take a look at it and get in the habit of doing something similar when creating a program, to help you debug it. i do it all the time.

the extra bubble displays 1s and 0s , for the logic.
it changes color, dark for 1 variable true, light if both are true.

Code:
#bubble_no_data_00

declare upper;

input MovAvgType = AverageType.EXPONENTIAL;

#######################  CONDITION 1  ##################################
input length = 7;
def na = Double.NaN;
def price0 = (high + low + close * 2) / 4;
def r0 = MovingAverage(MovAvgType, price0, length);
def r1 = stdev(price0, length);
def r2 = (price0 - r0) * 100 / r1;
def r3 = MovingAverage(MovAvgType, r2, length);
def u = MovingAverage(MovAvgType, r3, length);
def d = MovingAverage(MovAvgType, u, length);
def Buy0 = Crosses(u, d, CrossingDirection.ABOVE);
def Sell0 = Crosses(u, d, CrossingDirection.BELOW);
#AddChartBubble(Buy0, low, "LONG0", Color.GREEN, no);
#AddChartBubble(Sell0, high, "SHORT0", Color.MAGENTA, yes);
####################  END OF CONDITION 1  ##############################


#######################  CONDITION 2  ############################
input fastlength = 5;
input slowlength = 35;
input MACDlength=10;

def Value = MACD(fastLength, slowLength, MACDLength, MovAvgType).value;
def Avg = MACD(fastLength, slowLength, MACDLength, MovAvgType).Avg;
def Buy1 = value crosses above avg;
def sell1 = value crosses below avg;
#AddChartBubble(Buy1, low-0.01, "LONG1", Color.GREEN, no);
#AddChartBubble(Sell1, high+0.01, "SHORT1", Color.MAGENTA, yes);
####################  END OF CONDITION 2  ##############################


#################### UNIFY CONDITIONs 1 & 2  ###########################
def Buy  = Buy0  and Buy1;
def Sell = Sell0 and Sell1;
AddChartBubble(Buy, low-0.015, "LONG", Color.GREEN, no);
AddChartBubble(Sell, high+0.015, "SHORT", Color.MAGENTA, yes);



AddChartBubble(1, low*0.999,
Buy0 + " B0\n" +
Buy1 + " B1\n" +
Sell0 + " S0\n" +
Sell1 + " S0\n" 
,    (if (buy0 and buy1) then color.light_green
 else if (buy0 or buy1) then color.dark_green
 else if (sell0 and sell1) then color.light_red
 else if (sell0 or sell1) then color.dark_red
 else color.gray), no);
#
 

Attachments

  • 1.JPG
    1.JPG
    55.7 KB · Views: 13
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
366 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top