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 06-19-2017, 10:32 AM   #1
GeorgeW
Senior Member
 
Join Date: Nov 2014
Posts: 249
Thanks: 69
Thanked 23 times in 20 posts
Default NT8 misreading bars

Hello,
Are there any known circumstances under which NT8 is known to be occasionally misreading bars or not sending a signal when one would be expected based on the parameters in the code? The reason I ask is because I have 2 bars on a chart when I would have expected an arrow signal, but there was none. So I set up bool series to check if the conditions in my code were true or false. In the 1st instance, all the conditions for an arrow signal were true, but no arrow signal.In the 2nd instance, a bar is marked as false when it is true, and I have examined another bar, which is exactly the same (Close < Open; 1 tick upper wick, 2tick body, 1tick lower tail) , and that is marked as true. The check for that condition was:
Code:
if((close0 < open0 && (close0 == low0 || close0 == low0 + TickSize)) || ((open0 == close0) &&((Math.Abs(high0 - open0) > Math.Abs(low0 - open0)))))
				bearClose1[0] = true;
I've spent hours examining my code for errors, but as far as I can see, there are no errors in the code that should be causing this.

Thank you.
GeorgeW is offline  
Reply With Quote
Old 06-19-2017, 11:16 AM   #2
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 4,203
Thanks: 1,571
Thanked 1,015 times in 877 posts
Default

I have tracked down one when called from a strategy. Looks unrelated though.

http://ninjatrader.com/support/forum...97&postcount=5
sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 06-19-2017, 11:51 AM   #3
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 526
Thanks: 35
Thanked 113 times in 107 posts
Default

Hello GeorgeW,

Thanks for opening the thread.

If NinjaTrader is not triggering code within conditions that are true, we would definitely want to look into this further.

However, we would need to first confirm that you the variables for that condition allow it to become true. We would need to place Print() statements outside and inside the condition to:
1. Print out the variable values used to check to make sure the condition has become true,
2. Print out a message within the condition that says it has become true.

If the prints for these variables shows the condition should become true, and the print within the condition confirms that condition became true, the code within the condition must be executed as well. If it is a drawing object the syntax of that drawing object should be double checked. Orders should be double checked using Trace Orders.

If you have taken the steps above and have been able to determine that the logic is correct and NinjaTrader is not executing some code, please provide a barebones sample that can reproduce the issue so we can analyze it further on our end.

I have linked some resources for debugging and using Trace Orders for reference.

Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

TraceOrders: http://ninjatrader.com/support/forum...ead.php?t=3627

I look forward to assisting you further.

@Sledge, just as a head up, Jesse is out of the office today. Another teammate or I will try to get to that ticket when we have available time. If we do not get to submit a response, Jesse will be able to reach back when he returns.
Last edited by NinjaTrader_Jim; 06-19-2017 at 12:00 PM.
NinjaTrader_Jim is offline  
Reply With Quote
Old 06-19-2017, 11:42 PM   #4
GeorgeW
Senior Member
 
Join Date: Nov 2014
Posts: 249
Thanks: 69
Thanked 23 times in 20 posts
Default

Thanks for your reply, Jim.
I am not sure what the difference is between placing a print statement outside and inside the condition. I have set up the conditions certain types of bars or a stochastics condition etc and then placed the print statements after them. I was then able to view the results in the output window.
GeorgeW is offline  
Reply With Quote
Old 06-20-2017, 07:23 AM   #5
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 526
Thanks: 35
Thanked 113 times in 107 posts
Default

Hello GeorgeW,

Thanks for the reply.

Printing the values of the variables used in the condition before the condition is checked will tell what what is going wrong if the condition is not becoming true.

So I understand the issue correctly, you have a condition that when it becomes true, a drawing object is placed that doesn't draw? You also have a print statement that confirms this code has been reached?

If this is the case, have you confirmed that the syntax for the drawing object is correct? You can find example code in the help guide to reference syntax for the drawing objects you wish to use.

Drawing objects: https://ninjatrader.com/support/help...us/drawing.htm

If you can provide me an example of some code that becomes true and a drawing object with correct syntax is not working correctly, I could take a closer look.

I look forward to being of further assistance.
NinjaTrader_Jim is offline  
Reply With Quote
Old 06-20-2017, 01:54 PM   #6
GeorgeW
Senior Member
 
