NexusFi: Find Your Edge


Home Menu

 





Need help with limit orders


Discussion in NinjaTrader

Updated
    1. trending_up 3,232 views
    2. thumb_up 4 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Need help with limit orders

  #1 (permalink)
 kuranushka 
Near CME
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, FDAX, GC, 6E
Posts: 6 since Apr 2012
Thanks Given: 5
Thanks Received: 11

Hi. I am a beginner programmist. I've got the following question: I make a limited order to enter short. After that it comes to a "Working" state. I want to cancel it so that I could enter long having canceled my short order. The commands follow each other one after another but the second order is ignored by my broker. What could you suggest me to do?

 
Code
...
CancelOrder(notFilledOrder);
o = EnterLongLimit(BarsInProgress, true, DefaultQuantity, GetCurrentBid() -2 * TickSize, "");
...

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
Better Renko Gaps
The Elite Circle
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #3 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394



kuranushka View Post
Hi. I am a beginner programmist. I've got the following question: I make a limited order to enter short. After that it comes to a "Working" state. I want to cancel it so that I could enter long having canceled my short order. The commands follow each other one after another but the second order is ignored by my broker. What could you suggest me to do?

Can you post a code fragment? It isn't clear how you are processing the transactions.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394

Okay,

Looks like you added the code fragment above. Just an FYI, subscribers (or previous posters) don't know you have updated your posting, somethings it is better to add another post so the notification goes out.

I suspect your broker is getting orders out of sequency from NT and/or screening your "Long" order out before successfully pulling your open order off the market. That means you might need a delay. Have you tried to simply reverse the order? If you are Long 2, send a Short 2 to see if it takes that order. This might leave you net 0 contracts, so you might need to go short 4. This might be a good question for your broker. Also, enabling Order Trace will help you determine what is happening:
TraceOrders

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 kuranushka 
Near CME
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, FDAX, GC, 6E
Posts: 6 since Apr 2012
Thanks Given: 5
Thanks Received: 11

full code:

 
Code
        protected override void OnBarUpdate()
        {
			if (writeLog)
				fileOut = new StreamWriter(new FileStream(fileName, FileMode.Append, FileAccess.Write));
			IOrder o = null;
			IOrder oe = null;

			if (BarsInProgress == 1)
			{
				//if(Historical) return;
				if (writeLog)
					fileOut.WriteLine(Time[0] + " - " + DateTime.Now.ToString() + " - Close[0][0] = " + Closes[0][0] + ", Open[0][0] = " + Opens[0][0] + ", Close[1][0] = " + Closes[1][0] + ", Open[1][0] = " + Opens[1][0] + ", BarsInProgress = " + BarsInProgress);
				
				if (Closes[0][0] > Opens[0][0] && Closes[1][0] > Opens[1][0])
				{
					if (writeLog)
						fileOut.WriteLine(Position.Quantity + " " + Position.MarketPosition + " -> " + "EnterLong: " + Time[0] + " Close[0][0] = " + Closes[0][0] + ", Open[0][0] = " + Opens[0][0] + " Close[1][0] = " + Closes[1][0] + ", Open[1][0] = " + Opens[1][0]);
					
					if (hasNotFilled)
					{
						if (writeLog)
							fileOut.WriteLine("OBUCancel " + Position.Quantity + " " + Position.MarketPosition + " -> " + notFilledOrder.ToString());
						CancelOrder(notFilledOrder);
					}
					if (Position.MarketPosition == MarketPosition.Short)
						ExitShort();
					o = EnterLongLimit(BarsInProgress, true, DefaultQuantity, GetCurrentBid() -2 * TickSize, "");
					
					if (writeLog)
					{
						if (o != null)
							fileOut.WriteLine("OBUEnterL " + Position.Quantity + " " + Position.MarketPosition + " -> " + o.ToString());
						else
							fileOut.WriteLine("EnterLong null");
					}
	//				EnterLongLimit(DefaultQuantity, Close[0], "");
				}
				if (Closes[0][0] < Opens[0][0] && Closes[1][0] < Opens[1][0])
				{
					if (writeLog)
						fileOut.WriteLine(Position.Quantity + " " + Position.MarketPosition + " -> " + "EnterShort: " + Time[0] + " Close[0][0] = " + Closes[0][0] + ", Open[0][0] = " + Opens[0][0] + " Close[1][0] = " + Closes[1][0] + ", Open[1][0] = " + Opens[1][0]);
					
					if (hasNotFilled)
					{
						if (writeLog)
							fileOut.WriteLine("OBUCancel " + Position.Quantity + " " + Position.MarketPosition + " -> " + notFilledOrder.ToString());
						CancelOrder(notFilledOrder);
					}
					if (Position.MarketPosition == MarketPosition.Long)
						ExitLong();
					o = EnterShortLimit(BarsInProgress, true, DefaultQuantity, GetCurrentAsk() + 2 * TickSize, "");
					
					if (writeLog)
					{
						if (o != null)
							fileOut.WriteLine("OBUEnterS " + Position.Quantity + " " + Position.MarketPosition + " -> " + o.ToString());
						else
							fileOut.WriteLine("EnterShort null");
	//				EnterShortLimit(DefaultQuantity, Close[0], "");
					}
				}
			}
			if (BarsInProgress == 0)
			{
				if (writeLog)
					fileOut.WriteLine(Time[0] + " - " + DateTime.Now.ToString() + " - Close[0][0] = " + Closes[0][0] + ", Open[0][0] = " + Opens[0][0] + ", Close[1][0] = " + Closes[1][0] + ", Open[1][0] = " + Opens[1][0] + ", BarsInProgress = " + BarsInProgress);

				if (Closes[0][0] > Opens[0][0])
				{
					oe = ExitShort();
					if (writeLog)
					{
						if (oe != null)
							fileOut.WriteLine("OBUExitS " + Position.Quantity + " " + Position.MarketPosition + " -> " + oe.ToString());
						else
							fileOut.WriteLine("ExitShort null");
					}
	//			ExitShortLimit(Close[0], "", "");
				}
				if (Closes[0][0] < Opens[0][0])
				{
					oe = ExitLong();
					if (writeLog)
					{
						if (oe != null)
							fileOut.WriteLine("OBUExitL " + Position.Quantity + " " + Position.MarketPosition + " -> " + oe.ToString());
						else
							fileOut.WriteLine("ExitLong null");
					}
//				ExitLongLimit(Close[0], "", "");
				}
			}
			if (writeLog)
				fileOut.Close();
		}
		
		protected override void OnOrderUpdate(IOrder order)
		{
			hasNotFilled = false;
			if (order.Name != "Profit target" && order.Filled == 0)
			{
				hasNotFilled = true;
				notFilledOrder = order;
			}
			
			if (writeLog)
			{
				fileOut = new StreamWriter(new FileStream(fileName, FileMode.Append, FileAccess.Write));
				fileOut.WriteLine("OOU " + Position.Quantity + " " + Position.MarketPosition + " -> " + order.ToString());
				fileOut.Close();
			}
		}

Follow me on Twitter Started this thread Reply With Quote
  #6 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394

Hummm....

Okay, you are venturing into a very complex system as best I can tell. If you need this feature you can get it to work, but I would review the IORDER status in your OnOrderUpdate():
IOrder


If it is flagged as FILLED then it is true, otherwise, it isn't filled. There is a Partial Fill, so be careful...

Also, since this is an OrderUpdate, you should probably put that logic in the OnExecution() function:
OnExecution()

A call here means it happened...

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 kuranushka 
Near CME
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, FDAX, GC, 6E
Posts: 6 since Apr 2012
Thanks Given: 5
Thanks Received: 11

Could you please post a starategy or a piece of code that could show us the turnover of a starategy that uses limited orders and at the same time could guarantee their execution at a broker side.

Follow me on Twitter Started this thread Reply With Quote
  #8 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394


kuranushka View Post
Could you please post a starategy or a piece of code that could show us the turnover of a starategy that uses limited orders and at the same time could guarantee their execution at a broker side.

There are many out there posted, you are going to need to do a little digging. The Battle of the Bots thread in the elite section has Many posted. You may want to start with Myst as that is probably close to the structure you need:

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on August 1, 2012


© 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