Wrong type cast: different types after then and else: double vs class

Ive successfully made 4 different variations of this code but this forum is what I wanted, Where its green and says"Money Flow $+xyz" or is red and says "Money Flow $-xyz" the other forums all didn't include the + or - but I wanted to take it a step farther and am now stuck]. the 3 different ways I've playing around with it are detonated between the #---OR---- sections. I got the code from another study which the code I copied and pasted at the bottom. depending on what I do, it makes the ADDLABEL red, the 4th IF red or no red and says
"Wrong type cast: different types after then and else: double vs class com.devexperts.tos.thinkscript.data.CustomColor
Wrong type cast: different types after then and else: double vs class java.lang.String" here is the code:

Code:
#Money_Flow Declining or advancing

declare lower;
input price = close;

def MF = TotalSum(if price < price[1] then -price * volume else if price > price[1] then price * volume else 0);

def ZeroLine = 0;

#MF.SetDefaultColor(GetColor(8));
#ZeroLine.SetDefaultColor(GetColor(5));

plot MFD = MF - MF[1];
def na = Double.NaN;
#plot label_negative_Color = MFD < 0;
#plot label_positive_color = MFD > 0;
input show_MFD_Label = yes;

DefineGlobalColor("Pre_Cyan", CreateColor(0, 150, 200)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("Label2Green",  CreateColor(0, 200, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0));

AddLabel(yes,
if MF - MF[1] < 0     then "Money Flow $-" + MFD else
if MF - MF[1] > 0      then "Money Flow $+" + MFD else
if MF - MF[1] < 0     then GlobalColor("LabelRed") else
if MF - MF[1] > 0      then GlobalColor("Pre_Cyan") else na);
#----------------------------OR----------------------------
#AddLabel(yes,
#if MFD <= 0     then "Money Flow $-" + MFD else
#if MFD > 0      then "Money Flow $+" + MFD else
#if MFD < 0     then GlobalColor("LabelRed") else
#if MFD > 0      then GlobalColor("Pre_Cyan") else GlobalColor("LabelGreen"));
#----------------------------OR----------------------------
#AddLabel(yes,
#if MFD <= 0     then "Money Flow $-" + MFD else
#if MFD > 0      then "Money Flow $+" + MFD else
#if MFD < 0     then GlobalColor("LabelRed") else
#if MFD > 0      then GlobalColor("Pre_Cyan") else na);
####End Code

#Addlabel section taken from the following
#Name: ChrisStoplight LABELS ONLY
#Programmed By: Chris Ball (xxx) on #1/31/09
#Added Choppiness and Squeeze Indicator by [email protected] Lounge
#Added FW_Mobo_Basic
#Modified to add/change indicators
#Modified to show labels only @MerryDay 12/2020
#AddLabel(yes,
#if ADX <= 20   then "ADX No Trend " +round(ADX,0) else
#if ADX >  40   then "ADX WOW " +round(ADX,0) else  "ADX Trending " +round(ADX,0),
#if ADX < 20    then GlobalColor("LabelRed") else
#if ADX > 40    then GlobalColor("Pre_Cyan") else GlobalColor("LabelGreen"));
 

generic

Active member
@mourningwood4521 Simpler format

Code:
AddLabel(yes,
if MF - MF[1] < 0 then "Money Flow $-" + MFD else "Money Flow $+" + MFD,
if MF - MF[1] < 0 then GlobalColor("LabelRed") else GlobalColor("Pre_Cyan"));

If you want to keep the same format then this will work.

Code:
AddLabel(yes,
if MF - MF[1] < 0     then "Money Flow $-" + MFD else
if MF - MF[1] > 0      then "Money Flow $+" + MFD else "",
if MF - MF[1] < 0     then GlobalColor("LabelRed") else
if MF - MF[1] > 0      then GlobalColor("Pre_Cyan") else color.white);
 
Amazing! Thank you for the help @generic !!

I tried adding the "", on the first line and it wouldn't take it and I was getting pretty frustrated so I didn't try it on the second line.

So all I was doing wrong was forgetting the --> "", on line 2, and needed to change the very last word on the 4th line to color.white;?

What exactly does color.white change? I don't see any white on the chart.

I saw on another thread this https://usethinkscript.com/threads/expected-class-error.3858/post-35569

Code:
AddLabel(yes, " ", if cahold then GlobalColor("CloseAbove") else if cblohd then GlobalColor("CloseBelow") else GlobalColor("NoFlag"));
 

generic

Active member
@mourningwood4521 The problem is using Double.NaN for the text and color. The text portion accepts strings hence the "double vs class java.lang.String" so I replaced it with "" which is a empty string. "double vs class com.devexperts.tos.thinkscript.data.CustomColor" is just saying you can't use Double.NaN as a color so replacing it with any color will work, I just chose white.
 

Similar threads

Top