Request how to solve the think script below for ehler MESA moving average - ThinkOrSwim | futures.io
futures.io futures trading


Request how to solve the think script below for ehler MESA moving average
Started: by Danielwalker Views / Replies:167 / 0
Last Reply: Attachments:0

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

Request how to solve the think script below for ehler MESA moving average

  #1 (permalink)
Trading Apprentice
Singapore
 
Futures Experience: Intermediate
Platform: Thinkorswim
Favorite Futures: Stocks
 
Posts: 1 since May 2015
Thanks: 0 given, 0 received

Request how to solve the think script below for ehler MESA moving average

Dear All,

I found source code from trading view for the ehler adaptive moving average and try to convert it directly into think script and found a problem. The think script compile the code top down sequence but the code define the variables p at the bottom while the variable p is being used at the top part of the source code giving me the variable error. Does anyone able help me how to correct the code in such a way that it will work in think script?


tradingView source code:
-----------------------------------------------------------------------------------------------------------------------
src=input(hl2, title="Source")
fl=input(.5, title="Fast Limit")
sl=input(.05, title="Slow Limit")
sp = (4*src + 3*src[1] + 2*src[2] + src[3]) / 10.0
dt = (.0962*sp + .5769*nz(sp[2]) - .5769*nz(sp[4])- .0962*nz(sp[6]))*(.075*nz(p[1]) + .54)
q1 = (.0962*dt + .5769*nz(dt[2]) - .5769*nz(dt[4])- .0962*nz(dt[6]))*(.075*nz(p[1]) + .54)
i1 = nz(dt[3])
jI = (.0962*i1 + .5769*nz(i1[2]) - .5769*nz(i1[4])- .0962*nz(i1[6]))*(.075*nz(p[1]) + .54)
jq = (.0962*q1 + .5769*nz(q1[2]) - .5769*nz(q1[4])- .0962*nz(q1[6]))*(.075*nz(p[1]) + .54)
i2_ = i1 - jq
q2_ = q1 + jI
i2 = .2*i2_ + .8*nz(i2[1])
q2 = .2*q2_ + .8*nz(q2[1])
re_ = i2*nz(i2[1]) + q2*nz(q2[1])
im_ = i2*nz(q2[1]) - q2*nz(i2[1])
re = .2*re_ + .8*nz(re[1])
im = .2*im_ + .8*nz(im[1])
p1 = iff(im!=0 and re!=0, 360/atan(im/re), nz(p[1]))
p2 = iff(p1 > 1.5*nz(p1[1]), 1.5*nz(p1[1]), iff(p1 < 0.67*nz(p1[1]), 0.67*nz(p1[1]), p1))
p3 = iff(p2<6, 6, iff (p2 > 50, 50, p2))
p = .2*p3 + .8*nz(p3[1])
spp = .33*p + .67*nz(spp[1])
phase = atan(q1 / i1)
dphase_ = nz(phase[1]) - phase
dphase = iff(dphase_< 1, 1, dphase_)
alpha_ = fl / dphase
alpha = iff(alpha_ < sl, sl, iff(alpha_ > fl, fl, alpha_))
mama = alpha*src + (1 - alpha)*nz(mama[1])
fama = .5*alpha*mama + (1 - .5*alpha)*nz(fama[1])
pa=input(false, title="Mark crossover points")
plotarrow(pa?(cross(mama, fama)?mama<fama?-1:1:na):na, title="Crossover Markers")
fr=input(false, title="Fill MAMA/FAMA Region")
duml=plot(fr?(mama>fama?mama:fama):na, style=circles, color=gray, linewidth=0, title="DummyL")
mamal=plot(mama, title="MAMA", color=red, linewidth=2)
famal=plot(fama, title="FAMA", color=green, linewidth=2)
fill(duml, mamal, red, transp=70, title="NegativeFill")
fill(duml, famal, green, transp=70, title="PositiveFill")
ebc=input(false, title="Enable Bar colors")
bc=mama>fama?lime:red
barcolor(ebc?bc:na)
------------------------------------------------------------------------------------------------------------------------------

my think script source code:

input h = high;
input
l = low;

input fl = 0.5;
input sl = 0.05;


def hl2 = (h + l) / 2;

def sp = (4 * hl2 + 3 * hl2[1] + 2 * hl2[2] + hl2[3] / 10.0);

def dt = (0.0962 * sp + 0.5769 * (if IsNaN(sp[2]) then 0 else sp[2]) - 0.5769 * (if IsNaN(sp[4]) then 0 else sp[4]) - 0.0962 * (if IsNaN(sp[6]) then 0 else sp[6])) * (0.075 * (if IsNaN(p[1]) then 0 else p[1]) + 0.54);