Join Date: Nov 2014
Posts: 249
Thanks: 69
Thanked 23 times in 20 posts
Default

Hello Jim,

I have further clarified the issue. It is not the draw object that is the problem, as the arrows are being drawn correctly in most cases. It is Ninjascript that is occassionally not identifying a bar correctly. I've seen a couple of examples today, but I'll refer you to the first examples I saw on the 6B on 16/06/2017. The bar at 07:38:09 is a bear bar, but the print to the output window is showing bearCloseBar0 = false. I also try to pick it up from the next bar with bearCloseBar1, but that is also showing false. There is another example at 12:07:37.

I am attaching a simplified version of the code for you to test on your end (no arrow signals included). I have also attached images of the 2 examples I am referring to.
Attached Images
File Type: png 6B 09-17 (110 Tick) 2017_06_16_01.png (94.2 KB, 2 views)
File Type: png 6B 09-17 (110 Tick) 2017_06_16_02.png (101.7 KB, 2 views)
Attached Files
File Type: zip Test01.zip (2.0 KB, 1 views)
GeorgeW is offline  
Reply With Quote
Old 06-20-2017, 02:24 PM   #7
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 526
Thanks: 35
Thanked 113 times in 107 posts
Default

Hello GeorgeW,

Thanks for the reply.

If you think the bearCloseBar0 should have been set to true, you will need to verify the condition that sets this value to true actually becomes true in that instance, and allows the code within to execute..

I would suggest to test that period with Market replay data to reproduce so you can easily rewind.You will need to use Prints to verify the values of the condition below so you can verify that the logic allows it to become true.

For example:
Code:
if (close0 < open0)
	Print("Set 1 True!");
Each section of that condition will have to be verified so you can deduce if the condition is logically possible in that instance.

As I suggested previously, I would also advise to place a print within that code block so the output window can tell you when if bearCloseBar0 became true.

Code:
if((close0 < open0 && (close0 == low0 || close0 == low0 + TickSize)) || ((open0 == close0) &&((Math.Abs(high0 - open0) > Math.Abs(low0 - open0)))))
{
	bearCloseBar0[0] = true;
	Print("bearCloseBar0[0] is true!");
}
If you would like further assistance debugging your code, I could get you connected with a member of our Business Development team who could pass over a list of Certified NinjaScript Consultants who would be happy to help you debug your code. If that is the case, please write in to platformsupport[at]ninjatrader[dot]com with the thread URL and the text "Attention Jim."
NinjaTrader_Jim is offline  
Reply With Quote
Old 06-21-2017, 12:47 AM   #8
GeorgeW
Senior Member
 
Join Date: Nov 2014
Posts: 249
Thanks: 69
Thanked 23 times in 20 posts
Default

Hello Jim,

I have done all the suggested print statements. The bar on 6B on 16 June 2017 at 07:38:09 is constructed as follows:

Open 1.2819
High 1.2819
Low 1.2812
Close 1.2813
TickSize = 0.0001

…if(Close0 < Open0)– correctly identified as true.

The bar closes 1 tick above its low. Consequently:
..if(close0 == low0 + TickSize) This should be identified as true, but it is not. Even if rewritten
..if(low0 == close0 – TickSize) This should be identified as true, but it is not.

There is another example at 12:07:37 on the same instrument on the same day, also on a bar which closes 1 tick from its low. I have also seen a bull example on the 6E on 20/06/2017 at 01:09:02, this time where it was coded to identify the bar if it was a bull close 2 ticks from the high. These are not problems requiring debugging of my script, it is a serious and fundamental flaw in Ninjatrader 8. If you are unable to recognise this or deal with this issue, then can you please put me in touch with someone at Ninjatrader who can.

Thank you.
GeorgeW is offline  
Reply With Quote
Old 06-21-2017, 02:51 AM   #9
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,157
Thanks: 200
Thanked 720 times in 553 posts
Default

Hi George,

I would like to point your attention to the fact that you may not check double values for equality. This is a major coding crime!

Floating point values (double and float) need to be considered as approximations and not as exact values. This is particularly true after an arithmetic operation. But even without such an operation, the compiler may use varying precision for different values.

If I look at your code

