Paint Candle touching 500 SMA

vsr138173

New member
VIP
Hi All,
Can you please help me with code to highlight a candle where it touch 500 SMA and also UPTICK to the next candle after touch 500 SMA?

Thanks
 

BenTen

Administrative
Staff member
Staff
VIP
Here you go:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#

input price = close;
input length = 500;
input displace = 0;

plot SMA = Average(price[-displace], length);

AssignPriceColor(if close crosses SMA then color.white else color.current);
 

vsr138173

New member
VIP
Ben,

I am looking for a only UPTICK to the candle where candle touches 500 SMA and also uptick to the next candle after touching 500 SMA. I don't want to plot 500 SMA line.

v8Zm5Ui.png


Thanks for your help.
 

BenTen

Administrative
Staff member
Staff
VIP
If you just wanted arrows, then you don't even need a custom script. Just enable the "Show breakout signals" option in your default moving average indicator.

KIlCKLM.png
 

8Nick8

Active member
2019 Donor
VIP
Hi @BenTen, i tried to use this quote and scan for the last candle that touches 50SMA, but it does not scan out the results i wanted. May i also know what is the function of displace and how to modify the plot to scan for any candles that touches the 50SMA? Thanks
 

BenTen

Administrative
Staff member
Staff
VIP
@Nick You don't need that code to scan for candle crossing the 50 SMA. All you have to do is go to the Scan tab, create a new condition, and set it up where close crosses above, crosses below, or crosses the 50 SMA.

Here is an example:

T2K35Gg.png


Make sure to adjust the "length" to your desired moving average length.
 

Similar threads

Top