NexusFi: Find Your Edge


Home Menu

 





Cancel Pending Order Strategy Help!


Discussion in NinjaTrader

Updated
    1. trending_up 3,670 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 9 posts
    2. attach_file 1 attachments




 
Search this Thread

Cancel Pending Order Strategy Help!

  #1 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3

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

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863



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;
}

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


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)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


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
Elite Membership required to download: 2targets-unfinished.txt.txt
Reply With Quote
  #7 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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
    }
}

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


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

Reply With Quote
  #9 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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 :


Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #10 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3



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 :


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

Reply With Quote




Last Updated on November 1, 2015


© 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