Implementing a Momentum Oscillator Screener with Exponential Moving Averages in ProBuilder

20 Nov 2015
0 comment
0 attachment

This code snippet demonstrates how to create a momentum oscillator screener using exponential moving averages in ProBuilder. The screener identifies when the momentum oscillator crosses over zero, which can be a signal for potential trading opportunities.


Period = 14 //Number of Periods
ct = close //Today's close
S = 0
FOR i = 1 TO Period
    cp = close[i]
    r = (ct - cp) > 0 //R = Today's CLOSE - Previous Day's CLOSE, 1 = today > yesterday
    IF r = 0 THEN
        r = ((ct - cp) < 0) * -1 //R = Today's CLOSE - Previous Day's CLOSE, -1 = today < yesterday
    ENDIF
    s = s + r //Sum up all r's
NEXT
Ema5 = ExponentialAverage[5](s) //Histogram
Ema3 = ExponentialAverage[3](Ema5)//M-Oscillator
//Ema3b = ExponentialAverage[3](Ema3)//Signal Line
Result = Ema3 CROSSES OVER 0
SCREENER[Result](close AS "Price")

The code snippet above is structured to calculate a momentum oscillator based on the difference between today's close and the close of previous days, over a specified period. Here's a step-by-step breakdown:

  • Initialization: The period for the calculation is set to 14 days, and variables for today's close (ct) and the sum (s) are initialized.
  • Loop through the period: For each day in the period, the close price of the previous day (cp) is retrieved. The difference (r) is calculated and evaluated. If today's close is greater than the previous day's, r is 1; if less, r is -1.
  • Summing up differences: The differences are summed up to create a single value (s) representing the momentum over the period.
  • Calculating Exponential Moving Averages (EMAs): Two EMAs are calculated from the sum of differences: Ema5 is a 5-period EMA, and Ema3 is a 3-period EMA of Ema5, representing the main line of the momentum oscillator.
  • Detecting Crossover: The screener checks if Ema3 crosses over zero, which is a potential signal indicating a change in momentum.
  • Output: The screener outputs the close price when a crossover is detected.

This example illustrates how to implement a basic technical analysis tool in ProBuilder, useful for identifying momentum shifts in a dataset.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/m-oscillator-crossover/#post-93776

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
33
indicator
132
strategy
171

Recent Snippets

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) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Logo Logo
Loading...