plot the high low of 1 minute and 15 minutes bar during RTH 9:30 am ET (Pine script) - pine-script-v5

How do I plot horizontal lines using high and low of the first one minute bar after market opens at 9:30 (NYSE time)?
Possibly I would like to plot the open, high and close of 1st 1 minute bar.
Then when first 15 minutes is done, would like to plot the high and low of that bar as well.
I tried with OHLC indicator and others, but couldn't find something to tackle exactly this.
Also the below code that I got it from chatGPT, but it got couple of errors
type here
indicator("First Minute Bar High and Low", overlay=true)
var float firstBarHigh = na
var float firstBarLow = na
// Define the regular trading hours for the NYSE in Eastern Time
var tradingHoursStart = input("09:30-5", "Trading Hours")
var tradingHoursEnd = input("16:00-5", "Trading Hours")
var tradingHoursRange = time(tradingHoursStart + ":1234567-" + tradingHoursEnd + ":1234567")
// Define the desired time in Eastern Time
var timeInET = timenow("America/New_York")
if hour(timeInET) == 9 and minute(timeInET) == 30 and timeInET >= tradingHoursRange
if barstate.isfirst
firstBarHigh := high
firstBarLow := low
```plot(firstBarHigh, "First Minute High", color=color.green)
```plot(firstBarLow, "First Minute Low", color=color.red)

Related

Looking for current price > previous day high . Works fine but plotting for all the 5 minutes candle

Here is my usecase :
if currentprice of 5 minutes candle is greater than previous day high , plot the chart with the 'x' mark in green .
If currentprice of 5 minutes candle is lesser than previous day low , plot the chart with 'x' mark in green
This script prints the 'x' mark for every 5 minutes but I want to plot only first for the first time when condition is met
I used a counter to check if it is a new day but seems that is not working as expected
//#version=5
indicator("HLPrice", max_lines_count = 11, overlay=true)
emaValue8 = ta.ema(close,8)
emaValue21 = ta.ema(close,21)
vwapValue = ta.vwap(hlc3)
// to highlight the session
timeframe = "1D"
isNewDay = timeframe.change(timeframe)
bgcolor(isNewDay ? color.new(color.green, 80) : na)
[dh,dl,dc] = request.security(syminfo.ticker, "D", [high[1],low[1], close[1]], lookahead=barmerge.lookahead_on)
isNewDayy = time("D") != time("D")[1]
var plotcond = false
greaterThanPreviousDayHigh = false
lesserThanPreviousDayLow = false
if isNewDayy
plotcond := true
if close[0] > dh and plotcond
greaterThanPreviousDayHigh:=true
if close[0] < dl and plotcond
lesserThanPreviousDayLow:=true
plotshape(series=greaterThanPreviousDayHigh , title="Candle on All EMAs" ,color = color.green, size=size.tiny)
plotshape(series=lesserThanPreviousDayLow , title="Candle on All EMAs" ,color = color.red, size=size.tiny)

Candle high & low to appear on one timeframe only

I have the following code which marks out the high and low of a the 2H candle at the same time every day.
The problem I have is that if i switch to a lower timeframe, it adds the high and low to every candle and becomes very annoying.
Im not sure how to make the lines visible only on the 2H timeframe please.
// ENTRY LOCATION FOR EUROPEAN OPEN--------------------------------------------
string tfInput = input.timeframe("120", "Timeframe")
// Initialize variables on bar zero only
var hi = float(na)
var lo = float(na)
var line hiLine = na
var line loLine = na
// Detect changes in timeframe.
bool inSession = not na(time(timeframe.period, "2300-0100"))
if inSession
// New bar in higher timeframe; reset values and create new lines and box.
hi := high
lo := low
hiLine := line.new(bar_index - 2, hi, bar_index + 5, hi, color = color.blue, width = 2)
loLine := line.new(bar_index - 2, lo, bar_index + 5, lo, color = color.blue, width = 2)

Flutter hours and minute count issue

