Thanks.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
OnBarUpdate & OnMarketDepth
Collapse
X
-
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
-
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:
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
-
Originally posted by dsraider View PostHey RJay,
That sounds perfect but I can't seem to compile:
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
-
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;
}
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Mestor, 03-10-2023, 01:50 AM
|
11 responses
303 views
0 likes
|
Last Post
by z.franck
Today, 02:29 AM
|
||
Started by Padan, Today, 02:02 AM
|
0 responses
6 views
0 likes
|
Last Post
by Padan
Today, 02:02 AM
|
||
Started by bukowa, 11-09-2023, 06:07 PM
|
20 responses
407 views
0 likes
|
Last Post
by Adfra
Today, 01:36 AM
|
||
Started by yertle, Yesterday, 05:49 PM
|
2 responses
11 views
0 likes
|
Last Post
by yertle
Today, 12:12 AM
|
||
Started by kaywai, Today, 12:06 AM
|
0 responses
10 views
0 likes
|
Last Post
by kaywai
Today, 12:06 AM
|
Comment