Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
CalculateOnBarClose in strategy vs indicator
Collapse
X
-
Hello Tony,
I would not suggest using FirstTickOfBar in OnMarketData. See post #15 for a workaround.
The code will not work the same as it works in OnBarUpdate.
Please try and explain what you are trying to do without using an example.
What I think you are asking is:
"In OnMarketData, how do I tell what BarsInProgress is processing and if that update of OnMarketData is the first tick of a new bar for that BarsInProgress?"
Can you simplify your question or let me know that this is what you are asking?Last edited by NinjaTrader_ChelseaB; 09-17-2015, 12:31 PM.
-
Hello,
thank you for your reply. To answer the question and to explain please:
I refer only to ES and I have a strategy in a 1-min-chart with COBCfalse because I need IndicatorA with COBCfalse. And I have accurate conditions in onmarketdata. And I have indicatorA also in onmarketdata (as it works anyway with COBCfalse). All clear and this should work ok, yes?
The other condition I need is closes[1][0]>opens[1][0] of my secondary dataseries which is a small range-chart. I read in the replies here that FirstTickOfBar doesnt work in onmarketdata. This I understand. But my question now is if its maybe not important for secondary dataseries if the condition is in onmarketdata or onbarupdate (as onbarupdate refers to the primary dataseries, no?). So, I think I could code the secondary dataseries closes[1][0]>opens[1][0]&&FirstTickOfBar in onmarketdata and in onbarupdate and should work same. Is this correct? NEW QUESTION that appears now when writing these lines is if its necessary to code FirstTickOfBar(dataseries2), if this code exists. I think its not necessary because as the condition is in onmarketdata it will be automatically the next tick after closes[1][0]>opens[1][0]???
Thank you for your support
Tony
Leave a comment:
-
Hi Tony,
Ok, so what I understand is you want to call the secondary series from OnMarketData. I think you want to distinguish which dataseries the tick is coming from that is updating OnMarketData, is this correct?
The BarsInProgress is somewhat specific to OnBarUpdate. In otherwords, while the bar is building or closing, you will get OnMarketData updates for all dataseries sporadically as they come in. If both series are the same instrument, then OnMarketData will apply to both since they are both using the same prices. The bar series index doesn't matter here.
If you using two different instruments, which have two different market update prices, then you can use the MarketDataEventArgs.MarketData.Instrument object to see what the instrument name is. This will distinguish between different instruments. When using the same instrument, it doesn't matter because the market update price is used for both data series.
For example:
Code:protected override void OnMarketData(MarketDataEventArgs e) { Print(e.Price+" - "+e.MarketData.Instrument); }
Now with that said, if you are calling your indicator from another indicator or from a strategy, how are you planning to pass that information you've gotten from OnMarketData to the caller indicator or strategy?Last edited by NinjaTrader_ChelseaB; 09-16-2015, 02:28 PM.
Leave a comment:
-
Chelsea,
last try to this matter: When I have my conditions I need of primary dataseries in onmarketdata and I want to have also for secondary dataseries eg Closes[1][0]>Opens[1][0] does this work when I add this Closes[1][0]>Opens[1][0] in onmarketdata so that eg an entry is triggered when onmarketdata conditions on tickbasis are true AND the closes... of secondary dataseries? So that I dont need a variable and bring up secondary dataseries conditions closes... in onbarupdate seperately? With Closes[1][0]>Opens[1][0] I have then the COBCtrue for the secondary dataseries (even when this is coded in onmarketdata)?
I hope I could translate correctly to describe what I mean.
Thank you for your support!
Tony
Leave a comment:
-
Hi Tony,
Basically yes, if you are using the Strategy Wizard you can use one of the user variables as a substitute for a bool. 0 for false 1 for true. This essentially becomes a trigger that is set only when a new bar arrives.
When I mention plot to a dataseries, I really just mean that your 5 minute script is going to be making calls every 5 minutes and will only have a value from the indicator every 5 minutes when it calls it.
Really I'm just now sure how you plan to use this information or what you are trying to do. If you want to store it, then you need a data series to store it.
Below is a link to the help guide on the dataseries class.
http://ninjatrader.com/support/helpG...ries_class.htm
But to answer your question, yes, you can definitely add a secondary series to an indicator and do calculations with this, and then call the indicator from the strategy.
Leave a comment:
-
Hello Chelsea,
thank you for your reply.
Referring b.) Do I understand right to simply set eg Variable1=1 when condition is true in onmarketdata and then to use in onbarupdate "if(Variable1==1 and FirstTickOfBar) then do"?
Referring c.) how do you mean "plot to a secondary dataseries" please?
Referring LiveUntilCancelled (not manually of course): this would be the same then as here with c.) means with a plot from secondary dataseries? Or would that be more easy? And "YES the secondary dataseries is using the same instrument".
Thank you for your support
Tony
Leave a comment:
-
Hi Tony,
a) OnMarketData is similar to Calculate on bar close but includes more information and does not work historically (at all). With Calculate on bar close there is an update to OnBarUpdate for every last tick. With OnMarketData, there is update for every last, bid, and ask tick.
b) FirstTickOfBar does not work in OnMarketData, however, you could make your own variable that is a bool. Set the bool to false, until OnBarUpdate triggers, and then set it to true. The next tick in OnMarketData can see that is true and you can consider this update the first tick of the next bar. Then set the bool back to false waiting for the next bar to set it back to true.
c) If you are using a 5 minute chart and you have an indicator that is calling a 2 minute secondary series for calculations, you are still only going to get a value once every 5 minutes. An indicator plot is synced with the primary bar series (unless you use special code to sync this to a secondary series). In other words, the plot is only going to have 1 value for every 5 minute bar and won't have indexes for the 2 minute bars in between. So even though you can call the secondary series, you wouldn't have a place to store it since it has more bars than the larger time-frame. (Though again, you can sync a plot to a secondary series so that may be a workaround)
When it comes to liveUntilCancelled, the secondary timeframe can cause your order to be cancelled IF the secondary series is using the same instrument.
But you can of course manually cancel an order at anytime from any bars in progress.
Leave a comment:
-
Hello Chelsea,
thank you for your reply. Let me do the question different please for understanding all this:
a.) I work with conditions in onmaketdata in my script-strategy. When in Initialize is COBC=true then the conditions in onmarketdata work nevertheless on tick (like COBC=false) Correct?
b.) when I use for one of the conditions in onmarketdata "&&FirstTickOfBar" will this work then with close of bar or not because in onmarketdata there is no FirstTickOfBar possible?
c.) when I have a script-strategy running lets say in a 5 min chart. And I add an indicator with 1 min chart. And lets say after 2 minutes the "1-minute-indicator" shows the condition - will this work after 2 minutes (with COBCtrue of 2nd 1-minute-bar) in my script or only after 5 minutes (with COBCtrue of the 5 min bar)? Accurate example I need it for: an entrylimitorder I have in the 5 min chart working should be cancelled with a condition from the 1-minute-chart. If the 1-minute-chart-condition is true after 2 minutes, will this cancel the limitorder after 2 minutes at end of the 1-minute-bar (COBCtrue of the 1 minute) or only after the close of the 5min bar where the strategy is on?
Thank you
Tony
Leave a comment:
-
Hi Tony,
While NinjaTrader does not prevent an indicator from being set to Calculate on bar close as False while the calling script is set with Calculate on bar close is set to True, I have seen behavior where the updates to OnBarUpdate are out of order when this is the case. Our development discourages using different Calculate on bar close settings for a calling and callie script.
(The behavior is that you may see all of the historical updates of the indicator script all at once when the strategy starts instead of seeing the scripts alternate in OnBarUpdate() updates when processing historical data.)
If a strategy is set with Calculate on bar close as False, it will call the indicator with Calculate on bar close False as well.
Leave a comment:
-
tonynt,
I'm pretty sure that if you initialize the strategy with COBC = true then the indicators must also be COBC = true. But, we can leave it to the NT people to confirm.
Then for the indicators, it's a matter of putting them in the appropriate BarsInProgress. Of course, you can have a 1 quote or 1 trade bar, too.
Leave a comment:
-
COBC strategy - indicator
Hello,
what if the strategy is running COBC=true, is it then possible to have an indicator working with COBC=false?
And is it possible to have the indicator in another dataseries with different COBC
stragegy dataseries 1 minute with COBC=false and indicator used in the script with 2 Range and COBC=true
or
strategy dataseries 1 minute with COBC=true and indicator used in the script with 2 range and COBC=false?
Thank you
Tony
Originally posted by NinjaTrader_ChelseaB View PostHello pbmi66,
In this situation, do you have Calculate on bar close set to false as says is required in the documentation?
Are you running this in historical data? (With historical data Calculate on bar close is always true. From the help guide:
When indicators or strategies are running on historical data, OnBarUpdate() is only called on the close of each historical bar even if this property is set to false
http://www.ninjatrader.com/support/h...onbarclose.htm
Leave a comment:
-
Hello pbmi66,
Originally posted by pbmi66 View PostHi,
I think the documentation on FirstTickOfBar should be expanded to explain how it works/doesn't work with regard to Historical data processing.
For example, let's say you want to back-fill a 1-Min indicator, built on a tick-by-tick basis, with historical tick data via:
Add(this.Instrument.FullName,PeriodType.Tick,1,Mar ketDataType.Last); //BarsInProgress==1
In this scenario, when Ninja is processing Historical data :
- it first calls OnBarUpdate for EACH tick of the primary bar (the 1-Min bar), with BarsInProgress==1 (the .Last series), and
- then calls OnBarUpdate for the LAST tick of the primary bar (the 1-Min bar) with BarsInProgress=0.
[ie, it will call OnBarUpdate twice for the LAST tick]
But, FirstTickOfBar is always true, which is incorrect when BarsInProgress==0.
Furthermore, a reference to Close[0] or Closes[0][0] when BarsInProgress==0 will refer to the LAST tick.
Are you running this in historical data? (With historical data Calculate on bar close is always true. From the help guide:
When indicators or strategies are running on historical data, OnBarUpdate() is only called on the close of each historical bar even if this property is set to false
http://www.ninjatrader.com/support/h...onbarclose.htm
Leave a comment:
-
Originally posted by NinjaTrader_ChelseaB View PostHi bluelou,
FirstTickOfBar will only work in real-time data and does not work in backtest.
From the help guide:
"Indicates if the incoming tick is the first tick of a new bar. This property is only of value in scripts that run tick by tick which is when the CalculateOnBarClose property is set to false.
NOTE: This property should NOT be accessed outside of the OnBarUpdate() method."
http://www.ninjatrader.com/support/h...ttickofbar.htm
I have never found FirstTickOfBar to work incorrectly. Do you have an example "toy" script that can reproduce this?
I think the documentation on FirstTickOfBar should be expanded to explain how it works/doesn't work with regard to Historical data processing.
For example, let's say you want to back-fill a 1-Min indicator, built on a tick-by-tick basis, with historical tick data via:
Add(this.Instrument.FullName,PeriodType.Tick,1,Mar ketDataType.Last); //BarsInProgress==1
In this scenario, when Ninja is processing Historical data :
- it first calls OnBarUpdate for EACH tick of the primary bar (the 1-Min bar), with BarsInProgress==1 (the .Last series), and
- then calls OnBarUpdate for the LAST tick of the primary bar (the 1-Min bar) with BarsInProgress=0.
[ie, it will call OnBarUpdate twice for the LAST tick]
But, FirstTickOfBar is always true, which is incorrect when BarsInProgress==0.
Furthermore, a reference to Close[0] or Closes[0][0] when BarsInProgress==0 will refer to the LAST tick.
Leave a comment:
-
Originally posted by NinjaTrader_ChelseaB View PostHi bluelou,
FirstTickOfBar will only work in real-time data and does not work in backtest.
From the help guide:
"Indicates if the incoming tick is the first tick of a new bar. This property is only of value in scripts that run tick by tick which is when the CalculateOnBarClose property is set to false.
NOTE: This property should NOT be accessed outside of the OnBarUpdate() method."
I have never found FirstTickOfBar to work incorrectly. Do you have an example "toy" script that can reproduce this?
Leave a comment:
-
ChelseaB,
Yes, sorry, you are correct, FTOB has no effect on a backtest. No, sorry, I don't have any toy script. FWIW, I'd say it fails to mark a new bar around 1 out of 1000 bars. I have it in an indicator which I'm recoding so I can remove it.
~Lou
Originally posted by NinjaTrader_ChelseaB View PostHi bluelou,
FirstTickOfBar will only work in real-time data and does not work in backtest.
From the help guide:
"Indicates if the incoming tick is the first tick of a new bar. This property is only of value in scripts that run tick by tick which is when the CalculateOnBarClose property is set to false.
NOTE: This property should NOT be accessed outside of the OnBarUpdate() method."
http://www.ninjatrader.com/support/h...ttickofbar.htm
I have never found FirstTickOfBar to work incorrectly. Do you have an example "toy" script that can reproduce this?
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, 04-17-2024, 06:40 PM
|
6 responses
49 views
0 likes
|
Last Post
by algospoke
Today, 06:18 PM
|
||
Started by arvidvanstaey, Today, 02:19 PM
|
4 responses
11 views
0 likes
|
Last Post Today, 04:08 PM | ||
Started by samish18, 04-17-2024, 08:57 AM
|
16 responses
61 views
0 likes
|
Last Post
by samish18
Today, 03:30 PM
|
||
Started by jordanq2, Today, 03:10 PM
|
2 responses
11 views
0 likes
|
Last Post
by jordanq2
Today, 03:23 PM
|
||
Started by traderqz, Today, 12:06 AM
|
10 responses
21 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
Leave a comment: