Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 04-21-2011, 04:44 PM   #1
ScottieDog
Senior Member
 
Join Date: Aug 2010
Posts: 357
Thanks: 116
Thanked 9 times in 9 posts
Default Looking for a time alert indicator

Hi,

Looking for an indicator which allows the setting of an alarm daily based on time. So, for instance I can chose a audible alert to go off at 11:30 each day to tell me London is closing...

Yes, yes. I know I can just use a clock. LOL. Anyone know of an indicator which I can use in Ninja to alert me audibly at certain times every day ? Looked in the ninjascript file sharing, couldn´t find anything.

Thanks.
ScottieDog is offline  
Reply With Quote
Old 04-21-2011, 04:53 PM   #2
NinjaTrader_Dexter
NinjaTrader Customer Service
 
NinjaTrader_Dexter's Avatar
 
Join Date: Mar 2011
Location: Denver, CO
Posts: 103
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello ScottieDog,

Thank you for your post.

This can be done working with ToTime in NinjaScript. For example, if you wanted to play a sound at a bar timestamped at 11:30 you could do something like this:

Code:
if( ToTime(Time[0]) == 113000 )
{
    PlaySound(@"C:\alarmsound.wav");
}
For more information on working with times and dates please see the following example:
http://www.ninjatrader.com/support/f...ead.php?t=3226

Also, this indicator may do what you need, it appears to have an alert functionality:

http://www.ninjatrader.com/support/f...d=1&linkid=274
Last edited by NinjaTrader_Dexter; 04-21-2011 at 04:55 PM.
NinjaTrader_Dexter is offline  
Reply With Quote
Old 04-22-2011, 03:28 AM   #3
ScottieDog
Senior Member
 
Join Date: Aug 2010
Posts: 357
Thanks: 116
Thanked 9 times in 9 posts
Default

OK. Well, I have done a new NinjaScript which is attached below... I compiled it and then added the indicator to the chart..... Seems OK....

How can I add a few options inside the indicator preference ? So I can change the notification time, and the notification sound from inside the preferences, rather than editing the code each time ? What code do I add to the script ?

Can anyone help with that ? Thanks.





namespace NinjaTrader.Indicator
{
/// <summary>
/// Audible alert when reaching a specific point of the day
/// </summary>
[Description("Audible alert when reaching a specific point of the day")]
public class AlertTime : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
if( ToTime(Time[0]) == 113000 )

PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\2minsLondonclose.wav");
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Plot0.Set(Close[0]);
}

#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}

