Execute order only once in 4 hour window even though executing orders on the 15M timeframe - pine-script-v5

I would like to execute a buy/sell on the 15m timeframe but only once within a 4 hour timeframe (the current 4hr bar).
So if there is other orders found to execute on the 15m timeframe after one has executed, they do not fire.
Once the next 4 hour bar starts, it can execute one order.
Hope somebody can assist - thanks.
Getting too many orders firing within that window.

You can use the mod (%) operator to authorize a new order each new 4h bar :
var authorize_new_order = true
if hour % 4 == 0 and minute(time) == 0
authorize_new_order := true
if my_condition_to_enter_trade and authorize_new_order
authorize_new_order := false
// code to take the trade here

Related

Grafana 2 queries in same panel but set query interval difference

I have 2 queries in a grafana panel.
I want to run Query A every 5 min
I want to run Query B every 10 min, so I can check the value difference between each query using transform.
How can I set the query interval, I know I can change scrape interval but my goal here is to check pending messages and if it doesnt change in 10 min trigger an alert. I am trying to get a count at 1st minute and get count again at 10th minute. check the difference using transform and trigger an alert if no change (messages are not getting processed )
using grafana 7
Thanks !

How do you have an event go every hour in roblox?

I want to create an hourly event in roblox, but I don't know how to script the wait for 1 hour.
If you simply want a wait statement and know how you want to do this with your loop already programmed, a wait statement lasting an hour is wait(3600). Otherwise, here are some loop solutions that run code every hour according to the game or according to a time zone.
To run the script when the game starts, then do something every hour since then:
while true do
-- this should be the code that runs every hour
wait(3600)
end
To run according to UST (every time the minutes hit 0 in universal standard time):
while true do
local timeTable = os.date("!*t", tick())
if timeTable["min"] == "00" then
-- this should be the code that runs every hour
end
wait(1)
end
To run according to the local time zone (this only works in LocalScripts to my knowledge):
while true do
if os.date("%M", os.time()) == "00" then
-- this should be the code that runs every hour
end
wait(1)
end

Calculate sum overlapping minutes in tableau

I have two excel extracts, one containing the schedules of employees and the other containing the actual times the employees worked. There are multiple schedule blocks in a day and employees can have multiple activity start and stop times in or out of scheduled time.
Schedule:
Actvtivity:
I need to use this data to calculate the sum of actual minutes worked only during the scheduled time with Tableau. In the above images the first schedule event would have 115 minutes worked and the second line would have 92 totaling in 207.
I tried to start easy by only calculating activity entries that fall within both the start and stop of a scheduled block, but tableau either return nothing or the "Many to 1" *
attempt 1:
case attr([#Fields:Date]) when ATTR([ScheduleStopStart].[#fields:excDate])
then
if attr([Start]) >= Min([ScheduleStopStart].[Start])
and attr([Stop]) <= max([ScheduleStopStart].[Stop])
then datediff("minute", attr([Start]), attr([Stop]))
END
END
Attempt 2:
IF ATTR([#Fields:Date]) = ATTR([ScheduleStopStart].[#fields:excDate]) then (
if attr([Start]) >= attr([ScheduleStopStart].[Start])
and attr([Stop]) <= attr([ScheduleStopStart].[Stop])
then DATEDIFF("minute", attr([Start]),attr([Stop]))
else 0
end
)
else
0
END

TABLEAU Calculating a Running DISTINCT COUNT on usernames for last 3 months

Issue:
Need to show RUNNING DISTINCT users per 3-month interval^^. (See goal table as reference). However, “COUNTD” does not help even after table calculation or “WINDOW_COUNT” or “WINDOW_SUM” function.
^^RUNNING DISTINCT user means DISTINCT users in a period of time (Jan - Mar, Feb – Apr, etc.). The COUNTD option only COUNT DISTINCT users in a window. This process should go over 3-month window to find the DISTINCT users.
Original Table
Date Username
1/1/2016 A
1/1/2016 B
1/2/2016 C
2/1/2016 A
2/1/2016 B
2/2/2016 B
3/1/2016 B
3/1/2016 C
3/2/2016 D
4/1/2016 A
4/1/2016 C
4/2/2016 D
4/3/2016 F
5/1/2016 D
5/2/2016 F
6/1/2016 D
6/2/2016 F
6/3/2016 G
6/4/2016 H
Goal Table
Tried Methods:
Step-by-step:
Tried to distribute the problem into steps, but due to columnar nature of tableau, I cannot successfully run COUNT or SUM (any aggregate command) on the LAST STEP of the solution.
STEP 0 Raw Data
This tables show the structure Data, as it is in the original table.
STEP 1 COUNT usernames by MONTH
The table show the count of users by month. You will notice because user B had 2 entries he is counted twice. In the next step we use DISTINCT COUNT to fix this issue.
STEP 2 DISTINCT COUNT by MONTH
Now we can see who all were present in a month, next step would be to see running DISTINCT COUNT by MONTH for 3 months
STEP 3 RUNNING DISTINCT COUNT for 3 months
Now we can see the SUM of DISTINCT COUNT of usernames for running 3 months. If you turn the MONTH INTERVAL to 1 from 3, you can see STEP 2 table.
LAST STEP Issue Step
GOAL: Need the GRAND TOTAL to be the SUM of MONTH column.
Request:
I want to calculate the SUM of '1' by MONTH. However, I am using WINDOW function and aggregating the data that gave me an Error.
WHAT I NEED
Jan Feb March April May Jun
3 3 4 5 5 6
WHAT I GOT
Jan Feb March April May Jun
1 1 1 1 1 1
My Output after tried methods: Attached twbx file. DISTINCT_count_running_v1
HELP taken:
https://community.tableau.com/thread/119179 ; Tried this method but stuck at last step
https://community.tableau.com/thread/122852 ; Used some parts of this solution
The way I approached the problem was identifying the minimum login date for each user and then using that date to count the distinct number of users. For example, I have data in this format. I created a calculated field called Min User Login Date as { FIXED [User]:MIN([Date])} and then did a CNTD(USER) on Min User Login Date to get the unique user count by date. If you want running total, then you can do quick table calculation on Running Total on CNTD(USER) field.
You need to put Month(date) and count(username) in the columns then you will get result what you expect.
See screen below

Hide Total Row in Rep[orting services

I have a report with total lines after a show is being reported.
A show may run a week or several weeks. I want to hide the total line when there is only 1 week for the show but display the total line when there are more than one week. The example below should hide the Total row for "An American In Paris" but show for the other shows because they run for more than 1 week.I group by performance, week, start date.
I have tried:
=IIF(SUM(Fields!week_performance.Value)<=1,True,False)
and
=IIF((Fields!week_performance.Value)<=1,True,False)
neither seems to work, even if week = 1 the total line still shows
Performance week sales
A Gentlemens guide to Love & Murder 1 1500
2 2000
Total 3500
An American in Paris 1 1800
Total 1800
First Date 1 1900
2 2100
3 1800
Total 58000
I think what you need is the CountRows() function. In this case, using it as follows will default to the current scope (i.e., the group of the showing, in this case) and should count just 1.
=IIF(CountRows() = 1,true,false)
In addition to CountRows(), if you had some unique value per showing, you could use the following:
=IIF(CountDistinct(Fields!UniqueID.Value) = 1,true,false)
If this doesn't work, reply as a comment and I'll do my best to help.