Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Platform Technical Support

Platform Technical Support General platform technical support for NinjaTrader 8.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 05-21-2018, 08:35 AM   #1
gordongekko
Senior Member
 
Join Date: Nov 2017
Location: Las Vegas, NV
Posts: 120
Thanks: 74
Thanked 3 times in 3 posts
Default Strategy start behavior

I have several bots that are stuck in a position due to a large gap in price when the globex opened on Sunday. This strategy places a bracket order on both sides of the position and since the current market price is still within these brackets the strategy will not take any new positions until the price hits one of the bracket orders. I have tested all 4 of the options for the start behavior and none of them allow the user to just start the strategy from the current bar and since the minimum days to load is 1 and that gap is within the most recent day I don't see any way around this other than changing the time frame trading hours to something that doesn't include that gap. Is there a way to just run a strategy starting from the current bar without using any historical data on start-up?
gordongekko is offline  
Reply With Quote
Old 05-21-2018, 08:49 AM   #2
NinjaTrader_JoshG
NinjaTrader Customer Service
 
NinjaTrader_JoshG's Avatar
 
Join Date: Jun 2017
Location: Denver, CO
Posts: 642
Thanks: 15
Thanked 144 times in 139 posts
Default

Hello gordongekko,
Thanks for your post.

You could force your strategy to ignore all historical data and process its logic only once you are on real-time date by adding this line to the top of your strategies OnBarUpdate() logic.
Code:
if(State==State.Historical)return;
NinjaTrader_JoshG is online now  
Reply With Quote
The following user says thank you to NinjaTrader_JoshG for this post:
Old 05-21-2018, 08:58 AM   #3
gordongekko
Senior Member
 
Join Date: Nov 2017
Location: Las Vegas, NV
Posts: 120
Thanks: 74
Thanked 3 times in 3 posts
Default

Thanks for the quick reply. Generally I would prefer to leave have it start live when it the last historical trade finishes (when flat) but in situations like this I need an override. I'll add that as bool property option for these situations.
gordongekko is offline  
Reply With Quote
Old 05-21-2018, 01:34 PM   #4
gordongekko
Senior Member
 
Join Date: Nov 2017
Location: Las Vegas, NV
Posts: 120
Thanks: 74
Thanked 3 times in 3 posts
Default

Will this affect any indicators or variables used by the strategy that require historical data? For example if the strategy uses the 12 26 9 macd will it have to wait at least 26 bars after being enabled to generate a trigger assuming nothing else requires more data or will it be able to fire on bar 1?
gordongekko is offline  
Reply With Quote
Old 05-21-2018, 01:37 PM   #5
NinjaTrader_JoshG
NinjaTrader Customer Service
 
NinjaTrader_JoshG's Avatar
 
Join Date: Jun 2017
Location: Denver, CO
Posts: 642
Thanks: 15
Thanked 144 times in 139 posts
Default

Yes, this would effect anything that requires historical data.
NinjaTrader_JoshG is online now  
Reply With Quote
The following user says thank you to NinjaTrader_JoshG for this post:
Old 05-21-2018, 03:04 PM   #6
gordongekko
Senior Member
 
Join Date: Nov 2017
Location: Las Vegas, NV
Posts: 120
Thanks: 74
Thanked 3 times in 3 posts
Default

Thanks for clarifying this. So for this particular bot I'm going to run it with no historical data but use a time filter so the indicators will have their data but it wont be allowed to trigger until the time window is open.
gordongekko is offline  
Reply With Quote
Old 05-21-2018, 06:58 PM   #7
bltdavid
Senior Member
 
Join Date: Dec 2013
Location: Silicon Valley, California
Posts: 759
Thanks: 30
Thanked 260 times in 220 posts
Default

Quote:
Originally Posted by NinjaTrader_JoshG View Post
Yes, this would effect anything that requires historical data.
Really?

That sounds different from my NT7 experience.

Just because the strategy ignores historical data doesn't mean the indicators used by the strategy also ignore historical data -- how could they?

When "used by the strategy" I mean indicator references that are created in Initialize() or OnStartUp() -- before OnBarUpdate() is ever called.
bltdavid is offline  
Reply With Quote
Old 05-22-2018, 11:01 AM   #8
NinjaTrader_JoshG
NinjaTrader Customer Service
 
NinjaTrader_JoshG's Avatar
 
Join Date: Jun 2017
Location: Denver, CO
Posts: 642
Thanks: 15
Thanked 144 times in 139 posts
Default

Right. The indicators themselves would not ignore historical data. However, any calls to those indicators inside OnBarUpdate() would be ignored until you were in State.Realtime
NinjaTrader_JoshG is online now  
Reply With Quote
Old 05-22-2018, 01:17 PM   #9
bltdavid
Senior Member
 
Join Date: Dec 2013
Location: Silicon Valley, California
Posts: 759
Thanks: 30
Thanked 260 times in 220 posts
Default

Quote:
Originally Posted by gordongekko View Post
Will this affect any indicators or variables used by the strategy that require historical data? For example if the strategy uses the 12 26 9 macd will it have to wait at least 26 bars after being enabled to generate a trigger assuming nothing else requires more data or will it be able to fire on bar 1?
I think the better answer you're looking for is 'No, it will not affect any indicators, since they will still see the historical data in their own processing inside their own OnBarUpdate'.

That is, this line of code,

Code:
if(State==State.Historical)return;
absolutely affects what data your strategy will operate on inside its OnBarUpdate, but this line of code does not affect the data that the indicators are processing in their own OnBarUpdate.
bltdavid is offline  
Reply With Quote
Old 05-22-2018, 02:01 PM   #10
bltdavid
Senior Member
 
Join Date: Dec 2013
Location: Silicon Valley, California
Posts: 759
Thanks: 30
Thanked 260 times in 220 posts
Default

Some confusion may exist around how you use the indicators.

For example, say you access MACD(12,26,9) directly, with full arguments, and you don't access the indicator any other way ... for example,

Code:
if(State==State.Historical)return;
if(MACD(12,26,9) <test against condition ABC>)
      EnterLong();
else if (MACD(12,26,9) <test against condition XYZ>)
      EnterShort();
then in this case the MACD indicator will not "see" any of the historical data in its own OnBarUpdate, but the value of CurrentBar in your strategy and in the MACD will be the same -- meaning, the historical data is there for MACD to refer to, as necessary -- but the point is: MACD literally did not process any of the historical data in its own OnBarUpdate because (in this particular case) your code prevented MACD from being instantiated in time to be called with historical data.

EDIT:
I'm not strictly sure if what I said above is true, but it's the working model I have in my head. NinjaTrader support, could you please confirm everything in this posting?

But you can get around this 'limitation' by making the instantiation happen sooner.

How? Create a reference to MACD(12,26,9) before calling OnBarUpdate.
How? Easy, by adding MACD(12,26,9) to the chart.

If you use AddChartIndicator(MACD(12,26,9)), the MACD indicator will process all historical data in its own OnBarUpdate, despite the 5 lines of code above.

Make sense?
It all depends where in your strategy it first creates the reference to MACD(12,26,9).

The use of AddChartIndicator provides this very subtle and rarely talked about feature -- it allows the indicator to be instantiated in time such that it is guaranteed to process all historical bars in its own OnBarUpdate.

If you don't use AddChartIndicator, or create a reference to the indicator via some other means, then yes, the 5 lines of code above mean that on the first call to MACD(12,26,9) inside of OnBarUpdate, MACD will start processing with realtime data only (but all historical data is available to it, it just didn't process any of it inside its own OnBarUpdate).

But, the story gets more complicated:
Now we bump up against NinjaTrader's indicator caching code in the auto generated NinjaScript code at the bottom of every indicator. If some where else in NinjaTrader, such as in a chart or in another strategy, the MACD(12,26,9) has already been referenced -- then your strategy gets a copy of that previous created reference from the indicator cache -- and that copy will have most likely already processed all the historical data that your strategy is trying to skip over -- which is fine and expected and a good thing for you.