[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
Last edited by ScottieDog; 04-22-2011 at 05:39 AM.
ScottieDog is offline  
Reply With Quote
Old 04-22-2011, 06:43 AM   #4
NinjaTrader_Brett
NinjaTrader Product Management
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO
Posts: 7,239
Thanks: 149
Thanked 560 times in 479 posts
Default

Hello,

Please see this sample on how to create user defined input parameters.

http://www.ninjatrader.com/support/f...ead.php?t=5782

Let me know if you have any questions.
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-09-2017, 10:35 PM   #5
Slide588
Junior Member
 
Join Date: Jan 2016
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

Say if I want an alert to go off at every 9 minute mark of the hour, eg 3:09, 4:09 etc. How would I do this? Am also interested in minutes and seconds. eg 3:08:30, 4:08:30 etc.

Thanks, Stephen
Slide588 is offline  
Reply With Quote
Old 05-10-2017, 09:50 AM   #6
NinjaTrader_AlanS
NinjaTrader Customer Service
 
NinjaTrader_AlanS's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 253
Thanks: 2
Thanked 53 times in 53 posts
Default

Hello Slide588,

If you would like to do this, you would want to check the current time against the current bar's time to see if the value is at 9 minutes.

Here is a short code sample of how you could achieve this:
Code:
if(Time[0].Minutes == 9)
Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
If you would also want to incorporate seconds into your check, you can add the following logic:
Code:
if(Time[0].Minutes == 9 && Time[0].Seconds == 30)
Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
You can find more information on the Time object here:
http://ninjatrader.com/support/helpGuides/nt7/time.htm

You can find more information on the Alert() method here:
http://ninjatrader.com/support/helpGuides/nt7/alert.htm

Please let me know if I may be of any further assistance.
NinjaTrader_AlanS is offline  
Reply With Quote
Old 09-12-2017, 01:52 AM   #7
Slide588
Junior Member
 
Join Date: Jan 2016
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

Hi

I'm interested in firstly determining the time per bar automatically, so say 3 minute or 5 minute OHLC bars then having an Alert fire when the bar is 15 seconds from closing.

Got the Alert firing for certain times as below, now want to generalize this.

Thanks!
Slide588 is offline  
Reply With Quote
Old 09-12-2017, 11:16 AM   #8
NinjaTrader_AlanS
NinjaTrader Customer Service
 
NinjaTrader_AlanS's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 253
Thanks: 2
Thanked 53 times in 53 posts
Default

Hello Slide588,

Thanks for your post.

You can refer to the documentation time for more information on how to check the time of a bar:
http://ninjatrader.com/support/helpGuides/nt7/time.htm

Then you would need to create a time check to check if the bar is 15 seconds from closing. One way you could do this is to use the ToTime() method to check the current bar's closing time against the current time, then check if there are 15 seconds remaining on the current bar from the difference between the two time values.

For example, imagine we are running this script on a 3 minute bar object. This first check subtracts the current time by the previous bar's time. Checking the time stamp of a minute bar object will always return the time of the close of that bar. This is different than a Tick-based bar type, which will return the time stamp of the last recorded tick when we attempt to retrieve it. If there are 15 seconds left on the current bar, the difference between the closing time of the current bar and the current time will be 15 after ToTime() converts the DateTime values to integer values.
Code:
if(ToTime(Time[0]) - ToTime(DateTime.Now) == 15)
Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
Note that when you want to detect intra-bar events, you will need to set the CalculateOnBarClose property to false, so that your logic runs on each incoming tick rather than just once at the close of the bar. With this in mind, also consider that a tick will have to be received within the last 15 seconds of the bar in order for this logic to be ran and for your alert to trigger.

You can find more information about ToTime() and CalculateOnBarClose in our help guide here:
ToTime() - http://ninjatrader.com/support/helpG...nt7/totime.htm
CalculateOnBarClose - http://ninjatrader.com/support/helpG...onbarclose.htm

Please let me know if I may be of any further assistance.
NinjaTrader_AlanS is offline  
Reply With Quote
Old 09-13-2017, 01:19 AM   #9
Slide588
Junior Member
 
Join Date: Jan 2016
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

Hi Alan,

I looked up ToTime and this returns an integer value in HMMSS. So the suggested solution won't work as desired. eg 15 seconds to 12:03 would be 120300-120245. I could parse the returned integers to convert to seconds then subtract but is there an easier way?

Along the same lines, how can I tell how long a bar lasts for. ie for a 3 min bar I want 3 returned, 5 min bar 5 returned.

Thanks
Slide588 is offline  
Reply With Quote
Old 09-13-2017, 08:14 AM   #10
NinjaTrader_AlanS
NinjaTrader Customer Service
 
NinjaTrader_AlanS's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 253
Thanks: 2
Thanked 53 times in 53 posts
Default

Hello Slide588,

Thanks for your reply.

Are you able to see the code sample I provided in my previous post? I provided an example of how you would use the ToTime() method to check if there was 15 seconds left on the bar:

if(ToTime(Time[0]) - ToTime(DateTime.Now) == 15)

There is no need to parse the returned integers to convert to seconds. The purpose of the ToTime() function is to return DateTime objects in an integer format to make them easier to work with, such as the case here where we want to implement bar time checks.

You can use BarsInProgress to check which series OnBarUpdate() is being called by, then check the BarsPeriod.Value to retrieve the period value.

You can find more information on BarsInProgress and BarsPeriod.Value in our help guide here:

BarsInProgress - http://ninjatrader.com/support/helpG...inprogress.htm

BarsPeriod - http://ninjatrader.com/support/helpG...barsperiod.htm

Please let me know if I may be of any further assistance.
NinjaTrader_AlanS is offline  
Reply With Quote
Old 09-13-2017, 08:54 AM   #11
Slide588
Junior Member
 
Join Date: Jan 2016
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

> Are you able to see the code sample I provided in my previous post? I provided an
> example of how you would use the ToTime() method to check if there was 15 seconds > left on the bar:

> if(ToTime(Time[0]) - ToTime(DateTime.Now) == 15)

Hi Alan, yes I can see it and coded it and it doesn't work which is what I was pointing out.

eg for a 12:03 bar:

ToTime(Time[0] = 120300

15 seconds beforehand is:

ToTime(DateTime.Now) = 120245.

120300-120245 = 55.

See what I mean? Thanks
Slide588 is offline  
Reply With Quote
Old 09-13-2017, 09:26 AM   #12
NinjaTrader_AlanS
NinjaTrader Customer Service
 
NinjaTrader_AlanS's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 253
Thanks: 2
Thanked 53 times in 53 posts
Default

Hello Slide588,

Thanks for pointing that out - in this particular case we can amend the value in the check to 55 to represent being 15 seconds away from the close of the bar.

Please let me know if I may be of any further assistance.
NinjaTrader_AlanS is offline  
Reply With Quote
Old 09-13-2017, 10:23 AM   #13
Slide588
Junior Member
 
Join Date: Jan 2016
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

Unfortunately not Alan.

For the 12:00 bar we have:

ToTime(Time[0] = 120000

15 seconds beforehand is:

ToTime(DateTime.Now) = 115945

120000-115945 = ...

I'd actually like the alert to sound once at 15 seconds or less. Like I say, I can parse the values but would be surprised if there's not a call that does this. Could you please investigate.

Thanks
Slide588 is offline  
Reply With Quote
Old 09-13-2017, 10:52 AM   #14
NinjaTrader_AlanS
NinjaTrader Customer Service
 
NinjaTrader_AlanS's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 253
Thanks: 2
Thanked 53 times in 53 posts
Default

Hello Slide588,

To avoid this difficulty, we should create a check only looking at the minute seconds values:

if(DateTime.Now.Minute == (Time[0].Minute - 1) && (60 - DateTime.Now.Seconds) <= 15)

Please let me know if I may be of any further assistance.
NinjaTrader_AlanS is offline  
Reply With Quote
Old 09-14-2017, 01:10 AM   #15
Slide588
Junior Member
 
Join Date: Jan 2016
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

Thanks Alan, we'll still have trouble on the hour as 0 minutes - 1 is negative so have to check for that case. But I've got the idea. Cheers.
Slide588 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Alert display from alert Indicator kumaresh11 Platform Technical Support 1 06-17-2010 09:21 AM
Time parameters to alert simpletrades Indicator Development 4 01-13-2010 11:20 AM
time alert telbentel General Development 1 09-14-2009 02:03 PM
Alert Time stamp marketstudent Platform Technical Support 3 07-21-2009 08:38 AM
Time of Day Alert drago1 General Development 3 12-09-2008 01:59 PM


All times are GMT -6. The time now is 07:55 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.