Modified the study to be imported as a scanner. Comment/uncomment the desired signal arrow to scan for at the bottom of the code.
Shareable link: https://tos.mx/H79KxEJ
Shareable link: https://tos.mx/H79KxEJ
Code:
# PRC_HalfTrend Scanner
# Original indicator study by Mobius Apr 2020
# Comment/uncomment desired plot at end of script
# 2020.08.20 -john5788
input Amplitude = 3;
def lowpricei;
def highpricei;
def lowma;
def highma;
def barindex = BarNumber();
def nexttrend;
def maxlowprice;
def trend;
def minhighprice;
def up;
def down;
lowpricei = Lowest(low, Amplitude);
highpricei = Highest(high, Amplitude);
lowma = Average(low, Amplitude);
highma = Average(high, Amplitude);
if barindex > Amplitude and
nexttrend[1] == 1
{
maxlowprice = Max(lowpricei, maxlowprice[1]);
trend = if highma < maxlowprice[1] and close < low[1]
then 1
else trend[1];
nexttrend = if highma < maxlowprice[1] and close < low[1]
then 0
else nexttrend[1];
minhighprice = if highma < maxlowprice[1] and close < low[1]
then highpricei
else minhighprice[1];
}
else if nexttrend[1] == 0
{
minhighprice = Min(highpricei, minhighprice[1]);
trend = if lowma > minhighprice[1] and close > high[1]
then 0
else trend[1];
nexttrend = if lowma > minhighprice[1] and close > high[1]
then 1
else nexttrend[1];
maxlowprice = if lowma > minhighprice[1] and close > high[1]
then lowpricei
else maxlowprice[1];
}
else
{
maxlowprice = maxlowprice[1];
trend = trend[1];
nexttrend = nexttrend[1];
minhighprice = minhighprice[1];
}
if trend == 0
{
up = if trend[1] <> 0
then down[1]
else Max(maxlowprice[1], up[1]);
down = 0;
}
else if trend[1] <> 1
{
down = up[1];
up = 0;
}
else if trend == 1
{
down = Min(minhighprice, down[1]);
up = up[1];
}
else
{
up = up[1];
down = down[1];
}
def UpSignal = up[1] < 1 and up > 0;
def DownSignal = down[1] < 1 and down > 0;
plot UpSignalArrow = UpSignal within 5 bars;
#plot DownSignalArrow = DownSignal within 5 bars;
# End Code
Last edited: