thinkScript Expected Double Error: How to Fix?

mike8u

New member
Hi I am not a coder so I ran into a problem off the bat: What does it mean when it expects double? How can I fix it?

Code:
input last = pricetype.LAST;
plot DeltaOpen  =  (last - open) / open;
 
Solution
@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
Code:
AddLabel(x, if UpSignal then "correct" else "your text here",color.cyan);
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.
Looking at other labels in the forum can also help you see the different ways people code the AddLabel() function...

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Here you go:

Code:
input priceType = PriceType.LAST;
def LastPrice = close(priceType = priceType);
plot DeltaOpen  = (LastPrice - open) / open;
 

sgbaum88

New member
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);
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@sgbaum88 TOS does not use "marks around variable names"

Code:
#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 ;

This will correct the syntax so you won't get an error code. I didn't check the logic of what you were trying to do.
 

sgbaum88

New member
Thank you so much, MerryDay! That corrected the problem. I am making a watchlist custom column the displays a 1 when thee JK Trend Analyzer Study shows the Fast,Slow, and Base Lines all reach the 100 line, and a 0 when they do not.I use this as a possible buy signal.
 

adii800

Member
Ruby:
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";

Error: Expected double at 14:5
(this is the last line)

No clue why this is happening, I've tried using the AsText() function, which converts from number to String but no clue why that's happening :/
 
i wrote this. it looks good but it says its a invalid script because of expected double

Code:
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));
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@joshua74133 In line 25, you reference
def doji = hadoji and Vol.Color("Up"); Vol.Color("Up") is a format statement not a variable, perhaps you mean:
def doji = hadoji and close>close[1];
 
Last edited:

majidg

Member
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);
Can you please help with this error:
I get "double expected" error when I write the following:
plot x = if UpSignal then 1 else 0;
AddLabel(x,if upsignal then "correct" and color.cyan else double.nan);
 

Pensar

Well-known member
VIP
Lifetime
@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
Code:
AddLabel(x, if UpSignal then "correct" else "your text here",color.cyan);
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.
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
 
Solution

majidg

Member
@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
Code:
AddLabel(x, if UpSignal then "correct" else "your text here",color.cyan);
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.
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
Thanks alot Pensar for your kindness and quick response, it fixed the problem
 

majidg

Member
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.
 

Pensar

Well-known member
VIP
Lifetime
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.
Code:
AddChartBubble(!isnan(close) and isnan(close[-1]), line+.2, "current_price = " + close, Color.CYAN, no);
@majidg I think the above will work, test it and see.
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.
 

majidg

Member
Code:
AddChartBubble(!isnan(close) and isnan(close[-1]), line+.2, "current_price = " + close, Color.CYAN, no);
@majidg I think the above will work, test it and see.
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.
WOW!, thanks Pensar. I like the way you spend time to explain. I really appreciate.
 

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.
Top