Jump To Forum
Category : OmniTrader Professional Forum
- What's New
- OmniTrader Pro General Discussion
- OmniLanguage Discussion
- Omni Pilot Discussion
- Trade Plans In Strategies
- Feature Requests
- Integrated Brokerage
Category : OmniTrader Pro Resource Forum
- OmniTrader Pro Technical Support
- OmniTrader Pro Frequently Asked Questions
- OmniLanguage Frequently Asked Questions
- OmniPilot Frequently Asked Questions
- Tutorials & Additional Resources
- Technical Analysis Library
You are currently browsing as a guest.
to access more features
A Self-Moderated Community
ALL MEMBERS, PLEASE READ!
Vote for Members who contribute the most to your trading, and help us moderate content within the Forums.
Only forum moderators may post in this forum.
You are editing a message originally written by mgreenslet on 10/9/2007
<b>Q: How can I displace an indicator either forward or backwards? A:</b> To fully understand this you must know that fundamentally all that makes an indicator is an array of numbers, that is to say a series of numbers whos count is equal to that of the number of bars of data. In other words, for every bar of pricing data an indicator stores a number the corresponds to that bar. Displacing an indicator does not change any of the values, it just shifts the indicator horizontally left or right. Displacing an indicator to the right (or forward) is easy. All you need to do is to tell your new indicator "for every bar of data look back at yesterdays value of my desired indicator and use that value for today instead". You should already be familiar with the concept of referencing historical values. If you are not please see the following FAQ. http://www.omnitrader.com/omnitrader/proforum/thread-view.asp?threadid=1288&posts=1 With all arrays we have a starting point and an end point. If we try to request a value past either end it will result in an error since there is no value. So we must protect ourselves and ensure we never try to read past the bounds (that is either the start or end point) of the array. With historical look backs OmniLanguage will do this for you. For example if there are only 50 values in the array but you try to request the value 60 bars back of the same array, secretly we compensate for you and return the first value in the array to prevent compile errors. This will be a more critical topic when we talk about backwards displacement since we do not compensate for you in that direction. Here is an example of of forward displaced 14 period EMA [QUOTE]#Indicator #PARAM "ForwardOffset", 0, 0, 100 Plot("Forward EMA", EMA(Periods)[ForwardOffset]) Return EMA(Periods)[ForwardOffset][/QUOTE] Now here comes the tricky part; backwards displacment. We will use the same concept. We know that if we append  to our indicator it will look one bar back. So logically if we use[-1] it will look one bar forward. Using negative numbers in the look back to actually look forward is out of the scope of and intention of its use. As such a word of caution. Be very careful how you use it. Looking forward can introduce cheating into systems. Unless you posses physic powers you can only look into future and make decisions on historical data. So when it comes to prospecting the current market your historical performance results will be skewed. Here we need to ensure that we do not try to look past the last value of our indicator (or array) and stop trying to plot values once we reach the end. In order to do that we need two pieces of information. Were are we currently in the array, and how many total values are in our array. We can get our current location in the array at any time by calling the function 'Bar'. Bar will return a numerical number of our current location in the array, otherwise known as our current <i>index</i>. There is not technically a proper way to get the total number of values in our array. However that doesn't mean its not possible. We can use any of the price data arrays (such as C which returns the current close) since these are pre-populated and check its length property. It is also important to note that all arrays are 0 base indexed. That means when referencing a index, 0 is the first not 1. The length property just gives us a count, not the last index. So the last index we can check is C.Length - 1 or we can just check that we are always check values below C.Length and never equal to or greater. So now we have our required information and we can now check to see if we are at the end by checking to see if were we are in the array (bar) is less than (<) C.Length minus (-) our desired displacement offset. Here is an example. [QUOTE]#Indicator #PARAM "BackwardOffset", 0, 0, -100 If Bar < C.Length - BackwardOffset then Plot("Backward EMA", EMA(Periods)[BackwardOffset]) End If Return EMA(Periods)[BackwardOffset][/QUOTE] <b>*Note*</b> With the forward displacement you will notice a vertical line at the very beginning. If you will recall I mentioned that if you try to look past the beginning of an array we will compensate for you to prevent errors and return the first value in the array. This is why you will see that line. If you would like to hide that line you can check to ensure that you have a total number of bars that is greater than (>) your forward offset. [QUOTE]#Indicator #PARAM "ForwardOffset", 0, 0, 100 If Bar > ForwardOffset Then Plot("Forward EMA", EMA(Periods)[ForwardOffset]) End If Return EMA(Periods)[ForwardOffset][/QUOTE]
Registration req. : Off
HTML : On
Anon. posting : Off
IP visible : Off
Notify you whenever this thread is updated?
Include signature in this post?
For any problems or issues please contact our Webmaster at