price movement of 2 candles in raport with ATR - if-statement

I get this error on my code
Mismatched input 'alert' expecting 'end of line without line continuation'.
I want to make an alert when the price from 2 candles moves more than 1 ATR
my_atr = at(14)
if (close - open[1] > my_atr )
alert("bull case", alert.freq_once_per_bar_close)
else
alert("bear case", alert.freq_once_per_bar_close)

In pine there are very strict requirements for indentation four spaces or tabulation
if (close - open[1] > my_atr )
alert("bull case", alert.freq_once_per_bar_close)
else
alert("bear case", alert.freq_once_per_bar_close)

Related

Attempted READ of key larger than file maximum key size

I'm running a program to help document what is contained in our 30+year old database. During the course of this process, I am getting the following error message:
Attempted READ of record ID larger than file/table maximum record ID size of 255 characters.
My program is working like this:
LOOP WHILE I <= NUM.FILES
RECORD = ""
FILENAME = FILE.LIST<I>
ERROR = ""
DEBUG.RECORD = ""
HAVE.LOOKED = 0
OPEN 'DICT ':FILENAME TO D.FILE THEN
OPEN FILENAME TO T.FILE THEN
STATEMENT = "SSELECT ONLY DICT ":FILENAME:' BY FIELD.NO WITH FIELD.NO >= 0 AND WITH FIELD.NO <= 900 AND WITH FIELD # ".]"'
DEBUG = ""
PRINT FILENAME
EXECUTE STATEMENT RETURNING DEBUG
LOOP WHILE READNEXT FIELDNAME DO
READ FIELD.RECORD FROM D.FILE, FIELDNAME THEN
IF LEN(FIELDNAME) > BIGGEST.KEY.LEN THEN
BIGGEST.KEY = FIELDNAME
BIGGEST.KEY.LEN = LEN(FIELDNAME)
BIGGEST.KEY.FILE = "DICT ": FILENAME
PRINT FILENAME:" ":LEN(FIELDNAME):" ":FIELDNAME
END
USE.COUNT = ""
USE.LIST = ""
USE.COUNT.STATEMENT = "SELECT ":FILENAME:" WITH ":FIELDNAME:' # ""'
DEBUGS = ""
EXECUTE USE.COUNT.STATEMENT RTNLIST USE.LIST RETURNING DEBUGS
ROW = ""
ROW<1,1> = FIELD.RECORD<2> ; *Attribute Number
ROW<1,2> = FIELDNAME ; *Field Name
ROW<1,3> = FIELD.RECORD<1> ; *Field Type
ROW<1,4> = FIELD.RECORD<10> ; *Field Size
ROW<1,5> = FIELD.RECORD<12> ; *Is Multivalued: "" = no, "Y" = Multivalued, "###" = specific multivalue
ROW<1,6> = FIELD.RECORD<13> ; *Is Subvalued: "" = no, "Y" = Subvalued, "###" = specific subvalue
ROW<1,7> = FIELD.RECORD<7> ; *Automatic data output conversion
ROW<1,8> = FIELD.RECORD<8> ; *Correlative field definition
ROW<1,9> = FIELD.RECORD<11> ; *Field description
ROW<1,10> = #SELECTED ; *Number of records that don't have this field blank
RECORD<-1> = ROW
IF ROW<1,10> < 1 THEN
READ UNUSED.FIELDS FROM CHUCK.WORK, "FILE.DEBUG.UNUSED.FIELDS" ELSE
UNUSED.FIELDS = ""
END
UNUSED.FIELDS<-1> = FILENAME:VM:ROW
WRITE UNUSED.FIELDS ON CHUCK.WORK, "FILE.DEBUG.UNUSED.FIELDS"
END
IF FIELD.RECORD<2> = 0 AND #SELECTED > 0 AND HAVE.LOOKED = 0 THEN
LOOP WHILE READNEXT KEY FROM USE.LIST DO
IF LEN(KEY) > BIGGEST.KEY.LEN THEN
BIGGEST.KEY = KEY
BIGGEST.KEY.LEN = LEN(KEY)
BIGGEST.KEY.FILE = FILENAME
PRINT FILENAME:" ":LEN(KEY):" ":KEY
END
REPEAT
HAVE.LOOKED = 1
END
END
REPEAT
END ELSE
ERROR<-1> = "Failed to open file '":FILENAME:"'"
END
END ELSE
ERROR<-1> = "Failed to open file DICT '":FILENAME:"'"
END
WRITE RECORD ON CHUCK.WORK, "FILE.":FILENAME
WRITE DEBUG.RECORD ON CHUCK.WORK, "FILE.DEBUG.":FILENAME
READ CHUCK.LOG FROM CHUCK.WORK, "CHUCK.LOG" ELSE
CHUCK.LOG = ""
END
CHUCK.LOG<-1> = "FILE '":FILENAME:"' had ":DCOUNT(RECORD,AM):" fields"
IF ERROR THEN
CHUCK.LOG<-1> = ERROR
ERRORS<-1> = ERROR
END
WRITE CHUCK.LOG ON CHUCK.WORK,"CHUCK.LOG"
CLEARSELECT
I = I + 1
REPEAT
When I look at the database directly, I can't find any record IDs or keys with more than 35 characters in the file which is causing problems, and nothing longer than 70 characters in the entire database. Can anyone help identify why these records are getting flagged in this process but aren't discoverable directly?
Below is a program I wrote to specifically find the problematic records, but it can't find the culprit
OPEN "CHUCK.WORK" TO CHUCK.WORK ELSE
PRINT "UNABLE TO OPEN CHUCK.WORK"
RETURN
END
READ FILENAME FROM CHUCK.WORK, "LISTME" ELSE
PRINT "UNABLE TO READ LISTME"
RETURN
END
NUM.FILES = DCOUNT(FILENAME,AM)
FOR I = 1 TO NUM.FILES
OPEN FILENAME<I> TO T.FILE ELSE
PRINT "UNABLE TO OPEN ":FILENAME<I>
RETURN
END
EXECUTE 'SELECT ':FILENAME<I>
LOOP WHILE READNEXT KEY DO
IF LEN(KEY) > 20 THEN
PRINT FILENAME<I>:" ":LEN(KEY):" ":KEY
END
REPEAT
NEXT I
UPDATE
One of my coworkers identified the source of the problem, even though we haven't identified how to fix the problem:
one of our files has a multivalued field which is a key used in a correlative. For some reason, Universe is trying to read the entire attribute instead of the individual multivalue as the key, which causes the long record IDs. Anyone able to see whether I am doing something wrong in my code or if there is some setting in the database that we need to look at?
When you see this error it has nothing to do with the size of keys in file, it is simply that the #ID you are trying to READ is longer than 255 chars. When I have seen it usually show me what line in the source code it happened on. If you put this right before you that line you should be able to track it down.
IF LEN(THIS.ID) GT 255 THEN
DEBUG
END
Edit. Apparently the error in this case is does not reference a line number. I was not sure if this was omitted for clarity or was some difference in the UniVerse flavor, but I now believe its absence is a hint that the error message is coming from the shell and not that the interpreter.
OPEN '','VOC' TO FILE.VOC ELSE STOP "CANNOT OPEN FILE VOC"
STMT = "SELECT VAL WITH ":STR("A",256):" EQ 0"
EXECUTE STMT RTNLIST USE.LIST RETURNING DEBUGS
CRT "**************************************"
READ TEST FROM FILE.VOC,STR("A",256) ELSE NULL
END
Which on my system outputs this.
>RUN TEST.SC TEST.LONG.ID
Attempted READ of record ID larger than file/table maximum
record ID size of 255 characters.
RetrieVe: syntax error. Unexpected sentence without filename. Token was "".
Scanned command was SELECT 'VAL' WITH 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' EQ '0'
**************************************
Program "TEST.LONG.ID": Line 5, Attempted READ of record ID larger than file/t
able maximum
record ID size of 255 characters.
>
The first looks like your error message and would point to one of the dynamic SELECT statements you are building. #ID is synonymous with with record key and to carry the analogy a little further, it appears that you are trying to unlock your bike with one of those comically large "Keys to the City".

How to move to a different cell of an excel sheet based on a match?

I have an excel sheet in which I want to move to the next cell of same column if a match is true and then I need to get the content of that row in an array.
I am able to move to a different cell one time based on some defined value in column 0 but the next time if a match happens, I want to move to (row,col) (1,1) from (0,1), initially I am at (0,0). So, based on a match I am able to move to (0,1) but not able to move at (1,1) from (0,1).
for (my $i=$row_min; $i <= $row_max; $i++)
{
my $cell = $worksheet->get_cell($i , $col_min);
next unless $cell;
print("$cell\n");
my $value =$cell->value();
print("$value\n");
my $s= $col_min + 1;
if( defined $cell)
{
$cell =$worksheet->get_cell($i , $s);
$value =$cell->value();
print("$cell\n");
print("$value\n");
if ($value =~ m/^PG$/i )
{
print("I am working\n");
$cell=$worksheet->get_cell($row_min + 1,$s);
next unless $cell=~ m/^WAC$/i;
print("$cell\n");
$value=$cell->$value();
print("$value\n");
}
}
else
{
print("\n");
}
}
$cell=$worksheet->get_cell($row_min + 1,$s);
Perhaps you want to look at $i here instead of $row_min? $row_min has the same value on every row.

Regex pattern in Word 2013

I have a word document which contains 6 series of numbers (plain text, not numbered style) as following:
1) blah blah blah
2) again blah blah blah
.
.
.
20) something
And this pattern has been repeated six times. How can I used Regex and serialise all numbers before parentheses so that they start with 1 and end up with 120?
You can use VBA - add this to the ThisDocument module:
Public Sub FixNumbers()
Dim p As Paragraph
Dim i As Long
Dim realCount As Long
realCount = 1
Set p = Application.ActiveDocument.Paragraphs.First
'Iterate through paragraphs with Paragraph.Next - using For Each doesn't work and I wouldn't trust indexing since we're making changes
Do While Not p Is Nothing
digitCount = 0
For i = 1 To Len(p.Range.Text)
'Keep track of how many characters are in the number
If IsNumeric(Mid(p.Range.Text, i, 1)) Then
digitCount = digitCount + 1
Else
'We check the first non-number character we find to see if it is the list delimiter ")" and we make sure that there were some digits before it
If Mid(p.Range.Text, i, 1) = ")" And digitCount > 0 Then
'If so, we get rid of the original number and put the correct one
p.Range.Text = realCount & Right(p.Range.Text, Len(p.Range.Text) - digitCount) 'It's important to note that a side effect of assigning the text is that p is set to p.Next
'realCount holds the current "real" line number - everytime we assign a line, we increment it
realCount = realCount + 1
Exit For
Else
'If not, we skip the line assuming it's not part of the list numbering
Set p = p.Next
Exit For
End If
End If
Next
Loop
End Sub
You can run it by clicking anywhere inside of the code and clicking the "play" button in the VBA IDE.

GAWK - Multiple BEGIN and END sections

I'm trying to process a bunch of files extracting data using gawk.
File area fixed width space formatted file
I'm trying to extract data from two different lines matched by two different regular expressions but return the data from both of these lines on the ONE print statement.
I can achieve this with the following in a.awk file and use gawk -f to run it. the first BEGIN section setup up input file format (FIELDWIDTHs) and the second BEGIN I am trying to use a loop per file to output based on extracted data. The first END complete the inner BEGIN and the second to match the outer BEGIN.
However I can only apply this to one file at a time because if I apply to a bunch of files (as in gawk -f regex.awk km*.txt , I only get the last file's output.
Can I get a one line of output per file input without having to resort to a script file looping over the input files and running the awk script each time.
Thanks
BEGIN{
OFS=","; FIELDWIDTHS ="2 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12";
printf("Date, Turnover, SalesA, SalesB, SalesC, SalesD, Other Data\n");
}
BEGIN{ Sales = 0;
SalesA = 0;
SalesB = 0;
SalesC = 0;
SalesD = 0;
JointSales = 0;
Turnover = 0;
OtherData = 0;}
/^03/ || /^06/ {
if ($1 == "03") {
Sales = $15/100;
SalesA = $17/100;
SalesB = $26/100;
SalesC = $20/100;
SalesD = $22/100;
JointSales = SalesA - SalesB;
Turnover = JointSales + SalesB + SalesC + SalesD; }
else if ( $1 == "06") {
OtherData = substr($0,183,12)/100; }
# printf("%s, %10.2f, %10.2f, %10.2f, %10.2f, %10.2f, %10.2f\n", getDate(FILENAME), Sales, JointSales, SalesB, SalesC, SalesD, OtherData )
}
END{printf("%s, %10.2f, %10.2f, %10.2f, %10.2f, %10.2f, %10.2f\n", getDate(FILENAME), Sales, JointSales, SalesB, SalesC, SalesD, OtherData ) }
END {}
function getDate(str)
{ date = substr(str,3,6);
year = substr(date,1,2);
month= substr(date,3,2);
day=substr(date,5,2);
odate=(day"/"month"/"year);
return odate
}
If you are using gawk, you're in luck. In addition to BEGIN and END blocks, gawk implements BEGINFILE and ENDFILE blocks, which are executed just as you want: before and after processing each file. See the handy gawk programming guide.
Like all awk implementations, Gnu awk allows you to have multiple BEGIN and END blocks. All BEGIN blocks are run in order (first to last) before the first file is read, and all END blocks are run in the same first-to-last order after the last file is done. Since the same order is used for both types of special block, they don't "nest".
awk only allows one begin and end action set per run (though they can be spread across multiple blocks, they're all combined into one action set) and a run includes all files that you process.
If you want to do something between each file as well, the can use the ARGIND variable which holds the index of the current argument (zero-based). You just need to maintain the last argument index (initially zero) and, if the actual argument index is different, execute your special actions and update the last index.
With empty files (for which no code would be run), the current argument index may be more than one higher than the last so you may need to loop, incrementing the last index until it reaches the current one.
For example, let's print the lines of each file but with special markers for before, within and after. With the file a.in:
xyzzy
plugh
and a b.in file containing nothing, you can use the following script demo.awk:
function middleCheck() {
while (lastArgInd != ARGIND) {
print "MIDDLE after "lastArgInd":"ARGV[lastArgInd]
lastArgInd++
}
}
BEGIN { print "BEGIN"
lastArgInd = 1
}
{ middleCheck()
print " "$0
}
END { middleCheck()
print "END"
}
to effect an action between each file:
pax> vi demo.awk ; awk -f demo.awk b.in a.in a.in b.in a.in b.in b.in
BEGIN
MIDDLE after 1:b.in
xyzzy
plugh
MIDDLE after 2:a.in
xyzzy
plugh
MIDDLE after 3:a.in
MIDDLE after 4:b.in
xyzzy
plugh
MIDDLE after 5:a.in
MIDDLE after 6:b.in
END
You just have to make that action match what you need, your current "inner" end followed by your current "inner" begin.

How do I visual select a calculation backwards?

I would like to visual select backwards a calculation p.e.
200 + 3 This is my text -300 +2 + (9*3)
|-------------|*
This is text 0,25 + 2.000 + sqrt(15/1.5)
|-------------------------|*
The reason is that I will use it in insert mode.
After writing a calculation I want to select the calculation (using a map) and put the results of the calculation in the text.
What the regex must do is:
- select from the cursor (see * in above example) backwards to the start of the calculation
(including \/-+*:.,^).
- the calculation can start only with log/sqrt/abs/round/ceil/floor/sin/cos/tan or with a positive or negative number
- the calculation can also start at the beginning of the line but it never goes back to
a previous line
I tried in all ways but could not find the correct regex.
I noted that backward searching is different then forward searching.
Can someone help me?
Edit
Forgot to mention that it must include also the '=' if there is one and if the '=' is before the cursor or if there is only space between the cursor and '='.
It must not include other '=' signs.
200 + 3 = 203 -300 +2 + (9*3) =
|-------------------|<SPACES>*
200 + 3 = 203 -300 +2 + (9*3)
|-----------------|<SPACES>*
* = where the cursor is
A regex that comes close in pure vim is
\v\c\s*\zs(\s{-}(((sqrt|log|sin|cos|tan|exp)?\(.{-}\))|(-?[0-9,.]+(e-?[0-9]+)?)|([-+*/%^]+)))+(\s*\=?)?\s*
There are limitations: subexpressions (including function arguments) aren't parsed. You'd need to use a proper grammar parser to do that, and I don't recommend doing that in pure vim1
Operator Mapping
To enable using this a bit like text-objects, use something like this in your $MYVIMRC:
func! DetectExpr(flag)
let regex = '\v\c\s*\zs(\s{-}(((sqrt|log|sin|cos|tan|exp)?\(.{-}\))|(-?[0-9,.]+(e-?[0-9]+)?)|([-+*/%^]+)))+(\s*\=?)?\s*'
return searchpos(regex, a:flag . 'ncW', line('.'))
endf
func! PositionLessThanEqual(a, b)
"echo 'a: ' . string(a:a)
"echo 'b: ' . string(a:b)
if (a:a[0] == a:b[0])
return (a:a[1] <= a:b[1]) ? 1 : 0
else
return (a:a[0] <= a:b[0]) ? 1 : 0
endif
endf
func! SelectExpr(mustthrow)
let cpos = getpos(".")
let cpos = [cpos[1], cpos[2]] " use only [lnum,col] elements
let begin = DetectExpr('b')
if ( ((begin[0] == 0) && (begin[1] == 0))
\ || !PositionLessThanEqual(begin, cpos) )
if (a:mustthrow)
throw "Cursor not inside a valid expression"
else
"echoerr "not satisfied: " . string(begin) . " < " . string(cpos)
endif
return 0
endif
"echo "satisfied: " . string(begin) . " < " . string(cpos)
call setpos('.', [0, begin[0], begin[1], 0])
let end = DetectExpr('e')
if ( ((end[0] == 0) || (end[1] == 0))
\ || !PositionLessThanEqual(cpos, end) )
call setpos('.', [0, cpos[0], cpos[1], 0])
if (a:mustthrow)
throw "Cursor not inside a valid expression"
else
"echoerr "not satisfied: " . string(begin) . " < " . string(cpos) . " < " . string(end)
endif
return 0
endif
"echo "satisfied: " . string(begin) . " < " . string(cpos) . " < " . string(end)
norm! v
call setpos('.', [0, end[0], end[1], 0])
return 1
endf
silent! unmap X
silent! unmap <M-.>
xnoremap <silent>X :<C-u>call SelectExpr(0)<CR>
onoremap <silent>X :<C-u>call SelectExpr(0)<CR>
Now you can operator on the nearest expression around (or after) the cursor position:
vX - [v]isually select e[X]pression
dX - [d]elete current e[X]pression
yX - [y]ank current e[X]pression
"ayX - id. to register a
As a trick, use the following to arrive at the exact ascii art from the OP (using virtualedit for the purpose of the demo):
Insert mode mapping
In response to the chat:
" if you want trailing spaces/equal sign to be eaten:
imap <M-.> <C-o>:let #e=""<CR><C-o>"edX<C-r>=substitute(#e, '^\v(.{-})(\s*\=?)?\s*$', '\=string(eval(submatch(1)))', '')<CR>
" but I'm assuming you wanted them preserved:
imap <M-.> <C-o>:let #e=""<CR><C-o>"edX<C-r>=substitute(#e, '^\v(.{-})(\s*\=?\s*)?$', '\=string(eval(submatch(1))) . submatch(2)', '')<CR>
allows you to hit Alt-. during insert mode and the current expression gets replaced with it's evaluation. The cursor ends up at the end of the result in insert mode.
200 + 3 This is my text -300 +2 + (9*3)
This is text 0.25 + 2.000 + sqrt(15/1.5)
Tested by pressing Alt-. in insert 3 times:
203 This is my text -271
This is text 5.412278
For Fun: ascii art
vXoyoEsc`<jPvXr-r|e.
To easily test it yourself:
:let #q="vXoyo\x1b`<jPvXr-r|e.a*\x1b"
:set virtualedit=all
Now you can #q anywhere and it will ascii-decorate the nearest expression :)
200 + 3 = 203 -300 +2 + (9*3) =
|-------|*
|-------------------|*
200 + 3 = 203 -300 +2 + (9*3)
|-----------------|*
|-------|*
This is text 0,25 + 2.000 + sqrt(15/1.5)
|-------------------------|*
1 consider using Vim's python integration to do such parsing
This seems quite a complicated task after all to achieve with regex, so if you can avoid it in any way, try to do so.
I've created a regex that works for a few examples - give it a try and see if it does the trick:
^(?:[A-Za-z]|\s)+((?:[^A-Za-z]+)?(?:log|sqrt|abs|round|ceil|floor|sin|cos|tan)[^A-Za-z]+)(?:[A-Za-z]|\s)*$
The part that you are interested in should be in the first matching group.
Let me know if you need an explanation.
EDIT:
^ - match the beginning of a line
(?:[A-Za-z]|\s)+ - match everything that's a letter or a space once or more
match and capture the following 3:
((?:[^A-Za-z]+)? - match everything that's NOT a letter (i.e. in your case numbers or operators)
(?:log|sqrt|abs|round|ceil|floor|sin|cos|tan) - match one of your keywords
[^A-Za-z]+) - match everything that's NOT a letter (i.e. in your case numbers or operators)
(?:[A-Za-z]|\s)* - match everything that's a letter or a space zero or more times
$ - match the end of the line