Watchlist Items Color and EMA Strategy

ToSdrew777

New member
Hello All,
I am wondering if someone can help me. I have a simple EMA scalp strategy that is working great that is shared below:

A) I wait until the 20EMA is above the 50EMA, the 50EMA is above the 100EMA, and the 100EMA is above the 150EMA and the slope looks strong. The script is below and this is built into my Watchlist of usual stocks called STACKBULL

MovAvgExponential("length" = 20)."AvgExp" is less than MovAvgExponential("length" = 50)."AvgExp" and MovAvgExponential("length" = 50)."AvgExp" is less than MovAvgExponential("length" = 100)."AvgExp" and MovAvgExponential("length" = 100)."AvgExp" is less than MovAvgExponential("length" = 150)."AvgExp"

B) When lowest price of the 1min candle touches between the 20EMA and the 100EMA on an existing uptrend from above, I watch for the first candle to open back above the 20 (Best results are when the candle touches between the 20EMA and 50EMA and has a bullish pattern like a hammer.) The script is below which is also built into my Watchlist of usual stocks called MA-BULL

low is greater than or equal to MovAvgExponential("length" = 75)."avgexp" and low is less than or equal to MovAvgExponential("length" = 20)."avgexp"

O the watchlist, the STACKBULL column displays number “1” then I look for the MA-BULL column to also have a number “1” for the individual stock on the Watchlist then I see if the setup is something I am interested in.
1) How can I color code and make the “1s” to display as GREEN and if it is “0” - no color. It hurts my eyes and is sometimes confusing tracing the “1s” all the time??? I have been fooling around googling and nothing seems to work when I try to code it.
2) In addition, is there a way to combine the above parts A and B so I can have only 1 column on my watchlist where individual stocks are green when all conditions are satisfied?
3) Also, is it possible to add to the code for part A above to add a slope condition such as all slopes of 20/50/100/150EMAs are at least 30% up???
 

rad14733

Well-known member
VIP
@ToSdrew777 Perhaps the easiest method is to use AddLabel instead of plot... Then you can ditch the number altogether by displaying a blank space and use conditional code to paint the watchlist cell... That's how I code my custom watchlist columns that are for indication only and don't require numbers... For watchlist column cells you won't get an error if you use AddLabel and don't have a plot... You can also use multiple criteria and paint the cells accordingly...

Slopes can be calculated using Tan() or Atan()... Check the Thinkscript Learning Center for their implementation...
 

Pensar

Well-known member
VIP
@ToSdrew777 Here is something such as you are asking about. There is a discrepancy between your write-up and the code in section "A)" of your post, so I followed the description instead of the actual provided code. I also colored the background of each "1" watchlist cell green, you can delete that portion if you like.

Code:
# @ToSdrew777 at usethinkscript.com - "I wait until the 20EMA is above the 50EMA, the 50EMA is above the 100EMA, and the 100EMA is above the 150EMA and the slope looks strong. When lowest price of the 1min candle touches between the 20EMA and the 100EMA on an existing uptrend from above, I watch for the first candle to open back above the 20 (Best results are when the candle touches between the 20EMA and 50EMA and has a bullish pattern like a hammer."

def stackbull = expaverage(close,20) > expaverage(close,50)
                && expaverage(close,50) > expaverage(close,100)
                && expaverage(close,100) > expaverage(close,150);

def mabull = low >= expaverage(close,75) && low <= expaverage(close,20);

plot myconditions = if stackbull and mabull then 1 else 0;
myconditions.assignvaluecolor(if myconditions == 1 then color.green else color.black);

assignbackgroundcolor(if myconditions == 1 then color.green else color.black);
 

ToSdrew777

New member
@ToSdrew777 Here is something such as you are asking about. There is a discrepancy between your write-up and the code in section "A)" of your post, so I followed the description instead of the actual provided code. I also colored the background of each "1" watchlist cell green, you can delete that portion if you like.

Code:
# @ToSdrew777 at usethinkscript.com - "I wait until the 20EMA is above the 50EMA, the 50EMA is above the 100EMA, and the 100EMA is above the 150EMA and the slope looks strong. When lowest price of the 1min candle touches between the 20EMA and the 100EMA on an existing uptrend from above, I watch for the first candle to open back above the 20 (Best results are when the candle touches between the 20EMA and 50EMA and has a bullish pattern like a hammer."

def stackbull = expaverage(close,20) > expaverage(close,50)
                && expaverage(close,50) > expaverage(close,100)
                && expaverage(close,100) > expaverage(close,150);

def mabull = low >= expaverage(close,75) && low <= expaverage(close,20);

plot myconditions = if stackbull and mabull then 1 else 0;
myconditions.assignvaluecolor(if myconditions == 1 then color.green else color.black);

assignbackgroundcolor(if myconditions == 1 then color.green else color.black);

Pensar, Thank you a hundred times. That is exactly it. When it is written like that, it is a nice lesson also for the future.
 

Similar threads

Top