Click here to Login








Moving Average: Rule-based

by The trader, 5432 days ago
Share |






Probably the most popular trading indicator is the moving average. It is widely used in technical analysis and several other indicators use it in their calculation. For each bar, the moving average indicator calculates the average price of a time-series over the preceding N-bars.
The function name is 'rbsma', which stands for 'rule-based simple moving average'. This type of moving average does not calculate an average value of the last N-bars, but for N-bars that satisfy a specific rule.

Here is an example:
Let us say we want to calculate the average close price of for the last five Monday bars. We then should take the last five bars (bars that occurred on Monday) and calculate the average. Then repeat the process for all the available trading bars.

To do this with the 'rbsma' function, you will need to type:
rbsma(close, DayOfWeek() == 1, 5, 25);
The first parameter is the close price series.
The second parameter is the filter rule. It instructs the application to take into consideration only bars whose 'DayOfWeek' value is equal to one, which is Monday.
The third parameter is the number of occurrences to use in the moving average calculation.
The last parameter value defines the maximum number of bars to look for. A low value could result in the 'rbsma' function not finding the five occurrences where the filter rule passed. This could result in the calculation of a moving average with less than five values.
This doesn't mean that that you should put a very high value in this parameter to avoid this kind of problem. A high value generally needs more computation time and more time to calculate the function.

Here are some other examples:
rbsma(close, rsi(14) > 50, 20, 50);
This moving average rule returns the average close price for bars where the security price relative strength index indicator is above 50.

rbsma(volume, close > ref(close, 1), 20, 50);
This moving average rule returns the average volume for bars where the stock or security price closed higher than yesterday's value.

rbsma(volume, close > ref(close, 1), 20, 50) > rbsma(volume, close < ref(close, 1), 20, 50)
This is a moving average rule that returns one on bars where the average volume for the last 20 occurrences where the security price closed higher is greater than the average volume for the last 20 occurrences where the security price closed lower.

To use the 'rbsma' function as a classic moving average, you just need to set the rule formula to '1'.
rbsma(close, 1, 14, 14) is equal to sma(close, 14)

This function can also be modified to return another rule-based indicator; that is, an indicator that uses bars that pass a specific rule.


Share This ->
Share |


You have to log in to bookmark this object
What is this?
Additional Information




Type: Trading Indicator

Object ID: 324


Country:
All

Market: All

Style:
Technical Analysis

Reviews
You must log in first

Join now
and get instant access for free to the trading software, the Sharing server and the Social network website.
Click here


Related objects

Empty

Number of reviews
Click to add a review
Average rate
Click to rate this item
Number of times this object was downloaded
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object

Technical Analysis


Fundamental Analysis



Random Blog Posts

Stock split & dividend

Survivorship bias

Transaction Costs

How scripts communicate with each other

How to simulate options strategies

Organizing Trading Objects

Creating a download item: Initial Jobless Claims

How to search for a download item

Show All

Number of reviews
Click to add a review
Average rate
Click to rate this item
Number of times this object was downloaded
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object






QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.