Thanks.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
OnBarUpdate & OnMarketDepth
Collapse
X
-
dsraider,Originally posted by dsraider View PostMy code has OnBarUpdate followed by OnMarketDepth. I print from OnBarUpdate. Is there a way to grab a parameter from OnMarketDepth, like e.Price, and print from OnBarUpdate?
Thanks.
You can Print from OnMarketDepth.
RJay
-
rt6176,
Thanks but my If ---> Print statement is in OnBarUpdate. I have no problem moving Print down to Depth but I'm not sure if that's possible, as I don't know how to make one communicate with the other. Maybe a bool in OnBar following by an If (bool = true) Print in Depth?
Comment
-
Hi dsraider,Originally posted by dsraider View Postrt6176,
Thanks but my If ---> Print statement is in OnBarUpdate. I have no problem moving Print down to Depth but I'm not sure if that's possible, as I don't know how to make one communicate with the other. Maybe a bool in OnBar following by an If (bool = true) Print in Depth?
If you define the variable you want to print in the Initialize area, you can call it from any method.
You can assign a value to the variable in OnMarketDepth and you can print it from OnBarUpdate.
RJay
Comment
-
Hey RJay,
That sounds perfect but I can't seem to compile:
I'm sure I did something stupid. Do you see it?PHP Code:protected override void Initialize() { double lastPrice = 0; } protected override void OnBarUpdate() { Print(lastPrice); } protected override void OnMarketDepth(MarketDepthEventArgs e) { double lastPrice = e.Price; }
Comment
-
Your lastPrice variables are completely different and independent variables because of the way that you have defined them. They are each local to the scope where they are defined and so totally unrelated, despite the identity of name.Originally posted by dsraider View PostHey RJay,
That sounds perfect but I can't seem to compile:
I'm sure I did something stupid. Do you see it?PHP Code:protected override void Initialize() { double lastPrice = 0; } protected override void OnBarUpdate() { Print(lastPrice); } protected override void OnMarketDepth(MarketDepthEventArgs e) { double lastPrice = e.Price; }
Instead define the lastPrice in the "Variables" section, so that it is a class variable. Then access the variable from any event, by direct query.
Comment
-
Hey koganam,
I hear you loud and clear and that is what I normally do. The problem here, though, is that I'm trying to print OnMarketDepth data from OnBarUpdate because I need the OnBarUpdate logic to decide whether or not to print.
Defining lastPrice in Variables and then printing in OnBarUpdate just throws me a "0."
Maybe there's another way to print MarketDepth data from OnBar?
Comment
-
Originally posted by dsraider View PostHey koganam,
I hear you loud and clear and that is what I normally do. The problem here, though, is that I'm trying to print OnMarketDepth data from OnBarUpdate because I need the OnBarUpdate logic to decide whether or not to print.
Defining lastPrice in Variables and then printing in OnBarUpdate just throws me a "0."
Maybe there's another way to print MarketDepth data from OnBar?- You declare/define lastPrice as a class variable.
- You assign lastPrice in OnMarketDepth().
- You print/output lastPrice in OnBarUpdate().
You must assign a variable a value before you can see what value you assigned it.
Comment
-
I believe I understand you correctly but I'm still getting 0s with this:
PHP Code:#region Variables double lastPrice = 0; #endregion protected override void OnBarUpdate() { Print(lastPrice); } protected override void OnMarketData(MarketDepthEventArgs e) { double lastPrice = e.Price; }
Comment
-
Originally posted by dsraider View PostI believe I understand you correctly but I'm still getting 0s with this:
PHP Code:#region Variables double lastPrice = 0; #endregion protected override void OnBarUpdate() { Print(lastPrice); } protected override void OnMarketData(MarketDepthEventArgs e) { double lastPrice = e.Price; }
You need live market data or replay data running for this to work.Last edited by RJay; 01-29-2012, 03:38 PM.
Comment
-
I believe that I strongly advised you to access the value, without redeclaring it for local scope?Originally posted by dsraider View PostI believe I understand you correctly but I'm still getting 0s with this:
PHP Code:#region Variables double lastPrice = 0; #endregion protected override void OnBarUpdate() { Print(lastPrice); } protected override void OnMarketData(MarketDepthEventArgs e) { double lastPrice = e.Price; }
OK, I know I did not put it in quite those words.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
603 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
349 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
104 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
560 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment