Hi. Sorry to bother with such a seemingly simple script. I am stuck though. Please explain what I am doing incorrectly. When I run this script as a scan looking through the S&P 500, it returns stocks with price well above 2% from the 20 period EMA. Please advise. Thank you.
//Show stocks greater than or equal to, but less than 2% from, their 20d EMA.
//Variables
V1 = MA(BARS=20, CALC=Close);
V2 = ((CLOSE() - V1) /V1);
//Formula: close is at or above the 20 period ema, but close is 2% or less above the 20 period EMA
CLOSE() >= V1 and V2 <= .02;
Can you provide an example of a code that passed which shouldn’t have, and the properties of the scan you are using? The script looks ok to me based on a manual check:
20SMA Line with a 2% band, shaded green zone shows criteria matches when Close is in-between the two lines.
From what i can see you have Exponential Moving Averages on the chart, but are using Simple Moving Averages in the script. If you changed the Moving Averages to Simple on the chart you should see those two codes (ADBE and ZTS) are passing correctly.
Alternatively, adjust the scripts to use EMAs instead of SMAs and those two codes are no longer part of the scan results.
Thank you so much! Sorry I missed that. My brain is mush so many hours into my workday. You are exactly right in that the settings were not set to exponential. I even figured out how to script exactly what you did. I love Optuma, and I want to say that your your help means so much to me as I work become proficient in Optuma!