Code:
if(close0 == low0 + TickSize)
if(low0 == close0 – TickSize)
then it is obvious that it cannot work. The value on the right side of the equation is the result of a floating point arithmetic operation and may be different from the left value, even if the prices match.


Solutions for your problem

You have two options to modify that code as needed.

(1) Convert the double values into integers. For example you can divide both the left side and the right side of the equation by the ticksize and then round the result to the next integer. The integers can be compared for equality.

(2) Alternatively you may use two inequalities, for example you can replace

Code:
if(close == low + TickSize)   // this is a false statement
with
Code:
if(close > low + 0.5*TickSize && close < low + 1.5*TickSize)  // correct statement
The second statement checks whether the approximated value for close falls within a tick range around the approximated value for low + ticksize.
Harry is offline  
Reply With Quote
The following user says thank you to Harry for this post:
Old 06-21-2017, 05:26 AM   #10
JerryWar
Senior Member
 
Join Date: Mar 2009
Posts: 750
Thanks: 139
Thanked 95 times in 77 posts
Default

I have always used something like
if (Close == Instrument.MasterInstrument.RoundToTickSize(Low+Ti ckSize))
in these situations as I have found the built in vars Close and Low will be already be at an exact TickValue.
JerryWar is offline  
Reply With Quote
The following user says thank you to JerryWar for this post:
Old 06-21-2017, 06:16 AM   #11
GeorgeW
Senior Member
 
Join Date: Nov 2014
Posts: 249
Thanks: 69
Thanked 23 times in 20 posts
Default

Hello Harry,
Thank you for your detailed explanation, which I will use to adjust the code. Does that also mean "close == low" also has to be adjusted as it is a double value being checked for equality?
GeorgeW is offline  
Reply With Quote
Old 06-21-2017, 07:17 AM   #12
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 526
Thanks: 35
Thanked 113 times in 107 posts
Default

Thanks for providing that explanation, Harry.

@GeorgeW, we have a thread that explains some the implications of comparing doubles and internal floating point math and what you can do about it.

You can find it here: http://ninjatrader.com/support/forum...ead.php?t=3929

To answer your question: yes, you would be risking some sort of inequality if there are significant digits that are not equal. I.e. 1.00000001 != 1.00000002
NinjaTrader_Jim is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jim for this post:
Old 06-21-2017, 08:35 AM   #13
GeorgeW
Senior Member
 
Join Date: Nov 2014
Posts: 249
Thanks: 69
Thanked 23 times in 20 posts
Default

Thanks for the explanations Harry, JerryWar and Jim. I have tried both Harry's and JerryWar's methods, and I am now getting the signals.
GeorgeW is offline  
Reply With Quote
The following user says thank you to GeorgeW for this post:
Old 06-21-2017, 08:43 AM   #14
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,157
Thanks: 200
Thanked 720 times in 553 posts
Default

Quote:
Originally Posted by GeorgeW View Post
Hello Harry,
Thank you for your detailed explanation, which I will use to adjust the code. Does that also mean "close == low" also has to be adjusted as it is a double value being checked for equality?

"Close == Low" will probably work in most of the cases, however if you want to play it safe, you should make it a habit not to check double values for equality.

You should only check integers and booleans for equality. For double values best use inequalities or convert them to integers first.

I also invite you to look at the code of the Stochastics which uses a method ApproxCompare(0) which is another workaround for floating point comparisons.

Further you should read the Help Guide -> NinjaScript -> NinjaScript Best Practices, which has a section on Floating Point Comparisons.
Harry is offline  
Reply With Quote
The following user says thank you to Harry for this post:
Reply

Tags
nt8

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
Equivolume Bars space between bars NT8 yamzeq Add-On Development 7 03-09-2017 08:35 AM
Where are the Hourly Bars in NT8? sberry Platform Technical Support 1 01-09-2017 07:52 PM
NT8 blank bars MrN1njaTrader Platform Technical Support 2 01-02-2017 08:14 PM
NT8 bars are different than NT7 afshinmoshrefi Version 8 Beta 5 11-03-2016 07:58 AM
NT8 Bars.IsFirstBarOfSession ren37 Version 8 Beta 15 06-19-2016 04:54 PM


All times are GMT -6. The time now is 09:30 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. Visit the CFTC resources for education regarding the industry and signs of fraud.