Hello--I was out of the house for much of today, so I haven't been
able to respond until now.

Thanks to all who responded with suggestions!  Unfortunately, none of
them worked as is, probably because you're used to a different way of
approaching the problem and also because I probably should have
indicated a fake example to show what I was looking for.  Here are the
final versions of the code to accomplish my goal--please don't gasp
over the fact that I could create such "horrendous" looking lines of J
code.  They work, and that's all I care about (the 2 files at the
beginning are file r1 and file r2 derived from file r).  I got the
ideas here and there from the code you submitted.  The following lines
of code successfully accomplished my goal:

  filer1=. 1 0 0 0 # filer  NB. dates
  filer2=. 0 1 1 1 # filer  NB. work with high/low/close data

  if. 1 = pricetype do.  NB. arithmetic scale
    price=. filer2
  elseif. 2 = pricetype do.  NB. square-root scale
    price=. < every 10&*%: ". > every filer2  NB. x10
  elseif. 3 = pricetype do.  NB. logarithmic scale
    price=. < every 100&*10&^. ". > every filer2  NB. x100
  end.  NB. if

Mike Day asked, "You’ve already had some helpful, constructive,
replies.  All I’ve got to add is to wonder why you’re working with
boxed data if your data are as regular as your example suggests."

I work with boxed data because that's the way J imports stock market data:

      Date        Open   High     Low      Close    Volume
┌──────────┬──────┬──────┬──────┬──────┬────────┐
│2020-03-06│126.70│128.33│124.52│127.73│8193300 │
├──────────┼──────┼──────┼──────┼──────┼────────┤
│2020-03-09│120.16│122.41│117.28│117.81│10757500│
├──────────┼──────┼──────┼──────┼──────┼────────┤
│2020-03-10│122.78│124.88│115.76│124.77│11410700│
├──────────┼──────┼──────┼──────┼──────┼────────┤
│2020-03-11│121.01│122.58│116.38│117.97│8446500 │
├──────────┼──────┼──────┼──────┼──────┼────────┤
│2020-03-12│109.65│109.80│102.28│102.81│12512700│
└──────────┴──────┴──────┴──────┴──────┴────────┘

There are 3 types of data: Date, OHLC (rationals w/decimal fractions),
V (integers only).  (I realize that integers are a subset of
rationals, but Volume can never have decimal fractions, so I
considered it a third type of data for my purposes.)  Sorry for the
appearance of the table (it's copy-and-paste data), but that's the
main problem with proportional fonts, which I have no control over.
(Or, more accurately, I'm not aware of any control over fonts that I
may have in Gmail.)  The above table is the starting point for my J
program, which spends the remainder of the code manipulating the data
in various ways.  (For the following, Open prices and Volume are
omitted.)  In case you're interested, the following 3 tables show the
results for arithmetic ("normal") scaling, square-root scaling (x10),
and logarithmic scaling (x100) for IBM stock in the middle of the
March 2020 "crash":

┌──────────┬──────────┬──────────┬──────────┬──────────┐
│2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│
├──────────┼──────────┼──────────┼──────────┼──────────┤
│128.33    │122.41    │124.88    │122.58    │109.80    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│124.52    │117.28    │115.76    │116.38    │102.28    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│127.73    │117.81    │124.77    │117.97    │102.81    │
└──────────┴──────────┴──────────┴──────────┴──────────┘

┌──────────┬──────────┬──────────┬──────────┬──────────┐
│2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│
├──────────┼──────────┼──────────┼──────────┼──────────┤
│113.28    │110.64    │111.75    │110.72    │104.79    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│111.59    │108.30    │107.59    │107.88    │101.13    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│113.02    │108.54    │111.70    │108.61    │101.40    │
└──────────┴──────────┴──────────┴──────────┴──────────┘

┌──────────┬──────────┬──────────┬──────────┬──────────┐
│2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│
├──────────┼──────────┼──────────┼──────────┼──────────┤
│210.83    │208.78    │209.65    │208.84    │204.06    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│209.52    │206.92    │206.36    │206.59    │200.98    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│210.63    │207.12    │209.61    │207.18    │201.20    │
└──────────┴──────────┴──────────┴──────────┴──────────┘

And here are the same scalings for the Dow-Jones Industrial Average
(which has far higher prices):

┌──────────┬──────────┬──────────┬──────────┬──────────┐
│2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│
├──────────┼──────────┼──────────┼──────────┼──────────┤
│25994.38  │24992.36  │25020.99  │24604.63  │22837.95  │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│25226.61  │23706.07  │23690.34  │23328.32  │21154.45  │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│25864.77  │23851.02  │25018.16  │23553.22  │21200.61  │
└──────────┴──────────┴──────────┴──────────┴──────────┘

┌──────────┬──────────┬──────────┬──────────┬──────────┐
│2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│
├──────────┼──────────┼──────────┼──────────┼──────────┤
│1612.28   │1580.90   │1581.80   │1568.59   │1511.22   │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│1588.29   │1539.68   │1539.17   │1527.36   │1454.46   │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│1608.25   │1544.38   │1581.71   │1534.71   │1456.04   │
└──────────┴──────────┴──────────┴──────────┴──────────┘

┌──────────┬──────────┬──────────┬──────────┬──────────┐
│2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│
├──────────┼──────────┼──────────┼──────────┼──────────┤
│441.49    │439.78    │439.83    │439.10    │435.87    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│440.19    │437.49    │437.46    │436.79    │432.54    │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│441.27    │437.75    │439.83    │437.21    │432.63    │
└──────────┴──────────┴──────────┴──────────┴──────────┘

The program is a "ZigZag" (or "Hi-Lo") program to determine where
price highs and lows occur in a set of market data, giving the user 5
different sets of options to instruct the program how to operate.  The
end result of the program is NOT a chart with lines joining the highs
and lows as would be typical with a zigzag program (I currently know
nothing about creating market charts in J).  Rather, the output of the
program is a list of dates, each followed by the letter "H" (for a
high on the date) or the letter "L" (for a low on the date) which can
then be combined together with other kinds of data to achieve various
purposes.

Again, a big THANK YOU to everyone who suggested various solutions to
my query!  I greatly appreciate you all!

Harvey
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to