Bottom line:
Just use AddChartIndicator() and you'll have no issues.
bltdavid is offline  
Reply With Quote
Old 05-23-2018, 07:53 AM   #11
NinjaTrader_JoshG
NinjaTrader Customer Service
 
NinjaTrader_JoshG's Avatar
 
Join Date: Jun 2017
Location: Denver, CO
Posts: 642
Thanks: 15
Thanked 144 times in 139 posts
Default

bltdavid,
Couple of things here.

If you use the line if(State==State.Historical)return; in your strategies OnBarUpdate() than it will not process its logic until you reach State.Realtime. If your indicator does not have that same line in its code, it will still process historical data. Bottom line is no entry logic will be processed on historical data.

Also, AddChartIndicator() is simply used for displaying an indicator on a chart from within a strategy. It would not be used to load more historical data to process your logic on.
Help Guide - AddChartIndicator()

Please let me know if this doesn't clear everything up.
NinjaTrader_JoshG is online now  
Reply With Quote
Old 05-24-2018, 09:01 AM   #12
bltdavid
Senior Member
 
Join Date: Dec 2013
Location: Silicon Valley, California
Posts: 759
Thanks: 30
Thanked 260 times in 220 posts
Default

Quote:
Originally Posted by NinjaTrader_JoshG View Post
bltdavid,
Couple of things here.

If you use the line if(State==State.Historical)return; in your strategies OnBarUpdate() than it will not process its logic until you reach State.Realtime. If your indicator does not have that same line in its code, it will still process historical data. Bottom line is no entry logic will be processed on historical data.

Also, AddChartIndicator() is simply used for displaying an indicator on a chart from within a strategy. It would not be used to load more historical data to process your logic on.
Help Guide - AddChartIndicator()

Please let me know if this doesn't clear everything up.
Thanks Josh, but I think you failed to address my main point.

If your strategy has this in its OnBarUpdate(),

Code:
if(State==State.Historical)return;
if(MACD(12,26,9) <test against condition ABC>)
   EnterLong();
else if (MACD(12,26,9) <test against condition XYZ>)
   EnterShort();
and has no other MACD(12,26,9) references anywhere else in the strategy (eg, AddChartIndicator is not used), you've failed to explain how the MACD(12,26,9) is able to process any historical data in its own OnBarUpdate.

I mean, clearly, the MACD(12,26,9) is not being called with historical data, so that brings into question your statement in red below,

Quote:
Originally Posted by NinjaTrader_JoshG View Post
If you use the line if(State==State.Historical)return; in your strategies OnBarUpdate() than it will not process its logic until you reach State.Realtime. If your indicator does not have that same line in its code, it will still process historical data.
Obviously, the MACD does not have that same line of code, so you're saying it will process historical data. Well, sure it is capable of processing historical data, is that what you mean?

So, yes, we all know MACD is capable of processing historical data, but does it actually process historical data in this case above or not? If yes, then how?
bltdavid is offline  
Reply With Quote
Old 05-24-2018, 09:15 AM   #13
bltdavid
Senior Member
 
Join Date: Dec 2013
Location: Silicon Valley, California
Posts: 759
Thanks: 30
Thanked 260 times in 220 posts
Default

Quote:
Originally Posted by NinjaTrader_JoshG View Post
Also, AddChartIndicator() is simply used for displaying an indicator on a chart from within a strategy. It would not be used to load more historical data to process your logic on.
I don't think that's what I said.

My point is not more historical data, it's whether the indicator will see any historical data in its own OnBarUpdate.

I know what AddChartIndicator() does.

But you failed to respond directly to my comment that the reference passed to AddChartIndicator() is of any importance.

I'm saying that that indicator reference is important.

That act of creating that reference to pass to AddChartIndicator() happens to provide a very subtle service to the strategy, which is (see my previous post): "it allows the indicator to be instantiated in time such that it is guaranteed to process all historical bars in its own OnBarUpdate."

Is that statement true or false?
bltdavid is offline  
Reply With Quote
Old 05-24-2018, 10:28 AM   #14
NinjaTrader_JoshG
NinjaTrader Customer Service
 