def q1 = (0.0962 * dt + 0.5769 * (if IsNaN(dt[2]) then 0 else dt[2]) - 0.5769 * (if IsNaN(dt[4]) then 0 else dt[4]) - 0.0962 * (if IsNaN(dt[6]) then 0 else dt[6])) * (0.075 * (if IsNaN(p[1]) then 0 else p[1]) + 0.54);


def i1 = (if IsNaN(dt[3]) then 0 else dt[3]);


def jl = (0.0962 * i1 + 0.5769 * (if IsNaN(i1[2]) then 0 else i1[2]) - 0.5769 * (if IsNaN(i1[4]) then 0 else i1[4]) - 0.0962 * (if IsNaN(i1[6]) then 0 else i1[6])) * (0.075 * (if IsNaN(p[1]) then 0 else p[1]) + 0.54);


def jq = (0.0962 * q1 + 0.5769 * (if IsNaN(q1[2]) then 0 else q1[2]) - 0.5769 * (if IsNaN(q1[4]) then 0 else q1[4]) - 0.0962 * (if IsNaN(q1[6]) then 0 else q1[6])) * (.075 * (if IsNaN(p[1]) then 0 else p[1]) + .54);


def i2_ = i1 - jq;
def q2_ = q1 + jl;
def i2 = .2 * i2_ + .8 * (if IsNaN(i2[1]) then 0 else i2[1]);
def q2 = .2 * q2_ + .8 * (if IsNaN(q2[1]) then 0 else q2[1]);


def re_ = i2 * (if IsNaN(i2[1]) then 0 else i2[1]) + q2 * (if IsNaN(q2[1]) then 0 else q2[1]);


def im_ = i2 * (if IsNaN(q2[1]) then 0 else q2[1]) - q2 * (if IsNaN(i2[1]) then 0 else i2[1]);


def re = .2 * re_ + .8 * (if IsNaN(re[1]) then 0 else re[1]);


def im = .2 * im_ + .8 * (if IsNaN(im[1]) then 0 else im[1]);


def p1 = if (im != 0 and re != 0) then 360 / Tan(im / re) else (if IsNaN(p[1]) then 0 else p[1]);


def p2 = if p1 > 1.5 * (if IsNaN(p1[1]) then 0 else p1[1]) then 1.5 * (if IsNaN(p1[1]) then 0 else p1[1]) else if p1 < 0.67 * (if IsNaN(p1[1]) then 0 else p1[1]) then 0.67 * (if IsNaN(p1[1]) then 0 else p1[1]) else p1;



def p3 = if (p2 < 6) then 6 else if (p2 > 50) then 50 else p2;


rec p = .2 * p3 + .8 * (if IsNaN(p3[1]) then 0 else p3[1]);


def spp = .33 * p + .67 * (if IsNaN(spp[1]) then 0 else spp[1]);


def phase = Tan(q1 / i1);


def dphase_ = (if IsNaN(phase[1]) then 0 else phase[1]) phase;


def dphase = if (dphase_ < 1) then 1 else dphase_ ;

def alpha_ = fl / dphase;

def alpha = if (alpha_ < sl) then sl else if (alpha_ > fl) then fl else alpha_ ;


plot mama = alpha * hl2 + (1 - alpha) * (if IsNaN(mama[1]) then 0 else mama[1]);


plot fama = .5 * alpha * mama + (1 - .5 * alpha) * (if IsNaN(fama[1]) then 0 else fama[1]);

Reply With Quote

Reply



futures.io > > > > Request how to solve the think script below for ehler MESA moving average

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

2016 True Edge Awards: Voting is open until Jan 21!

Now
 

Bookmap New Indicator Panel, Cumulative Delta, Order Flow demo

Jan 17
 

An Afternoon with FIO member Massive l

Elite only

Leo Murphy: Making sense of Technical Analysis and Random Walk

Elite only
 

FuturesTrader71: Ask Me Anything

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
TOS Script Needed OBV and 20 Moving Average thescream80 ThinkOrSwim 2 June 18th, 2015 08:40 PM
Pine Script Translation Request: ValueWhen compupix ThinkOrSwim Programming 0 November 22nd, 2014 05:02 PM
Beginner script advice or request mcteague NinjaTrader Programming 3 November 12th, 2012 07:57 PM
MAMA (Mesa Adaptive Moving Average) EA motoko Platforms and Indicators 0 August 29th, 2011 06:02 PM
Request: Script to download historical data Henrik Platforms and Indicators 2 January 4th, 2010 02:23 PM


All times are GMT -4. The time now is 02:06 AM.

no new posts
Page generated 2017-01-18 in 0.08 seconds with 19 queries on phoenix via your IP 174.129.187.112