Need help with limit orders - NinjaTrader Programming | futures io social day trading
futures io futures trading


Need help with limit orders
Updated: Views / Replies:1,929 / 7
Created: by kuranushka Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Need help with limit orders

  #1 (permalink)
Elite Member
Near CME
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: CL, FDAX, GC, 6E
 
Posts: 6 since Apr 2012
Thanks: 5 given, 11 received

Need help with limit orders

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, "");
...


Last edited by kuranushka; July 31st, 2012 at 05:34 PM.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 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
Reply With Quote
 
  #4 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 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
Reply With Quote
 
  #5 (permalink)
Elite Member
Near CME
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 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();
			}
		}

Reply With Quote
 
  #6 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 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
Reply With Quote
 
  #7 (permalink)
Elite Member
Near CME
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 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.

Reply With Quote
 
  #8 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 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:
https://futures.io/elite-automated-ninjatrader-trading/8465-ducmans-first-strategy-called-myst-57.html#post224845

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
The following 4 users say Thank You to NJAMC for this post:

Reply



futures io > > > > > Need help with limit orders

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill of Limit Orders MWinfrey Traders Hideout 16 August 9th, 2014 07:40 PM
Market orders vs limit Twiddle Traders Hideout 4 February 9th, 2012 10:54 PM
Limit Orders COTtrader Traders Hideout 17 August 22nd, 2010 03:24 PM
ATM and Limit Orders spinnybobo NinjaTrader Programming 6 June 12th, 2010 09:06 PM
A little trouble with limit orders... BigDog NinjaTrader Programming 8 June 21st, 2009 08:07 PM


All times are GMT -4. The time now is 02:36 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, 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
Page generated 2017-12-15 in 0.11 seconds with 19 queries on phoenix via your IP 54.226.132.197