Incompatible parameter/Invalid statement error

cabe1332

Member
Hi All,

I appreciate your assistance in advance. When I need to add something I usually comb the site and the scripts available. But, I seem to not find the solution for my issue.

Code:
input lengthmo = 5;
def c = close;
def Momentum = c - c[lengthmo];
def NegMomentum = c - c[lengthmo];;
def mopos = if Momentum >= 0 then 3 else 2;
def moneg = if Momentum < 0 then 3 else 2;
def MoMo = if Momentum >= 0 then momentum else if Momentum < 0 then NegMomentum else double.nan;
def MoMoInd = round(MoMo)* 100;

I am getting the following when I try to use the following def with the script above. The above script works, but the additional def throws me an error. What am I doing wrong or how can fix it? Thank you in advance. @cabe1332

def MoMoText == if MoMoInd >= 0 then "Mo UP" else "Mo DN";

Error: Invalid statement: def at 44:1
def MoMoText = if MoMoInd > 0 then "Mo UP" else "Mo DN";
Error:
Incompatible parameter: "Mo UP" at 44:5
Incompatible parameter: "Mo DN" at 44:5
Expected double at 44:5
 
Solution
Please delete the 'def MoMoText = if MoMoInd > 0 then "Mo UP" else "Mo DN";' and replace the bubble code with the following. Since I don't have all of the code, I think this should do what you want.

Code:
addChartBubble(bn == currentBar - barsBack, close,
    if Highstaterange and NoPos then "$ " + round(close,4) + (if MoMoInd > 0 then "| Mo UP" else "| Mo DN")  + MoMoInd
        + " | " + round(Pctawayhi,0) + "% near 52Wk Hi " + asDollars(Wk52Hi)
        # + " | $ " + Round(GetOpenPL) + " | " + AsPercent(PercentChg)

      else if Highstaterange and !Wk52Hireached  then "$ " + round(close,4) + (if MoMoInd > 0 then "| Mo UP" else "| Mo DN") + MoMoInd
        + " | " + round(Pctawayhi,0) + "% near 52Wk Hi " + asDollars(Wk52Hi)...

BenTen

Administrative
Staff
VIP
Looks incomplete to me. Take a look at the following example:

Ruby:
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
 

cabe1332

Member
Hi @BenTen, really I just wanted the value or text "UP" or "DN" added with "Mo UP" or "Mo DN" in the conditions below. Thanks for the quick reply. @cabe1332

Code:
addChartBubble(bn == currentBar - barsBack, close,
    if Highstaterange and NoPos then "$ " + round(close,4) + " | Mo " + MoMoInd
        + " | " + round(Pctawayhi,0) + "% near 52Wk Hi " + asDollars(Wk52Hi)
        # + " | $ " + Round(GetOpenPL) + " | " + AsPercent(PercentChg)

      else if Highstaterange and !Wk52Hireached  then "$ " + round(close,4) + " | Mo " + MoMoInd
        + " | " + round(Pctawayhi,0) + "% near 52Wk Hi " + asDollars(Wk52Hi)
         + " | $ " + Round(GetOpenPL) + " | " + AsPercent(PercentChg)

      else if NoPos then "$ " + round(close,4) + " | Mo " + MoMoInd

        else "$ " + round(close,4) + " | Mo " + MoMoInd
           + " | $ " + Round(GetOpenPL) + " | " + AsPercent(PercentChg),

    # background color
        if price >= price[1] then color.green else color.red);
 

SleepyZ

Active member
Please delete the 'def MoMoText = if MoMoInd > 0 then "Mo UP" else "Mo DN";' and replace the bubble code with the following. Since I don't have all of the code, I think this should do what you want.

Code:
addChartBubble(bn == currentBar - barsBack, close,
    if Highstaterange and NoPos then "$ " + round(close,4) + (if MoMoInd > 0 then "| Mo UP" else "| Mo DN")  + MoMoInd
        + " | " + round(Pctawayhi,0) + "% near 52Wk Hi " + asDollars(Wk52Hi)
        # + " | $ " + Round(GetOpenPL) + " | " + AsPercent(PercentChg)

      else if Highstaterange and !Wk52Hireached  then "$ " + round(close,4) + (if MoMoInd > 0 then "| Mo UP" else "| Mo DN") + MoMoInd
        + " | " + round(Pctawayhi,0) + "% near 52Wk Hi " + asDollars(Wk52Hi)
         + " | $ " + Round(GetOpenPL) + " | " + AsPercent(PercentChg)

      else if NoPos then "$ " + round(close,4) + (if MoMoInd > 0 then "| Mo UP" else "| Mo DN") + MoMoInd

        else "$ " + round(close,4) + (if MoMoInd > 0 then "| Mo UP" else "| Mo DN") + MoMoInd
           + " | $ " + Round(GetOpenPL) + " | " + AsPercent(PercentChg),

    # background color
        if price >= price[1] then color.green else color.red);
 
Solution

cabe1332

Member
Please delete the 'def MoMoText = if MoMoInd > 0 then "Mo UP" else "Mo DN";' and replace the bubble code with the following. Since I don't have all of the code, I think this should do what you want.
@SleepyZ that worked. Thank you. cabe1332

iYOBlzc.png
 

Similar threads

Top