NexusFi: Find Your Edge


Home Menu

 





MIT/LIT anyone with good working example code?


Discussion in NinjaTrader

Updated
    1. trending_up 3,597 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread

MIT/LIT anyone with good working example code?

  #1 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184

Greets!

NT doesnt have a supported option for Market/Limit If Touched orders, and looking at the threads online I did find little to go on. Basically I am trying to get the same fill I get with market orders, but at a price that is closer to targets I would use in limit orders.

 
Code
		protected override void OnMarketData(MarketDataEventArgs e)
		
			if (e.MarketDataType == MarketDataType.Ask)

{

if ( e.Price >= touch_price )

    {

        EnterLimit ( ) ;

    }

}
.. and thats all .. TraderWerks 2009 May

This is a work in progress== I am trying to shift the order entry from OnBarUpdate to OnMarketData but am not sure if I am interpreting the intent/use correctly.

Guru response definitely appreciated,
Jon

Writing to you from the wonderful province of Ontario, Canada. Home to the world's biggest natural negative ion generator, the Niagara Falls, and to those that dare to know how to go over it in a barrel. SALUTE!
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Bigger Wins or Fewer Losses?
Traders Hideout
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465


The intent is that you look at the price every tick, with OnMarketData. So you are constantly looking at the price so that it gives you a lot of flexibility in order management.

Math. A gateway drug to reality.
Reply With Quote
  #4 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


traderwerks View Post
The intent is that you look at the price every tick, with OnMarketData. So you are constantly looking at the price so that it gives you a lot of flexibility in order management.

Hi traderwerks!

Thanks.. I do appreciate the response.

I am, I think, so ingrained in 'OnBarUpdate' mindset that I am having a conceptual challenge on how that will integrate together (with OnMarketData) to manage the trade.

For example, this is typically what my strategy orders from
 
