OK. I'm stumped. Zero Lag EMA on Tick Charts

mashume

Expert
VIP
Lifetime
OK. I've been banging my head against this for too long. This code works just fine on time based charts, but not at all on tick based charts. Sometimes I can look at code and tell why... but not this time. Anyone have an idea what in this code keeps it from running on tick based charts?

It's from Mobius Zero Lag MACD for reference.

Code:
input length = 10;
input price = close;
def K = floor(2 / (length + 1));
def lag = floor((length - 1) / 2);
def ZLEMA = K * (2 * price - price[lag]) + (1 - K) * ZLEMA[1];
plot data = ZLEMA;

I even tried this in place of the original definition given above to no avail.
Code:
def ZLEMA = K * (2 * price - getValue(price, lag)) + (1 - K) * ZLEMA[1];

I'm sure that, as soon as I post this, it will all be clear. But for now, I'm stumped.

-mashume
 
Solution
OK. For those who may run into this some day in the future, it works if you explicitly make everything a float rather than an int. No idea if this is new, or always been there.
This code works:
Code:
input length = 40.0;
input price = close;
def K = (2.0 / (length + 1.0));
def lag = ((length - 1.0) / 2.0);
def ZLEMA = K * (2.0 * price - getValue(price, lag)) + (1.0 - K) * ZLEMA[1];
addLabel(yes, zlema);
plot data = ZLEMA;

:dumbfounded:

-mashume
OK. I've been banging my head against this for too long. This code works just fine on time based charts, but not at all on tick based charts. Sometimes I can look at code and tell why... but not this time. Anyone have an idea what in this code keeps it from running on tick based charts?

It's from Mobius Zero Lag MACD for reference.

Code:
input length = 10;
input price = close;
def K = floor(2 / (length + 1));
def lag = floor((length - 1) / 2);
def ZLEMA = K * (2 * price - price[lag]) + (1 - K) * ZLEMA[1];
plot data = ZLEMA;

I even tried this in place of the original definition given above to no avail.
Code:
def ZLEMA = K * (2 * price - getValue(price, lag)) + (1 - K) * ZLEMA[1];

I'm sure that, as soon as I post this, it will all be clear. But for now, I'm stumped.

-mashume
Using floor in def K results in zero. Therefore, I could not get it to plot as is on time also.
 
@mashume
@SleepyZ is correct:
0t6zTkr.png

Ruby:
input length = 10;
input price = close;
def K = floor(2 / (length + 1));
def lag = floor((length - 1) / 2);
def ZLEMA = K * (2 * price - price[lag]) + (1 - K) * ZLEMA[1];
plot data = ZLEMA;

AddChartbubble(close>open, high, "k= " +K +"\n"+ zlema, color.violet);
 
OK. For those who may run into this some day in the future, it works if you explicitly make everything a float rather than an int. No idea if this is new, or always been there.
This code works:
Code:
input length = 40.0;
input price = close;
def K = (2.0 / (length + 1.0));
def lag = ((length - 1.0) / 2.0);
def ZLEMA = K * (2.0 * price - getValue(price, lag)) + (1.0 - K) * ZLEMA[1];
addLabel(yes, zlema);
plot data = ZLEMA;

:dumbfounded:

-mashume
 
Solution
OK. For those who may run into this some day in the future, it works if you explicitly make everything a float rather than an int. No idea if this is new, or always been there.
This code works:
Code:
input length = 40.0;
input price = close;
def K = (2.0 / (length + 1.0));
def lag = ((length - 1.0) / 2.0);
def ZLEMA = K * (2.0 * price - getValue(price, lag)) + (1.0 - K) * ZLEMA[1];
addLabel(yes, zlema);
plot data = ZLEMA;

:dumbfounded:

-mashume


i am confused too.
first, let me say, i don't use tick charts, so i may be missing something.
i'm just curious about tick charts.

the fixed code in post #4 doesn't plot anything for me on a tick chart.
i added a yellow bubble to show the values of data, and all are N/A ?
i picked tick chart in settings > time axis , and didn't change anything else.


