Syntax error: An 'else' block expected

dvelz702

New member
I've been trying to figure this error for a over a weeks now with no luck. Frankly I don't know if it's possible to make it work. I don't know much about scripting, just enough to give myself headaches. I got it down to one final error which I can't fiqure out. Any help is appreciated.

This is line #70, I'm asuming :23 are character from the beginning of the line.

"Syntax error: An 'else' block expected at 75:23"

Diff.AssignValueColor(if Diff >= 0 then if h3 and DiffHi[offset] then Diff.Color("UpperUpFrac") else if Diff <= 0 and h3 and DiffHi[offset] then Diff.Color("LowerUpFrac") else if Diff <= 0 and l3 and DiffLo[offset] then Diff.Color("LowerDwnFrac") else if Diff >= 0 then l3 and DiffLo[offset] else Diff.Color("UpperUpFrac"));
 
Solution
I've been trying to figure this error for a over a weeks now with no luck. Frankly I don't know if it's possible to make it work. I don't know much about scripting, just enough to give myself headaches. I got it down to one final error which I can't fiqure out. Any help is appreciated.

This is line #70, I'm asuming :23 are character from the beginning of the line.

"Syntax error: An 'else' block expected at 75:23"

Diff.AssignValueColor(if Diff >= 0 then if h3 and DiffHi[offset] then Diff.Color("UpperUpFrac") else if Diff <= 0 and h3 and DiffHi[offset] then Diff.Color("LowerUpFrac") else if Diff <= 0 and l3 and DiffLo[offset] then Diff.Color("LowerDwnFrac") else if Diff >= 0 then l3 and DiffLo[offset] else Diff.Color("UpperUpFrac"));

people...
I've been trying to figure this error for a over a weeks now with no luck. Frankly I don't know if it's possible to make it work. I don't know much about scripting, just enough to give myself headaches. I got it down to one final error which I can't fiqure out. Any help is appreciated.

This is line #70, I'm asuming :23 are character from the beginning of the line.

"Syntax error: An 'else' block expected at 75:23"

Diff.AssignValueColor(if Diff >= 0 then if h3 and DiffHi[offset] then Diff.Color("UpperUpFrac") else if Diff <= 0 and h3 and DiffHi[offset] then Diff.Color("LowerUpFrac") else if Diff <= 0 and l3 and DiffLo[offset] then Diff.Color("LowerDwnFrac") else if Diff >= 0 then l3 and DiffLo[offset] else Diff.Color("UpperUpFrac"));

people,
don't post partial code
posting partial code and expecting others to decipher it is lazy.
i had to create 6 variables and 4 colors, just to get started


this is wrong ,
then instead of and
else if Diff >= 0 then l3 and DiffLo[offset]

should be
else if Diff >= 0 and l3 and DiffLo[offset]

-------------------------------


no color listed after this condition
else if Diff >= 0 and l3 and DiffLo[offset]

-----------------------------

you have a then if
Diff.AssignValueColor(if Diff >= 0 then if h3

should end the formula with 2 else's
else color.gray
else color.blue);



this part may have worked, but i changed it anyway

i changed the first part, to check the opposite, to remove the nested if then.
i assumed you want d>= 0 to decide on a color, so i checked for the opposite as the first condition.
if diff < 0 then Color.GRAY
so undesired diff values are not passed on to the if then color choices.

---------------------------

write each condition, each if then, on a different line. it makes it easier to read and debug.


Code:
def offset = 2;
def DiffHi = 1;
def difflo = 0;
def h3 = 1;
def l3 = 0;

plot diff = close;

diff.DefineColor("UpperUpFrac", Color.GREEN);
diff.DefineColor("LowerUpFrac", Color.CYAN);
diff.DefineColor("Lowerupfrac", Color.YELLOW);
diff.DefineColor("LowerDwnFrac", Color.RED);

diff.AssignValueColor(
  if diff < 0 then Color.GRAY
    else if h3 and DiffHi[offset] then diff.Color("UpperUpFrac")
    else if diff <= 0 and h3 and DiffHi[offset] then diff.Color("LowerUpFrac")
    else if diff <= 0 and l3 and difflo[offset] then diff.Color("LowerDwnFrac")
    else if diff >= 0 and l3 and difflo[offset] then diff.Color("UpperUpFrac")
    else color.gray
);

-----------------


original code line fixed
...add else color, at the end
...add color to 4th condition , else if Diff >= 0 and l3 and DiffLo[offset] then ...

Code:
Diff.AssignValueColor(
  if Diff >= 0 then
    if h3 and DiffHi[offset] then Diff.Color("UpperUpFrac")
    else if Diff <= 0 and h3 and DiffHi[offset] then Diff.Color("LowerUpFrac")
    else if Diff <= 0 and l3 and DiffLo[offset] then Diff.Color("LowerDwnFrac")
    else if Diff >= 0 and l3 and DiffLo[offset] then Diff.Color("LowerDwnFrac")
    else Diff.Color("UpperUpFrac")
  else color.gray
);
 
Last edited:
Solution

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