Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Indicator Development

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

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 12-05-2017, 02:20 PM   #1
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default Message sent out when data is historical

Hi

I have an issue with an indicator. Whenever a special condition arises, a message should be sent out, however not within historical data.

I have set the following check:

if (State != State.Historical)

Messages will be sent out anyway, no matter what state the data bar has.
What's the correct way to prevent this?
Sweet&Sour is offline  
Reply With Quote
Old 12-05-2017, 03:03 PM   #2
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 1,063
Thanks: 33
Thanked 209 times in 204 posts
Default

Hello,

Thank you for the post.

I have made a sample indicator that will only print out a message in real time. Please compare your script to mine to check for differences. If this does not resolve the issue please post a snippet of your condition.

Please see the following page for instructions on importing a script:
https://ninjatrader.com/support/help...us/?import.htm

I look forward to hearing of your results.
Attached Files
File Type: zip ReturnHistorical.zip (1.4 KB, 1 views)
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 12-05-2017, 10:30 PM   #3
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default

I have change the state from != State.Historical to == State.Realtime.
I assume that now, only messages are sent out when the candle is in the real time state or is this different?

protected override void OnBarUpdate()
{
SendMailMessage("mail@domain.com", "Text")
}

private void SendMailMessage(string MailRecipient, string Message)
{
if (State == State.Realtime)
{
if (SendMessageToMail == true)
{
SendMail(MailRecipient, Message + " - State is:" + State.ToString());
}
}
}
Last edited by Sweet&Sour; 12-05-2017 at 10:34 PM.
Sweet&Sour is offline  
Reply With Quote
Old 12-06-2017, 12:59 PM   #4
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 1,063
Thanks: 33
Thanked 209 times in 204 posts
Default

Hello,

Thank you for the reply.

Correct, any logic within if(State == State.RealTime) will be executed only on real-time data.

You don't have to worry about setting this up though, the help guide page of SendMail() function states that this function will never be called in the State.Historical state.

Quote:
1. This method can only be called once the State has reached State.Realtime. Calls to this method in any other State will be silently ignored (in contrast to the implementation for AddOns)
https://ninjatrader.com/support/help.../?sendmail.htm

Please let us know if we may be of any further assistance.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 12-06-2017, 10:57 PM   #5
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default

I saw this in the KB as well however, resizing or refreshing the chart has occasionally triggered historical alerts. Or when the connection has been lost and manually re-establish, old events are also sometimes triggered.

Personally, I have the impression that there is a bug in NT which is causing this. Obviously the state isn't always correctly handled. Therefore i made a little extension into the message part which also also shows the state when a message get's triggered.
Sweet&Sour is offline  
Reply With Quote
The following user says thank you to Sweet&Sour for this post:
Old 12-06-2017, 11:33 PM   #6
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 4,521
Thanks: 1,695
Thanked 1,108 times in 950 posts
Default

Quote:
Originally Posted by Sweet&Sour View Post
I saw this in the KB as well however, resizing or refreshing the chart has occasionally triggered historical alerts. Or when the connection has been lost and manually re-establish, old events are also sometimes triggered.

Personally, I have the impression that there is a bug in NT which is causing this. Obviously the state isn't always correctly handled. Therefore i made a little extension into the message part which also also shows the state when a message get's triggered.
Interesting theory. So you believe these old events are firing for historical but reporting as realtime?

It wouldn't surprise me.

I would do up a test - but I haven't had TDA chart data in NT8 since 8.0.8.0 for RTH charts.
sledge is offline  
Reply With Quote
Old 12-06-2017, 11:59 PM   #7
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default

It's more a fact than theory :-)
I've been able to observe such funny mismatches more often in the past. Hence, I log now outgoing messages including time, state, candle id and candle time.
Sweet&Sour is offline  
Reply With Quote
Old 12-07-2017, 10:34 AM   #8
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 1,063
Thanks: 33
Thanked 209 times in 204 posts
Default

Hello,

Thank you for the reply.

I have made a simple script that confirms the functionality of the State property is nominal. If you have a script that reproduces this error I would be happy to test it out.

Please let us know if we may be of any further assistance.
Attached Files
File Type: cs HistReal.cs (3.3 KB, 1 views)
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 12-07-2017, 11:04 AM   #9
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default

Hi Chris,

That's a nice and tiny code snippet which may work all the times. Having much more complexity in the indicator and leaving the indicator running for days or even weeks may give a different result.

Just as i said, i have added some additional lines which shows, which candle on which day in which state has produce the signal. Just a few minutes a go, I've got such a signal and a log time stamp was generated which, in this case, was correct.

2017-12-07 17:29:59:797|1|16|07.12.2017 11:29:59 CurrentBar is:1759 Current Bar Time is 07.12.2017 05:30:00 State is:Realtime
Sweet&Sour is offline  
Reply With Quote
Old 12-07-2017, 01:33 PM   #10
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 1,063
Thanks: 33
Thanked 209 times in 204 posts
Default

Hello,

Thank you for the reply.

If you could provide an example script that does this I could try to reproduce the issue on my computer.

I look forward to your reply.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 12-11-2017, 11:47 AM   #11
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default

Hi Chris,

Today, I have resized my chart an the indicator started to send you a bunch of "old messages". They are all from the past but the state is always realtime. Here are the details. How can this happen in a simple 60 min. Chart of XBI?

2017-12-11 18:38:58:690|1|16|12.12.2017 12:38:58 CurrentBar is:22 Current Bar Time is15.12.2016 05:30:00 State is:Realtime
2017-12-11 18:38:59:357|1|16|12.12.2017 12:38:59 CurrentBar is:56 Current Bar Time is22.12.2016 04:30:00 State is:Realtime
2017-12-11 18:38:59:998|1|16|12.12.2017 12:38:59 CurrentBar is:65 Current Bar Time is23.12.2016 06:30:00 State is:Realtime
2017-12-11 18:39:00:547|1|16|12.12.2017 12:39:00 CurrentBar is:93 Current Bar Time is30.12.2016 06:30:00 State is:Realtime
2017-12-11 18:39:01:111|1|16|12.12.2017 12:39:01 CurrentBar is:106 Current Bar Time is04.01.2017 05:30:00 State is:Realtime
2017-12-11 18:39:01:813|1|16|12.12.2017 12:39:01 CurrentBar is:190 Current Bar Time is23.01.2017 05:30:00 State is:Realtime
2017-12-11 18:39:02:359|1|16|12.12.2017 12:39:02 CurrentBar is:237 Current Bar Time is31.01.2017 10:00:00 State is:Realtime
2017-12-11 18:39:02:939|1|16|12.12.2017 12:39:02 CurrentBar is:344 Current Bar Time is23.02.2017 05:30:00 State is:Realtime
2017-12-11 18:39:03:531|1|16|12.12.2017 12:39:03 CurrentBar is:361 Current Bar Time is27.02.2017 08:30:00 State is:Realtime
2017-12-11 18:39:04:154|1|16|12.12.2017 12:39:04 CurrentBar is:470 Current Bar Time is21.03.2017 04:30:00 State is:Realtime
2017-12-11 18:39:04:724|1|16|12.12.2017 12:39:04 CurrentBar is:493 Current Bar Time is24.03.2017 06:30:00 State is:Realtime
2017-12-11 18:39:05:318|1|16|12.12.2017 12:39:05 CurrentBar is:539 Current Bar Time is04.04.2017 04:30:00 State is:Realtime
2017-12-11 18:39:05:952|1|16|12.12.2017 12:39:05 CurrentBar is:568 Current Bar Time is10.04.2017 05:30:00 State is:Realtime
2017-12-11 18:39:06:590|1|16|12.12.2017 12:39:06 CurrentBar is:574 Current Bar Time is11.04.2017 04:30:00 State is:Realtime
2017-12-11 18:39:07:110|1|16|12.12.2017 12:39:07 CurrentBar is:631 Current Bar Time is24.04.2017 05:30:00 State is:Realtime
2017-12-11 18:39:07:720|1|16|12.12.2017 12:39:07 CurrentBar is:701 Current Bar Time is08.05.2017 05:30:00 State is:Realtime
2017-12-11 18:39:08:294|1|16|12.12.2017 12:39:08 CurrentBar is:729 Current Bar Time is12.05.2017 05:30:00 State is:Realtime
2017-12-11 18:39:09:094|1|16|12.12.2017 12:39:09 CurrentBar is:755 Current Bar Time is17.05.2017 10:00:00 State is:Realtime
2017-12-11 18:39:09:726|1|16|12.12.2017 12:39:09 CurrentBar is:760 Current Bar Time is18.05.2017 08:30:00 State is:Realtime
2017-12-11 18:39:10:252|1|16|12.12.2017 12:39:10 CurrentBar is:801 Current Bar Time is26.05.2017 07:30:00 State is:Realtime
2017-12-11 18:39:10:933|1|16|12.12.2017 12:39:10 CurrentBar is:820 Current Bar Time is01.06.2017 05:30:00 State is:Realtime
2017-12-11 18:39:11:615|1|16|12.12.2017 12:39:11 CurrentBar is:999 Current Bar Time is10.07.2017 05:30:00 State is:Realtime
2017-12-11 18:39:12:252|1|16|12.12.2017 12:39:12 CurrentBar is:1013 Current Bar Time is12.07.2017 05:30:00 State is:Realtime
2017-12-11 18:39:12:792|1|16|12.12.2017 12:39:12 CurrentBar is:1108 Current Bar Time is31.07.2017 09:30:00 State is:Realtime
2017-12-11 18:39:13:449|1|16|12.12.2017 12:39:13 CurrentBar is:1125 Current Bar Time is03.08.2017 05:30:00 State is:Realtime
2017-12-11 18:39:14:002|1|16|12.12.2017 12:39:13 CurrentBar is:1156 Current Bar Time is09.08.2017 08:30:00 State is:Realtime
2017-12-11 18:39:14:613|1|16|12.12.2017 12:39:14 CurrentBar is:1173 Current Bar Time is14.08.2017 04:30:00 State is:Realtime
2017-12-11 18:39:15:246|1|16|12.12.2017 12:39:15 CurrentBar is:1199 Current Bar Time is17.08.2017 09:30:00 State is:Realtime
2017-12-11 18:39:16:249|1|16|12.12.2017 12:39:16 CurrentBar is:1216 Current Bar Time is22.08.2017 05:30:00 State is:Realtime
2017-12-11 18:39:17:000|1|16|12.12.2017 12:39:17 CurrentBar is:1471 Current Bar Time is12.10.2017 08:30:00 State is:Realtime
2017-12-11 18:39:17:505|1|16|12.12.2017 12:39:17 CurrentBar is:1547 Current Bar Time is27.10.2017 07:30:00 State is:Realtime
2017-12-11 18:39:18:131|1|16|12.12.2017 12:39:18 CurrentBar is:1563 Current Bar Time is31.10.2017 08:30:00 State is:Realtime
2017-12-11 18:39:18:728|1|16|12.12.2017 12:39:18 CurrentBar is:1580 Current Bar Time is03.11.2017 04:30:00 State is:Realtime
2017-12-11 18:39:19:340|1|16|12.12.2017 12:39:19 CurrentBar is:1602 Current Bar Time is08.11.2017 06:30:00 State is:Realtime
2017-12-11 18:39:19:848|1|16|12.12.2017 12:39:19 CurrentBar is:1636 Current Bar Time is15.11.2017 05:30:00 State is:Realtime
2017-12-11 18:39:20:334|1|16|12.12.2017 12:39:20 CurrentBar is:1728 Current Bar Time is05.12.2017 09:30:00 State is:Realtime
2017-12-11 18:39:20:884|1|16|12.12.2017 12:39:20 CurrentBar is:1738 Current Bar Time is07.12.2017 05:30:00 State is:Realtime

