Scan for price touching moving average in ThinkorSwim

jas

New member
I need a Thinkorswim scanner which scan stocks whose last few previous daily bar's open, close, low or high touches or almost too close to desired moving averages means act as support or resistance. Can also able to scan for at least 2 different moving averages in a scan so that scan will return stocks which touches either of 2 moving averages.
 

cdjohnson73

New member
I wrote this little code that tells me when stocks break the 9 EMA (close("period" = AggregationPeriod.MIN, "priceType" = PriceType.LAST) crosses above MovAvgExponential()."AvgExp" within 2 bars). It says a 1.0 for stocks that meet it and a 0.0 for stocks that don't.
Is there a way to only show stocks that show the 1.0 instead of showing me both ones that fir and don't fit? If not is there a way to highlight the ones that do fit the indicator?

P.S. I have a screenshot but cannot figure out how to put the attachment on here.
 

rad14733

Well-known member
VIP
I wrote this little code that tells me when stocks break the 9 EMA (close("period" = AggregationPeriod.MIN, "priceType" = PriceType.LAST) crosses above MovAvgExponential()."AvgExp" within 2 bars). It says a 1.0 for stocks that meet it and a 0.0 for stocks that don't.
Is there a way to only show stocks that show the 1.0 instead of showing me both ones that fir and don't fit? If not is there a way to highlight the ones that do fit the indicator?

P.S. I have a screenshot but cannot figure out how to put the attachment on here.

It's virtually impossible to accurately help with code we can't see... Please post the code in question... I have a feeling I know what the problem is but, again, it's tough to debug without seeing the code...
 

rad14733

Well-known member
VIP
Perhaps, but until you can post your request properly I'm not wasting additional time here... You were asked to post your code, which should be done in an orderly fashion using the </> icon to properly format... You posted what you want, but not where you want it, and that is mixed in with text, making it our job to sort out - which I'm not doing because I'm making a point here... You simply aren't making it easy for us to help you even though you were given such advice by @MerryDay as well... Put forth some effort and make it easy for us to help you...
 

cdjohnson73

New member
Hey all, apologies for the confusion and thank you for taking the time to tell me what I was missing. My current code is:
Code:
close("period" = AggregationPeriod.MIN, "priceType" = PriceType.LAST) crosses above MovAvgExponential()."AvgExp" within 2 bars
I have another code for seeing the percent change over 1 minute which is:
Code:
def bk = close; def change = 100*(1-bk/bk[1]); plot signal = change; signal.AssignValueColor (Color.BLACK); AssignBackgroundColor( if change > 10 then color.green else if change >5 then color.light_green else Color.light_GRAY);
My question is: is there a way to modify the second code so that it can highlight the setup of my first code? Sorry for doing it wrong I hope this is correct
 

cdjohnson73

New member
Perhaps, but until you can post your request properly I'm not wasting additional time here... You were asked to post your code, which should be done in an orderly fashion using the </> icon to properly format... You posted what you want, but not where you want it, and that is mixed in with text, making it our job to sort out - which I'm not doing because I'm making a point here... You simply aren't making it easy for us to help you even though you were given such advice by @MerryDay as well... Put forth some effort and make it easy for us to help you...
Apologies, I'm still very new here. Is there a place here I can go to learn more about the site format? I agree you shouldn't have to be inconvenienced in order to help me, and I'm grateful for the time you've taken thus far in trying to help me. I am bad at words and typing so sorry again if I came off short and rude and thank you for telling me the right way to post something.
 
Last edited:

rad14733

Well-known member
VIP
@cdjohnson73 If you click on the link that @MerryDay provided above it is a single post in an entire topic she has compiled of helpful hints... Please take the time to read the entire topic as she has put a lot of time and effort into it for new members like yourself to benefit from...
 

Pensar

Well-known member
VIP
Hey all, apologies for the confusion and thank you for taking the time to tell me what I was missing. My current code is:
Code:
close("period" = AggregationPeriod.MIN, "priceType" = PriceType.LAST) crosses above MovAvgExponential()."AvgExp" within 2 bars
I have another code for seeing the percent change over 1 minute which is:
Code:
def bk = close; def change = 100*(1-bk/bk[1]); plot signal = change; signal.AssignValueColor (Color.BLACK); AssignBackgroundColor( if change > 10 then color.green else if change >5 then color.light_green else Color.light_GRAY);
My question is: is there a way to modify the second code so that it can highlight the setup of my first code? Sorry for doing it wrong I hope this is correct
@cdjohnson73 Where are you trying to use this code?

If in a scan, try close crosses above expaverage(close,14) within 2 bars and select the necessary aggregation to scan from the dropdown menu. The default length you are referencing for the EMA is 14, in case you're wondering why I chose that length. Remember that scans only update every 3 minutes or so at best, so using a 1 min agg might not work very well.

If in a watchlist column -
Code:
def data = close crosses above expaverage(close,14) within 2 bars;
AddLabel(1,if data then "Crossing" else "", if data then color.green else color.black);
AssignBackgroundColor(if data then color.green else color.black);
This will color both the text and the background green when the conditions are true. you can change the quoted text in the label to display whatever you want, as well as the color. Select the necessary aggregation for the column from the dropdown menu.

I havent tested any of this code, so make sure it works.
 

cdjohnson73

New member
@cdjohnson73 Where are you trying to use this code?

If in a scan, try close crosses above expaverage(close,14) within 2 bars and select the necessary aggregation to scan from the dropdown menu. The default length you are referencing for the EMA is 14, in case you're wondering why I chose that length. Remember that scans only update every 3 minutes or so at best, so using a 1 min agg might not work very well.

If in a watchlist column -
Code:
def data = close crosses above expaverage(close,14) within 2 bars;
AddLabel(1,if data then "Crossing" else "", if data then color.green else color.black);
AssignBackgroundColor(if data then color.green else color.black);
This will color both the text and the background green when the conditions are true. you can change the quoted text in the label to display whatever you want, as well as the color. Select the necessary aggregation for the column from the dropdown menu.

I havent tested any of this code, so make sure it works.
I was trying to on the sidebar with a watchlist but I may try the scan for the fun of it. Yes it works like a charm thank you very much for taking your time to help me!
 

Similar threads

Top