Jim Dean![]() Sage ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3433 Joined: 3/13/2006 Location: L'ville, GA ![]() | 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] ![]() |