There is no magic in the code to send messages. It just a simple void which is called after a trading calculation has been completed.

private void OpenClosePositions(GenericTraderMarketPositionType mpType)
{
switch (mpType)
{
case GenericTraderMarketPositionType.OpenNewLongPositio n:
{
if (tradingPosition != GenericTraderMarketPositionTrend.Long)
{
if (State == State.Realtime)
{
if (SendMessageToMail == true)
{
SendMail(MailRecipient, StrategyName + " Trader has changed at " + Time[0].ToString("dd.MM.yyyy hh:mm:ss") + ": Buy " + LongInst + " and Sell " + ShortInst + "", "";
}
}
tradingPosition = GenericTraderMarketPositionTrend.Long;
}
break;
}
case GenericTraderMarketPositionType.OpenNewShortPositi on:
{
....
}
}

}
Last edited by Sweet&Sour; 12-11-2017 at 12:03 PM.
Sweet&Sour is offline  
Reply With Quote
Old 12-12-2017, 01:50 PM   #12
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 1,063
Thanks: 33
Thanked 209 times in 204 posts
Default

Hello,

Thank you for the reply.

I am assuming the print statements that print out the CurrentBar, Current Bar Time, and State are within this function you have posted.

From where in your script are you calling this function? Is this running from a backtest in the Strategy Analyzer or are these prints from chart loading?

If possible please post the code statement that prints the current bar and time and describe the context of the snippet.

I look forward to your reply.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 12-12-2017, 02:29 PM   #13
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default

Quote:
Originally Posted by NinjaTrader_ChrisL View Post
Hello,

Thank you for the reply.

I am assuming the print statements that print out the CurrentBar, Current Bar Time, and State are within this function you have posted.

From where in your script are you calling this function? Is this running from a backtest in the Strategy Analyzer or are these prints from chart loading?

If possible please post the code statement that prints the current bar and time and describe the context of the snippet.

I look forward to your reply.
The print statements that print out the CurrentBar, Current Bar Time, and State are called within this function, right after the message call.

The function OpenClosePositions is called from within OnBarUpdate.

Log(DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss")
+ " CurrentBar is:" + CurrentBars[0].ToString()
+ " Current Bar Time is" + Time[0].ToString("dd.MM.yyyy hh:mm:ss")
+ " State is:" + State.ToString()
, NinjaTrader.Cbi.LogLevel.Information);

It's a chart which is open on my desktop. The code has been loaded as an indicator. Please note that in general, real-time message are sent out correctly (which indicates that the code is working as expected). The problem only appears when i resize the chart or when i scroll within the chart from right to left or vice versa.
Last edited by Sweet&Sour; 12-12-2017 at 02:32 PM.
Sweet&Sour is offline  
Reply With Quote
Old 12-12-2017, 03:59 PM   #14
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 1,063
Thanks: 33
Thanked 209 times in 204 posts
Default

Hello,

Thank you for the reply.

There seems to be an interaction with OnRender(). OnRender() is called during window resize and chart scroll events, among many other chart events. OnRender() is also called in real time only so this has a high probability of conveying what the issue is in this script.

Without the syntax of this script, I can not tell what this issue is for certain though.

I look forward to hearing of your results.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 12-12-2017, 10:27 PM   #15
Sweet&Sour
Member
 
Join Date: Jul 2017
Location: Thailand
Posts: 71
Thanks: 2
Thanked 5 times in 5 posts
Default

The code is irrelevant because it does what it should....as long as I do not move the window or scroll in it.

I personally have the impression that the State does not always what it should do, especially when it leaves the OnBarUpdate method. But the hint with OnRenderTargetChanged / OnRender is usefull.

Can you send me a little code snippet in which I can check what happens with the State in OnRenderTargetChanged/OnRender when i resize/scroll the chart window? Capturing some data during resizing/scrolling could already help...
Sweet&Sour 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
Getting illogical error message when importing historical data that makes no sense mrengleman Version 8 Beta 1 03-25-2016 07:17 AM
Historical data persists after deleting from historical data manager? llstelle Platform Technical Support 1 03-25-2012 06:35 PM
Error message: historical data in your database is corrupted adamus Platform Technical Support 18 08-22-2011 09:38 AM
Error message when backtesting & NT shut down message Hamming Platform Technical Support 5 12-19-2010 02:50 PM
Ninja 7-Beta 14 and 15-Error message-impossible to release the message Art09 Platform Technical Support 5 05-19-2010 04:22 PM


All times are GMT -6. The time now is 12:00 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.