Cancel Pending Order Strategy Help! - NinjaTrader Programming | futures io social day trading
futures io futures trading


Cancel Pending Order Strategy Help!
Updated: Views / Replies:753 / 9
Created: by kidvic 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
 

Cancel Pending Order Strategy Help!

  #1 (permalink)
Trading for Fun
Los Angeles, CA
 
Futures Experience: Intermediate
Platform: NinjaTrader, ThinkOrSwim
Favorite Futures: Options, Futures
 
Posts: 92 since Mar 2015
Thanks: 13 given, 2 received

Cancel Pending Order Strategy Help!

double SetupEntry = Low[1];
double SetupStop = High[1];
double T1 = Low[1] - (12 * Ticks);


if (Setup)
{
EnterShortStopLimit(0, true, 1, SetupEntry, SetupEntry, "Short");
SetStopLoss("Short", CalculationMode.Price, SetupStop, false);
SetProfitTarget("Short", CalculationMode.Price, T1);
}

This submits an order when Setup is CurrentBar, and stays active until I cancel it. How do I set a cancel order to a pending order?
I want to cancel this Limit order if the price touches SetupStop before SetupEntry.
Keep in mind, my SetupStop is the value of High[1] when it is CurrentBar, in other words it will change after each new bar.
How do I cancel the "pending order" when the price is trading at or above SetupStop? (The price that was High[1] when Setup was true)?

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
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,507 since Sep 2013
Thanks: 1,710 given, 3,722 received
Forum Reputation: Legendary



kidvic View Post
double SetupEntry = Low[1];
double SetupStop = High[1];
double T1 = Low[1] - (12 * Ticks);


if (Setup)
{
EnterShortStopLimit(0, true, 1, SetupEntry, SetupEntry, "Short");
SetStopLoss("Short", CalculationMode.Price, SetupStop, false);
SetProfitTarget("Short", CalculationMode.Price, T1);
}

This submits an order when Setup is CurrentBar, and stays active until I cancel it. How do I set a cancel order to a pending order?
I want to cancel this Limit order if the price touches SetupStop before SetupEntry.
Keep in mind, my SetupStop is the value of High[1] when it is CurrentBar, in other words it will change after each new bar.
How do I cancel the "pending order" when the price is trading at or above SetupStop? (The price that was High[1] when Setup was true)?


double SetupStop = High[1];
double T1 = Low[1] - (12 * Ticks);
IOrder myEntryOrder = null;

if (Setup)
{
myEntryOrder = EnterShortStopLimit(0, true, 1, SetupEntry, SetupEntry, "Short");
SetStopLoss("Short", CalculationMode.Price, SetupStop, false);
SetProfitTarget("Short", CalculationMode.Price, T1);
mynotExecuted=true;
}

if (OrderInvalidated && notExecuted)
{
CancelOrder(myEntryOrder);
}

protected override void OnExecution(IExecution execution)
{
if (myEntryOrder != null && myEntryOrder == execution.Order)
notExecuted=false;
}

Reply With Quote
 
  #4 (permalink)
Trading for Fun
Los Angeles, CA
 
Futures Experience: Intermediate
Platform: NinjaTrader, ThinkOrSwim
Favorite Futures: Options, Futures
 
Posts: 92 since Mar 2015
Thanks: 13 given, 2 received


rleplae View Post
double SetupStop = High[1];
double T1 = Low[1] - (12 * Ticks);
IOrder myEntryOrder = null;

if (Setup)
{
myEntryOrder = EnterShortStopLimit(0, true, 1, SetupEntry, SetupEntry, "Short");
SetStopLoss("Short", CalculationMode.Price, SetupStop, false);
SetProfitTarget("Short", CalculationMode.Price, T1);
mynotExecuted=true;
}

if (OrderInvalidated && notExecuted)
{
CancelOrder(myEntryOrder);
}

protected override void OnExecution(IExecution execution)
{
if (myEntryOrder != null && myEntryOrder == execution.Order)
notExecuted=false;
}

Thanks for the reply. Tried the code. Didn't work. Getting errors on intellisense. All my code was under OnBarUpdate() method, I have no variables, or anything else, if that makes a difference.

Reply With Quote
 
  #5 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,507 since Sep 2013
Thanks: 1,710 given, 3,722 received
Forum Reputation: Legendary


kidvic View Post
Thanks for the reply. Tried the code. Didn't work. Getting errors on intellisense. All my code was under OnBarUpdate() method, I have no variables, or anything else, if that makes a difference.

the example was conceptual

post your complete file
and i will insert the code (and test) so it works

Reply With Quote
 
  #6 (permalink)
Trading for Fun
Los Angeles, CA
 
Futures Experience: Intermediate
Platform: NinjaTrader, ThinkOrSwim
Favorite Futures: Options, Futures
 
Posts: 92 since Mar 2015
Thanks: 13 given, 2 received


rleplae View Post
the example was conceptual

post your complete file
and i will insert the code (and test) so it works

It's not quite done, still working on some other things.....
But here it is. (As you can see still working on the order quantity)

