• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

Trying to group multiple conditions into one scanner

I want when:
ADX[1] > ADX:
& RSI < 50;
& RSI[1] > 50;
&PPO > PPO[1];
&PPOEMA > PPOEMA[1];
& PPO > PPOEMA;
for my line/dataprofile to show a 1 when all these conditions are met and show a 0 if only one or any combination of these is not met.

When I string these together as individuals,
Code:
def rsi_1 = RSI < Trendline;
def rsi_2 = RSI[1] > Trendline;
plot Condition_RSI_1 = RSI_1;
plot Condition_RSI_2 = RSI_2;

I have my 2 lines which follow their rules. when I input this:
Code:
def RSI_3 = if(rsi_1 + rsi_2) then 1 else 0 and if (RSI > Trendline or RSI[1] < Trendline) then 0 else 1;
plot  Condition_RSI_3 = RSI_3;

It's not working and the line isn't going to zero when both of the conditions are not met.

Here is the script I have so far for the current one I'm having issues with. I'm including everything with the # and I've deleted a lot that wasn't working.

Code:
declare lower;
#ADX
input length_ADX = 5;
input averageType_ADX = AverageType.WILDERS;
def ADX = DMI(length_ADX, averageType_ADX).ADX;
#-------------------------------------------------------------------------
#ppo and signal line
input fastPeriod   = 6;
input slowPeriod   = 15;
input signalPeriod = 9;
input price_1        = close;
def fastEma   = ExpAverage( price_1, fastPeriod );
def slowEma   = ExpAverage( price_1, slowPeriod );
def periodOK  = fastPeriod < slowPeriod;
AddLabel( !periodOK, "ERROR: fastPeriod MUST be less than slowPeriod" );
def ppo      = if periodOK then ((fastEma - slowEma) / slowEma) * 100 else 0;
def _signal   = ExpAverage( ppo, signalPeriod );
#----------------------
def PpoEma   = _signal;
def zeroLine = 0;
#----------------------------------------------------------------------------------
#RSI
input length = 5;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input trendline =  50;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
#def UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
#def DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
#----------------------------------------------------------------------------------
def Adx_1 = ADX < ADX[1];
#def ADX_11 = ADX > ADX[1];
def rsi_1 = RSI < Trendline;
#def RSI_11 = RSI > Trendline;
def rsi_2 = RSI[1] > Trendline;
#def RSI_21 =  RSI[1] < Trendline;
#def RSI_3 = if(RSI < Trendline + RSI[1] > Trendline) then 1 else 0 and if (RSI > Trendline or RSI[1] < Trendline) then 0 else 1;
def RSI_3 = if(rsi_1 + rsi_2) then 1 else 0 and if (RSI > Trendline or RSI[1] < Trendline) then 0 else 1;
def PPO_1 = ppo < ppo[1];
#def PPO_11 = ppo > ppo[1];
# and if(ppo > ppo[1]) then 0 else 1 and if(PpoEma < PpoEma[1]) then 0 else 1 and if(ppo > PpoEma) then 0 else 1 and if(ppo > ppo[1] + PpoEma < PpoEma[1]) then 0 else 1 and if(ppo > ppo[1] + ppo > PpoEma) then 0 else 1 and if(PpoEma < PpoEma[1] + ppo < PpoEma) then 0 else 1;
def PPO_2 = PpoEma > PpoEma[1];
#def PPO_22 = PpoEma < PpoEma[1];
def PPO_3 = ppo > PpoEma;
#def PPO_33 = ppo < PpoEma;
def PPO_4 = if (PPO_1 + PPO_2 + PPO_3) then 1 else 0;# and if (PPO_11 or PPO_22 or PPO_33) then 0 else 1;
#plot dataprofile_RSI= if (ADX_1 + RSI_1) then 1 else 0 and  if (ADX_1 or RSI_1) then 0 else 1;
##plot dataprofile_ADX_RSI = if(ADX_1 + RSI_3) then 1 else 0 and if(ADX_1 or RSI_3) then 0 else 1;
#plot dataprofile = if(ADX_1;
#Plot dataprofile_2 = RSI_3;
#plot dataprofile_3 = PPO_1 + PPO_2 + PPO_3;
#plot dataprofile_3 = PPO_4;

