In ThinkScript, how would I code a lookback period for engulfed bars that would be BarNumber() - the bar number from where the lookback begins? - thinkscript

How would I do a lookback period for engulfed bars that would be the most recent bar number <BarNumber()> minus the bar number from where the lookback begins in order to look back for a period of UP TO all the bars loaded into the chart? I'm not sure of how to call a bar number from a historical bar. Would it be GetValue(bn, )?
So far I have not tried anything that worked.

Related

Extracting currency value in Google Sheets with regex

I am trying to extract the tip value from columns in Google Sheets. What would be the proper regex argument to use to do this? Some columns do not have the tip value, and in this case i would like it to return "0".
Tip - 20% x $134.00Damage Waiver: 5% x $40.20Coupon: Thanks for considering us!! x -$10.00Tax: 7.25% of $700.20 x $50.76
If the input string (let's say at A1) has the word "Tip", and the first dollar symbol after that initiates the amount of interest, then do:
=IFNA(VALUE(REGEXEXTRACT(A1, "\bTip\b[^$]*\$([\d.]+)")), 0)
This expression will produce a number type, so the dollar is not included.
Apply the desired number formatting to the cell where you place this formula to show a currency symbol, and the required number of decimals.

Extract £ or % value from Google Sheets with REGEXTRACT

I have a Google Sheets formula that extracts a £ currency value or a percentage discount from a block of text.
=REGEXEXTRACT(B2,"[\d,.£%]+") - Extracts £ value or % discount (but other numbers too)
=REGEXEXTRACT(B2,"[\d,.]+") - Extracts digits, commas, or periods
However, if the text contains any others numbers before the £ value or % discount they get extracted first.
How can I only extract the £ value or % discount from each cell in Google Sheets?
The maximum discount displayed is 2 decimal places maximum, which may help in building a formula to extract 4 digits left or right of the value.
EXAMPLE DATA
Amy Wills 44% Discount
1Direction Food 45.37% Discount
AllUnder20 £120 Commission
AATU 13.31% Discount
Tickets4You £70 Commission
AllAboutU £7 Commission
Andrea Cardini 4% Discount
You can use
=JOIN("", REGEXEXTRACT(B2, "£(\d+(?:[.,]\d+)?)|(\d+(?:[.,]\d+)?)%"))
Details:
£(\d+(?:[.,]\d+)?) - matches a £ and then matches and captures into Group 1 one or more digits followed with one or zero occurrences of ./, and then one or more digits
| - or
(\d+(?:[.,]\d+)?)% - matches and captures into Group 2 one or more digits followed with one or zero occurrences of ./, and then one or more digits, and then a % is matched.
See the demo screenshot:
See the RE2 regex demo.
Based on your samples, this should work.
=SUMPRODUCT(N(SPLIT(B2," ")))
You can see it at work here in cell C2.

Regex - lazy match first pattern occurrence, but no subsequent matching patterns

I need to return the first percentage, and only the first percentage, from each row in a file.
Each row may have one or two, but not more than two, percentages.
There may or may not be other numbers in the line, such as a dollar amount.
The percentage may appear anywhere in the line.
Ex:
Profits in California were down 10.00% to $100.00, a decrease from 22.6% the prior year.
Profits in New York increased by 0.9%.
Profits in Texas were up 1.58% an increase from last year's 0.58%.
I can write a regex to capture all occurrences:
[0-9]+\.[0-9]+[%]+?
https://regex101.com/r/owZaGE/1
The other SO questions I've perused only address this issue when the pattern is at the front of the line or always preceded by a particular set of characters
What am I missing?
/^.*?((?:\d+\.)?\d+%)/gm
works with a multiline flag, no negative lookbehind (some engines don't support non-fixed width lookbehinds). Your match will be in the capture group.
Mine is similar to you except I allowed numbers like 30% (without decimal points)
\d+(\.\d+)?%
I don't know what language you are using, but in python for getting the first occurrence you can use re.search()
Here is an example:
import re
pattern = r'\d+(\.\d+)?%'
string = 'Profits in California were down 10.00% to $100.00, a decrease from 22.6% the prior year.'
print(re.search(pattern, string).group())
I was able to solve using a negative lookbehind:
(?<!%.*?)([0-9]+\.[0-9]+[%]+?)

Regular expression to match time slots

I am dealing with a patient day calendar with time slots.
Each hour is divided into two equal time slots.
If the person is available for the whole 1 hour it is is denoted as 11.
If not available for the whole hour : 00.
Available for first half only : 10 .
Available for second half only : 01 .
So the entire calendar of the patient has 48 digits
But for now, just to ease things, we will assume we are looking from 12AM to 6AM only.
So the calendar will be [01]{12}
Suppose the patient is available from 12AM to 3AM and 4AM to 6AM.
Now his calendar can be marked as
111111001111
Now the doctors' calendar is also stored in the similar way
Now suppose the appointment window is fixed as 1 hour, I need to find all the doctors having a 1 hour available timeslots within patient's available timeslot
The doctors' availability outside the patient's available time doesn't matter, ie in this case 3AM to 4AM
Basically, I want to write a regex to match all those
I tried (^([01]{2})(?=(?:[01]{0,2}11))([01]{4})|^([01]{8})(?=(?:[01]{0,2}11))([01]{2})) but this is giving match for any doctor who dont have any free slot in patient's availablilty but any 1 hour free slot after 6AM also –
The following seems to validate all the schedules from 12AM to 6AM where doctor have at least an hour available in either the timeslot 12AM to 3Am or 4AM to 6AM:
^(?=(?:[01]{0,4}|[01]{8,10})11)[01]{12}$
See the online demo
^ - Start line anchor.
(?= - Open positive lookahead:
(?: - Open non-capture group to write out alternations:
[01]{0,4} - Assert position is followed by 0-4 times a zero or one.
| - Or:
[01]{8,10} - Assert position is followed by 8-10 times a zero or one.
) - Close non-capture group.
11 - Literally match "11" which represents an available hour.
) - Close positive lookahead.
[01]{12} - Match a zero or 1, exactly 12 times.
$ - End string anchor.

Use RegEx to match data in cell in order to pull out to new rows in Excel

I have a spreadsheet containing numerous cells of data, but each cell contains numerous lines without carriage return or line feed. I want to create new rows by matching each occurrence of a ten digit number and grabbing the number and all text up until the next occurrence.
For example, this is one cell's text.
8770304350 PRINTER 4610-2CR W/IRON GRAY COVERS (2921) $750.75 2881057001 PAYMENT DEVICE - VERIFONE MX915 - WALMART CONSIGNE 8770242020 DISPLAY 4820-5GB USB W/ I/O SUPPORT IRON GRAY $907.27 8770242216 KEYPAD-MSR 3 TRACK IRON GREY $213.85 2881037020 CONSIGNED- SCANNER DS6878-SR20117WR IMAGER 2D BLUE
I want to split it into new rows each time there is a ten digit number so it would end up looking like this where each line is a new row.
8770304350 PRINTER 4610-2CR W/IRON GRAY COVERS (2921) $750.75
2881057001 PAYMENT DEVICE - VERIFONE MX915 - WALMART CONSIGNE
8770242020 DISPLAY 4820-5GB USB W/ I/O SUPPORT IRON GRAY $907.27
8770242216 KEYPAD-MSR 3 TRACK IRON GREY $213.85
2881037020 CONSIGNED- SCANNER DS6878-SR20117WR IMAGER 2D BLUE
I tried using RegEx on my own, but i was either matching just the number or the entire string and it's very complicated to me.
For example, this tried the look ahead but ended up selecting all text except first number and last selection.
(?<=[0-9]{10}).*(?=[0-9]{10})
You may use
\b\d{10}.*?(?=\s*\b\d{10}|$)
See the regex demo. If there can be line breaks, replace .*? with [\s\S]*?.
Details
\b - leading word boundary
\d{10} - 10 digits
.*? - any 0+ chars other than line break chars as few as possible
(?=\s*\b\d{10}|$) - a positive lookahead that, immediately to the right of the current location, requires
\s*\b\d{10} - 0+ whitespaces, word boundary and 10 digits
| - or
$ - end of string.