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.


This message cannot be deleted. It is the first message of the thread.
Administrators or moderators may choose to delete the entire thread


 
Jim Dean

Sage
2000100010010010010025
Posts: 3433

Joined: 3/13/2006
Location: L'ville, GA

User Profile
 
Subject : Linear Regression Channel - Example Code
Posted : 6/13/2009 12:55 PM
Post #12185

This indicator is not only a powerful tool for analysis, which fits into the same kind of thinking as N's Fulcrum Tool, but also provides a bucketful of coding-technique examples.

Amongst other things, it shows:
1. how to use PlotPriceTrendLine to show both line-segments and extensions
2. how to calculate a LinReg fit to a set of data (corrected code)
3. how to manually calculate Standard Deviation
4. how to limit calc-time to just the historical bars required
5. how to provide price-basis alternatives to the user
6. how to specify an input date, and how to find the bar it matches
7. how to use the DebugMsg statements to help with program development
8. how to use iif() and line-wrap ( _) features
9. how to assign an initial value in a Dim statement
10. how to name variables for easy reading and short code lines
11. how to use indentation to make code easier to read
12. how to use comments to explain what's going on

The line-colors are set up for use on a black background. If you normally use a light-colored background, you should manually change the colors in the code.

This code corrects an error in LinReg calc's that previously was distributed as a part of various line-drawing indicators (not the standard ones that Matthew has posted from the Nirvana library). The fix is noted in this code with a comment that contains "***fxd***". If you have other code that uses similar LinReg calc's, I strongly suggest that you double-check it against this implementation.

The code also illustrates how to get around a BUG that is currently in OLang - when PlotPrice or PlotPriceTrendLine are used in the indicator, OT automatically opens a new Indicator pane when the indicator is applied to the chart, even though all the plots should have been in the Price pane. By using at least one PlotPrice statement, it provides an object that can be "grabbed" in the extra pane and moved onto the Price pane. This makes the extra pane disappear, and if you save the Template, it will always look the way it's supposed to when you come back to it. When this OLang/OT bug is finally fixed, no change to the code is required - the Price line that is the basis for the LinReg calc will plot correctly in the first place.


Enjoy!



[Edited by Jim Dean on 3/28/2015 7:26 AM]

Attached file : aJDndLinRegChan.rtf (9KB - 1543 downloads)
Attached file : aJDndLinRegChan.png (18KB - 2936 downloads)

Deleting message 12185 : Linear Regression Channel - Example Code


Nirvana Systems
For any problems or issues please contact our Webmaster at webmaster@nirvsys.com.