#plot dataprofile_4 = if(dataprofile + dataprofile_2 + dataprofile_3) then 1 else 0;
#plot condition_PPO_3 = if (ppo > PpoEma) then 1 else if (PpoEma > ppo) then 0 else 1;
#plot condition_PPO_2 = if (PpoEma > PpoEma[1]) then 1 else 0 and if (PpoEma[1] > PpoEma) then 0 else 1;
#plot condition_PPO_1 = if (ppo < ppo[1]) then 1 else 0 and if (ppo[1] > ppo) then 0 else 1;
#def  dataprofile_PPO_1 = condition_PPO_1;
#def  dataprofile_PPO_2 = condition_PPO_2;
#def  dataprofile_PPO_3 = condition_PPO_3;

#plot dataProfile_PPO   = if (dataprofile_PPO_1 + dataprofile_PPO_2 + dataprofile_PPO_3) then 1 else 0 and if (dataprofile_PPO_1 or dataprofile_PPO_2 or dataprofile_PPO_3) then 0 else double.NaN and if(dataprofile_PPO_1 + dataprofile_PPO_2) then 0 else double.NaN and if(dataprofile_PPO_1 + dataprofile_PPO_3) then 0 else double.NaN and if(dataprofile_PPO_1 + dataprofile_PPO_3) or dataprofile_PPO_1 or dataprofile_PPO_2 or dataprofile_PPO_3 then 0 else double.NaN;

#plot dataProfile_PPO   = dataprofile_PPO_1 + dataprofile_PPO_2 + dataprofile_PPO_3;
#plot dataprofile_
#---------
plot Condition_RSI_1 = RSI_1;
plot Condition_RSI_2 = RSI_2;
plot  Condition_RSI_3 = RSI_3;

Another study I made that is completely unrelated to this one is the following using what I believe is the same format because I tried to copy it.
And this study works perfectly fine on the chart and the version I converted to a scan inquiry is flawless.

Code:
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;
#input showBreakoutSignals = no;

def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;
#plot UpSignal = if Diff crosses above 0 then 0 else Double.NaN;
#plot DownSignal = if Diff crosses below 0 then 0 else Double.NaN;


input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.SIMPLE;
#input showBreakoutSignals = {default "No", "On SlowK", "On SlowD", "On SlowK & SlowD"};

def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;

def SlowD = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;

#plot DataProfile = (slowK[1] < slowD[1]) and (slowK > SlowD);


#plot DataProfile = (slowK[1] < slowD[1]) and (slowK > SlowD) and (lowest(SlowK[1], 3) < 50);

#plot DataProfile = (slowK[1] < slowD[1]) and (slowK > SlowD) and (lowest(SlowK[1], 3) < 70) and (Diff[1] < Diff);

#plot chart = if((slowK[1] < slowD[1]) and (slowK > SlowD) and (lowest(SlowK[1], 3) < 50) and (Diff[1] < Diff)) then 1 else 0;

def MACD = (Diff[1] < Diff);

def Stoch_Slow = (SlowK[1] < SlowD[1]) and (SlowK > SlowD);

def Stoch_Slow_1 = (lowest(SlowK[1], 3) < SlowK);

def Stoch_Slow_2 = slowK > slowD;

#def Stoch_Slow_2 = highest(SlowK[2]) > slowK;

#plot dataprofile = if(MACD + Stoch_Slow) then 1 else 0 and if(MACD or stoch_Slow)then 0 else 1;

plot dataprofile = if(MACD + Stoch_Slow + Stoch_Slow_1 + Stoch_Slow_2) then 1 else 0 and if(MACD or stoch_Slow or Stoch_Slow_1 or Stoch_Slow_2)then 0 else 1;

the # on the lines leading to the bottom is me showing my work on how I got there.

So, Im pretty confused why I can't combine the terms I want at the top on the script I am currently working with.
 

BenTen

Administrative
Staff
VIP
The scanner is working for me. What am I missing here?

Screen-Shot-2021-01-20-at-2-52-52-PM.png
 