I need to sum the hours and minutes so I am doing this like ill convert hours in second and minutes in second then sum it
var totalServiceSeconds = minsSeconds + hoursSeconds;
var c = Duration(seconds: totalServiceSeconds);
print('c ${c.toString()}');
it's showing c 25:05:00.000000 which is correct
Know I need to show this as hours and minutes in the text widget. So I am converting to DateTime like this
var format = DateFormat("HH:mm");
DateTime totalServiceTime = format.parse(c.toString());
But it's printing it like this totalServiceTime 1970-01-02 01:05:00.000
This issue is only when the hours are 24 or more. If my hours are 24 then it's showing 0 and if greater than 24 then it's showing 1 2 so on. I know it because it's considering 24 as 0 but what can I do about this?
I want to show 24 if it's 24 hours or if greater than 24 like 26 need to show 26.
You do not want to convert it into a DateFormat because time steps of 24 hours is how they count a full day. Instead you should format var c as shown below
var totalServiceSeconds = minsSeconds + hoursSeconds;
var c = Duration(seconds: totalServiceSeconds);
print('c ${c.toString()}');
String FormatDuration = "${c.inHours}:${c.inMinutes.remainder(60)}:${(c.inSeconds.remainder(60))}";
print(FormatDuration);
String FormatDuration2 = "${c.inHours} hours ${c.inMinutes.remainder(60)} minutes ${(c.inSeconds.remainder(60))} seconds";
print(FormatDuration2);
The output will then be
c 25:05:00.000000 <-------previous
25:5:0 <-------new option 1
25 hours 5 minutes 0 seconds <-------new option 2

Tableau - How to calculate date/time difference and result in full date/time?

I'm trying to calculate a difference between connection time and disconnected time. See image below. But DATEPART formula that I'm using only allows me to use one parameter (hour, minute, second,...)
However, as in the image, I have an ID where disconnection at 3/1/17 2:35:22PM and connection back at 3/2/17 1:59:38 PM
Ideal Response: 23 hours, 24 minutes and 16 seconds
but using the formula:
ZN(LOOKUP(ATTR(DATEPART('minute', [Disconnected At])),-1)-(ATTR(DATEPART('minute', [Connected At]))))
it isn't doing the trick.
Could someone help me to achieve my ideal response? Or similar result that would give me the completeness of date and time?
Thank You
Tableau ScreenShot
Use DATEDIFF by seconds between your two dates. Then create a calc field as follows:
//replace [Seconds] with whatever field has the number of seconds in it
//and use a custom number format of 00:00:00:00 (drop the first 0 to get rid of leading 0's for days)
IIF([Seconds] % 60 == 60,0,[Seconds] % 60)// seconds
+ IIF(INT([Seconds]/60) %60 == 60, 0, INT([Seconds]/60) %60) * 100 //minutes
+ IIF(INT([Seconds]/3600) % 24 == 0, 0, INT([Seconds]/3600) % 24) * 10000 //hours
+ INT([Seconds]/86400) * 1000000 // days
for more information, check out this blog post where I got this from. http://drawingwithnumbers.artisart.org/formatting-time-durations/

VBSCRIPT - Have Current Time and a Duration and want to calculate start time based on these values

Example:
Time = 09:41:46
Duration = 0:00:17 (IE 17 seconds)
Start Time = Time - Duration
Clearly I can't just break this up into hours minutes and seconds and do a basic minus operation given the 60 minute hour and 60 second minute etc.
Can't seem to get my head around how to calculate this and hoping someone has come across this before :).
You can use the DateAdd function.
For example, this will subtract 17 seconds from the specified date/time.
DateAdd("s", -17, "1/1/2013 09:41:46")
Try this
Time = 09:41:46
Duration = 0:00:17
Start_Time = FormatDateTime(Time - Duration, 3)
wscript.echo hour(Start_Time)
wscript.echo minute(Start_Time)
wscript.echo second(Start_Time)
References:
https://www.w3schools.com/asp/asp_ref_vbscript_functions.asp#date