A little trouble with limit orders... - NinjaTrader Programming | futures io social day trading
futures io futures trading


A little trouble with limit orders...
Updated: Views / Replies:2,651 / 8
Created: by BigDog Attachments:1

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
 

A little trouble with limit orders...

  #1 (permalink)
Member
Chicago
 
Futures Experience: Advanced
Platform: X_Trader, Ninja
Broker/Data: Advantage/TT and Mirus/ZenFire
Favorite Futures: ES
 
Posts: 60 since Jun 2009
Thanks: 0 given, 16 received

A little trouble with limit orders...

I'm having some trouble getting my Limit Orders to Cancel on this Ninja Script... would really appreciate it if some kind soul could take a look and help me out...

also attached the file

Thanks!

 
Code
        protected override void OnBarUpdate()
        {
            // Submit an entry limit order if we currently don't have an entry order open
            if (entryOrder == null && Close[0] > Open[0])
            {
                entryOrder = EnterLongLimit(0, true, 1, Median[0] + -2 * TickSize, "MyEntry");
            }
  
            if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + (7 * (TickSize / 2)))
            {
                // Checks to see if our Stop Order has been submitted already
                if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice)
                {
                    // Modifies stop-loss to breakeven
                    stopOrder = ExitLongStop(0, true, stopOrder.Quantity, Position.AvgPrice, "MyStop", "MyEntry");
                }
            }
        }

        /// <summary>
        /// Called on each incoming order event
        /// </summary>
        protected override void OnOrderUpdate(IOrder order)
        {
            // Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
            if (entryOrder != null && entryOrder.Token == order.Token)
            {    

                // Reset the entryOrder object to null if order was cancelled without any fill
                if (order.OrderState == OrderState.Working
                    && order.LimitPrice < GetCurrentBid() - 4 * TickSize)
                {
                    CancelOrder(entryOrder);
                    entryOrder = null;
                }
            }
        }
        
        /// <summary>
        /// Called on each incoming execution
        /// </summary>
        protected override void OnExecution(IExecution execution)
        {
            if (entryOrder != null && entryOrder.Token == execution.Order.Token)
            {
                if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                {
                    // Stop-Loss order 4 ticks below our entry price
                    stopOrder     = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "MyStop", "MyEntry");
                    
                    // Target order 8 ticks above our entry price
                    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 8 * TickSize, "MyTarget", "MyEntry");
                    
                    // Resets the entryOrder object to null after the order has been filled or partially filled
                    if (execution.Order.OrderState != OrderState.PartFilled)
                    {
                        entryOrder     = null;
                    }
                }
            }
            
            // Reset our stop order and target orders' IOrder objects after our position is closed.
            if ((stopOrder != null && stopOrder.Token == execution.Order.Token) || (targetOrder != null && targetOrder.Token == execution.Order.Token))
            {
                if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                {
                    stopOrder = null;
                    targetOrder = null;
                }
            }
        }

        /// <summary>
        /// Called on each incoming position event
        /// </summary>
        protected override void OnPositionUpdate(IPosition position)
        {
            // Print our current position to the lower right hand corner of the chart
            DrawTextFixed("MyTag", position.ToString(), TextPosition.BottomRight);
        }

Attached Files
Register to download File Type: zip LimitOrder.zip (2.2 KB, 30 views)
Reply With Quote
 
  #2 (permalink)
Member
Chicago
 
Futures Experience: Advanced
Platform: X_Trader, Ninja
Broker/Data: Advantage/TT and Mirus/ZenFire
Favorite Futures: ES
 
Posts: 60 since Jun 2009
Thanks: 0 given, 16 received

bump to top

Reply With Quote
 
  #3 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,352 given, 83,231 received


BigDog,

I don't have any experience with IOrder actually, I just never needed it I guess. Perhaps some other people will, and they can examine the code more closely.

Mike

Reply With Quote
 
  #4 (permalink)
Elite Member
Cologne
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus/Zen-Fire, Velocity/TT
Favorite Futures: Futures, Stocks
 
Posts: 10 since Jun 2009
Thanks: 29 given, 2 received

Hm ... maybe there is a timing problem. LimitOrders are only active for one bar. If you want to cancel the order manually it could be already cancelled by NT?

What is the detailed error-message? What says the log-tab?

Reply With Quote
 
  #5 (permalink)
Member
Chicago
 
Futures Experience: Advanced
Platform: X_Trader, Ninja
Broker/Data: Advantage/TT and Mirus/ZenFire
Favorite Futures: ES
 
Posts: 60 since Jun 2009
Thanks: 0 given, 16 received

from my discussions with Josh, apparently i should be able to use ticks as a criteria to cancel limit orders too... the issue i'm noticing is when i get to the part which contains the cancellation logic... its not executing... yet for what its worth it seems sound...

Reply With Quote
 
  #6 (permalink)
Elite Member
Cologne
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus/Zen-Fire, Velocity/TT
Favorite Futures: Futures, Stocks
 
Posts: 10 since Jun 2009
Thanks: 29 given, 2 received

No exceptions, no errors?

I believe you have to put some Print(..) statements in your code.
What are the values of the order-variables, what is the place in your code
which is executed and which is not ...

Reply With Quote
 
  #7 (permalink)
Member
Chicago
 
Futures Experience: Advanced
Platform: X_Trader, Ninja
Broker/Data: Advantage/TT and Mirus/ZenFire
Favorite Futures: ES
 
Posts: 60 since Jun 2009
Thanks: 0 given, 16 received

Darth,
absolutly none... not a single error at all... just isn't reading the order.LimitPrice variable... which is odd because shouldn't be an issue being in the OnOrderUpdate() section...

Reply With Quote
 
  #8 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,352 given, 83,231 received

It might be useful to post a video illustrating exactly what is occurring. You might try the jing software package (free) if you need one for video capturing.

Mike

Reply With Quote
 
  #9 (permalink)
Elite Member
Florida
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: CL, NQ, NG
 
Posts: 456 since Jun 2009
Thanks: 1,359 given, 383 received

BigDog,
I've tried to get this strat to place orders but was having no luck. I've commented out some of the lines you've been using and am able to get orders to go.

Now for your question. If you cancel the orders, is it due to a no-fill and then you just want to re-position the limit to the new Median[0] +/- 2ticks? or is it time based?

kz



Reply With Quote

Reply



futures io > > > > > A little trouble 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
EasyLanguage, Mulitcharts and Limit Orders nismo EasyLanguage Programming 28 April 4th, 2013 06:47 AM
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
Time Breakout with limit orders rajafx1 NinjaTrader Programming 1 December 23rd, 2009 03:52 PM
Limit Orders - Proving a fill zeller4 NinjaTrader Programming 1 August 28th, 2009 04:14 AM


All times are GMT -4. The time now is 09:26 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-14 in 0.13 seconds with 20 queries on phoenix via your IP 54.82.56.95