Implementing Zero-Lag MACD Indicator in ProBuilder

21 Jun 2016
0 comment
0 attachment

This code snippet demonstrates how to implement a Zero-Lag Moving Average Convergence Divergence (MACD) indicator using the ProBuilder programming language. The Zero-Lag MACD aims to reduce the lag associated with standard MACD calculations by using Double Exponential Moving Averages (DEMA).


defparam drawonlastbaronly=true
x = close

//Calcul DEMA[12]
indic1 = ExponentialAverage[12](close)
indic2 = ExponentialAverage[12](indic1)
A = indic1[1]
B = indic2[1]
Lox = 264*A-143*B

//Calcul DEMA[26]
indic3 = ExponentialAverage[26](close)
indic4 = ExponentialAverage[26](indic3)
C = indic3[1]
D = indic4[1]
Fast = 1300*C-675*D

//Calcul MACD ZERO LAG bougie courante
e = x*(17416/123201)+264/169*A-11/13*B-1300/729*C+25/27*D

//Calcul DEMA[9](e)
indic5 = ExponentialAverage[9](e)
indic6 = ExponentialAverage[9](indic5)
I = indic5[1]
J = indic6[1]
Sign = 144*I-80*J

//Calcul MACD ZEROLAG bougie[1]
z11 = DEMA[12](close)
z22 = DEMA[26](close)
f = z11[1] – z22[1]

//Calcul de y pour que MACD ZR – MACDZR[1] = 0 soit e – f =0
y = (f*123201+169*Fast-729*Lox)/17416

//Calcul de z pour que MACD ZR – Signal soit e = z3
z = (9*Lox/4225-36*Fast/72900+Sign/100-264/169*A+11/13*B+1300/729*C-25/27*D)/(17416/123201-435400/8555625)

//Renvoie la valeur de y pour e = flag
DRAWTEXT(” ———- #z# MACD ZeroLag Reverse”,barindex,y,dialog,standard,13) coloured(204,0,0)
DRAWTEXT(” ———- #z# MACD Signal Reverse”,barindex,z,dialog,standard,13) coloured(51,204,0)
return

The code snippet above is structured into several key sections:

  • Initialization: Sets the drawing parameter to only the last bar for clarity.
  • DEMA Calculations: Computes the Double Exponential Moving Averages for 12 and 26 periods, which are used to calculate the fast and slow lines of the MACD.
  • Zero-Lag MACD Calculation: Combines the current price with the previously calculated DEMAs to compute a zero-lag value of the MACD.
  • Signal Line Calculation: Uses a DEMA over the zero-lag MACD to compute the signal line.
  • Historical MACD Calculation: Calculates the MACD values for the previous bar to compare against the current zero-lag MACD.
  • Adjustment Calculations: Computes values ‘y’ and ‘z’ to adjust the MACD and its signal line towards zero-lag behavior.
  • Output: Displays the calculated values on the chart using the DRAWTEXT function, with specific colors for differentiation.

This example is useful for understanding advanced financial indicator calculations and their implementation in trading systems using ProBuilder.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/formulation-ema/page/3/#post-96554

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Shark Senior
Code artist, my biography is a blank page waiting to be scripted. Imagine a bio so awesome it hasn't been coded yet.
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...