TTM wave A column with 4 color in TOS


Category:
0
0

I tried writing the code for the four color for wave A and getting this error
syntax error: an else block expected at 3:6

plot waveA = TTM_Wave().Wave1;
AssignBackgroundColor(if waveA >= 0 then if waveA > waveA[1] then Color.CYAN else color.BLUE
else if waveA <= 0 then if waveA < waveA[1] then Color.RED else color.YELLOW);

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on February 2, 2023 9:18 am
338 views
0
Private answer

Because I understand you are trying to learn how to do this for your self I provide some guidance rather than a direct solution. The colors you have attempted to use are the same exact colors as used in the TTM_Squeeze indicator. So you will find the code provided with the following video contains your solution:

https://www.hahn-tech.com/thinkorswim-ttm-squeeze-watchlist/

Now I will copy a specific section of the code from that video here so you can see how the if/then/else statement is properly configured:

hist.assignvaluecolor(if squeezeHistogram >= 0 then
if squeezeHistogram > squeezeHistogram[1] then color.CYAN else color.BLUE
else if squeezeHistogram < squeezeHistogram[1] then color.RED else color.YELLOW);

Now compare that pattern with what you have attempted and you should be able to identify where you went wrong.

Writing code is not easy. It takes an incredible degree of attention to detail. Every single character in the syntax must be in the proper location. If you still can't work this out, you should go back to a solution with only 2 colors and practice that until you master it.

[EDIT] The author of this post requested the solution because they were not able to get it working. I will provide a 3 step solution which shows how to convert the squeezeHistogram colors to work on Wave A of the TTM_Wave indicator:

Step one:

replace the first section "hist.assignvaluecolor" with a new function: "AssignBackgroundColor"

This is the result of setp 1:

AssignBackgroundColor(if squeezeHistogram >= 0 then
if squeezeHistogram > squeezeHistogram[1] then color.CYAN else color.BLUE
else if squeezeHistogram < squeezeHistogram[1] then color.RED else color.YELLOW);

Step two:

replace all occurrences of "squeezeHistogram" with "waveA". (HINT: You can do this in any text editor using the "find/replace" function)

This is the result of step 2:

AssignBackgroundColor(if waveA >= 0 then
if waveA > waveA[1] then color.CYAN else color.BLUE
else if waveA < waveA[1] then color.RED else color.YELLOW);

Step three;

Now we assemble the pieces, combining the first line of your original attempt to the result from step 2:

plot waveA = TTM_Wave().Wave1;
AssignBackgroundColor(if waveA >= 0 then
if waveA > waveA[1] then color.CYAN else color.BLUE
else if waveA < waveA[1] then color.RED else color.YELLOW);

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on February 2, 2023 10:34 am
0
Can you send me the solution to the 4 colors for Wave A question. Tried again and still getting error. if wave A is >0 and > than 1 bar ago, then cyan, if not color blue if wave A is
( at February 4, 2023 12:25 pm)
0
I have updated my solution to provide the step-by-step instructions for converting the squeezeHistogram colors to your waveA plot. FYI, if you truly are trying to learn how to do this, I suggest you take the time to follow my step-by-step instructions on your own rather than just copy/paste my final solution in step 3. Doing stuff like this in code is very basic. If you are struggling to learn how to do this then you need to do a lot more practice.
( at February 4, 2023 1:47 pm)
0
Thank you.
( at February 4, 2023 1:56 pm)