How to calculate 5 minute rolling mean of ATR with Pine script (TradingView)? - mean

In TradingView Pine script, I want to calculate:
ATR taking high, low, close data with a timeperiod of 30 minutes
5 minute rolling mean of ATR
In Python, I do this:
# Calculate the Average True Range(ATR)
df_indicator['ATR'] = talib.ATR(df_indicator['high'], df_indicator['low'], df_indicator['close'], timeperiod=30)
# Calculate the rolling mean of ATR
df_indicator['ATR_MA_5'] = df_indicator['ATR'].rolling(5).mean()
How can I do this in TradingView Pine script?

Pine has a built-in function atr().
To get the value atr for the current symbol on the current timeframe with a length of 30, use atr(30).
To get the value atr for the current symbol on the timeframe 5 minute with a length of 30, use security(syminfo.ticker, "5", atr(30)).

Related

Pine Script V5 plotting daily timeframe open price on 5 min chart

I would like to plot the open price from daily timeframe on my 5 minute timeframe chart with the below codes. Turned out the open rice from previous day is plotted.
//#version=5
indicator("My script", overlay=true)
o = request.security(syminfo.ticker, "D", open)
plot(o)
You don't need security for that. You can simply use the time() to see if it is a new day and store the open price in a var variable. This way, your script will be more efficient.
var float daily_open = na
is_new_day = ta.change(time("D"))
daily_open := is_new_day ? open : daily_open // Update the price when it is a new day, keep its value otherwise
plot(daily_open)
If you really want to use the security(), you should add barmerge.lookahead_on.
o = request.security(syminfo.ticker, "D", open, lookahead=barmerge.lookahead_on)

How to calculate the difference in minutes between two bedtimes (NOT time elapsed)?

I'm trying to get Google Sheets functions to calculate the difference in minutes between two bedtimes and have been spinning my wheels for at least five hours on this. Here are four examples of what I'm trying to accomplish:
BEDTIME 1 BEDTIME 2 DIFF IN MINS
9:00 PM 9:15 PM 15
9:00 PM 10:00 PM 60
11:30 PM 1:00 AM 90
1:00 AM 11:00 PM 120
As you can see, the date doesn't figure at all. I apologize for not offering up code, but I've tried at least half a dozen approaches from other answers and they aren't working -- mainly, I suspect, because most people are looking to find the time elapsed between the two times whereas I'm looking to determine "how much earlier" or "how much later" one bedtime is relative to another (always expressed as a positive value).
Any help would be appreciated. Thanks.
Times are stored as numbers between 0 and 1. If you subtract two times and multiply the result by 24 x 60 = 1440 and format as a number you’ll get number of minutes. I think you’ll need something like:
=MIN(ABS(1440*(B1-A1)), ABS(1440*(B1-A1-1)), ABS(1440*(B1-A1+1)))
The difference between two times is a duration. The question requests that durations be converted to "digital minutes", but that is often not as readable as one would think. 175 minutes is more difficult to understand than 2:55 hours.
There is therefore usually no point in multiplying by 24 * 60 — instead, just use the duration value as is:
=min( abs(B2 - A2), abs(B2 - A2 - 1), abs(B2 - A2 + 1) )
Format the result cell as Format > Number > Duration.
See this answer for an explanation of how date and time values work in spreadsheets.
use arrayformula:
=INDEX(IFERROR(1/(1/TRANSPOSE(QUERY(TRANSPOSE(
IF(A2:A&B2:B="", 0, ABS(1440*(B2:B-A2:A+{-1, 0, 1})))),
"select "&TEXTJOIN(",", 1,
"min(Col"&ROW(A2:A)-ROW(A2)+1&")"))))),, 2)
or:
=INDEX(IFERROR(1/(1/QUERY(SPLIT(FLATTEN(
ROW(A2:A)&"×"&ABS(1440*(B2:B-A2:A+{-1, 0, 1}))), "×"),
"select min(Col2) group by Col1 label min(Col2)''"))))
Try to implement a modulus function in your code. It would basically do something like this:
If x = -5, then y = f(x) = – (-5) = 5, since x is less than zero
If x = 10, then y = f(x) = 10, since x is greater than zero
If x = 0, then y = f(x) = 0, since x is equal to zero
Therefore calculating how much time passed without negative values.

Jenkins job scheduler

