I’m wanting to have a study at the bottom of a chart that shows ETFs and the top 10 holdings and if how those holdings look if they have a bullish or bearish EMA crossover. If it is bullish (5 is over 21) then a green dot, bearish (5 below 21) then a red dot. The script section of this code is giving me issues to achieve this. I’ve left out part of the code (max 5000 characters) but I have all 10 spaces listed.
Declare lower;
#inputs
input symbol5 = \”QQQ\”;
input symbol4 = \”SPY\”;
input symbol3 = \”XLE\”;
input symbol2 = \”XLK\”;
input symbol1 = \”XLF\”;
input showLabels = yes;
input length1 = 5;
input length2 = 21;
input price = close;
input displace = 0;
defineGlobalColor(\”BearishEMA\”, color.red);
defineGlobalColor(\”BullishEMA\”, color.green);
script SymbolExpAverage {
input symbol = \”\”;
def length1 = \”\”;
def length2 = \”\”;
def price = close;
def displace = 0;
if length1 == ExpAverage(close(period = P1), length1) and
length2 == ExpAverage(close(period = P1), length2) then {length1 = Double.NaN; length2 = Double.NaN;} }
def s1s = SymbolExpAverage(symbol1);
def s2s = SymbolExpAverage(symbol2);
def s3s = SymbolExpAverage(symbol3);
def s4s = SymbolExpAverage(symbol4);
def s5s = SymbolExpAverage(symbol5);
#plots
plot symb1 = if !IsNaN(close) and !isNan(close(symbol1)) then 1 else Double.NaN;
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
symb1.SetLineWeight(5);
symb1.AssignValueColor(if s1s >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”));
AddChartBubble(showLabels and isNan(close) and !isNan(close[1]) and !isNan(close(symbol1)[1]), 1, \”1: \” + symbol1,if s1s[1] >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”), yes);
symb1.HideBubble();
plot symb2 = if !IsNaN(close) and !isNan(close(symbol2) ) then 2 else Double.NaN;
symb2.SetPaintingStrategy(PaintingStrategy.POINTS);
symb2.SetLineWeight(5);
symb2.AssignValueColor(if s2s >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”));
AddChartBubble(showLabels and isNan(close[4]) and !isNan(close[5]) and !isNan(close(symbol2)[5]), 2, \”2: \” + symbol2,if s2s[5] >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”), yes);
symb2.HideBubble();
plot symb3 = if !IsNaN(close) and !isNan(close(symbol3) ) then 3 else Double.NaN;
symb3.SetPaintingStrategy(PaintingStrategy.POINTS);
symb3.SetLineWeight(5);
symb3.AssignValueColor(if s3s >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”));
AddChartBubble(showLabels and isNan(close) and !isNan(close[1]) and !isNan(close(symbol3)[1]), 3, \”3: \” + symbol3,if s3s[1] >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”), yes);
symb3.HideBubble();
plot symb4 = if !IsNaN(close) and !isNan(close(symbol4) ) then 4 else Double.NaN;
symb4.SetPaintingStrategy(PaintingStrategy.POINTS);
symb4.SetLineWeight(5);
symb4.AssignValueColor(if s4s >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”));
AddChartBubble(showLabels and isNan(close[4]) and !isNan(close[5]) and !isNan(close(symbol4)[5]), 4,\”4: \” + symbol4,if s4s[5] >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”), yes);
symb4.HideBubble();
plot symb5 = if !IsNaN(close) and !isNan(close(symbol5) ) then 5 else Double.NaN;
symb5.SetPaintingStrategy(PaintingStrategy.POINTS);
symb5.SetLineWeight(5);
symb5.AssignValueColor(if s5s >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”));
AddChartBubble(showLabels and isNan(close) and !isNan(close[1]) and !isNan(close(symbol5)[1]), 5, \”5: \” + symbol5,if s5s[1] >= 0 then GlobalColor(\”BullishEMA\”) else GlobalColor(\”BearishEMA\”), yes);
symb5.HideBubble();
#Spacers
symb1.hideTitle();
symb2.hideTitle();
symb3.hideTitle();
symb4.hideTitle();
symb5.hideTitle();
plot spacer0 = if !isNan(close) and !isNan(close(symbol10)) then 10.5 else double.nan;
plot spacer1 = if !isNan(close) and !isNan(close(symbol1)) then 1.5 else double.nan;
plot spacer2 = if !isNan(close) and !isNan(close(symbol2)) then 2.5 else double.nan;
plot spacer3 = if !isNan(close) and !isNan(close(symbol3)) then 3.5 else double.nan;
plot spacer4 = if !isNan(close) and !isNan(close(symbol4)) then 4.5 else double.nan;
plot spacer5 = if !isNan(close) and !isNan(close(symbol5)) then 5.5 else double.nan;
spacer0.setdefaultColor(color.gray);
spacer1.setdefaultColor(color.gray);
spacer2.setdefaultColor(color.gray);
spacer3.setdefaultColor(color.gray);
spacer4.setdefaultColor(color.gray);
spacer5.setdefaultColor(color.gray);
spacer0.hideTitle();
spacer1.hideTitle();
spacer2.hideTitle();
spacer3.hideTitle();
spacer4.hideTitle();
spacer5.hideTitle();
Like this:
Like Loading...