Calculating Highest and Lowest Exponential Moving Averages Since Last Trade

14 Jan 2019
0 comment
0 attachment

This code snippet demonstrates how to calculate the highest and lowest values of an Exponential Moving Average (EMA) since the last trade using the ProBuilder language. It ensures that there are enough bars to perform the calculation and that a trade has occurred.


if barindex >= 10 and tradeindex <> 0 then
    EMA=exponentialaverage[10](close)
    HH=highest[barindex-tradeindex](EMA)
    LL=lowest[barindex-tradeindex](EMA)
endif
graph HH as "HighestEMA"
graph LL as "LowestEMA"

Explanation of the Code:

  • Conditional Check: The code starts by checking if there are at least 10 bars (`barindex >= 10`) and if at least one trade has occurred (`tradeindex <> 0`). This is crucial to avoid errors in calculating the EMA when there isn’t enough data or no trades have been made.
  • Calculating EMA: If the conditions are met, the Exponential Moving Average (EMA) of the last 10 closing prices (`close`) is calculated using exponentialaverage[10](close).
  • Finding Highest and Lowest EMA: The highest (`HH`) and lowest (`LL`) values of the EMA since the last trade are then calculated. This is done by using the highest[barindex-tradeindex](EMA) and lowest[barindex-tradeindex](EMA) functions, which look back from the current bar to the bar of the last trade.
  • Graphing Results: Finally, the highest and lowest EMAs are graphed with labels “HighestEMA” and “LowestEMA” respectively, allowing for visual representation of these values over time.

This snippet is particularly useful for traders or analysts who want to track the volatility or stability of prices since the last trade by observing the extremes of a moving average indicator.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/finding-highest-and-lowest-ema/#post-132918

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.
Vonasi Master
V-oyaging ON A S-mall I-ncome
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...