NinjaTrader_JoshG's Avatar
 
Join Date: Jun 2017
Location: Denver, CO
Posts: 642
Thanks: 15
Thanked 144 times in 139 posts
Default

In the situation you are describing the indicator can see its own historical data. The strategy can see that historical data as well, but will not process its logic until it's in State.Realtime

Quote:
But you failed to respond directly to my comment that the reference passed to AddChartIndicator() is of any importance.

I'm saying that that indicator reference is important.

That act of creating that reference to pass to AddChartIndicator() happens to provide a very subtle service to the strategy, which is (see my previous post): "it allows the indicator to be instantiated in time such that it is guaranteed to process all historical bars in its own OnBarUpdate."

Is that statement true or false?
I don't believe that its as important as you are making it out to be. That would not help the indicator to process more or less historical data in its own OnBarUpdate(). I believe it is more efficient than defining that indicator each time, but it will not boost your historical data loading times

Are you implying that if you used the indicator elsewhere and do not pass a reference into AddChartIndicator that it would not be guaranteed to process all historical bars in its own OnBarUpdate?
NinjaTrader_JoshG is online now  
Reply With Quote
Old 05-25-2018, 01:38 AM   #15
bltdavid
Senior Member
 
Join Date: Dec 2013
Location: Silicon Valley, California
Posts: 759
Thanks: 30
Thanked 260 times in 220 posts
Default

Quote:
Originally Posted by NinjaTrader_JoshG View Post
In the situation you are describing the indicator can see its own historical data. The strategy can see that historical data as well, but will not process its logic until it's in State.Realtime
Huh? Here again, you lack specificity. You said 'can see'. Ok, do you really mean capable of seeing or actually seeing and processing the same historical data as seen by the strategy? The capability of MACD "seeing" historical data is not at issue.

Quote:
Originally Posted by NinjaTrader_JoshG View Post
That would not help the indicator to process more or less historical data in its own OnBarUpdate(). I believe it is more efficient than defining that indicator each time, but it will not boost your historical data loading times.
I never mentioned 'boosting' of load times, that is not at issue.

Quote:
Originally Posted by NinjaTrader_JoshG View Post
Are you implying that if you used the indicator elsewhere and do not pass a reference into AddChartIndicator that it would not be guaranteed to process all historical bars in its own OnBarUpdate?
Exactly!

At least, that's what I keep asking you for confirmation.

If this is the only code in the strategy where MACD(12,26,9) is called,

Code:
protected override void OnBarUpdate()
{
     if(State==State.Historical)return;
     if(MACD(12,26,9) <test against condition ABC>)
         EnterLong();
     else if (MACD(12,26,9) <test against condition XYZ>)
         EnterShort();
}
Then please explain how the MACD is able to see and process any historical data in its own OnBarUpdate?

We all know MACD is capable of processing historical data, but in the above case, what happens? Does the MACD(12,26,9) process any historical data or not?

If you assert that the MACD(12,26,9) will process the same amount of historical data that the strategy processes (the strategy effectively ignores all its historical data, but it still sees all of it and processes all of it by returning early), then please explain how MACD(12,26,9) is able to see those same historical bars?

For example, using the OnBarUpdate above, if the first realtime bar is CurrentBar=5000, does the MACD(12,26,9) process historical bars 0 - 4999 or not?
Last edited by bltdavid; 05-25-2018 at 09:28 AM. Reason: OnBarUpdate returns early, not false
bltdavid 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
Live stop/target order behavior different than sim behavior brohnhdon Strategy Development 4 05-15-2018 03:32 PM
ATM Behavior: MIT order with pre-set Stop behavior AsterixBT Strategy Development 3 02-08-2018 12:20 PM
Start Behavior Yesiam Strategy Development 5 04-04-2017 08:40 AM
Difference between Time Frame start and manual Strategy start Turtle Trader Strategy Development 7 06-15-2010 08:09 AM
Stop and Start behavior Turtle Trader Strategy Development 1 04-28-2010 01:49 PM


All times are GMT -6. The time now is 07:10 AM.

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.