How to send alert at a certain time - time

I'd like to write a pine-script that will send me a report of the stock, says, it's pivot points, rsi, etc ... at 7am every morning and 3pm when mrkt close. I know how to do the alert, it's the trigger is I don't know how to tell it to send me the alert at 7am and 3pm.
Any thought on how to accomplish this? I look into timestamp or time, but don't know how to make that condition to send the alert.
Thanks

There are multiple ways of doing it, one of them is to create a session from time x to time y and get the start and the end of it.
I added comments for each section to see how it's working.
//#version=4
study("My Script", overlay = true)
//Sessions
session = input(title="Session", type=input.session, defval="0930-1555")
//Check if it's new bars
is_newbar2(sess) =>
t = time("D", sess)
na(t[1]) and not na(t) or t[1] < t
//Check if it's in session
is_session(sess) =>
not na(time(timeframe.period, sess))
//Call the function
Session = is_session(session)
//Plot the background color to see the session
bgcolor(Session ? color.new(color.aqua, 95) : na)
//Start and end of the session
start = Session and not Session[1]
end = (not Session) and Session[1]
//Plot the start and the end of the session
plotshape(start, style=shape.labeldown, color = color.aqua, text = "Start", textcolor = color.black, size = size.small)
plotshape(end, style=shape.labeldown, color = color.purple, text = "End", textcolor = color.black, size = size.small)
//Alerts
if start
alert("text alert", alert.freq_once_per_bar)
if end
alert("text alert", alert.freq_once_per_bar_close)
It's very important to write the starting of the session (if it start at 7am, then write exactly 07:00) and the time from the last candle of the session (if you are in 5m chart and the session expire at 2pm, write 13:55, if you are in 1H chart write 13:00...and so on), that's because after the end of the session, Tradingview will block any functions...since the market is closed, so we need to get the last bar of the session.
For the alerts, you just put your text and it's ready to go.

Related

Can anyone help getting a box to display using time as coordinates in Pinescript V5?

Hi beginner coder apologise for being basic, im trying to learn to code with pinescript, i just want to draw a box around the NY open, with 9:30-10:30 as left and right sides, and the high and low price within that hour as the top and bottom.
Its for making backtesting easier so eventually want it drawn between the user inputted time period on every NY open, but for now I cant get one to display at all.
I'm not getting any errors, is there a problem with how i'm creating the condition to only draw the box within the two allowed time periods?
Or am I not even close? :)
indicator("justabox", overlay=true)
startdate = input.time(timestamp("15 december 2022 04:00"), title = "Start Date")
enddate = input.time(timestamp("16 december 2022 04:00"), title = "end date")
nysess = not na (time("","0930-1030"))
daytime = time("1D")
onehour = 1000 * 60 * 60
oneminute = 1000 * 60
leftside = daytime + (onehour*9)+(oneminute*30)
rightside = daytime +(onehour*10) +(oneminute*30)
float top = na
float bottom = na
bool indate = na
if (timenow >= startdate and timenow<= enddate)
`indate := true`
else
`indate := false`
if (indate and nysess)
`top := ta.highest(high,12)`
`bottom := ta.lowest(low,12)`
`boxy = box.new(leftside, top, rightside, bottom)`
I was expecting a box to be drawn between 9:30am and 10:30 am with its top and bottom set at the high and low price within that hour.
i tried simplifying the code down to just the user inputted time period as a condition and setting the box at last_bar_index[120] and last_bar_index as its left and right without a session condition and i tried just drawing two lines at high and low price, im following tutorials and dont seem to be doing much different, but i cant find one specific to what im doing.
Thanks for your time.
Check whether the current bar is within the NY open session
nysess = time("0930-1030")
If the current bar is within the NY open session, draw a box
if nysess
top = high
bottom = low
leftside = time("0930")
rightside = time("1030")
boxy = box.new(leftside, top, rightside, bottom)

Remove a screenGUI when unequipping

