Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Trading on level 2 values
Collapse
X
-
Comment
-
ok, maybe I explained it wrong.
im in onmarketdepth,
and I am generating a few list and collecting data every time onmarketdepth is called. then I proceed to calculate some average with this data. Lets say I need 10 past values from those list,
right now I obviously get an error from ninjatrader saying that I don't have that data.
This strategy has no chart of any kind, and runs free of a specified bar size.
I was thinking of making a counter and then when it reaches 10, then I could calculate my average?,
I know this may seem weird, but after 10 updates, I dont need this counter to keep going. how should I stop it.
ChanceHero
Comment
-
thanks,
that might work as well, ill let you know.
also, since my data is getting generated a such a high speed, I can physically see my RAM usage going up every second. Right now this is not a problem but I am not actually doing anything but generating values and it eats up 100 mb in 1 minute. Any treads which discuss having list which only hold the last 100 - 10000 observations - so that my RAM is not overloaded with values which are never going to be used?
ChanceHero
Comment
-
You could look into using an alternative data structure like queque or stack, or trim the array list as needed - http://msdn.microsoft.com/en-us/libr...rimtosize.aspx
Comment
-
cancel order, exitlonglimit and exitlonstoplimit
I am getting am error and its driving me nuts.
when I get a signal, and all oks :
1) it places a limit long entry
2) if it gets filled then the profit and exit are placed
3) otherwize, if the price runs up on me then my order is canceled.
==) I get :
**NT** Error on calling 'OnMarketDepth' method for strategy 'BidAskRatio/6adb6b5c588247dd86627f55af5cab79': Object reference not set to an instance of an object.
I just cant see the mistake.... help
PHP Code:protected override void OnMarketDepth(MarketDepthEventArgs e) { updateOrderBook(e); //We really don't care about the data itself, just that we update ourselves when the data changes. // check if an order is taken place Print(DateTime.Now.ToLongTimeString()+ " " +current.ToString("0.000000000") +" " + previous.ToString("0.000000000")); if(Position.MarketPosition == MarketPosition.Flat){ Print(DateTime.Now.ToLongTimeString() + " no position "); entryOrderLong = null; } else{ Print(DateTime.Now.ToLongTimeString() + " in position "); } Print(DateTime.Now.ToLongTimeString() + " reset passed "); if (entryOrderLong == null && Position.MarketPosition == MarketPosition.Flat) { buytest0=true; Print(DateTime.Now.ToLongTimeString() + " long test 0 = " + buytest0); } else { buytest0=false; Print(DateTime.Now.ToLongTimeString() + " long test 0 = " + buytest0); } Print(DateTime.Now.ToLongTimeString() + " test 0 done "); //going long if (urrent> previous){ //pass first test buytest1=true; Print(DateTime.Now.ToLongTimeString() + " long test 1 = " + buytest1); } else { buytest1=false; Print(DateTime.Now.ToLongTimeString() + " long test 1 = " + buytest1); } Print(DateTime.Now.ToLongTimeString() + " test 1 done "); // signal 2 is ok. this now is simply garbage condition if(buytest1==true){ buytest2 =true; Print(DateTime.Now.ToLongTimeString() + " long test 2 = " + buytest2); } else { buytest2=false; Print(DateTime.Now.ToLongTimeString() + " long test 2 = " + buytest2); } Print(DateTime.Now.ToLongTimeString() + " test 2 done "); //no position are open or waiting and signal #1 , #2 is ok. if (buytest0 == true && buytest1 == true && buytest2 == true){ entryOrderLong = EnterLongLimit(1,GetCurrentBid() ,"golong1"); // print some coments Print(DateTime.Now.ToLongTimeString() + " all test pass " ); Print(DateTime.Now.ToLongTimeString() + " entering long " ); //set some values to be able to canel the trade longcancel = GetCurrentAsk()+(2*TickSize); Print(DateTime.Now.ToLongTimeString() + " long cancel = "+ longcancel.ToString("0.00") ); } Print("cancel test 5 initial cancel = " + canceltest5); if(canceltest5==true){ //if the pending order / working order is placed and was passed by two ticks, then cancel the trade Print("cancel long limits- " + longcancel.ToString("0.00") + GetCurrentAsk().ToString("0.00")); Print("cancel test 5 before cancel = " + canceltest5); Print("order status" + entryOrderLong.ToString()); if ( canceltest5==true &&GetCurrentAsk() >= longcancel ){ Print("in - just before a cancel"); CancelOrder(entryOrderLong); Print("Price is beyond range of the limit: cancel trade and retry "); //entryOrderLong = null; } } previous = current; return; } //end of onmarketdepth protected override void OnOrderUpdate(IOrder entryOrderLong){ if(entryOrderLong.OrderState == OrderState.Working){ canceltest5=true; Print("cancel test 5 in the place where we set equal to true = " + canceltest5); } if (entryOrderLong.OrderState == OrderState.Filled){ canceltest5=false; exitlonglimit1 = ExitLongLimit(1, Position.AvgPrice+2*TickSize, "initprofit1","golong1"); Print(DateTime.Now.ToLongTimeString() + " setting profit limit at price " + Position.AvgPrice+4*TickSize); exitlongstoplimit1 = ExitLongStopLimit(1,Position.AvgPrice - (4 * TickSize),Position.AvgPrice - (4 * TickSize), "stoploss1","golong1"); Print("cancel test 5 = " + canceltest5); } return; }
Comment
-
chancehero, you would need to look into isolating the faulty code section via try / catch - http://www.ninjatrader.com/support/f...ead.php?t=9825
You are likely missing a check for null while accessing your IOrder properties.
Comment
-
thanks found it,
do you know of any threads that deal with unmanaged orders, thee help file is rather light
thanks
Comment
-
Unfortunately I'm not aware of any really here. Think of it like a simplified stripped down order entry scheme, allowing for only Submit, Change and Cancel orders. The rest would be dealt with in your custom code, so the ultimate flexibility without any order handling rules / limitations implied by NT's internal framework that would be 'guarding' the managed approach normally.
Signal tracking wise comparable to the ATM Strategy Create() methods for invoking ATM's from NinjaScripts.
Comment
-
ok,
I have changed my code to use unmanaged. the idea I get from this is that you have to be explicit about all that you do.
Comment
-
stop strategy after profit threshold reached
hi,
what do I do if I want to stop my strategy after it reaches a certain level of profit.
ex:
PHP Code:protected override void OnMarketDepth(MarketDepthEventArgs e) { if( Performance.AllTrades.TradesPerformance.GrossProfit >=100 ){ // stop strategy. } }
Comment
-
count
hi, thanks for the help, worked like a charm - exactly what I wanted
next question
do you know of any treads that discuss tracking your position in the while the order has been accepted but has not been filled.
the ideal that I am having trouble with is that I know if a contract has been sold at the price
thus if im waiting to be filled, then I know I am moving up, but I still have no idea when the number of pending contracts increase , and then drop, where the drop is , behind or in front of me.
let me know if you dont understand or need some clarifications.
thanks
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
616 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
357 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
561 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
566 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment