Pine script Security function differ in return values when called with syminfo.tickerid and Security symbol directly - security

could someone help me with this clarification:
EMA9 calculated using security function, one with syminfo.tickerid and the other one with Security symbol differ in the value returned. Shouldn't they be same? Below is the snippet of code.. Any help is highly appreciated..
Thanks.
//EMA9 calculation function
get_Close_EMA9_Stats()=>(close - ta.ema(close,9)) *100 / close
//EMA9 function called using security function passing syminfo.tickerid and security symbol----
request.security(*syminfo.tickerid*, "W",get_Close_EMA9_Stats() , lookahead = barmerge.lookahead_on) //Case1
request.security(*"NSE:APOLLOHOSP"*, "W",get_Close_EMA9_Stats() , lookahead = barmerge.lookahead_on) //Case2
//VALUES from Case 1 and 2 DIFFER..SHOULDN'T THEY BE SAME WHEN THE SAME TICKER BEING USED BUT ONE HAVING SYMINFO.TICKERID AND THE OTHER SECURITY SYMBOL DIRECTLY IN THE SECURITY FUNCTION

When I try on my end, both request.security() calls yield the same result.
Maybe the symbol you have on your chart differs from NSE:APOLLOSHOP ?
You can check the value of syminfo.tickerid by adding this code at the end of your script.
if barstate.islastconfirmedhistory
var lbl = label.new(na, na, syminfo.tickerid, color=chart.bg_color, textcolor=chart.fg_color)
label.set_xy(lbl, bar_index, high)

Related

Does 'position()' have to be explicitly included in this Xpath?

This returns all the first 'nd's as expected
select="osm/way/nd[1]"
This returns all the lasts:
select="osm/way/nd[last()]"
This returns both:
select="osm/way/nd[position() = 1 or position() = last()]"
Is there a syntax to remove position() function?
Something like this, but works?
select="osm/way/nd[[1] or [last()]]"
There has been some debate about allowing a new syntax to select a range https://github.com/qt4cg/qtspecs/issues/50#issuecomment-799228627 e.g. osm/way/nd[#1,last()] might work in a future XPath 4 but currently it is all up in the air of a lot of debate and questionable whether a new operator is helpful instead of doing osm/way/nd[position() = (1, last())].

Using a nested IF statement to simulate battery but need to compute actual values not comments

Trying to come up with a nested IF statement that works within a specified limit (battery state of charge) taking the necessary inputs over time.
[Sample Data Sheet]
My attempt to formulate for the State of charge operation is given below
= IF(AND(D5+A6-B6>=0.2*$G$1, D5+A6-B6<=0.95*$G$1), D5+A6-B6,0)
= IF(AND(D5+A6-B6<0.2*$G$1), D6= 0.2*$G$1+(D5+A6-B6).
= IF(AND(D5+A6-B6>0.95*$G$1), D6= 0.95*$G$1.
=IF(D5+A6-B6<=0.2*$G$1), 0.2*$G$1+(D5+A6-B6), IF(AND(D5+A6-B6>=0.2*$G$1, D5+A6-B6<=0.95*$G$1), D5+A6-B6,0), IF(D5+A6-B6>=0.95*$G$1), 0.95*$G$1)))
=IF(D5+A6-B6>=0.95*$G$1), 0.95*$G$1, IF(AND(D5+A6-B6>=0.2*$G$1, D5+A6-B6<=0.95*$G$1), D5+A6-B6,0), IF(D5+A6-B6<=0.2*$G$1), 0.2*$G$1+D5+A6-B6)))
I keep getting errors that my formulae are incorrect, please help for both state of charge and spare generation equations.
Thanks
Below is the link to the sample sheet that I have created.
https://drive.google.com/file/d/1kmhkBybMg18Odrow5jElcEt8RcLXqCFH/view?usp=sharing
I'm Assuming the G1 value is 1 or more than 1. Also, I'm also assuming the formula is for E5 cell. Here is the proposed solution.
=IF((D5+A6-B6)<(0.2*$G$1),(0.2*$G$1)+(D5+A6-B6),IF((D5+A6-B6)>(0.95*$G$1), (0.95*$G$1), IF(AND((D5+A6-B6)>=(0.2*$G$1), (D5+A6-B6)<=(0.95*$G$1)), (D5+A6-B6),"not in range")))
Here is the same equation expanded ( to see the logic and sequence ) :
=IF((D5+A6-B6)<(0.2*$G$1) , (0.2*$G$1)+(D5+A6-B6),
IF((D5+A6-B6)>(0.95*$G$1) , (0.95*$G$1),
IF(AND( (D5+A6-B6)>=(0.2*$G$1),(D5+A6-B6)<=(0.95*$G$1)) , (D5+A6-B6),"not in range"
)
)
)
Please have a check.

Separate number with symbol in Excel

I am looking for a function in Microsoft Excel that can separate number with symbol. For the example :
I want to separate number in this code:
12345_ABCD
I am looking for a function that can enables me to get the number (in this case 12345) without another character (in this case _ABCD).
And the problem is the the total character of number can be vary. For the example, it can be 12345_ABCD or 234_ABC or 34567_AB.
Please kindly help my problem. Thanks for your concern
If your cells always have numbers in front and then an underscore you could use this:
=Left(A1;Find("_";A1)-1)
Here is the function to get the number alone (in your case)
Public Function segregatenumber(a As String)
segregatenumber = Left(a, InStr(a, "_") - 1)
End Function
then you may use it as function in Excel cells

passing Jan of selected year by default in prompt

I have 2 year-month prompts. If I don't select any year-month in 1st prompt, report should by default, run from January of the same year, selected in 2nd prompt. My prompts are value prompts and have string values. Please help me materialise the requirement. I have already tried # prompt macro, ?prompt?, case when etc. I am nto sure, If javascript would help.
I'm going to assume your underlying date fields are not stored as DATE value types since you're using strings. This may be easier split into 4 prompts: from month, from year, to month, to year.
The filter would then be an implied if:
(
(?FROM_YEAR? = '' or ?FROM_MONTH? = '') and
[database_from_month] = '01' and
[database_from_year] = ?TO_YEAR? and
[database_to_month] = ?TO_MONTH? and
[database_to_year] = ?TO_YEAR?
)
OR
(
(?FROM_YEAR? <> '' or ?FROM_MONTH? <> '') and
[database_from_month] = ?FROM_MONTH? and
[database_from_year] = ?FROM_YEAR? and
[database_to_month] = ?TO_MONTH? and
[database_to_year] = ?TO_YEAR?
)
The above style filter is superior for many reasons:
More likely to be sargeable
Easy to understand
Uses simple built-in Cognos functions; more likely to be cross-version compliant
No issues with cross-browser support you would get with Javascript
Code snippet would work in other Cognos studios (Business Insight, etc)
You've likely seen CASE statements in filters throws an error. The CASE statement is passed to SQL, not compiled into a SQL statement via Cognos. Hence it's not seen as proper syntax.

Calling a Scalar Function from SubSonic

I've got a SQL Server function that returns a scalar BIT value and takes one parameter. The following gives you an idea:
CREATE FUNCTION dbo.[fnTest] (#StringToTest VARCHAR(10))
RETURNS BIT
AS
BEGIN
DECLARE #b BIT
IF #StringToTest = 'A' SET #b = 0 ELSE SET #b = 1
RETURN (#b)
END
GO
Being very new (days!) to SubSonic - how would I call this using SubSonic?
(I'm using a web site with the basic "subsonic.abp" file with an asterisk in it).
Got it!
Here's how in VB:
Return New SubSonic.InlineQuery().ExecuteScalar(Of Boolean)("SELECT dbo.[fnTest](#StringToTest)", StringToTest)
Thanks all, hope this helps someone else,
Thomas

Resources