Checking for flatlining Moving Average
- This topic has 5 replies, 3 voices, and was last updated 3 months ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
Similar topics:
Forums › ProRealTime English forum › ProScreener support › Checking for flatlining Moving Average
Good morning, hoping that someone might be able to assist me please.
Currently looking at sideways/consolidation movemnts.
Which is the easiest way to code to check whether a given moving average has been in a very tight range for the previous x periods?
Many thanks in advance.
Simon
Hi,
Step 1 – Store your moving average into a variable, for example named my myMA :
myMA =
Step 2 – Define from words to quantity what a « very tight range » means to you, and store it into a variable, for example named maxrange:
maxrange =
Step 3 – Define highest within x of your MA and lowest within x of your MA, and store in a true or false condition how further apart they are relatively to your maxrange :
MAHH=highest[x](myMA)
MALL=lowest[x](myMA)
condition = (MAHH-MALL)<=maxrange
And, because we are in the proscreener forum, and screeners have a more limited history than indicators and strategies, assuming you asked this to include within a screener, for this to work properly you would of course also need to ensure your moving average was already existing at the oldest of those x bars, that is to say the sum of [your moving average period] + [x] – 1 must be lower or equal to your max screener history (for example, moving average period 200, and x = 100, wouldn’t work for a 256 number of bars screener max history on prt complete, but would be ok for a 1024 max on prt premium)
Thanks JC
Step 2 – Define from words to quantity what a « very tight range » means to you
Somewhat tricky as different timeframes so can’t use absolute amounts/%
Perhaps need to utilise std deviation (not very good as that!) or alternatively and more simple but maybe less effective if to count the number of bars (within the last 20 for example) where the bar has touched the ma, a reading of > x would indicate a flat(ening) ma particularly if over longer timeframes (eg weekly) and higher ma’s (eg 80)
Try this one:
1 2 3 4 5 6 7 8 9 10 11 |
ONCE X = 0.05 //0.1% is the percentage wothin which an MA is considered FLAT ONCE N = 20 //10 candles in a row is the requirement to tell an MA is FLAT Sma1 = average[100,0](close) Sma2 = average[N,0](Sma1) SmaGap = abs(Sma1 - Sma2) <= (Sma1 * X / 100) BackgroundColor("White",255) FlatLine = (summation[N](SmaGap) = N) IF FlatLine THEN BackgroundColor("Green",50) ENDIF RETURN SMA1 AS "Sma1",SMA2 AS "Sma2" |
Find exclusive trading pro-tools on