EMA Proximity Filter Returning Inconsistent Results
Forums › ProRealTime English forum › ProBuilder support › EMA Proximity Filter Returning Inconsistent Results
- This topic has 3 replies, 3 voices, and was last updated 2 days ago by
JS.
-
-
07/22/2025 at 2:45 PM #249019
EMA Proximity Filter Issue in Stock Screener — Help Needed
I’m encountering inconsistent results with my EMA proximity filter in a stock screener. The filter should only show stocks within a specified distance (in nATR units) from the 200EMA, but some stocks pass while others don’t—even when they meet the criteria.
Examples (Scanning NASDAQ):
$SERV
ATR: 7.6%
Distance from EMA: 15%
nATR distance ≈ 1.97 → Should fail, but appears in scan$GRRR
ATR: 11.6%
Distance from EMA: 4%
nATR distance ≈ 0.34 → Should pass, but missing from scanWould appreciate your help on this, thank you.
Current ProScreener Code
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768// --- Main Parameters ---atrPeriod = 14 // ATR calculation periodvolumePeriod = 50 // Volume averaging periodemaPeriod = 200 // EMA period for proximity checksmaPeriod = 200 // SMA period for proximity check// --- Moving Average Proximity Parameters ---ONCE EnableMovingAverageCheck = 1 // Set to 1 to enable the EMA proximity check, 0 to disableONCE MaxNATRDistanceFromEMA = 1.0 // Maximum distance from EMA in nATR unitsONCE EnableSMACheck = 0 // Set to 1 to enable the SMA proximity check, 0 to disableONCE MaxNATRDistanceFromSMA = 1.0 // Maximum distance from SMA in nATR units// --- Filter Parameters ---minVolatility = 5 // Minimum acceptable volatility (nATR %)maxVolatility = 99 // Maximum acceptable volatility (nATR %)minLiquidity = 15000000 // Minimum avg currency volumemaxLiquidity = 10000000000000000 // Maximum avg daily currency volume// --- Calculations ---// 1. Volatility measurement (nATR)atr = AverageTrueRange[atrPeriod](Close)nATR = 100 * atr / Close // nATR as percentage of price// 2. Liquidity measurementavgVolume = Average[volumePeriod](Close * Volume)// 3. Moving average calculationsemaX = ExponentialAverage[emaPeriod](Close)smaX = Average[smaPeriod](Close)// Calculate distances in nATR unitsdistanceFromEMA = 100 * ABS(Close - emaX) / Close // Distance as percentagenATRDistEmaX = distanceFromEMA / nATR // Convert to nATR unitsdistanceFromSMA = 100 * ABS(Close - smaX) / ClosenATRDistSmaX = distanceFromSMA / nATR// --- Apply All Filters ---// Ensure we have enough data for calculationsIF BarIndex < volumePeriod OR BarIndex < emaPeriod THENvalid = 0ELSE// 1. Volatility filter with rangecond1 = nATR >= minVolatility AND nATR <= maxVolatility// 2. Liquidity filter with rangecond2 = avgVolume >= minLiquidity AND avgVolume <= maxLiquidity// 3. Moving Average proximity checksIF EnableMovingAverageCheck = 1 THENemaFilter = nATRDistEmaX <= MaxNATRDistanceFromEMAELSEemaFilter = 1 // Always pass if disabledENDIFIF EnableSMACheck = 1 THENsmaFilter = nATRDistSmaX <= MaxNATRDistanceFromSMAELSEsmaFilter = 1 // Always pass if disabledENDIF// Combined condition - ALL must be truevalid = cond1 AND cond2 AND emaFilter AND smaFilterENDIF// Output result sorted by volatilitySCREENER[valid] SORT BY nATR AS "Volatility (%)"07/22/2025 at 4:16 PM #249021The problem may be that you’re trying to calculate a 200-period exponential moving average with the free version of PRT. In the free version the screener has a capacity of 256 bars and in the premium 1024. Therefore the exponential moving average won’t be calculated correctly. You can easily check it:
123456789// --- Main Parameters ---emaPeriod = 200 // EMA period for proximity checksmaPeriod = 200 // SMA period for proximity checkema=average[emaPeriod,1](close)sma=average[smaPeriod,0](close)// Output result sorted by volatilityscreener(ema as "EMA", sma as "SMA")Check the values obtained for the EMA and you’ll see that they’re not correct, whereas those for the SMA are.
Solution: reduce the number of periods…1 user thanked author for this post.
07/23/2025 at 11:43 AM #249048Since I compute distance between last close and its EMA with a period smaller than the 256 capacity, I do not understand why there is not enough data for accurate results.
I could use a higher timeframe with lower MA period or purshase the premium version if capacity is the problem but I would like to understand why it is the problem in the first place.
Can you clarify this please?
Thank you
07/23/2025 at 12:02 PM #249049Hi,
An EMA is a recursive filter where each value is calculated using previous EMA values…To achieve a stabilized and reliable calculation, approximately 3 times the chosen period is needed — in this case, 3 × 200 = 600 (history)candles…
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on