Jim Dean
 Sage
       Posts: 3433
Joined: 3/13/2006
Location: L'ville, GA
User Profile |
Once and a while I make a "head-slapper" discovery ... something that would have been *really* useful if I'd only known before that it was possible within OLang. This is about one of those discoveries.
For robust, well-written code, it's often desirable to be able to report information to the user in textual form ... and especially to report the reasons why a calculation can't be done with a particular set of inputs, and what to do about it. In the past, I've used a sort of laborious process of printing big gray X's on the chart, and reporting the problem/solution in the OLang Editor Debug Pane ... but that forces the user to open the editor and to find out what the problem is, and how to fix it.
VBA has a useful function that can simplify this, if it's applied properly (an important qualifier, btw) ... "MsgBox(Message, Buttons, Title)"
I created a demo routine, which has to "do something" so that I can use the MsgBox to report what's happening ... so I set up an algorithm that plots the stairstep HHV & LLV of Close, using a specified LookBack window (default=50 bars)... enhanced by simple check to report whenever that value jumps/drops beyond its prior high/low by some input percentage (default=2%). (This might actually be useful for some kinds of System logic ... but the main purpose of this is to illustrate the Syntax of MsgBox).
The example uses a lot of "string-building", including plain text, values from calculated variables, and simple formatting using line-feeds to space things out. The "&" (ampersand) operator is at the heart of this ... it concatenates two pieces into one string. There are many other string functions you can use ... I've posted about them before ... things like len() and left() and right() and mid().
Click here to see the full writeup about this, and to download the code (at no charge). I'm pretty pleased about this ... it's not often that I find something that can add a whole new dimension to the usefulness of OLang routines!
The snapshot below shows the output of the routine, both plotted and on the focus list ... but the main thing is the popup boxes that it creates. The final input param lets you decide if you want notification every time a new Extreme High or Low is hit ... or if you want to wait till the end of the processing and see two lists of all the hits.
Enjoy!

[Edited by Jim Dean on 3/27/2015 5:51 PM]
Attached file : aJDndMsgBox messages & chartsnap.png (140KB - 1168 downloads)
|
Jim Dean
 Sage
       Posts: 3433
Joined: 3/13/2006
Location: L'ville, GA
User Profile |
MsgBox is not about retrieving data from the environment ... it's for reporting information to the user about the process being calculated, such as errors, warnings, or information.
The error and warning capabilities have two main uses:
1. Error if it's impossible to do the task with the current inputs (usually related to #bars loaded) ... ideally, the message tells the user how many additional bars are needed, so it's easy to fix.
2. Warning if the task will work, but is either limited in usefulness, or combo of inputs goes outside "reasonable" bounds so the results have questionable value.
... I didn't show this in the demo - maybe I should add something ... these messages would usually be generated within the "bar=0" initialization section.
The information capabilities are effectively limitless. The demo shows two types:
1. "As you go" pauses the "loop" execution midway, to highlight cases of interest. I set up Y/N/cancel to control whether this continues or morphs to just a summary or dies completely ... but a more useful implementation might have used Yes to MARK the point (paint a hashmark on the screen), No to continue without marking, and Cancel to deactivate the As You Go checking.
2. "At the end" is set up to appear only when the processing hits the HRE bar (ie bar=numrec-1). It reports either a final state at the HRE, or statistical summary of the history, or both. Since you can format the message with as much detail as you want, MUCH info can be provided here ... it's sort of like a turbo combination of a FL column plus the VoteLine advisor. Normally it would just have an OK button ... but if you have a LOT of info potentially to present, then Y/N/Cancel or just Y/N could be used to continue through several "panels" of detail.
The important thing to remember as a programmer, in order not to annoy the user with many unwanted popups (esp when indic is applied to FL or used in a live Strat), is to ALWAYS provide an input to "toggle" the MsgBox popup feature off/on (or on in more than one state, such as Errors only or Errs + Warnings or Err+Warn+Info).
(Message has 3 revisions)
|