Code:
# zerolagmodfloatfloor_0
input length = 40.0;
input price = close;
def K = (2.0 / (length + 1.0));
def lag = ((length - 1.0) / 2.0);
def ZLEMA = K * (2.0 * price - getValue(price, lag)) + (1.0 - K) * ZLEMA[1];
addLabel(yes, zlema);
plot data = ZLEMA;

addchartbubble(1, high, data, color.yellow, yes);
#


htFQKK8.jpg


-------------------------------

i made a study with 3 variations of the code, in 1 study,
. 2 - orig with floor()
. 3 - floats, w/o floor()
. 4 - floats, with floor()

none of them plot a valid value for data?


Code:
# math_floor_zero_lag_00

#https://usethinkscript.com/threads/ok-im-stumped-zero-lag-ema-on-tick-charts.14929/
#OK. I'm stumped. Zero Lag EMA on Tick Charts
#mashume  3/22
#1
#OK. I've been banging my head against this for too long. This code works just fine on time based charts, but not at all on tick based charts. Sometimes I can look at code and tell why... but not this time. Anyone have an idea what in this code keeps it from running on tick based charts?

def bn = barnumber();
def na = double.nan;

#It's from Mobius Zero Lag MACD for reference.

input length1 = 10;
input price1 = close;
def K1 = Floor(2 / (length1 + 1));
def lag1 = Floor((length1 - 1) / 2);
def ZLEMA1 = K1 * (2 * price1 - price1[lag1]) + (1 - K1) * ZLEMA1[1];
plot data1 = ZLEMA1;

#I even tried this in place of the original definition given above to no avail.
#Code:
#def ZLEMA = K * (2 * price - getValue(price, lag)) + (1 - K) * ZLEMA[1];

#I'm sure that, as soon as I post this, it will all be clear. But for now, I'm stumped.

#-mashume
#Mashume
#Scientific Programmer, Trader, Dad, RPN fanatic in the PacNW



#SleepyZ
#2
#Using floor in def K results in zero. Therefore, I could not get it to plot as is on time also.


#MerryDay
#3
#@mashume
#@SleepyZ is correct:

#0t6zTkr.png
#Ruby:


#  2 - orig with floor()
input length2 = 10;
input price2 = close;
def K2 = Floor(2 / (length2 + 1));
def lag2 = Floor((length2 - 1) / 2);
def ZLEMA2 = K2 * (2 * price2 - price2[lag2]) + (1 - K2) * ZLEMA2[1];
plot data2 = ZLEMA2;

#AddChartBubble(close > open, high, "k= " + K2 + "\n" + ZLEMA2, Color.VIOLET);



#mashume
#4
#OK. For those who may run into this some day in the future, it works if you explicitly make everything a float rather than an int. No idea if this is new, or always been there.
#This code works:


#  3 - floats, w/o floor()
input length3 = 40.0;
input price3 = close;
def K3 = (2.0 / (length3 + 1.0));
def lag3 = ((length3 - 1.0) / 2.0);
def ZLEMA3 = K3 * (2.0 * price3 - GetValue(price3, lag3)) + (1.0 - K3) * ZLEMA3[1];
plot data3 = ZLEMA3;
AddLabel(yes, ZLEMA3);





#  4 - floats, with floor()
input length4 = 40.0;
input price4 = close;
def K4 = floor(2.0 / (length4 + 1.0));
def lag4 = ((length4 - 1.0) / 2.0);
def ZLEMA4 = K4 * (2.0 * price4 - GetValue(price4, lag4)) + (1.0 - K4) * ZLEMA4[1];
plot data4 = ZLEMA4;
addLabel(yes, zlema4);


#  2 - orig with floor()
#  3 - floats, w/o floor()
#  4 - floats, with floor()

# show bubble every s bars
def s = 10;
def x = bn % s == 0;

addchartbubble(x, low,
"K2  " + k2 + " - orig with floor() |  data2  " + data2 + "\n" +
"K3  " + k3 + " - floats, w/o floor() |  data3  " + data3 + "\n" +
"K4  " + k4 + " - floats, with floor() |  data4  " + data4 + "\n"
, color.violet, no);

#
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
572 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top