Pine Script V5 getting syntax error when checking boolean value with 'If' statement - if-statement

Trying to detect 3 specific EMA crosses, assign them to boolean variable, plot them and set alerts when their conditions are true.
No problem detecting and plotting the 3 crosses when they occur but when I try to set alerts using 'If' statement to check boolean value = true, I get a syntax error at the if statement.
Error is :
Syntax error at input 'end of line without line continuation'
I've tried a thousand different ways to get rid of the syntax error. How am I so stumped on a simple syntax error? Lol I need a fresh set of eyes to look at this for me. Maybe its obvious?
Code:
Continuationema = ta.crossover(ema2_, ema8_)
plotshape(Continuationema, style=shape.triangleup, color=color.new(color.blue, 0), location=location.abovebar)
Bearema = ta.crossunder(ema1_, ema2_)
plotshape(Bearema, style=shape.triangledown, color=color.new(color.red, 0), location=location.abovebar)
Bullema = ta.crossover(ema2_, ema3_)
plotshape(Bullema, style=shape.triangleup, color=color.new(color.green, 0), location=location.belowbar)
// Set Alerts
If Continuationema
strategy.entry("Continuation",strategy.long,alert_message="Uptrend Detected")
alert("Uptrend Continuation Detected. EMA2 Crossing Over EMA8")
*** Syntax error at input 'end of line without line continuation'*** appears at the above 'If' statement

It is you IF statement wich is not well written, you should not use Capital ( If ) but :
if Continuationema == true

Related

Value at 'body' failed to satisfy constraint: Member must not be null

I'm trying to run a prediction using a sagemaker endpoint. The input format is comma separated features and | separated observations.
However when I try to iterate over the input data and invoke the end point on every iteration like this :
ENDPOINT_NAME = "my_endpoint"
runtime= boto3.client('runtime.sagemaker')
results = []
for r in request_body.split('|'):
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
ContentType='text/csv',
Body=r)
result = json.loads(response['Body'].read().decode())
results.append(result)
I get the following error:
ValidationError: an error occurred (ValidationError) when calling the InvokeEndpoint operation: 1 validation error detected: Value at 'body' failed to satisfy constraint: Member must not be null
As a sanity check I ran :
for r in request_body.split('|'):
print(r)
And I get the result I expect to get:
3.0,0.0,4795.0,0.0,1.0,24.0,30.0,25.0,3.0
3.0,2.0,3818.0,0.0,3.0,10.0,22.0,11.0,11.0
5.0,0.0,3565.0,0.0,1.0,79.0,89.0,80.0,-66.0
5.0,-1.0,3227.7,0.0,0.0,16.0,17.0,17.0,1.0
5.0,0.0,3375.0,0.0,2.0,21.0,45.0,22.0,6.0...etc
Which leads me to believe that the logic in extracting the separate observations is sound, but somehow when I execute the call I get this null value error.
The idea is to get ordered predictions so that I can later map them to an id that is not part of the training features and hence not in the dataset.
Thank you in advance.
I had the same issue. Check if you are also passing to the endpoint an empty "r".
request_body.split('|') will generate a list with each of the rows of the dataframe, but it will also include one empty: ''

oracle.jdbc.OracleDatabaseException: ORA-01722: invalid number

Getting the above error but the offending column is not a number. Somehow it is related to the cycle_code column which is a string. My query is hacky since I dont have full control over building it so I have to append another condition at the end ( "!= 'ABC'"). If I remove that condition the query works. I dont understand why im getting an invalid number error though?
select * from my_view WHERE ... CYCLE_CODE IN ( 'XYZ' ) AND CYCLE_CODE != 'ABC';

Mutliple IF statements results in False instead of Blank ("")

Multiple IF statements are giving me a FALSE response instead of the requested BLANK.
I figured that the last of the IF statements that has a "" would give BLANK if none of the conditions are met.
I've tried isolating each IF to see if I'm missing a statement but I don't see it.
Here is my formula:
=IF((LEFT(D5,2))=H2,IF(C5="Yearly",G5,IF(C5="Fixed Monthly",G5/12,"")))
How can I modify this formula so that it does not give me a FALSE and instead gives me a BLANK as requested on the 3rd IF statement.
Thank you.
You may an else condition to the first if statement:
Here is my formula:
=IF(LEFT(D5,2)=H2, IF(C5="Yearly",
G5,
IF(C5="Fixed Monthly",G5/12,"")),
"") <-- add this
My guesd is that because you did not specify an explicit else condition, Excel is defaulting to showing FALSE.

IF Formula returning error or not doing a section of the formula

I have a formula in my report to select a field based on requirements:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" and {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT})
else '0'
When I run the report it works ok until I try to load a specific page. When I try to load the page I get an error of 'The string is non numeric'. The formula is called in another formula:
{COR_TBL.COR_EXPECTED_DATE} + 2 + ToNumber({#FRM_NOTES})
I have ran the query on the server of:
SELECT * FROM EXT_TBL WHERE EXT_KEY_TYPE = "SO" AND EXT_ACTION_FLAG_9 = "Y";
This returned me two rows of data. I have narrowed it down to a specific entry that is causing the issue, but in the database the row has N in the field action flag 9 instead of Y so it shouldn't be throwing me the error in my report.
The action field 9 is flagged on only two records both of which contain a 7 in the EXT_TEXT feild so I have no idea why I am getting the error.
I also tried a nested if statement of:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" then (if {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT}))
else '0'
But it still gave me the same error.
Thanks
I was able to fix the issue by removing the nested if statement and just putting all the conditions in the original statement:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) AND {EXT_TBL.EXT_KEY_TYPE} = "SO"
AND {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
THEN {EXT_TBL.EXT_TXT} ELSE '0'
This seems to have fixed the issue.

What is the "select when" syntax for?

Experimenting with the language I've found that select is defined in the global scope and its precedence is higher than local variables.
def example(select)
puts select
end
example 3
# Syntax error in eval:3: unexpected token: end (expecting when, else or end)
So experimenting with select step by step I get this:
select 1 end
# Syntax error in eval:3: unexpected token: end (expecting when, else or end)
and then
select when 1 end
# Syntax error in eval:1: invalid select when expression: must be an assignment or call
then
select when x = 1 end
# Syntax error in eval:1: invalid select when expression: must be an assignment or call
then
select when x
# Syntax error in eval:1: unexpected token: EOF (expecting ',', ';' or '
I'll skip ahead a few steps as you should have an idea of how I've come to my question…
select when x;
else y
end
# Error in line 1: undefined local variable or method 'x_select_action'
and lastly
x_select_action = 4
select when x;
else y
end
# Error in line 3: undefined method 'x_select_action' (If you declared 'x_select_action' in a suffix if, declare it in a regular if for this to work. If the variable was declared in a macro it's not visible outside it)
So there is this keyword in the language which precedes local variables precedence and I don't know what it's for. But apparently it looks for x_select_action when x is given as a when clause. What is this select for and how is it meant to be used?
Searching online I see select defined on Enumerable, Hash, Channel, and Array… but at first glance these don't seem to be it.
Thanks for the help!
It's similar to Go's select: https://tour.golang.org/concurrency/5
But it still needs some tweaks to be finished, that's why there are no docs about it yet.