Adding Custom Column Color When Study Was Built W/Condition Wizard


Category:
0
0

Hello Pete.  Welcome back my friend!  Glad to see you are recovering so well. I wanted to run something by you.  I have a custom study that I use in several custom watchlist columns.  It puts the 1 in the column if the conditions of the study are met.  Pretty basic.  I built this study with the condition wizard and the resulting thinkscript is in a different format than what I see in your videos because you are actually doing the coding and I am relying on the wizard to do mine.  When I look at your videos that pertain to changing the background color of custom columns, they all appear to be referencing code that you entered vs. what TOS enters via the wizard.  I use your TTM Squeeze study in one of my columns and it turns green when the conditions are met.  I love how that makes it easier to identify and not miss opportunities.  Is it possible to get the same color changing code on things built with the wizard?  Or would the code have to be re-written using actual coding “language” like what you use.  I am attaching some photos that show both the condition wizard inputs, the resulting thinkscript and also a snapshot of the custom columns I use.  The far right column is the TTM one I described above with the green highlights.  Thanks in advance for any guidance you can provide!

Attachments:
RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on July 25, 2019 10:42 am
597 views
1
Private answer

The Condition Wizard

For the benefit of the rest of our viewers, let's make sure they know where to view the video I just published showing how to use the Condition Wizard on Thinkorswim:

https://www.hahn-tech.com/thinkorswim-condition-wizard/

In that video I go through the basics and show how to use the Condition Wizard to build custom scans, alerts, chart studies and watchlist columns. From that video we learn that after building your code in Condition Wizard, you can jump over to the thinkScript Editor side and copy/paste the code it produces:

open is greater than 20 and MovAvgExponential("length" = 2)."AvgExp" crosses above MovAvgExponential("length" = 4)."AvgExp" and DynamicMomentumIndex()."DYMI" is greater than 45 and TTM_Squeeze()."Histogram" is greater than -5 and RelativeVolumeStDev()."RelVol" is greater than 0.01 and Momentum()."Momentum" is greater than 0

That is the code I got after creating the set of conditions shown in your screenshots. Which we actually not screenshots. Those were pictures of your screen, taken with a camera. You can get much better results by using the built in tools available on every computer that actually capture the screen and save it as an image file.

Converting the Code to a Variable Assignment

Ok so we have the code from your set of conditions. Great. Next step, we learn how to convert that to a variable assignment that can be used to color the background of your watchlist column. By the way, I have already planned this as the topic of my next video. Stay tuned.

Here I am creating a variable named "myCondition" and assigning the result of your conditions as it's value:

def myCondition = open is greater than 20 and MovAvgExponential("length" = 2)."AvgExp" crosses above MovAvgExponential("length" = 4)."AvgExp" and DynamicMomentumIndex()."DYMI" is greater than 45 and TTM_Squeeze()."Histogram" is greater than -5 and RelativeVolumeStDev()."RelVol" is greater than 0.01 and Momentum()."Momentum" is greater than 0;

Notice I began the statement with the keyword "def", followed by the variable name, and then placed an equal sign before pasting the exact same code generated by you through the Condition Wizard. At the very end, I placed a semicolon ';'. Which is very important!

Assigning the Background Color

Now we only need to add one more line of code to use the value of that condition to change the color of the background on our watchlist. We'll be using a function named "AssignBackgrounColor()". Details here:

http://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AssignBackgroundColor.html

AssignBackgroundColor(if myCondition then Color.GREEN else Color.RED);

In English: Assign background color green IF myCondition variable equals 'yes'. Otherwise, assign background color red.

Oh yeah, the compiler will be expecting at least one plot statement. Which we can simply create like this:

plot data = myCondition;

You can place that after the line used to assign the background color.

That's it, we're all done.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on July 25, 2019 12:30 pm
0
Thank you so much Pete! I would have never figured that out. I deleted what I had and copied/pasted all of your code and for some reason I wasn't getting anything. Even my "1's" were not showing in the columns anymore. I was stuck then I realized the issue. The source that feeds my watchlist does not allow any stocks over $20. Since I copied and pasted over my original code which stipulated "Open is less than 20" , I didn't realize that the code you established for "myCondition" was actually looking for stocks greater than $20. Since I filter those out of my data source, it resulted in zero results in my columns. Once i changed the word "Greater" to "Less" it works perfectly! I tried for over a week to figure this out on my own lol. Thanks again for your expertise!
( at July 25, 2019 1:48 pm)
0
Glad you got that working. In the future we can avoid these typos if you just copy the code from the thinkScript editor in stead of providing a screenshot of less than perfect quality.
( at July 25, 2019 5:29 pm)
0
thank you for sharing your knowledge
( at October 9, 2019 11:26 pm)