Incompatible parameter/Invalid statement error

cabe1332

Active 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)
         +...
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"));
 
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);
 
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
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
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
160 Online
Create Post

Similar threads

Similar threads

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