How do I create a strategy trigger for a daily trade at a certain time? - time

I want to test a simple strategy based on time: every day at fixed time check some conditions and go long. every day at fixed time exit.
Whatever I try to get timeOpenCondition I get syntax error.
Tried things similar to:
EntryTime = if hour=0800 and minute=0
ExitTime = if hour=1400 and minute=0
It feels like I don't get the concept of how this works. Appreciate any help!

Related

Condition is true if 15 seconds have passed

i am new to pinescript but i am facing an huge problem when i try to work with time.
The problem is:
I have an indicator that shows buy (or sell) on the current candlestick but sometimes it disappear. I wanted to add a control where if the buy is true for more than 15 second (average time where the signal will no longer disappear), the alert will send me a notification.
I tried so many things like putting the 'timenow' in a variable and compare as follow
BuyTime := timenow
If timenow - BuyTime >= 15000
RealBuy = true
And many more things that i dont perfectly remember..
I dont know why but i wasn't able to get it to work, any suggestion please?
Thanks in advance

Using grafana counter to visualize weather data

I'm trying to visualize my weather data using grafana. I've already made the prometheus part and now I face an issue that hunts me for quite a while.
I created an counter that adds temperature indoor every five minutes.
var tempIn = prometheus.NewCounter(prometheus.CounterOpts{
Name: "tempin",
Help: "Temperature indoor",
})
for {
tempIn.Add(station.Body.Devices[0].DashboardData.Temperature)
time.Sleep(time.Second*300)
}
How can I now visualize this data that it shows current temperature and stores it for unlimited time so I can look at it even 1 year later like an normal graph?
tempin{instance="localhost:9999"} will only display added up temperature so its useless for me. I need the current temperature not the added up one. I also tried rate(tempin{instance="localhost:9999"}[5m])
How to solve this issue?
Although a counter is not the best solution for this use case, you can use the operator increase.
Increase(tempin{instance="localhost:9999"}[5m])
This will tell you how much the counter increased in the last five minutes

Initialize Variables in Power Automate Flow

I am wondering about power automate flow and I issues I had.
I am trying to set up initialize variables for checking time (european standard time) in my rules.
Expression looks like this -
startOfHour(convertFromUtc(triggerOutputs()?['body/receivedDateTime'],'Central European Standard Time','t'), 't')
Under variables I have condition which (True/Not) like this -
YES - time is greater than 22:30 PM
NO - time is less than 8:00 AM
If condition is true, my e-mail is forwarded to another outlook mailbox.
If not, nothing happened.
But this flow doesn't work :D
Can you help me resolve it ?
Thanks a lot !
First part prtscrn
Second part prtscrn
Given the information provided, I suggest the following:
Get the current time.
Convert it to the desired time zone. You can use the built in function to avoid calculation errors.
Convert only hour and minute to Integer. For example, 14:33 would be 1433.
Compare integers. This is: if time is greater than 2230 and less than 830, then forward email.
The flow might look like this:

Code for a function that just returns after an hour -interview question

I saw this question online from an interview:
Suppose you have this code:
void myFunction(){
int time = clcTime();
while (clcTime()-time!=3600);
}
When clcTime() is a method that returns the seconds that passed since 00:00 of today.
(1). Find what this code snippet does.
(2). Some QA tester said this code fails at specific case. What's that case and how can you solve that issue?
(3). Another QA tester that during the day this code worked fine, but when he got to sleep - something went wrong. What can possibly be the problem and how can you solve it?
My attempt:
For (1), I think this function just suppose to run in a loop for an hour.
For (3), I think the problem is when the time variable get its value when the current hour of the day is in the range [23:00:00,23:59:59]. And that's because on that case, the value of time will be in the range [23*3600,23*3600 + 3599] and clcTime() can't return a matching value in the range [24*3600, 24*3600 + 3599]. So in that case, we know that the condition 'clcTime()-time' will never get a value of 3600 and we will get an infinite loop.
My suggestion for solving it is replacing the while line with those lines:
int measure = clcTime() - time;
int measureModulo = measure % 3600;
while (measure==0 || measureModulo!=0){
measure = clcTime() - time;
measureModulo = measure % 3600;
}
The only problem I still have is that I can't figure out (2) - I don't find any other problem with this code.
Do you have any idea what else can be problematic with this code?
Also, please feel free to correct me if I was wrong with what I wrote for (1) and (3).
Another problem with this code, and your fix, is that it checks clcTime() for an exactly matching value. If the system is busy and the loop doesn't get to run for more than a second, then it will miss the matching second and continue waiting for at least another hour.
Also there will be problems when the user changes the system clock or system time zone, when daylight savings time comes into or out of effect, when the clock is automatically adjusted for leap seconds, etc.

Find the difference between 2 dates and check if smaller than a given value

my issue is that I want to be able to get two time stamps and compare if the second (later taken) one is less than 59 minutes away from the first one.
Following this thread Compare two dates with JavaScript
the date object may do the job.
but first thing i am not happy with is that it takes the time from my system.
is it possible to get the time from some public server or something?
cause there always is a chance that the system clock gets manipulated within the time stamps, so that would be too unreliable.
some outside source would be great.
then i am not too sure how to get the difference between 2 times (using 2 date objects).
many issue that may pop up:
time being something like 3:59 and 6:12
so just comparing minutes would give the wrong idea.
so we consider hours too.
biut there the issue with the modulo 24.
day 3 23:59 and day 4 0:33 wouldnt be viewed proper either.
so including days too.
then the modulo 30 thing, even though that on top changes month for month.
so month and year to be included as well.
so we would need the whole date, everything from current year to second (because second would be nice too, for precision)
and comparing them would require tons of if clauses for year, month, etc.
do the date objects have some predfeined date comparision function that actually keeps all these things in mind (havent even mentioned leap years yet, have I)?
time would be very important cause exactly at the 59 minutes mark (+-max 5 seconds wouldnt matter but getting rmeitely close to 60 is forbidden)
a certain function would have to be used that without fail closes a website.
script opens website at mark 0 min, does some stuff rinse and repeat style and closes page at 59 min mark.
checking the time like every few seconds would be smart.
Any good ideas how to implement such a time comparision that doesnt take too more computer power yet is efficient as in new month starting and stuff doesnt mess it up?
You can compare the two Date times, but when creating a date time there is a parameter of DateTime(value) which you can use.
You can use this API to get the current UTC time which returns a example JSON array like this:
{
"$id":"1",
"currentDateTime":"2019-11-09T21:12Z",
"utcOffset":"00:00:00",
"isDayLightSavingsTime":false,
"dayOfTheWeek":"Saturday",
"timeZoneName":"UTC",
"currentFileTime":132178075626292927,
"ordinalDate":"2019-313",
"serviceResponse":null
}
So you can use either the currentFileTime or the currentDateTime return from that API to construct your date object.
Example:
const date1 = new Date('2019-11-09T21:12Z') // time when I started writing this answer
const date2 = new Date('2019-11-09T21:16Z') // time when I finished writing this answer
const diff = new Date(date2-date1)
console.log(diff.toTimeString()) // time it took me to write this
Please keep in mind that due to network speeds, the time API will be a little bit off (by a few milliseconds)

Resources