I already made a question on cooldown a weapon and I made a screenGUI to show the player when they can shoot again implementing the same debounce code. The problem is I've got no clue on how to delete the screengui/textlabel from the screen. As every tool I'm planing on doing has its own GUI, if the screenGUI of one tool doesn't delete, it will overlap with the same tool's GUI/ other tools GUI.
I already tried hiding the text label as stated in this question like this
player.PlayerGui.ScreenGui.TextLabel.Visible = false but
1) It only makes it disappear first time its unequipped and
2) Im afraid that given it doesn't get deleted, but rather hidden, after some time, stacked hidden GUIs will somehow affect the games smoothness in some way.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
--Creaets a text label with the text Block Ready! on it when the player
local function onEquip()
print("screengui1")
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = player.PlayerGui
local textLabel = Instance.new("TextLabel")
textLabel.Parent = screenGui
textLabel.BackgroundTransparency = 0.85
textLabel.Position = UDim2.new(0, 1100, 0, 550)
textLabel.Size = UDim2.new(0, 150, 0, 50)
textLabel.BackgroundColor3 = BrickColor.White().Color
textLabel.Text = "Block ready!"
end
local isGunOnCooldown = false
local cooldownTime = 3 --seconds
mouse.Button1Down:Connect(function()
-- debounce clicks so the text dont changes (its cooldown is the same as the gun cooldown the GUI is within)
if isGunOnCooldown then
return
end
-- change the text,
isGunOnCooldown = true
player.PlayerGui.ScreenGui.TextLabel.Text = "Reloading..."
-- start the cooldown and reset it along with the test
spawn(function()
wait(cooldownTime)
isGunOnCooldown = false
player.PlayerGui.ScreenGui.TextLabel.Text = "Block ready!"
end)
end)
local function onUnequip()
--code to delete the gui goes here
end
tool.Equipped:connect(onEquip)
tool.Unequipped:connect(onUnequip)
I just need explanation on how to delete the screenGUI that contains the textlabel shown to the player when they unequip the weapon
The easiest way to handle this is to keep a reference to the UIElement when you first create it. Then when you equip the tool, you simply set the Parent. When you unequip, you set the Parent to nil. This way, you know that there will always be one element, you are simply controlling when it is visible.
local function createAmmoUI()
--Creates a text label with the text Block Ready! on it when the player
local screenGui = Instance.new("ScreenGui")
local textLabel = Instance.new("TextLabel")
textLabel.Name = "Message"
textLabel.Parent = screenGui
textLabel.BackgroundTransparency = 0.85
textLabel.Position = UDim2.new(0, 1100, 0, 550)
textLabel.Size = UDim2.new(0, 150, 0, 50)
textLabel.BackgroundColor3 = BrickColor.White().Color
textLabel.Text = "Block ready!"
return screenGui
end
-- make a persistent UI element to show off how much ammo is left and when reload is done
local ammoUI = createAmmoUI()
local function onEquip()
-- when the tool is equipped, also show the UI
print("Equipping Tool to current Player")
ammoUI.Parent = player.PlayerGui
end
local function onUnequip()
-- when the tool is unequipped, also remove the UI from the screen entirely
print("Unequiping Tool UI")
ammoUI.Parent = nil
end
local isGunOnCooldown = false
local cooldownTime = 3 --seconds
mouse.Button1Down:Connect(function()
-- debounce clicks so the text dont changes (its cooldown is the same as the gun cooldown the GUI is within)
if isGunOnCooldown then
return
end
-- change the text,
isGunOnCooldown = true
ammoUI.Message.Text = "Reloading..."
-- start the cooldown and reset it along with the test
spawn(function()
wait(cooldownTime)
isGunOnCooldown = false
ammoUI.Message.Text = "Block ready!"
end)
end)
tool.Equipped:connect(onEquip)
tool.Unequipped:connect(onUnequip)

Swift - using timers/system clock/background threads to do something in my application every hour

I'm using:
var alarm = NSUserNotification()
var currentTime = NSDate()
alarmTime = currentTime.dateByAddingTimeInterval(60)
alarm.deliveryDate = alarmTime
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification(alarm)
To get a notification that will fire an hour from the current time, the problem is I want the app to automatically set up another alarm after the first one finishes. NSTimer doesn't seem like it will work because once the app goes to the background it kills the timer. What can I do to achieve this? Can I piggy back another method onto a NSUserNotification
Edit: it also needs to be dynamic, I can't just set the repeat variable of the notification because I need to be able to switch how far out the alarm will be each time it resets.
You just have to set your deliveryRepeatInterval and deliveryTimeZone, as follow:
// set your deliveryTimeZone to localTimeZone
alarm.deliveryTimeZone = NSTimeZone.localTimeZone()
// The date components that specify how a notification is to be repeated.
// This value may be nil if the notification should not repeat.
// alarm.deliveryRepeatInterval = nil
// The date component values are relative to the date the notification was delivered.
// If the calendar value of the deliveryRepeatInterval is nil
// the current calendar will be used to calculate the repeat interval.
// alarm.deliveryRepeatInterval?.calendar = NSCalendar.currentCalendar()
// to repeat every day, set .deliveryRepeatInterval.day to 1.
alarm.deliveryRepeatInterval?.day = 1
// to repeat every hour, set .deliveryRepeatInterval.hour to 1.
alarm.deliveryRepeatInterval?.hour = 1
alarm.deliveryDate = NSDate().dateByAddingTimeInterval(60)
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification(alarm)

