I have a study that plots 8, 21, 34, 55, and 89 ema averages. These are the averages that John Carter said he uses in one of his videos. When the 8 and 21 ema cross, the script calculates the percent difference between the 8 ema's current bar and the previous bar. The script puts a bubble everywhere there is a cross, but I only want the last bubble to show for the last 8/21 ema crossover. The idea behind this study is to get a feel for how strong the cross is. The percent changes are so small that I multiplied
the calculation by a factor of 100 to get more readable numbers. The higher the number the stronger the cross. Here is the script. I've tried but can't figure out how
to eliminate all the bubbles except the last one.
the calculation by a factor of 100 to get more readable numbers. The higher the number the stronger the cross. Here is the script. I've tried but can't figure out how
to eliminate all the bubbles except the last one.
Code:
declare lower;
input first =8;
input second = 21;
input third = 34;
input fourth = 55;
input fifth = 89;
def limit_bubble_display = 1;
def bubbles_to_display = 1;
plot num1 = ExpAverage(close,first);
num1.SetDefaultColor(Color.GREEN);
plot num2 = ExpAverage(close,second);
num2.SetDefaultColor(Color.WHITE);
plot num3 = ExpAverage(close,third);
num3.SetDefaultColor(Color.MAGENTA);
plot num4 = ExpAverage(close,fourth);
num4.SetDefaultColor(Color.CYAN);
plot num5 = ExpAverage(close,fifth);
num5.SetDefaultColor(Color.RED);
def num1crossabove = if num1 crosses above num2 then 1 else 0 ;
plot N1CA = num1crossabove;
N1CA.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
N1CA.SetDefaultColor(color.green);
def num1crossbelow = if num1 crosses below num2 then 1 else 0;
plot N1CB = num1crossbelow;
N1CB.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
N1CB.SetDefaultColor(color.red);
# Multiplied the percent difference by a factor of 100 to get numbers more easily read and compared.
# The higher numbers represent steeper crosses on a relative basis.
def crosspercent = if N1CA or N1CB then ((num1 - num1[1])/num1[1])*100 else double.nan;
AddChartBubble(N1CA or N1CB, high, crosspercent,if num1crossabove then Color.light_green else color.red, no);