Code
 {	if ( (Position.MarketPosition == MarketPosition.Flat) && (timeSeries[0] >= 1)  )
             // Try to go LONG
	{   if (	WatchToGoLong == 1 )	
	//
		{  if   ( BarsInProgress == 0 )
                   		 {	
		tVars.vLow = Close[0];
		tVars.vHigh = Close[0];
		tVars.cStopLossTicks = iStopLossTicks;
	SetStopLoss(CalculationMode.Ticks, tVars.cStopLossTicks * vTickMult);					
DrawTriangleUp(CurrentBar.ToString() + "sl", true, 0, Close[0] - tVars.cStopLossTicks * TickSize * vTickMult, Color.DarkGreen);
	// Enter Long
		if ((iOrderL1 == null && iQuantity1 != 0)
	iOrderL1 = EnterLongLimit(0, true, iQuantity1, Closes[0][0] + 2*TickSize, sENTRY1L);
and I am starting to think in this fashion to move the ordering into

 
Code
		protected override void OnMarketData(MarketDataEventArgs e)
		
			if (e.MarketDataType == MarketDataType.Ask)

{

if ( e.Price >= touch_price )

   {	
		tVars.vLow = Close[0];
		tVars.vHigh = Close[0];
		tVars.cStopLossTicks = iStopLossTicks;
	SetStopLoss(CalculationMode.Ticks, tVars.cStopLossTicks * vTickMult);					
DrawTriangleUp(CurrentBar.ToString() + "sl", true, 0, Close[0] - tVars.cStopLossTicks * TickSize * vTickMult, Color.DarkGreen);
	// Enter Long
		if ((iOrderL1 == null && iQuantity1 != 0)
	iOrderL1 = EnterLongLimit(0, true, iQuantity1, Closes[0][0] + 2*TickSize, sENTRY1L);
} 
}
with the OnBarUpdate just manages the indicators and conditions that go along with that
...

 
Code
{	if ( (Position.MarketPosition == MarketPosition.Flat) && (timeSeries[0] >= 1)  )
             // Try to go LONG
	{   if (	WatchToGoLong == 1 )	
	//
		{  if   ( BarsInProgress == 0 )
                   		 {  touch_price = Closes[0][0]  }
}
}
}
but my gut says that this is too simplistic and I am missing an element to have it function correctly. Input from your experience is definitely appreciated.

Jon

Writing to you from the wonderful province of Ontario, Canada. Home to the world's biggest natural negative ion generator, the Niagara Falls, and to those that dare to know how to go over it in a barrel. SALUTE!
Started this thread Reply With Quote
  #5 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465


Trader.Jon View Post
 
Code
		tVars.vLow = Close[0];
		tVars.vHigh = Close[0];
		tVars.cStopLossTicks = iStopLossTicks;
	SetStopLoss(CalculationMode.Ticks, tVars.cStopLossTicks * vTickMult);					
DrawTriangleUp(CurrentBar.ToString() + "sl", true, 0, Close[0] - tVars.cStopLossTicks * TickSize * vTickMult, Color.DarkGreen);

but my gut says that this is too simplistic and I am missing an element to have it function correctly. Input from your experience is definitely appreciated.

Jon

It is a good start but I would leave the above code for BarUpdate. You just need the parts that need to be in OnMarketData as small as possible. ( And it doesn't need to be there ).

OnBarUpdate DOES just manages the indicators and anything that has High[0], etc needs to be in there.

It is not as difficult as people think. I have been using limit with touch orders in my strats for a couple of years and trading live everyday for a while and they work nicely.

Math. A gateway drug to reality.
Reply With Quote
Thanked by:
  #6 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


traderwerks View Post

It is not as difficult as people think. I have been using limit with touch orders in my strats for a couple of years and trading live everyday for a while and they work nicely.

traderwerks,

Again, thanks for the share..

Just to clarify then, to sync my head, and nothing code specific ..

It really doesnt matter what chart type/period is being used, and you are using the normal(?!) available EnterLongStopLimit() with (I guess) true bool condition (because I am thinking on adding a cancel order if not filled in 2 bars etc). For some reason my feeling was there might be different Enter() commands only useable inside OnMarketData, but cant find any in the help

This has been REALLY helpful!

Thanks
Jon

Writing to you from the wonderful province of Ontario, Canada. Home to the world's biggest natural negative ion generator, the Niagara Falls, and to those that dare to know how to go over it in a barrel. SALUTE!
Started this thread Reply With Quote
  #7 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465


Trader.Jon View Post

It really doesnt matter what chart type/period is being used, and you are using the normal(?!) available EnterLongStopLimit() with (I guess) true bool condition (because I am thinking on adding a cancel order if not filled in 2 bars etc).

Well, you are mostly correct. It would be a EnterLongLimit order. No sense in putting a stop orde r in OnMarketData.


Trader.Jon View Post

For some reason my feeling was there might be different Enter() commands only useable inside OnMarketData, but cant find any in the help

OnMarketData is just like OnBarUpdate, only it happens a lot more often ( usually ). So anything you can use in OnBarUpdate, you can use in OnMarketData.

Math. A gateway drug to reality.
Reply With Quote
Thanked by:
  #8 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


traderwerks View Post
OnMarketData is just like OnBarUpdate, only it happens a lot more often ( usually ). So anything you can use in OnBarUpdate, you can use in OnMarketData.

traderwerks,

With your (much appreciated) assistance I was able to get an order placed and covered in a strategy, running parallel to orders placed with OnBarUpdate. I didnt change any of the entry handling code: just moved to code as suggested
 
Code
											#region Region_OnMarketData
//		
    protected override void OnMarketData(MarketDataEventArgs e)
					{
			 //Update bid / ask / spread variables
           UpdateBidAskSpread(out cAsk, out cBid, out cSpread);  
		

if ( e.Price == touch_price )

   {	Print("Last = "+e.Price);	 		
	if ((iOrderL1 == null || Historical) && iQuantity1 != 0)
	{	iOrderL1 = EnterLongLimit(0, true, iQuantity1, Closes[0][0] + 1*TickSize, sENTRY1L); 
		LL_EntryBar0_OMD_L1 = CurrentBars[0];
			Print("Entered LL_Order from OnMarketData PreviousBar#= "+CurrentBars[0]+", Time of bar=  "+Times[0][0]+", bar closed "+Closes[0][0]+", BarHI= "+Highs[0][0]+", BarLO= "+Lows[0][0]);
						
	}
	
	}
	
		}
Prints show me behaviour I expected, plus some I didnt. The orders in OnBarUpdate are only submitted once,
 
Code
 iOrderL5 = EnterLongStopLimit(0, true, iQuantity5, Closes[0][0]+ 2*TickSize, Closes[0][0]+ 1*TickSize, sENTRY5L);
	iOrderL2 = EnterLong(0, iQuantity2, sENTRY2L);
and are not submitted again when actively working, but the OnMarketData order is submitted on every tick even when working
 
Code
 	iOrderL1 = EnterLongLimit(0, true, iQuantity1, Closes[0][0] + 1*TickSize, sENTRY1L);
The 'entries per direction' is set to 1 so the orders are not sent out, but it is still bothersome that the order handling isnt working the same.

From the output:
 
Code
Last = 1.404
3/28/2011 7:45:55 AM Entered internal PlaceOrder() method at 3/28/2011 7:45:55 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.4041 StopPrice=0 SignalName='e1L' FromEntrySignal=''
3/28/2011 7:45:55 AM Ignored PlaceOrder() method at 3/28/2011 7:45:55 AM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.4041 StopPrice=0 SignalName='e1L' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
Entered LL_Order from OnMarketData PreviousBar#= 653, Time of bar=  3/28/2011 7:45:52 AM, bar closed 1.404, BarHI= 1.4052, BarLO= 1.404
Last = 1.404
3/28/2011 7:45:55 AM Entered internal PlaceOrder() method at 3/28/2011 7:45:55 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.4041 StopPrice=0 SignalName='e1L' FromEntrySignal=''
3/28/2011 7:45:55 AM Ignored PlaceOrder() method at 3/28/2011 7:45:55 AM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.4041 StopPrice=0 SignalName='e1L' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
Entered LL_Order from OnMarketData PreviousBar#= 653, Time of bar=  3/28/2011 7:45:52 AM, bar closed 1.404, BarHI= 1.4052, BarLO= 1.404
Last = 1.404
3/28/2011 7:45:56 AM Entered internal PlaceOrder() method at 3/28/2011 7:45:56 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.4041 StopPrice=0 SignalName='e1L' FromEntrySignal=''
3/28/2011 7:45:56 AM Ignored PlaceOrder() method at 3/28/2011 7:45:56 AM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.4041 StopPrice=0 SignalName='e1L' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
Entered LL_Order from OnMarketData PreviousBar#= 653, Time of bar=  3/28/2011 7:45:52 AM, bar closed 1.404, BarHI= 1.4052, BarLO= 1.404
Last = 1.404
Any thoughts or suggestions?
Jon

Followup: Even though the 1L long entry from OnMarketData was stopped out, the print is still showing entry price would be 1.404. The next bar closed 1.4030 and was a trigger bar for a market order L2 that was completed, but the e.Price still printing out at 1.4040

Writing to you from the wonderful province of Ontario, Canada. Home to the world's biggest natural negative ion generator, the Niagara Falls, and to those that dare to know how to go over it in a barrel. SALUTE!
Started this thread Reply With Quote
  #9 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465

After you place your order, reset your touch price or whatever so you don't get any more orders. The order will be cancelled at the end of the bar.

Math. A gateway drug to reality.
Reply With Quote
Thanked by:
  #10 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184



traderwerks View Post
After you place your order, reset your touch price or whatever so you don't get any more orders. The order will be cancelled at the end of the bar.

I think thats probably the only thing I havent tried yet
It is annoying that I am still restricted by bar updates (in a way)

Thanks,
Jon

Writing to you from the wonderful province of Ontario, Canada. Home to the world's biggest natural negative ion generator, the Niagara Falls, and to those that dare to know how to go over it in a barrel. SALUTE!
Started this thread Reply With Quote




Last Updated on March 28, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts