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 03-08-2018, 02:10 PM   #1
hansob3
Junior Member
 
Join Date: Feb 2018
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default last price greater then high of bar

On my chart I have an indicator that prints only when the last price via the onmarketupdate function is greater than high[0]. Should that be possible? I was thinking that they should at least be equal.
hansob3 is offline  
Reply With Quote
Old 03-08-2018, 02:25 PM   #2
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your post.

OnMarketData() will actually be called after OnBarUpdate() and therefore would not have the last price above the High[0] unless the OnMarketData() was updating outside the Trading Hours Template defined start and end times (which is the only time OnBarUpdate() is called).

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 03-09-2018, 06:40 AM   #3
hansob3
Junior Member
 
Join Date: Feb 2018
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Here is a snippet of the debug output where I am having an issue.

2018-03-09 06:31:58:451 OnMarketUpdate:
CurrentBar: 825
Price: 2740.25
Vol: 2
Bid: 2740 - Ask: 2740.25
2018-03-09 06:31:58:451 Bar Added - Down to Up
Last Price: 2740.25
Reversal Price: 2740.25
2018-03-09 06:31:58:451 OnBarUpdate:
CurrentBar: 826

The timestamps are identical but the Bar added needs to come first in the sequence. I have a modified Point and Figure that I use but the logic of when a bar is created is the same as the builtin version. In the attached screenshot you can see the high/close of the bar but yet I get a tick above printed. Those 2 lots should be the beginning of the next bar.

My thinking is that the Bars would generate the events that the indicators would consume.
Attached Images
File Type: jpg Capture.JPG (8.7 KB, 8 views)
hansob3 is offline  
Reply With Quote
Old 03-09-2018, 10:30 AM   #4
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your response.

Are you building your own bar type here or using an indicator to render the bars?

Can you attach your script to your response?

You can export your file by going to Tools > Export > NinjaScript Add On > Add > select your file > OK > Export > name the file 'NTsupport' > Save.

The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 03-09-2018, 12:09 PM   #5
hansob3
Junior Member
 
Join Date: Feb 2018
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

I use a modified point and figure to build the bars. I tried exporting but I get an error about DayBarsType(), MinuteBarsType(), ... not in the assembly. It is in the initial lookback days method. All I did was copy the original Point and Figure but changed some of the logic but I did not change any of the logic that decides when a new bar should be added. I added a print statement to print right after the AddBar is called. I use the close, 1 tick 4 box reversal with a base period of 1 tick and tick replay checked. I do not break on EOD.


Attached is a test script that I made to go with the bars that allows you to see the debug messages.

I am using an indicator to render the volume numbers on the chart. I would like to do it as a bar type.

I forgot to mention that this happens on every bar, just easier to see when its above the high/low.
Attached Files
File Type: zip NTSupport.zip (1.5 KB, 3 views)
Last edited by hansob3; 03-09-2018 at 12:21 PM.
hansob3 is offline  
Reply With Quote
Old 03-13-2018, 09:34 AM   #6
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your patience.

Here is an excerpt from my Output:
Quote:
OnBarUpdate:
CurrentBar: 286

OnMarketData:
CurrentBar: 286
Price: 2786.75
Vol: 1
High: 2789.75 - Low: 2784.75
Bid: 2786.75 - Ask: 2787

OnBarUpdate:
CurrentBar: 287

OnMarketData:
CurrentBar: 287

Price: 2787
Vol: 5
High: 2786.75 - Low: 2785.25
Bid: 2786.75 - Ask: 2787

OnBarUpdate:
CurrentBar: 287

OnMarketData:
CurrentBar: 287
Price: 2787
Vol: 1
High: 2786.75 - Low: 2785.25
Bid: 2786.75 - Ask: 2787
We can clearly see OnBarUpdate is called first here. I am failing to understand the item we are investigating here. Can you provide further detail on what you are inquiring on?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 03-13-2018, 09:59 AM   #7
hansob3
Junior Member
 
Join Date: Feb 2018
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

The issue I am having is that the AddBar method within the bar type is not called before the OnBarUpdate within the indicator. I have attached the bar type that I use. If you use that bar type with the previous indicator you get the results that I originally posted.

So my question is shouldn't the bar type AddBar be called before calling the OnBarUpdate within the indicator? In the sequence of events it shows that even though the price has met the if statement within the bar type to add a bar it is not called till after the OnBarUpdate and OnMarketData events are called.

Thanks

Bryan
Attached Files
File Type: cs MyBarVS.cs (25.0 KB, 1 views)
hansob3 is offline  
Reply With Quote
Old 03-13-2018, 12:17 PM   #8
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your response.

I am still receiving the output I saw before even with 'MyBarVS'. Do I need to use a specific 'Box Size', 'Base Period Type', 'Base Period Value', or 'Reversal' to see what you are reporting?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 03-13-2018, 12:24 PM   #9
hansob3
Junior Member
 
Join Date: Feb 2018
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

I use a 1 for box size, 4 for reversal, base type is 1 tick with tick replay enabled.
hansob3 is offline  
Reply With Quote
Old 03-13-2018, 01:33 PM   #10
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your response.

I am seeing the same results as I was with the 1 Minute base period. Can you copy your Output to a text document and then attach the document to your response?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 03-14-2018, 06:54 AM   #11
hansob3
Junior Member
 
Join Date: Feb 2018
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

See attachment.

Take the example at the 2018-03-14 07:35:30:272 mark. That line is printed out when a new bar is added. You can see the last price is 2781 and that matches the reversal price, hence the new bar. If you take a look a few lines above you see the OnMarketData event with that same price, that tick should have triggered the AddBar and that OnMarketData event should be the first tick on the newly added bar.

Thanks,
Bryan
Attached Files
File Type: zip debug_output.zip (56.3 KB, 3 views)
File Type: cs MyBarVS.cs (25.8 KB, 0 views)
File Type: cs Test.cs (3.8 KB, 1 views)
Last edited by hansob3; 03-14-2018 at 07:12 AM.
hansob3 is offline  
Reply With Quote
Old 03-15-2018, 08:59 AM   #12
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your response.

Your Logged details show that the 2781 price level triggering the AddBar is called first as seen below:
Quote:
2018-03-14 07:35:30:272 Bar Added - Up to Down
Last Price: 2781
Reversal Price: 2781
2018-03-14 07:35:30:272 OnBarUpdate:
CurrentBar: 1495
2018-03-14 07:35:30:272 OnMarketData:
CurrentBar: 1495
Price: 2781
Vol: 1
High: 2781 - Low: 2781
Bid: 2781 - Ask: 2781.25
While that same price is seen in a bar update and market data update directly before does not suggest that it is what called the AddBar.

Do you have an example where the AddBar is shown last and the next OnBarUpdate and the next OnMarketData calls are not the exact same price?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 03-15-2018, 12:07 PM   #13
hansob3
Junior Member
 
Join Date: Feb 2018
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default

Attached is another log with timestamps. Take a look at the very last one in the file. Timestamp: 2018-03-15 12:48:53:780


Quote:
2018-03-15 12:48:53:780 OnBarUpdate:
CurrentBar: 476
Time: 636567149322030000
2018-03-15 12:48:53:780 OnMarketData:
CurrentBar: 476
Price: 2751.75
Vol: 1
High: 2752.75 - Low: 2752
Bid: 2751.75 - Ask: 2752
Time: 636567149322030000
2018-03-15 12:48:53:835 Bar Added - Up to Down
Last Price: 2751.75
Reversal Price: 2751.75
Time: 636567149322260000
2018-03-15 12:48:53:835 OnBarUpdate:
CurrentBar: 477
Time: 636567149322260000
2018-03-15 12:48:53:835 OnMarketData:
CurrentBar: 477
Price: 2752
Vol: 1
High: 2751.75 - Low: 2751.75
Bid: 2751.75 - Ask: 2752
Time: 636567149322260000
Quote:
While that same price is seen in a bar update and market data update directly before does not suggest that it is what called the AddBar.
What calls AddBar?

A tick came in at 2751.75 and was added to bar 467, but that same tick is what triggers the AddBar logic. Shouldn't that tick that came in fire the AddBar logic before is reaches the OnBarUpdate and MarketData events? What event triggers the OnBarUpdate?
Attached Files
File Type: zip debug_output.zip (65.9 KB, 1 views)
hansob3 is offline  
Reply With Quote
Old 03-19-2018, 08:04 AM   #14
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your response.

AddBar() is called in OnDataPoint() based on the BarsTypes' logic in OnDataPoint().

I am only able to see this behavior with your BarsType which is just the PointAndFigureBarsType. I will continue to test further and follow up with you when I have any details.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 03-20-2018, 07:22 AM   #15
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,646
Thanks: 783
Thanked 2,012 times in 1,938 posts
Default

Hello hansob3,

Thank you for your patience.

This occurs when the tick has the same price level for the last tick of the bar and the tick of the new bar. AddBar triggers the OnBarUpdate call and we known that OnMarketData will be called after OnBarUpdate. The behavior you are seeing is expected and in the proper sequence.

Please let me know if you have any questions.
NinjaTrader_PatrickH 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
Marking Medium term High which is greater than previous and next short term High baqer110 Platform Technical Support 3 01-12-2016 02:25 PM
Error: Stop price is greater than or equal to close price whiterhino Strategy Development 1 09-25-2014 03:28 AM
Previous Days Bar High Ahead Of Price? tshirtdeal General Development 3 04-01-2011 08:02 PM
error trigger price must be greater than last price rogerad Platform Technical Support 4 01-05-2009 04:47 PM
High greater than Highest High of last 20 Bars SamIam Strategy Development 1 08-19-2007 04:58 PM


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