Trader4TOS
Member
This tool is designed to scan for specific conditions in the price action and moving averages of a given security. Here's an explanation of the script:
- Study Definition: The script is declared as a lower study, which means it will be plotted on the chart below the price action.
- Input Variables: The script allows you to customize various input variables to adjust the length of exponential moving averages (EMAs) used in the calculations. The lengths specified are length1, length2, length3, length4, and length5.
- Exponential Moving Averages (EMA): The script calculates five EMAs based on the closing prices of the security using the lengths provided in the input variables. The EMAs are stored in the variables ema1, ema2, ema3, ema4, and ema5, respectively.
- Upside and Downside Gaps: The script scans for upside and downside gaps in the price action. An upside gap occurs when the open price is higher than the previous close, and the low price is higher than the previous high. A downside gap occurs when the open price is lower than the previous close, and the high price is lower than the previous low. These conditions are captured using the upsideGap and downsideGap variables.
- Breaks Above EMAs: The script scans for breaks above the EMAs. It checks if the current close price is higher than the previous EMA value and if the low price is also higher than the previous EMA value for each EMA length. These conditions are captured using the breakAboveEMA1, breakAboveEMA2, breakAboveEMA3, breakAboveEMA4, and breakAboveEMA5 variables.
- Demand and Supply Breaks: The script scans for demand breaks to the downside and supply breaks to the upside. A demand break occurs when the open price is lower than the previous close, and the low price is lower than the previous low. A supply break occurs when the open price is higher than the previous close, and the high price is higher than the previous high. These conditions are captured using the demandBreak and supplyBreak variables.
- Scan Filters: The scan filters are combined using the "or" logical operator to identify any occurrence of the defined conditions. The plot "scanFilter" is assigned the value of true whenever any of the conditions (upsideGap, downsideGap, breakAboveEMA1, breakAboveEMA2, breakAboveEMA3, breakAboveEMA4, breakAboveEMA5, demandBreak, or supplyBreak) are met.
Ruby:
# Levels scanner created by Trader4TOS 06/22/2023
# Additional features include Supply and Demand criteria. Along with gap fills.
# Define study
declare lower;
# Define input variables
input length1 = 21;
input length2 = 50;
input length3 = 100;
input length4 = 200;
input length5 = 300;
# Calculate exponential moving averages (EMA)
def ema1 = ExpAverage(close, length1);
def ema2 = ExpAverage(close, length2);
def ema3 = ExpAverage(close, length3);
def ema4 = ExpAverage(close, length4);
def ema5 = ExpAverage(close, length5);
# Scan for upside and downside gaps
def upsideGap = open > close[1] and low > high[1];
def downsideGap = open < close[1] and high < low[1];
# Scan for breaks above EMAs
def breakAboveEMA1 = close > ema1[1] and low > ema1[1];
def breakAboveEMA2 = close > ema2[1] and low > ema2[1];
def breakAboveEMA3 = close > ema3[1] and low > ema3[1];
def breakAboveEMA4 = close > ema4[1] and low > ema4[1];
def breakAboveEMA5 = close > ema5[1] and low > ema5[1];
# Scan for demand breaks to the downside and supply breaks to the upside
def demandBreak = open < close[1] and low < low[1];
def supplyBreak = open > close[1] and high > high[1];
# Add scan filters
plot scanFilter = upsideGap or downsideGap or breakAboveEMA1 or breakAboveEMA2 or breakAboveEMA3 or breakAboveEMA4 or breakAboveEMA5 or demandBreak or supplyBreak;
Last edited: