Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Trading on level 2 values
Collapse
X
-
-
on market depth update
Hi,
I have a problem,
I took the SampleMarketDepth indicator code from the previous post (the one given by ninja trader), and made some changes. The ideal was that I wanted to print the complete book every time a value in my book changed.
so I took the :
and placed it in the :PHP Code:// Prints the L2 Ask Book we created. Cycles through the whole List and prints the contained objects. Print("Ask Book"); for (int idx = 0; idx < askRows.Count; idx++) Print("Ask Price=" + askRows[idx].Price + " Volume=" + askRows[idx].Volume + " Position=" + idx); // Prints the L2 Bid Book we created. Cycles through the whole List and prints the contained objects. Print("Bid Book"); for (int idx = 0; idx < bidRows.Count; idx++) Print("Bid Price=" + bidRows[idx].Price + " Volume=" + bidRows[idx].Volume + " Position=" + idx);
with the rest of the code on top. (I included a picture of my problem)PHP Code:protected override void OnMarketDepth(MarketDepthEventArgs e) { }
NOTE : I know that the comment says that it cycles through the book, but I need this to stop - I want to update the whole book. (I want to see the full 10 bid and ask every time the book updates)
Where do I need to make the change?
Thanks
JP
-
cummulative dept - onmarket order
Found the answer, although I think my code could be simplified... if anyone knows how I would be very happy.
Anyway, to transform the SampleMarketDepth.cs indicator code that was given by ninjatrader into a strategy and to give you cummulative depth you do this:
1) add variables :
=== From ===
[PHP]
2) then in OnMarketDepth(MarketDepthEventArgs e)PHP Code:private long sum1 = 0; private long sum2 = 0; private int bidbookfilled=0; private int askbookfilled=0;
=== From ===
=== To ===PHP Code:protected override void OnMarketDepth(MarketDepthEventArgs e) { // Prints the L2 Ask Book we created. Cycles through the whole List and prints the contained objects. Print("Ask Book"); for (int idx = 0; idx < askRows.Count; idx++) Print("Ask Price=" + askRows[idx].Price + " Volume=" + askRows[idx].Volume + " Position=" + idx); // Prints the L2 Bid Book we created. Cycles through the whole List and prints the contained objects. Print("Bid Book"); for (int idx = 0; idx < bidRows.Count; idx++) Print("Bid Price=" + bidRows[idx].Price + " Volume=" + bidRows[idx].Volume + " Position=" + idx);
3) and the rest is the same.PHP Code:protected override void OnMarketDepth(MarketDepthEventArgs e) { // Prints the L2 Ask Book we created. Cycles through the whole List and prints the contained objects. ///Print("Ask Book"); for (int idx = 0; idx < askRows1.Count; idx++) { ///Print("Ask Price=" + askRows1[idx].Price + " Volume=" + askRows1[idx].Volume + " Position=" + idx); if (idx == 9) { askbookfilled=1; sum1 = askRows1[0].Volume + askRows1[1].Volume + askRows1[2].Volume + askRows1[3].Volume + askRows1[4].Volume + askRows1[5].Volume + askRows1[6].Volume + askRows1[7].Volume + askRows1[8].Volume + askRows1[9].Volume ; } } // Prints the L2 Bid Book we created. Cycles through the whole List and prints the contained objects. ///Print("Bid Book"); for (int idx = 0; idx < bidRows1.Count; idx++) { ///Print("Bid Price=" + bidRows1[idx].Price + " Volume=" + bidRows1[idx].Volume + " Position=" + idx); if (idx == 9) { bidbookfilled=1; sum2 = bidRows1[0].Volume + bidRows1[1].Volume + bidRows1[2].Volume + bidRows1[3].Volume + bidRows1[4].Volume + bidRows1[5].Volume + bidRows1[6].Volume + bidRows1[7].Volume + bidRows1[8].Volume + bidRows1[9].Volume ; } } if (bidbookfilled==1 && askbookfilled==1) { Print("OnMarketDepth()"); Print("Time : " + DateTime.Now.ToLongTimeString()); Print("Cummulative Dept ASK is " + sum1 ); Print("Cummulative Dept BID is " + sum2 ); bidbookfilled=0; askbookfilled=0; Print(Environment.NewLine); }
4) ***if you know how to simplify this please reply and give the code.
ChanceHero
Comment
-
saving output
Hi,
I have a SERIOUS problem
I am trying to save some values from a strategy to a text file, the problem is that I call upon
and in variables:PHP Code:using System.IO; using System.Text;
and in the code:PHP Code:TextWriter tw = new StreamWriter("c:\\strat_data.txt");
PHP Code:tw.WriteLine(DateTime.Now.ToLongTimeString() + "," + ask );
the problem is that the system IO is interfering with my actually being able to load the strategy (it simply disappears from my options)
HELP,
ChanceHeroLast edited by chancehero; 02-05-2012, 11:17 AM.
Comment
-
YUp, just disappeared, regardless, I used the link below and just did that and it worked.
ChanceHero
Comment
-
random numbers and saving their values
Hi,
new problem, I am generating a log of a random number and I need to use the previous generated values (lets say the last 10 values) in the OnMarketDepth.
This is what I have up to now. Any leads on how I can do this?
PHP Code:#region Variables private double x; //random number private double logx; // log of random number #endregionPHP Code:protected override void OnMarketDepth(MarketDepthEventArgs e) { { Random RandomClass = new Random(); x = RandomClass.Next(0, 10); logx=Math.Log(x); } }
thanks,
ChanceHero
Comment
-
list
hi,
exactly, felling pretty stupic right now
. Thanks , the list is perfect.
Next Question
I am noticing something with the
I am calling this in onMarketDepthPHP Code:random RandomClass = new Random(); x = RandomClass.Next(0, 10); logx=Math.Log(x);
and the random number has a clear time component to it. it clearly uses hours, minutes and seconds and 1/2 seconds. since it spits out the same value within 1/2 a second. I included my output file.
time , log (random) , and some other number which is update every time onmarketdepth is called.
how can I get a random number which will actually be updated with onmarketdepth?
ThanksAttached Files
Comment
-
random number time problem
sorry, to clarify,
the random number is called , when ever the lvl2 book is updated and fully rebuilt. (I have 10 ask and 10 bid)
i guess, what I am asking is it their other pseudo random number generator which don't have a time component ? because I need this at that precise time - and can't have the random number lagging.
ChanceHero
Comment
-
I would closely review the comments made here as the challenges you run into are mentioned as well - http://www.dotnetperls.com/random
So far I've not personally worked in this area, but the above should give you hopefully some hints to tackle it.
Comment
-
thanks, it worked ok.
in onmarketdepth, how do I create a condition to make sure I have enough data. (the same ideal as if I have a MA of 5 periods, to make sure I have 5 data points.)
ChanceHero
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
596 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
556 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
554 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment