Checking for flatlining Moving Average

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #238444 quote
    sgrech
    Participant
    Junior

    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

    #238445 quote
    JC_Bywan
    Moderator
    Master

    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)

    sgrech and Iván González thanked this post
    #238446 quote
    sgrech
    Participant
    Junior

    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)

    #238489 quote
    sgrech
    Participant
    Junior

    Any further comment please 🙂

    #238570 quote
    sgrech
    Participant
    Junior

    Hoping someone is able to help me?

    #238602 quote
    robertogozzi
    Moderator
    Master

    Try this one:

    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"
    sgrech thanked this post
    x-2.jpg x-2.jpg
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Checking for flatlining Moving Average


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
sgrech @sgrech Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by robertogozzi
1 year, 5 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 10/03/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...