How can I set Jenkins to run a job at a particular time?
Like if I'd like to set it to 8:30am every weekday and this is what I could do
H 7 * * 1-5
this randomly picks up 7:35am as running time.
H is a pseudo-random number, based on the hash of the jobname.
When you configured:
H 7
you are telling it:
At 7 o'clock, at random minute, but that same minute very time
Here is the help directly from Jenkins (just click the ? icon)
To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible. For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast, using H H * * * would still execute each job once a day, but not all at the same time, better using limited resources.
The H symbol can be used with a range. For example, H H(0-7) * * * means some time between 12:00 AM (midnight) to 7:59 AM. You can also use step intervals with H, with or without ranges.
The H symbol can be thought of as a random value over a range, but it actually is a hash of the job name, not a random function, so that the value remains stable for any given project
If you want it at 8:30 every weekday, then you must specify just that:
30 8 * * 1-5
Take a look at http://www.cronmaker.com/
0 30 8 ? * MON,TUE,WED,THU,FRI *
30 8 * * 1-5
This would start at 8:30am Mon-Fri.
0 and 7 are Sundays.
Not sure what the H does but I am assuming it takes the lower case hex of h and applies 68 which is 35 in decimal... lol. Don't do that.
Following this format:
Minute Hour DayOfMonth DayOfWeek Day
It picks that time because you told it that it can, as imagine you already know:
minute, hour, day of month, month, day of week.
Now you have user H which allows Jenkins to pick at random. So you have told it to run between 7-8 every week day.
Change this to:
30 8 * * 1-5
Hope this helps!

analyze outlook calendar data in spss

I downloaded Conference Room Usage from outlook.
I want to know
How busy are the conference rooms?
What are the hot times?
Who are the super users?
Who are not the super users?
How many recurrent meetings take place.
This issue i'm having is that I need the duration between the "StartTime" and the "EndTime"; but they are currently strings!
start end starttime endtime
1/1/2014 1/1/2014 5:00:00 PM 5:00:00 PM
Also, it's likely safe to assume that StartTimes and EndTimes do not straddle two days, but perhaps I want to check for this.
Perhaps conversion to a 24-hour clock might help; "Duration" is then "EndTime" - "StartTime". How can i convert back to a 12-hour clock for the uninitiated. Finally, I need the day of the week (Monday, Tuesday, etc) an event falls on.
This can mostly be accomplished through the wizard.
some sudo code that should do the trick would be
COMPUTE Start=number(StartDate, ADATE10).
VARIABLE LEVEL Start (SCALE).
FORMATS Start (ADATE10).
VARIABLE WIDTH Start(10).
EXECUTE.
COMPUTE starttimetest=number(StartTime, TIME8).
VARIABLE LEVEL starttimetest (SCALE).
FORMATS starttimetest (TIME8).
VARIABLE WIDTH starttimetest(8).
EXECUTE.
compute teststartadd=start+starttimetest.
DO if index(starttime,'PM') gt 0 and subs(starttime,1,2) ne '12' .
COMPUTE Realstart=datesum(teststartadd,12,'hours').
ELSE.
COMPUTE REALstart=TESTstartADD.
END IF.
COMPUTE End=number(EndDate, ADATE10).
VARIABLE LEVEL End (SCALE).
FORMATS End (ADATE10).
VARIABLE WIDTH End(10).
EXECUTE.
COMPUTE endtimetest=number(endTime, TIME8).
VARIABLE LEVEL endtimetest (SCALE).
FORMATS endtimetest (TIME8).
VARIABLE WIDTH endtimetest(8).
EXECUTE.
compute testendadd=end+endtimetest.
DO if index(endtime,'PM') gt 0 and subs(endtime,1,2) ne '12' .
COMPUTE RealEnd=datesum(testendadd,12,'hours').
ELSE.
COMPUTE REALEND=TESTENDADD.
END IF.
exe.
delete vars Start
starttimetest
teststartadd
End
endtimetest
testendadd.
exe.
formats RealEnd RealStart(datetime23).
compute Length=datedif(realend,realstart,'hours').
if length > 12 check=1.
freq check.
compute StartWkDay=XDATE.WKDAY(realstart).
compute EndWkDay=XDATE.WKDAY(realEnd).
string StartDayText EndDayText(a8).
you'll have to convert using something like
*if XDATE.WKDAY(realstart)=1 startdaytext="Sunday".

Operations on DateTime in rails

Is it possible to subtract one DateTime from another and get the result in Time.
Example if we subtract 2011-08-27 01:00:00 UTC from 2011-08-29 08:13:00 UTC, the result should be 55:13:00 (hope I didn't make a mistake while calulating :p)
Thanks.
Time is generally expressed in seconds when doing math like this, even fractional seconds if you want. A Time represents a specific point in time, which while internally represented as seconds since the January 1, 1970 epoch, is not intended to be a scalar unit like that.
If you have two DateTime objects, you can determine the difference between them like this:
diff = DateTime.parse('2011-08-29 08:13:00 UTC').to_time - DateTime.parse('2011-08-27 01:00:00 UTC').to_time
# => 198780.0
Once you have the number of seconds, the rest is simply a formatting problem:
'%d:%02d:%02d' % [ diff / 3600, (diff / 60) % 60, diff % 60 ]
# => "55:13:00"

Resources