Attached Files
Register to download File Type: txt 2targets-unfinished.txt.txt (1.9 KB, 6 views)
Reply With Quote
 
  #7 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,507 since Sep 2013
Thanks: 1,710 given, 3,722 received
Forum Reputation: Legendary


kidvic View Post
It's not quite done, still working on some other things.....
But here it is. (As you can see still working on the order quantity)

Still very rough, but it shows you how to do.
you would need to second trade (reset variables),
maybe exit strategy, etc...

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// TwoTargetBull
    /// </summary>
    [Description("TwoTargetBull")]
    public class TwoTargetBull : Strategy
    {
		#region Variables
		public IOrder myEntryOrder;
		public bool myNotExecuted;
		#endregion

        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			myEntryOrder = null;
			myNotExecuted = true;
        }
		
		// this method is called everytime there is an execution
		protected override void OnExecution(IExecution execution)
		 {
			// order can not be cancelled any more, we are in the trade....
 			if (myEntryOrder != null && myEntryOrder == execution.Order)
 				myNotExecuted=false;
 		 }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
 
			double SetupStop = Low[1];
			double SetupEntry = Close[1];	
			double T1 = SetupEntry + (5 * TickSize);
			double T2 = SetupEntry + (8 * TickSize);
			bool OrderInvalidated = false;

			if  (Close[0] < Close[1] && Low[1] == Low[2]) 
				{
				myEntryOrder = EnterLongStopLimit(0, true, 2, SetupEntry, SetupEntry, "T1");
				SetStopLoss("T1", CalculationMode.Price, SetupStop, false);
				SetProfitTarget("T1", CalculationMode.Price, T1);
//				SetProfitTarget2("T2", CalculationMode.Price, T2);
				myNotExecuted = true;
				}

			/// write your code that will trigger the cancel of the order
			// whatever condition goes next : 
			if (1 == 2)
				{
					OrderInvalidated = true;
				}
			
			// if OrderInvaldiate true and order not yet executed, cancel it
			if (OrderInvalidated && myNotExecuted)
				{
				CancelOrder(myEntryOrder);
				}
				
		}
		
	
		
        #region Properties
    
        #endregion
    }
}

Reply With Quote
The following user says Thank You to rleplae for this post:
 
  #8 (permalink)
Trading for Fun
Los Angeles, CA
 
Futures Experience: Intermediate
Platform: NinjaTrader, ThinkOrSwim
Favorite Futures: Options, Futures
 
Posts: 92 since Mar 2015
Thanks: 13 given, 2 received


rleplae View Post
Still very rough, but it shows you how to do.
you would need to second trade (reset variables),
maybe exit strategy, etc...

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// TwoTargetBull
    /// </summary>
    [Description("TwoTargetBull")]
    public class TwoTargetBull : Strategy
    {
		#region Variables
		public IOrder myEntryOrder;
		public bool myNotExecuted;
		#endregion

        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			myEntryOrder = null;
			myNotExecuted = true;
        }
		
		// this method is called everytime there is an execution
		protected override void OnExecution(IExecution execution)
		 {
			// order can not be cancelled any more, we are in the trade....
 			if (myEntryOrder != null && myEntryOrder == execution.Order)
 				myNotExecuted=false;
 		 }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
 
			double SetupStop = Low[1];
			double SetupEntry = Close[1];	
			double T1 = SetupEntry + (5 * TickSize);
			double T2 = SetupEntry + (8 * TickSize);
			bool OrderInvalidated = false;

			if  (Close[0] < Close[1] && Low[1] == Low[2]) 
				{
				myEntryOrder = EnterLongStopLimit(0, true, 2, SetupEntry, SetupEntry, "T1");
				SetStopLoss("T1", CalculationMode.Price, SetupStop, false);
				SetProfitTarget("T1", CalculationMode.Price, T1);
//				SetProfitTarget2("T2", CalculationMode.Price, T2);
				myNotExecuted = true;
				}

			/// write your code that will trigger the cancel of the order
			// whatever condition goes next : 
			if (1 == 2)
				{
					OrderInvalidated = true;
				}
			
			// if OrderInvaldiate true and order not yet executed, cancel it
			if (OrderInvalidated && myNotExecuted)
				{
				CancelOrder(myEntryOrder);
				}
				
		}
		
	
		
        #region Properties
    
        #endregion
    }
}

strategy not enabling. Error in log: Error on calling 'onbarupadate' object reference not set to an instance of an object


Last edited by kidvic; November 1st, 2015 at 06:15 AM. Reason: Correcting
Reply With Quote
 
  #9 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,507 since Sep 2013
Thanks: 1,710 given, 3,722 received
Forum Reputation: Legendary


kidvic View Post
strategy not enabling. Error in log: Error on calling 'onbarupadate' object reference not set to an instance of an object

