I am trying to create a multi-time frame scanner that is true when the last of 4 conditions becomes true within x bars.
Conditions:
The scanner requires an aggregation period per study. I can’t use the study below since it has multi-aggregation periods. I can’t produce a way to re-create the study in scanner.
Any pointers appreciated.
Thanks,
Dave
Conditions:
- # Close > 10wk moving average
- # Close > 40wk moving average
- # Close > 200day moving average
- # Relative strength vs S&P500 is increasing
The scanner requires an aggregation period per study. I can’t use the study below since it has multi-aggregation periods. I can’t produce a way to re-create the study in scanner.
Any pointers appreciated.
Thanks,
Dave
Code:
# Used for scanner
# Search for companies that meet this criteria
# Close > 10wk moving average
# Close > 40wk moving average
# Close > 200day moving average
# Relative strength vs S&P500 is increasing
declare lower;
input price = FundamentalType.CLOSE;
input wklyaggregationPeriod = AggregationPeriod.WEEK;
input shortwklylength = 10;
input longwklylength = 40;
input dailyaggregationPeriod = AggregationPeriod.DAY;
input longdaylength = 200;
input displace = 0;
input showOnlyLastPeriod = no;
def shortwklySMA;
if showOnlyLastPeriod and !IsNaN(close(period = wklyaggregationPeriod)[-1]) {
shortwklySMA = Double.NaN;
} else {
shortwklySMA = Average(Fundamental(price, period = wklyaggregationPeriod)[-displace], shortwklylength);
}
def longwklySMA;
if showOnlyLastPeriod and !IsNaN(close(period = wklyaggregationPeriod)[-1]) {
longwklySMA = Double.NaN;
} else {
longwklySMA = Average(Fundamental(price, period = wklyaggregationPeriod)[-displace], longwklylength);
}
def longdailySMA;
if showOnlyLastPeriod and !IsNaN(close(period = dailyaggregationPeriod)[-1]) {
longdailySMA = Double.NaN;
} else {
longdailySMA = Average(Fundamental(price, period = dailyaggregationPeriod)[-displace], longdaylength);
}
#Relative strength
input CorrelationWithSecurity = "SPX";
def close2 = close(CorrelationWithSecurity);
def RS = if close2 == 0 then 0 else close/close2;
input RSAvgLength = 50;
input averageType = AverageType.SIMPLE;
def RSAvg = MovingAverage(averageType, RS, RSAvgLength);
def RSAvgInc = RSAvg[1] < RSAvg;
plot GreaterThanAvgs = close > shortwklySMA and close > longwklySMA and close > longdailySMA and RSAvgInc;