when I chart it, The orange line isn't doing what it should. The orange line should be at zero when both conditions are false or if only 1 condition is true. And the orange line should be at 1 when both conditions are true. currently RSI condition 1 is cyan and RSI Condition 2 is pink.

The line for both conditions is orange and should be at 1 when both conditions are true, and it's showing its at 1 for days a time when only 1 condition is true. that's what I don't get. I always make sure my graphs are squared away because the scan will get results no matter what and if the chart doesn't show what I want, the Scan won't be of any use to me.

I'm on my laptop and none of the 4 shareable Imgur links are working for me when I try to insert the links using the add image button.
edit got it to insert the photo.

unQi12k.png
 
Last edited:

rad14733

Well-known member
VIP
@mourningwood4521 I think you have a logic error in the following line of code... I have provided what I believe is the correct code...

Ruby:
def RSI_3 = if(rsi_1 + rsi_2) then 1 else 0 and if (RSI > Trendline or RSI[1] < Trendline) then 0 else 1;

Ruby:
def RSI_3 = if (rsi_1 + rsi_2) and (RSI > Trendline or RSI[1] < Trendline) then 1 else 0;

You cannot have multiple assignments in a single statement... Not sure if the logic is totally correct but I'm fairly certain that your line is incorrect...

Edited to add: I see what you're trying to do now... You're daisy-chaining logic conditionals which can be confusing... I'll dig deeper in a bit...
 
Last edited:
@rad14733 RSI > Trendline is the opposite of RSI_1, where RSI_1 = RSI < Trendline. I will play around with the format you suggested and see if I can get the program to take the phrases. I started out with a format similar to what you suggested and it wouldn't take it, which is why I was using the second half.

Im thinking about reformatting it so every time one statement is true = 1, so if all 7 of my statements are true then I would have a graph line at 7, and say I have a bunch of days where 6 happen, then I can further refine my scan. I can also easily pick out other patterns that are occurring whereas if I just have a 0-1 oscillator, I wouldn't be able to pick out the other patterns.

Thank you for spending time looking into this for me.
 
So I decided to change it so I can see a value of 6 as having all of my parameters met. So here is a screenshot of what it looks like, and a current theory I'm working on. I haven't back tested this yet, so it could be nothing.

EETWrlt.png


Code:
#Hint: Shows a graph of 6 conditiojs when all 6 conditions are true you get a reading of 6.       File with the same name with Duplicate at the end contains all the knitty gritty on the PPO cloud data

declare lower;
#ADX
input length_ADX = 5;
input averageType_ADX = AverageType.WILDERS;
def ADX = DMI(length_ADX, averageType_ADX).ADX;
#-------------------------------------------------------------------------
#ppo and signal line
input fastPeriod   = 6;
input slowPeriod   = 15;
input signalPeriod = 9;
input price_1        = close;
def fastEma   = ExpAverage( price_1, fastPeriod );
def slowEma   = ExpAverage( price_1, slowPeriod );
def periodOK  = fastPeriod < slowPeriod;
AddLabel( !periodOK, "ERROR: fastPeriod MUST be less than slowPeriod" );
def ppo      = if periodOK then ((fastEma - slowEma) / slowEma) * 100 else 0;
def _signal   = ExpAverage( ppo, signalPeriod );
#----------------------
def PpoEma   = _signal;
def zeroLine = 0;
#----------------------------------------------------------------------------------
#RSI
input length = 5;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input trendline =  50;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
#def UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
#def DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
#----------------------------------------------------------------------------------
def Adx_1 = if(ADX < ADX[1]) then 1 else 0;
def rsi_1 = if(RSI < Trendline) then 1 else 0;
def rsi_2 = if(RSI[1] > Trendline) then 1 else 0;
def RSI_3 = if(rsi_1 + rsi_2) then 1 else 0;
def PPO_1 = if(ppo < ppo[1]) then 1 else 0;
def PPO_2 = if(PpoEma > PpoEma[1]) then 1 else 0;
def PPO_3 = if(ppo > PpoEma) then 1 else 0;

plot dataprofile = ADX_1 + RSI_1 + RSI_2 + PPO_1 + PPO_2 + PPO_3;
 
Top