problem was in the initial code
it was executing on historical data
now it runs


 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// TwoTargetBull
    /// </summary>
    [Description("TwoTargetBull")]
    public class TwoTargetBull : Strategy
    {
		#region Variables
	    private IOrder myEntryOrder=null;
		
		public bool myNotExecuted;
		#endregion

        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			myEntryOrder = null;
			myNotExecuted = true;
        }
		
		// this method is called everytime there is an execution
		protected override void OnExecution(IExecution execution)
		 {
			// order can not be cancelled any more, we are in the trade....
 			if (myEntryOrder != null && myEntryOrder == execution.Order)
 				myNotExecuted=false;
 		 }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
 
			
			if(Historical) 
				return;
			
			double SetupStop = Low[1];
			double SetupEntry = Close[1];	
			double T1 = SetupEntry + (5 * TickSize);
			double T2 = SetupEntry + (8 * TickSize);
			bool OrderInvalidated = false;

			if  (Close[0] < Close[1] && Low[1] == Low[2] && myNotExecuted == false) 
				{
				myEntryOrder = EnterLongStopLimit(0, true, 2, SetupEntry, SetupEntry, "T1");
				SetStopLoss("T1", CalculationMode.Price, SetupStop, false);
				SetProfitTarget("T1", CalculationMode.Price, T1);
//				SetProfitTarget2("T2", CalculationMode.Price, T2);
				myNotExecuted = true;
				}

			/// write your code that will trigger the cancel of the order
			// whatever condition goes next : 
			if (1 == 2)
				{
					OrderInvalidated = true;
				}
			
			// if OrderInvaldiate true and order not yet executed, cancel it
			if (OrderInvalidated && myNotExecuted)
				{
				 AtmStrategyCancelEntryOrder("T1");
				 myNotExecuted = false;
				 myEntryOrder = null;
				}
		}
        #region Properties
    
        #endregion
    }
}

you might be interested to study a live strategy i wrote on :

https://futures.io/elite-automated-trading/32559-ron-s-alpha-trade-method-ninjatrader-advanced-trade-management-bot-21.html

Reply With Quote
The following user says Thank You to rleplae for this post:
 
  #10 (permalink)
Trading for Fun
Los Angeles, CA
 
Futures Experience: Intermediate
Platform: NinjaTrader, ThinkOrSwim
Favorite Futures: Options, Futures
 
Posts: 92 since Mar 2015
Thanks: 13 given, 2 received



rleplae View Post
problem was in the initial code
it was executing on historical data
now it runs


 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// TwoTargetBull
    /// </summary>
    [Description("TwoTargetBull")]
    public class TwoTargetBull : Strategy
    {
		#region Variables
	    private IOrder myEntryOrder=null;
		
		public bool myNotExecuted;
		#endregion

        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			myEntryOrder = null;
			myNotExecuted = true;
        }
		
		// this method is called everytime there is an execution
		protected override void OnExecution(IExecution execution)
		 {
			// order can not be cancelled any more, we are in the trade....
 			if (myEntryOrder != null && myEntryOrder == execution.Order)
 				myNotExecuted=false;
 		 }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
 
			
			if(Historical) 
				return;
			
			double SetupStop = Low[1];
			double SetupEntry = Close[1];	
			double T1 = SetupEntry + (5 * TickSize);
			double T2 = SetupEntry + (8 * TickSize);
			bool OrderInvalidated = false;

			if  (Close[0] < Close[1] && Low[1] == Low[2] && myNotExecuted == false) 
				{
				myEntryOrder = EnterLongStopLimit(0, true, 2, SetupEntry, SetupEntry, "T1");
				SetStopLoss("T1", CalculationMode.Price, SetupStop, false);
				SetProfitTarget("T1", CalculationMode.Price, T1);
//				SetProfitTarget2("T2", CalculationMode.Price, T2);
				myNotExecuted = true;
				}

			/// write your code that will trigger the cancel of the order
			// whatever condition goes next : 
			if (1 == 2)
				{
					OrderInvalidated = true;
				}
			
			// if OrderInvaldiate true and order not yet executed, cancel it
			if (OrderInvalidated && myNotExecuted)
				{
				 AtmStrategyCancelEntryOrder("T1");
				 myNotExecuted = false;
				 myEntryOrder = null;
				}
		}
        #region Properties
    
        #endregion
    }
}

you might be interested to study a live strategy i wrote on :

https://futures.io/elite-automated-trading/32559-ron-s-alpha-trade-method-ninjatrader-advanced-trade-management-bot-21.html

Thank you. I fixed that error// but ill test this new code.


Last edited by kidvic; November 1st, 2015 at 06:50 AM. Reason: testing
Reply With Quote

Reply



futures io > > > > > Cancel Pending Order Strategy Help!

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
Cancel Order olres7 NinjaTrader Programming 10 October 21st, 2015 12:57 PM
Indicator with buttons to create pending order with strategy at swing high/low matevisky NinjaTrader 1 November 22nd, 2014 04:41 AM
cancel last order terratec NinjaTrader Programming 16 September 1st, 2011 02:17 PM
ATM Order Cancel Project Baseheadz NinjaTrader Programming 4 August 16th, 2011 12:32 AM
Help wanted! Long/short strategy with cancel order and trail stop mrticks NinjaTrader Programming 9 October 26th, 2010 05:15 PM


All times are GMT -4. The time now is 02:56 PM.

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-18 in 0.14 seconds with 20 queries on phoenix via your IP 54.92.194.75