Implementing a Stochastic MACD Oscillator in ProBuilder

04 May 2016
0 comment
0 attachment

This code snippet demonstrates how to create a Stochastic MACD Oscillator using the ProBuilder programming language. The Stochastic MACD is a technical indicator that combines the principles of stochastic oscillators and MACD (Moving Average Convergence Divergence) to provide insights into the momentum and trend strength of a financial instrument.


LookBack = 20
LL = lowest[LookBack](low)
HH = highest[LookBack](high)
StEMA12 = (Average[12,1](close) - LL) / (HH - LL)
StEMA26 = (Average[26,1](close) - LL) / (HH - LL)
StMACD = (StEMA12 - StEMA26) * 100
SigLine = Average[9,1](StMACD)
RETURN StEMA12 AS "Ema12", StEMA26 AS "Ema26", StMACD AS "Macd", SigLine AS "Signal", 0 AS "Zero"

Explanation of the Code:

  • LookBack = 20: Sets the lookback period to 20 bars for calculating the lowest and highest values in the specified range.
  • LL = lowest[LookBack](low): Calculates the lowest low of the past 20 bars.
  • HH = highest[LookBack](high): Calculates the highest high of the past 20 bars.
  • StEMA12 and StEMA26: These lines compute the 12-period and 26-period Exponential Moving Averages (EMAs) of the normalized close price. The normalization is done by subtracting the lowest low and dividing by the range (highest high – lowest low) over the lookback period.
  • StMACD = (StEMA12 – StEMA26) * 100: Calculates the Stochastic MACD line by subtracting the 26-period EMA from the 12-period EMA and scaling the result by 100.
  • SigLine = Average[9,1](StMACD): Computes the signal line, which is a 9-period EMA of the Stochastic MACD line.
  • RETURN: Outputs the values of StEMA12, StEMA26, StMACD, and SigLine. Additionally, it outputs a constant zero line for reference in charting applications.

This code is a practical example of how to implement custom technical indicators in ProBuilder, useful for analyzing financial markets.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/stochastic-macd-oscillator/#post-110443

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.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

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

Snippets Categories

global
35
indicator
134
strategy
171

Recent Snippets

How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
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 [...]
Logo Logo
Loading...