Message for Limited time, thread.sleep(x) is not working - Windows Phone

I want to just show a Message for a short time in TextBlock.
I'm using this code
Label1.Text = "Wrong Password!";
System.Threading.Thread.Sleep(5000);
Label1.Text = " ";
But this is not working, if anyone have other better logic then please do Answer!
The code above will sleep the UI thread, so what essentially happens is this:
Request that label text be set to "Wrong Password!" (not updated till next UI thread tick)
Sleep for 5 seconds
Request that label text be set to ""
UI thread ticks, label is set to ""
To work around this do something like:
Label1.Text = "Wrong Password!";
// start a new background thread
new Thread(new ThreadStart(() =>
{
Thread.Sleep(5000);
// interacting with Control properties must be done on the UI thread
// use the Dispatcher to queue some code up to be run on the UI thread
Dispatcher.BeginInvoke(() =>
{
Label1.Text = " ";
});
})).Start();
This will:
Request that the label text be set to "Wrong Password!"
Start a different thread that sleeps for 5000ms
In the meanwhile the UI Thread continues to execute so the Label gets updated to "Wrong Password!"
5000ms passes and the background requests that the label text be cleared
the UI thread ticks and updates the label

Animate Button size, then revert to null

I am trying to create an animation to make it look like a button turns over and the back shows. So what I was trying to do is:
1- Show a button with BackgroundColor x. (The button now has a Width of null, the property ActualWidth does have a value.)
2- Create a double animation that changes the width of the button to zero.
DoubleAnimation widthAnimation = new DoubleAnimation();
widthAnimation.From = this.ActualWidth;
widthAnimation.To = 0;
widthAnimation.SpeedRatio = 3;
widthAnimation.Duration = TimeSpan.FromMilliseconds(800);
3- Change the BackgroundColor of the button.
ColorAnimation colorAnimation = new ColorAnimation();
colorAnimation.From = State ? _xColor : _yColor;
colorAnimation.To = State ? _yColor : _xColor;
colorAnimation.BeginTime = TimeSpan.FromMilliseconds(400);
colorAnimation.Duration = TimeSpan.Zero;
4- Change the width back to it's original value.
widthAnimation.AutoReverse = true;
The problem is when the animation runs twice the animation reads this.ActualWidth while animating, which causes it to fail to the original width. How can I solve this? I would like to set the Width back to null again, but it seems impossible to me.
You'd better use xaml style and template to "declare" what you want and let WPF/Silverlight take care of all.
If you try to do the same thing by code you can do it but you need to know what the framework does behind the scenes.
Basically you can set
- Style to define the values of some properties of the control
- DataTemplate to define the visual representation of the control's content
- ControlTemplate to define the appearance of the control
Each of those can have Triggers
- Property Triggers
to set properties or starts actions, such as an animation
when a property value changes or when an event is raised;
EventTriggers and Storyboards
to start a set of actions based on the occurrence of an event
If you like to learn about XAML Style and Template,
take a look at http://msdn.microsoft.com/en-us/library/ms745683.aspx
Spend a day to learn and save many hours (or days) of try and error and frustration!
To go right to the point, in your case I think you should use a Storyboard.
See http://msdn.microsoft.com/en-us/library/ms742868.aspx
where you can find also the code equivalent of XAML examples
I came to the idea to targetting the MaxWidth instead of the actual Width. I now use a KeyFrameCollection which sets the MaxWidth to int.MaxValue at the start (so also at the end when using autoreverse).
It will work fine untill there will be phones with a resolution bigger than the max int value.
The code:
DoubleAnimationUsingKeyFrames widthAnimation = new DoubleAnimationUsingKeyFrames();
widthAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame()
{
KeyTime = TimeSpan.Zero,
Value = int.MaxValue,
});
widthAnimation.KeyFrames.Add(new LinearDoubleKeyFrame()
{
KeyTime = TimeSpan.FromMilliseconds(1),
Value = ActualWidth,
});
widthAnimation.KeyFrames.Add(new LinearDoubleKeyFrame()
{
KeyTime = TimeSpan.FromMilliseconds(400),
Value = 0,
});
widthAnimation.Duration = TimeSpan.FromMilliseconds(400);
widthAnimation.AutoReverse = true;

Resources