Add to Chart operation failed, reason: line 37: mismatched character '\n' expecting '"'Converting Alpha trend to strategy - pine-script-v5

I am trying to convert Alpha trend indicator to a strategy and line 37 is giving me the error message on subject line . Any advice how to fix line 37 would be appreciated.
Line 37 '('buySignalk"and O1 > K2, title='Potential BUY Alarm', message='BUY SIGNAL!')
Line 38 '('sellSignalk" and O2 > K1, title='Potential SELL Alarm', message='SELL SIGNAL!')

Related

How to extract data set from a text file?

Am quite new in the Unix field and I am currently trying to extract data set from a text file. I tried with sed, grep, awk but it seems to only work with extracting lines, but I want to extract an entire dataset... Here is an example of file from which I'd like to extract the 2 data sets (figures after the lines "R.Time Intensity")
[Header]
Application Name LabSolutions
Version 5.87
Data File Name C:\LabSolutions\Data\Antoine\170921_AC_FluoSpectra\069_WT3a derivatized lignin LiCl 430_GPC_FOREVER_430_049.lcd
Output Date 2017-10-12
Output Time 12:07:32
[Configuration]
Instrument Name BOTAN127-Instrument1
Instrument # 1
Line # 1
# of Detectors 3
Detector ID Detector A Detector B PDA
Detector Name Detector A Detector B PDA
# of Channels 1 1 2
[LC Chromatogram(Detector A-Ch1)]
Interval(msec) 500
# of Points 9603
Start Time(min) 0,000
End Time(min) 80,017
Intensity Units mV
Intensity Multiplier 0,001
Ex. Wavelength(nm) 405
Em. Wavelength(nm) 430
R.Time (min) Intensity
0,00000 -709779
0,00833 -709779
0,01667 17
0,02500 3
0,03333 7
0,04167 19
0,05000 9
0,05833 5
0,06667 2
0,07500 24
0,08333 48
[LC Chromatogram(Detector B-Ch1)]
Interval(msec) 500
# of Points 9603
Start Time(min) 0,000
End Time(min) 80,017
Intensity Units mV
Intensity Multiplier 0,001
R.Time (min) Intensity
0,00000 149
0,00833 149
0,01667 -1
I would greatly appreciate any idea. Thanks in advance.
Antoine
awk '/^[^0-9]/&&d{d=0} /R.Time/{d=1}d' file
Brief explanation,
Set d as a flag to determine print line or not
/^[^0-9]/&&d{d=0}: if regex ^[^0-9] matched && d==1, disabled d
/R.Time/{d=1}: if string "R.Time" searched, enabled d
awk '/R.Time/,/LC/' file|grep -v -E "R.Time|LC"
grep part will remove the R.Time and LC lines that come as a part of the output from awk
I think it's a job for sed.
sed '/R.Time/!d;:A;N;/\n$/!bA' infile

Xtext 2.8+ formatter, formatting HiddenRegion with comment

I am using Xtext 2.9 formatter and I am trying to format hiddenRegion which contains comment. Here is part of my document region i am trying to format:
Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement
Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion
35 0 H
35 15 S ""xxx::a::b"" Refblock:namespace=Namespace
50 0 H
50 1 S "}" Refblock:RCBRACKET
E Refblock PackageHead:Block=Refblock path:PackageHead/Block=Package'xxx_constants'/head=Model/packages[0]
51 0 H
51 1 S ":" PackageHead:COLON
E PackageHead Package:head=PackageHead path:Package'xxx_constants'/head=Model/packages[0]
52 >>>H "\n " Whitespace:TerminalRule'WS'
"# asd" Comment:TerminalRule'SL_COMMENT'
15 "\n " Whitespace:TerminalRule'WS'<<<
B Error'ASSD' Package:expressions+=Expression path:Package'xxx_constants'/expressions[0]=Model/packages[0]
67 5 S "error" Error:'error'
72 1 H " " Whitespace:TerminalRule'WS'
and corresponding part of the grammar
Model:
{Model}
(packages+=Package)*;
Expression:
Error | Warning | Enum | Text;
Package:
{Package}
'package' name=Name head=PackageHead
(BEGIN
(imports+=Import)*
(expressions+=Expression)*
END)?;
Error:
{Error}
('error') name=ENAME parameter=Parameter COLON
(BEGIN
(expressions+=Estatement)+
END)?;
PackageHead:
Block=Refblock COLON;
Problem is that when i try prepend some characters before error keyword
for example
error.regionFor.keyword('error').prepend[setSpace("\n ")]
This indentation is prepended before the comment and not behind it. This results into improper formatting in case of single line comment before the 'error' keyword.
To provide more clarity, here is example code from my grammar and description of desired behavior:
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
This is expected result: (one space to the left)
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
and this is the actual result with prepend method
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
As the document structure says, the HiddenRegion is in this case is the statement:
# asd
error
How can i prepend my characters directly before the keyword 'error' and not before the comment? Thanks.
I assume you're creating an indentation-sensitive language, because you're explicitly calling BEGIN and END.
For indentation-sensitive language my answer is: You'll want to overwrite
org.eclipse.xtext.formatting2.internal.HiddenRegionReplacer.applyHiddenRegionFormatting(List<ITextReplacer>)
The methods append[] and prepend[] you're using are agnostic to comments and at a later time applyHiddenRegionFormatting() is called to decide how that formatting is weaved between comments.
To make Xtext use your own subclass of HiddenRegionReplacer, overwrite
org.eclipse.xtext.formatting2.AbstractFormatter2.createHiddenRegionReplacer(IHiddenRegion, IHiddenRegionFormatting)
For languages that do not do whitespace-sensitive lexing/parsing (that's the default) the answer is to not call setSpace() to create indentation or line-wraps.
Instead, do
pkg.interior[indent]
pkg.regionFor.keyword(":").append[newLine]
pkg.append[newLine]

Displaying human-readable text in perl Log::Report stack traces

A library that I'm using XML::Compile::Translate::Reader calls Log::Report's error method
or error __x"data for element or block starting with `{tag}' missing at {path}"
, tag => $label, path => $path, _class => 'misfit';
As I've got Log::Report set to debug mode, it returns a stack trace for an error.
[11 07 2014 22:17:39] [2804] error: data for element or block starting with `MSISDN' missing at {http://www.sigvalue.com/acc}TA
at /usr/local/share/perl5/XML/Compile/Translate/Reader.pm line 476
Log::Report::error("Log::Report::Message=HASH(0x2871cf8)") at /usr/local/share/perl5/XML/Compile/Translate/Reader.pm line 476
<snip>
XML::Compile::SOAP::Daemon::LWPutil::lwp_run_request("HTTP::Request=HASH(0x2882858)", "CODE(0x231ba38)", "HTTP::Daemon::ClientConn::SSL=GLOB(0x231b9c0)", undef) at /usr/local/share/perl5/XML/Compile/SOAP/Daemon/LWPutil.pm line 95
Any::Daemon::run("XML::Compile::SOAP::Daemon::AnyDaemon=HASH(0x7a3168)", "child_task", "CODE(0x2548128)", "max_childs", 36, "background", 1) at /usr/local/share/perl5/XML/Compile/SOAP/Daemon/AnyDaemon.pm line 75
XML::Compile::SOAP::Daemon::AnyDaemon::_run("XML::Compile::SOAP::Daemon::AnyDaemon=HASH(0x7a3168)", "HASH(0x18dda00)") at /usr/local/share/perl5/XML/Compile/SOAP/Daemon.pm line 99
(eval)("XML::Compile::SOAP::Daemon::AnyDaemon=HASH(0x7a3168)", "HASH(0x18dda00)") at /usr/local/share/perl5/XML/Compile/SOAP/Daemon.pm line 94
XML::Compile::SOAP::Daemon::run("XML::Compile::SOAP::Daemon::AnyDaemon=HASH(0x7a3168)", "name", "rizserver.pl", "background", 1, "max_childs", 36, "socket", [7 more]) at ./rizserver.pl line 95
There is lots of juicy data in those HASH, SCALAR, GLOB, and other elements that I want to get logged; as we are having trouble logging the original request in case it doesn't match.
I've explored using
Some leads that I don't know how to use are using Log::Dispatch, or some sort of Filter on Log::Report; but in the end, all I really want is to apply Data::Dumper to those elements.

Example of 'a subroutine may have several entry and exit points'

I'm reading the paper of Non structured programming, and found it says:
Unlike a procedure, a subroutine may have several entry and exit points, and a direct jump into or out of subroutine is (theoretically) allowed
I can't understand it, could anyone give me an code sample of:
a subroutine may have several entry and exit points
a direct jump into or out of subroutine
Thanks
10 A = 1
20 GOSUB 100
30 A = 2
40 GOSUB 110
50 A = 3
60 GOTO 130
70 END
100 PRINT A
110 PRINT "HELLO"
120 IF A = 1 THEN RETURN
130 PRINT "THERE"
140 IF A = 3 THEN GOTO 70
150 RETURN
The subroutine has three entry points (lines 100, 110, and 130) and three exit points (lines 120, 140, and 150). There is a direct jump into line 130 (from line 60) and a direct jump out (at line 140).

read .yml files in matlab

I would like to read .yml files in Matlab. These files contain coordinates x and y of key points on a face image. I looked for different tools but I don't seem to find any answers.
My .yml files look like this
YAML:1.0
Image file: "00032009.jpg"
Contours count: 8
Contours:
-
Name: FO
Count: 41
Closed: 0
Points:
-
x: 682.5947265625000000
y: 743.1998901367187500
-
x: 685.9638061523437500
y: 771.3800659179687500
......
and so on
Note 00032009.jpg is an image of a face
x and y are coordinates of a point on a face Eg: the right corner of an eye etc
Could you please point out a way to read the file and then display the points on the face image?
Edit 1: Here is the error I get
Error: File: ReadYamlRaw.m Line: 14 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
What is weird is line 14 in ReadYamlRaw.m
[pth,~,~]= fileparts(mfilename('fullpath'));
Parse error at ','(second one) and ']' usage appears to be invalid matlab syntax.
So what is the use of ~ in there and why is there an error?
Edit2: I replaced the ~ in the line above with dummy variables then I get this errors O_O
Error using ==> ReadYamlRaw>scan at 81
Unknown data type: logical
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>scan_list at 116
result{ii} = scan(i);
Error in ==> ReadYamlRaw>scan at 77
result = scan_list(r);
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
I also tried with a different yml file that looks like this
%YAML:1.0
RE-C:
x: 919
y: 580
LE-C:
x: 1209
y: 597
N-C:
x: 1063
y: 698
FO-B:
x: 1045
y: 1114
REL-O:
x: 852
y: 597
REL-I:
x: 986
y: 600
REL-T:
x: 918
y: 564
And I get the following errors
Java exception occurred:
while scanning a directive
in "<string>", line 1, column 1:
%YAML:1.0
^
expected alphabetic or numeric character, but found :(58)
in "<string>", line 1, column 6:
%YAML:1.0
^
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
at
org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
Maybe someone can make something out of these or you could point out another set of functions that would work? I searched but didn't find any except this one.
It's YAML file indeed (as #DavidBrown mentioned in his comment, the extension does not matter). But it has some problems. Don't know if it's due to wrong YAML format or MATLAB implementation.
I've installed YAMLMATLAB and played a little with your file.
YamlStruct = ReadYaml(yaml_file);
YAMLMATLAB returns error if the files is feed as is. It works only if I comment the first line and remove spaces from field names. So the beginning of the file looks like this:
#YAML:1.0
Imagefile: 00032009.jpg
Contourscount: 8
...skipped the rest...
Then I get the correct structure. For example you can access the 1st point's x coordinate as
YamlStruct.Contours{1}.Points{1}.x
ans =
682.5947
UPDATE
Space in filed names is actually a known problem in YAMLMATLAB. See the report and possible solution here.
UPDATE 2
According to comment from #Jirka_cigler (YAMLMATLAB developers group):
In the program release 0.4.3 we added support for whitespaces in field
names, so the problem should not appear again.
Great!
I've also removed previous developers comment on the problem in the first UPDATE since it's not true any more.
ZozaniDB Database Toolbox comes with a Matlab-native YAML implementation that handles the .yml file here. To parse a string or a file, use:
>> yaml_parse ( str )
>> yaml_read ( filename )