Need help with limit orders - futures io
futures io



Need help with limit orders


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Need help with limit orders

(login for full post details)
  #1 (permalink)
 kuranushka 
Near CME
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, FDAX, GC, 6E
 
Posts: 6 since Apr 2012
Thanks: 5 given, 11 received

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 futures io?
Time Segmented Volume
NinjaTrader
Color templates for MT5 40 items
Platforms and Indicators
Questioning Conventional Wisdom
Treasury Notes and Bonds
1 min chart v-shape scan help please
ThinkOrSwim
TradingView help in improving Anchored Vwap
Platforms and Indicators
 
 
(login for full post details)
  #3 (permalink)
 NJAMC 
Atkinson, NH USA
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,970 since Dec 2010
Thanks: 3,036 given, 2,379 received



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 futures io Trade Journal Reply With Quote
 
(login for full post details)
  #4 (permalink)
 NJAMC 
Atkinson, NH USA
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,970 since Dec 2010
Thanks: 3,036 given, 2,379 received

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 futures io Trade Journal Reply With Quote
 
(login for full post details)
  #5 (permalink)
 kuranushka 
Near CME
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, FDAX, GC, 6E
 
Posts: 6 since Apr 2012
Thanks: 5 given, 11 received

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
 
(login for full post details)
  #6 (permalink)
 NJAMC 
Atkinson, NH USA
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,970 since Dec 2010
Thanks: 3,036 given, 2,379 received

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 futures io Trade Journal Reply With Quote
 
(login for full post details)
  #7 (permalink)
 kuranushka 
Near CME
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, FDAX, GC, 6E
 
Posts: 6 since Apr 2012
Thanks: 5 given, 11 received

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
 
(login for full post details)
  #8 (permalink)
 NJAMC 
Atkinson, NH USA
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,970 since Dec 2010
Thanks: 3,036 given, 2,379 received


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 futures io Trade Journal Reply With Quote
The following 4 users say Thank You to NJAMC for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > Need help with limit orders


Last Updated on August 1, 2012


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing

Your Charts Should Speak To You w/Bob Cometta

Elite only
 

Our 12-year anniversary w/ $$,$$$ prizes (check soon)

August
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts