OmniTrader Professional Forum OmniTrader Professional Forum
forums calendars search
today this week
register logon control panel Forum Rules
You are currently browsing as a guest.
You should logon 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.

[Random Quote] -

  Current location        Thread information  
OmniTrader Pro Resource Forum
OmniLanguage Frequently Asked Questions
How Do I Displace Indicators?
Last Activity 12/2/2008 10:19 AM
0 replies, 2999 viewings

Jump to page : 1
Now viewing page 1 [25 messages per page]
back reply
Printer friendly version

^ Top
Matthew Greenslet

Posts: 2077

Joined: 2/27/2006

User Profile
Subject : How Do I Displace Indicators?
Posted : 10/9/2007 1:18 PM
Post #6862

Q: How can I displace an indicator either forward or backwards?


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.

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

#PARAM "ForwardOffset", 0, 0, 100

Plot("Forward EMA", EMA(Periods)[ForwardOffset])

Return EMA(Periods)[ForwardOffset]

Now here comes the tricky part; backwards displacment. We will use the same concept. We know that if we append [1] 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 index.

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.


#PARAM "BackwardOffset", 0, 0, -100

If Bar < C.Length - BackwardOffset then
Plot("Backward EMA", EMA(Periods)[BackwardOffset])
End If

Return EMA(Periods)[BackwardOffset]

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.

#PARAM "ForwardOffset", 0, 0, 100

If Bar > ForwardOffset Then
Plot("Forward EMA", EMA(Periods)[ForwardOffset])
End If
Return EMA(Periods)[ForwardOffset]

[Edited by Matthew Greenslet on 9/24/2008 3:37 PM]

Jump to page : 1
Now viewing page 1 [25 messages per page]
back reply

Legend    Action      Notification  
Forum Moderator
Registered User
Unregistered User
E-Mail this thread to a friend
Toggle e-mail notification

Nirvana Systems
For any problems or issues please contact our Webmaster at