# FRAMA Fractal Adaptive Moving Average with Standard Deviation Bands For ThinkOrSwim

#### MLlalala

##### Member
Just wonder if anone intrested coding this. John Ehlers wrote a paper on this moving average

https://www.mesasoftware.com/papers/FRAMA.pdf

I think this looks very good on its own function as a moving average. Furthermore, we could add bands on top this, to see how well price fit in this channel.

Anyone?

FRAMA Fractal Adaptive Moving Average with Standard Deviation Bands For ThinkOrSwim
found on OneNote
Ruby:
``````Mobius©: # FRAMA Fractal Adaptive Moving Average with Standard Deviation Bands
# Mobius
# V01.07.2013

input n = 16;
input price = HL2;
input SDmult = 3;
input DisplayBands = yes;

def n1;
def n2;
def n3;
def hh;
def ll;
def dimen;
def alpha;
def filt;

N3 = (Highest(high, N) - Lowest(low, N)) / N;
HH = high;
LL = low;

def count = fold i = 0 to (n/2)
with p
do if GetValue(HH, GetMaxValueOffset(hh, n/2), n) > HH
then GetValue(HH, GetMaxValueOffset(hh, n/2), n)
else if GetValue(LL, GetMinValueOffset(ll, n/2), n) < LL
then GetValue(LL, GetMinValueOffset(ll, n/2), n)
else count[1];

N1 = (HH - LL) / (N/2);
def HH1 = high[n/2];
def LL1 = low[n/2];
def count2 = fold j = n/2 to n
with q
do if GetValue(HH1, GetMaxValueOffset(HH1, n/2), n) > HH1
then GetValue(HH1, GetMaxValueOffset(HH1, n/2), n)
else if GetValue(LL1, GetMinValueOffset(LL1, n/2), n) < LL1
then GetValue(LL1, GetMinValueOffset(LL1, n/2), n)
else count[1];

N2 = (count - count2) / (N / 2);
dimen = if N1 > 0 and N2 > 0 and N3 > 0 then (Log(N1 + N2) - Log(N3)) / Log(2) else 0;
alpha = if Dimen == .7
then .02
else if Dimen == .05
then .33
else if Exp(-4.6*(Dimen - 1)) < .01
then .01
else if Exp(-4.6* (Dimen - 1)) > 1 then 1
else 0;
Filt = alpha * Price + (1 - alpha) * Filt[1];

plot FRAMA = Inertia(filt, n);
FRAMA.SetDefaultColor(Color.Yellow);

def SD = StDev(close, n);

plot upper = FRAMA + (SDmult * SD);
upper.SetHiding(!DisplayBands);
upper.SetDefaultColor(CreateColor(50,50,50));
plot lower = FRAMA - (SDmult * SD);
lower.SetHiding(!DisplayBands);
lower.SetDefaultColor(CreateColor(50,50,50));``````

Last edited:

87k+ Posts
384 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?