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;
 

BenTen

Administrative
Staff
VIP
Here you go:

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

mike8u

New member
Thank you BenTen, how can I use this on the MarketWatch tables? I realize that it is plotting to the chart and not as a column on MarketWatch which I thought I was doing.
 

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

BenTen

Administrative
Staff
VIP
@sgbaum88 You may need to double check the following:

Code:
plot BuySignal = if("JKTA_Slow" >= 100 and "JKTA_Base" >= 100 and "JKTA_Fast" >=  99) then 1 else 0;

What are you trying to define/plot?
 

MerryDay

Well-known member
VIP
@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 :/
 

Similar threads

Top