AddLabel(x, if UpSignal then "correct" else "your text here",color.cyan);
declare lower;
input price = close;
input setting_R = {"5", "10", default "15"};
input fastLength = 5;
input slowLength = 20;
input oversold = 20;
input overbought = 80;
def os = oversold;
def ob = overbought;
def period;
switch (setting_R) {
case "5":
period = 5;
case "10":
period = 10;
case "15":
period = 15;
}
def fast = ExpAverage(price, fastLength) - ExpAverage(price, slowLength);
def base = ExpAverage(price, fastLength);
def slow = ExpAverage(price, slowLength);
def hs = Highest(slow, period);
def ls = Lowest(slow, period);
def JKTA_Slow = if hs == ls then 0 else ((hs - slow) / (hs - ls) * (-100) + 100);
def hb = Highest(base, period);
def lb = Lowest(base, period);
def JKTA_Base = if hb == lb then 0 else ((hb - base) / (hb - lb) * (-100) + 100);
def hf = Highest(fast, period);
def lf = Lowest(fast, period);
def JKTA_Fast = if hf == lf then 0 else ((hf - fast) / (hf - lf) * (-100) + 100);
def line50 = 50;
def line0 = 0;
def line100 = 100;
plot BuySignal = if("JKTA_Slow" >= 100 and "JKTA_Base" >= 100 and "JKTA_Fast" >= 99) then 1 else 0 ;
AssignBackgroundColor( if BuySignal then Color.LIGHT_GREEN else Color.DARK_RED);
BuySignal. AssignValueColor( if BuySignal then Color.BLACK else Color.RED);
#change your line of code:
plot BuySignal = if("JKTA_Slow" >= 100 and "JKTA_Base" >= 100 and "JKTA_Fast" >= 99) then 1 else 0 ;
#to this line of code:
plot BuySignal = JKTA_Slow >= 100 and JKTA_Base >= 100 and JKTA_Fast >= 99 ;
def TF = GetAggregationPeriod();
def Displayed_TF = if TF < 3600000 then TF / 60000 + "m" else if TF < 86400000 then TF / 3600000 + "h" else if TF < 604800000 then TF / 86400000 + "D" else TF / 604800000 + "W";
input length = 50;
plot Vol = volume;
plot VolAvg = Average(volume, length);
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.AssignValueColor(if close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
#Inputs
input factor = 0.001;
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def haHigh = Max(high, haopen);
def haHigh2 = Max(haHigh, haclose);
def haLow = Min(low, haopen);
def haLow2 = Min(haLow, haclose);
def RSI = RSI();
def HAdoji = ((haclose >= (1 - factor) * haopen and haclose <= (1 + factor) * haopen) or (haopen >= (1 - factor) * haclose and haopen <= (1 + factor) * haclose)) and (haclose > haLow2) and (haopen > haLow2);
def doji = hadoji and Vol.Color("Up");
plot signal =doji;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.SetDefaultColor(CreateColor(0, 0, 153));
Can you please help with this error:I am trying to script a Watchlist Custom Column. I get an ” expected double” error code at the end. I am fairly new to coding and have no idea what that means or how to fix it. Can you help?
Code:declare lower; input price = close; input setting_R = {"5", "10", default "15"}; input fastLength = 5; input slowLength = 20; input oversold = 20; input overbought = 80; def os = oversold; def ob = overbought; def period; switch (setting_R) { case "5": period = 5; case "10": period = 10; case "15": period = 15; } def fast = ExpAverage(price, fastLength) - ExpAverage(price, slowLength); def base = ExpAverage(price, fastLength); def slow = ExpAverage(price, slowLength); def hs = Highest(slow, period); def ls = Lowest(slow, period); def JKTA_Slow = if hs == ls then 0 else ((hs - slow) / (hs - ls) * (-100) + 100); def hb = Highest(base, period); def lb = Lowest(base, period); def JKTA_Base = if hb == lb then 0 else ((hb - base) / (hb - lb) * (-100) + 100); def hf = Highest(fast, period); def lf = Lowest(fast, period); def JKTA_Fast = if hf == lf then 0 else ((hf - fast) / (hf - lf) * (-100) + 100); def line50 = 50; def line0 = 0; def line100 = 100; plot BuySignal = if("JKTA_Slow" >= 100 and "JKTA_Base" >= 100 and "JKTA_Fast" >= 99) then 1 else 0 ; AssignBackgroundColor( if BuySignal then Color.LIGHT_GREEN else Color.DARK_RED); BuySignal. AssignValueColor( if BuySignal then Color.BLACK else Color.RED);
AddLabel(x, if UpSignal then "correct" else "your text here",color.cyan);
Thanks alot Pensar for your kindness and quick response, it fixed the problem@majidg The error is likely coming from your AddLabel() function. The correct method is "AddLabel( boolean visible, Any text, CustomColor color)"; the problem label attempts to combine the text and color parameters. Change it to something such as
The "boolean visible" parameter is simply yes/no, true/false or or 1/0. By your using plot "x" as the "boolean visible", you already have the label turning on when x equals 1 and off when x equals 0, so there's no need to add "else double.nan" in the label.Code:AddLabel(x, if UpSignal then "correct" else "your text here",color.cyan);
Looking at other labels in the forum can also help you see the different ways people code the AddLabel() function.
https://usethinkscript.com/resources/thinkscript-addlabel-adding-custom-labels-to-your-chart.8/
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddLabel
Hi Pensar, one more question on addchartbubble. I want to write the last price on the current price line, is this correct?Thanks alot Pensar for your kindness and quick response, it fixed the problem
Hi Pensar, one more question on addchartbubble. I want to write the last price on the current price line, is this correct?
AddChartBubble(yes, line+.2, "current_price =", Color.CYAN, no);
I want to add price for the last bar on the line, but it put price on every bar. Thanks for your help.
AddChartBubble(!isnan(close) and isnan(close[-1]), line+.2, "current_price = " + close, Color.CYAN, no);
WOW!, thanks Pensar. I like the way you spend time to explain. I really appreciate.@majidg I think the above will work, test it and see.Code:AddChartBubble(!isnan(close) and isnan(close[-1]), line+.2, "current_price = " + close, Color.CYAN, no);
Think of plotting chart bubbles as graphing a point using the x and y axis. Using the isnan() line assigns the bubble at only one point along the horizontal x-axis, and "line+.2" assigns it at only one point along the vertical y-axis. The "yes" or "no" at the end makes the bubble plot above or below the point you select.
can someone please assist, I get The error message "Expected double at 5:10"
input fastLength = 5;
input slowLength = 34;
input oscillatorLength = 5;
def AO = MACD(fastLength, slowLength, "close").Diff;
def AO_EMA = ExpAverage(AO, oscillatorLength);
def l1 = low < low[1] and low[1] < low[2];
def l2 = low == lowest(low, 10);
def l3 = low < low[2] and low[2] < low[3];
def w = l1 and l2 and l3;
def ao_crossed_below_zero = AO < 0 and AO[1] > 0;
def ao_turned_red = AO_EMA < AO_EMA[1];
def ao_turned_green = AO_EMA > AO_EMA[1];
plot w_bottom = if w and ao_crossed_below_zero and ao_turned_red and ao_turned_green then low else double.nan;
# error2_macd
#https://usethinkscript.com/threads/thinkscript-expected-double-error-how-to-fix.3073/#post-123645
#post18
#wussay #18
#can someone please assist, I get The error message "Expected double at 5:10"
#declare lower;
input fastLength = 5;
input slowLength = 34;
input oscillatorLength = 5;
input MACDLength = 9;
#def AO = MACD(fastLength, slowLength, "close").Diff;
#def AO = MACD(fastLength, slowLength, close).Diff;
def AO = MACD(fastLength, slowLength, macdlength).Diff;
def AO_EMA = ExpAverage(AO, oscillatorLength);
def l1 = low < low[1] and low[1] < low[2];
def l2 = low == Lowest(low, 10);
def l3 = low < low[2] and low[2] < low[3];
def w = l1 and l2 and l3;
def ao_crossed_below_zero = AO < 0 and AO[1] > 0;
def ao_turned_red = AO_EMA < AO_EMA[1];
def ao_turned_green = AO_EMA > AO_EMA[1];
def x = ao_crossed_below_zero and ao_turned_red and ao_turned_green;
plot w_bottom = if w and ao_crossed_below_zero and ao_turned_red and ao_turned_green then low else Double.NaN;
w_bottom.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
w_bottom.SetDefaultColor(Color.green);
w_bottom.setlineweight(3);
w_bottom.hidebubble();
#------------------
#plot z = 0;
addchartbubble(1, high,
#ao + "\n" +
#l1 + "\n" +
#l2 + "\n" +
#l3 + "\n" +
#w + "\n" +
ao_crossed_below_zero + "\n" +
ao_turned_red + "\n" +
ao_turned_green + "\n" +
w_bottom
, (if x then color.yellow else color.gray), yes);
#
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.