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 member
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 member
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

Administrative
Staff member
Staff
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 :/
 

joshua74133

Member
VIP
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
@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];

When posting scripts, it is easier for posters to read scripts if you click on this icon at the top of your post and then paste the code.
QNUw9Yh.png
 

Similar threads

Top