Can you Create a Repetitive Time Alert in ThinkScript


0
0

I want something to alarm me at the end of each bar, specifically 15 min, but I am using 1 min so I can test it.   It seems if I mention a function like Seconds from Time or GetTime, it does not work the alarm or sound alert at all.   declare once_per_works with a true statement but the ticks come at any time in the time interval.    These are methods I  have tried.  Could you give a hint.   I remember in being easy in MTL4, and NinjaScript.

#TimeAlert

declare once_per_bar;

#Method 1

input MinNo=15;

def BarTimeCount=GetTime(); # (in milliseconds)

def AlarmBarCount= GetTime() + MinNo*60*1000; #milliseconds

 

def Alarm= BarTimeCount[0] >= AlarmBarCount[1];

AddLabel(yes,”BarTimeCount is “+BarTimeCount is “+AlarmBarCount+ “AlarmBarCount,Color.DARK_GREEN);

 

#Method 2

def DaySecPST= SecondsfromTime(2100);

def TFSec=MinNo* 60 *1000;

def Alarm= if DaySecPST/TFSec- Floor(DaySecPST/TFSec) <= 60000;

 

 

#def Alarm= if SecondsfromTime(2100)/ TF*60*1000- Floor(SecondsfromTime(2100)/MinNo*60*1000) <= 60000;

AddLabel(yes,”DaySecPST is “+DaySecPST+”Floor DaySecPST is “+Floor(DaySecPST,Color.DARK_GREEN);

 

 

 

#Method 3

def Alarm= RegularTradingEnd(GetTime())/MinNo*60*1000

– Floor(RegularTradingEnd (GetTime()) /MinNo*60*1000) <= MinNo*60*1000;

 

 

#Method 4

cum= cum[1]+1;

def Alarm= if (cum/TF)- Floor(cum/TF) =0 then 1 else 0;

 

#Method 5

declare once_per_bar;

Alarm==1;

Alert(Alarm, MinNo+” Min Alarm”, Alert.Once, Sound.Bell);

 

RESOLVED
Marked as spam
Posted by (Questions: 13, Answers: 18)
Asked on March 11, 2018 1:54 pm
1120 views
0
Private answer

I am a bit confused. You posted this in the “Alerts and Notifications” topic. Your request is to be alerted at the end of each bar. Yet the first three of your examples do not use the Alert function at all. The first three make use of the AddLabel method. Which has nothing do to with alerts. So I’m going to provide my solution to the Alert part of your question. No chart labels.

The solution may be much simpler than you realize. We can set an alert, one that triggers on every bar. We set that alert to tigger once per bar.

Alert(yes, "new bar", Alert.BAR, Sound.RING);

I have not tested it. But I think it should work.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on March 11, 2018 2:46 pm
0

Sorry, assumed it. I am using this as the alert paragraph.
Alert(Yes,MinNo+” Min Alarm”, Alert.Bar, Sound.Bell);
Alert(Alarm,MinNo+” Min Alarm”, Alert.Once, Sound.Bell);
Alert(Alarm,MinNo+” Min Alarm”, Alert.Once, Sound.Bell);

So I do have Alert.Bar-and not Alert.Once in one of them. I have changed them all to Alert. Bar but does not work.

( at March 11, 2018 5:28 pm)
0

Did you try my solution then? Set alert condition to yes. It always triggers. For every bar. It is set to Alert once per bar. So instead of alerting at the close of the bar it alerts at the beginning of the new bar. Which is just milliseconds apart.

( at March 11, 2018 5:35 pm)
0
Private answer

This is now the entire program:

#ADLTimeAlert

declare once_per_bar;

input MinNo=1;

#######################ALERT####################################
Alert(Yes,MinNo+” Min Alarm”, Alert.Bar, Sound.Bell);
Alert(Yes,MinNo+” Min Alarm”, Alert.Bar, Sound.Bell);
Alert(Yes,MinNo+” Min Alarm”, Alert.Bar, Sound.Bell);

It is ToS Compatible but does not sound an alarm  or Alert .  But my

SingleAlarmPrcAlert program operates great!  I  can hear 3 chimes nice a clear.

 

Marked as spam
Posted by (Questions: 13, Answers: 18)
Answered on March 11, 2018 8:00 pm
0

So you got things working as you requested? Not sure why you are still adding the statement “declare once_per_bar” as this is already implied by the alert type: “Alert.BAR”.

( at March 11, 2018 9:13 pm)
0
Private answer

Crazy,  I could not get not get anything to alarm on Sunday.  True the redundancy or the declare statement and the Alert.Bar  might have caused the problems.  I was trying so many  things.   Anyway sound an alert is  working as before, but again it is not exactly every minute- sometimes it is 70 seconds, sometimes 51 seconds as I have it on a 1 min/60 sec chart.  I could swear  the variation was more, but I guess 19 %  +- is not that bad.

Originally, I was looking for less than %5.  I can see in my messages the recording of the alert and time, and it  at a low 00 in the minute and a high  19 in the minute range.

If there is way getting less variation, let me know. Otherwise, I will mark it as resolved in 2   days.

 

 

 

Marked as spam
Posted by (Questions: 13, Answers: 18)
Answered on March 13, 2018 6:00 pm
0

Now that I understand what you have been expecting to achieve I have some great news for you. Give up. You will never get there with Thinkorswim. This is because Thinkorswim uses a data aggregator for the streaming quotes. You will never have a one min bar close at exactly 60 seconds on Thinkorswim. The data comes through in buckets. Not for every single tick. If you want something that will sound an alarm at the end of every 60 seconds. Go buy one. I mean go by an application or a piece of hardware. Don’t rely on the data feed of a trading platform and expect to make this happen.

( at March 13, 2018 7:07 pm)
0

Just tried it on 5 min. It really is at most 19 seconds on that too. I should have realized it is will be a much smaller % on the 15 min. Really just amazed at that all the time-related function/ methods I tried, did not work at all.

( at March 13, 2018 7:34 pm)
0
Private answer

It is resolved.   Probably that is why the Time-related functions I used seemed to shut the alert off.

Marked as spam
Posted by (Questions: 13, Answers: 18)
Answered on March 13, 2018 7:36 pm