Need Help with simple strategy on canceling orders - NinjaTrader Programming | futures io social day trading
futures io futures trading


Need Help with simple strategy on canceling orders
Updated: Views / Replies:1,096 / 2
Created: by floyd084 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 simple strategy on canceling orders

  #1 (permalink)
Elite Member
boston, ma
 
Futures Experience: Intermediate
Platform: NT7
Broker/Data: amp/zenfire
Favorite Futures: es
 
Posts: 10 since Feb 2010
Thanks: 3 given, 0 received

Need Help with simple strategy on canceling orders

So im trying to write a simple strategy that makes a market based on bollinger bands. It's very basic so far and I have it to a point where I can offer or bid at the price I want. What im trying to do is cancel the sitting orders if price crosses the mid point of the bollingers. The strategy so far places an order based on price in relation to the 20 period ma for a bollinger. I'm either offering or bidding at the extreme bands, if price is above the 20 period ma im offering, below and im bidding. What I need to do is cancel the previous order if price doesnt fill me and moves above or below the ma. Heres the code I have so far. It will place a singal order but wont remove it and place a new one if price crosses the middle band. Any help would be greatly appreciated. I've looked at the ninjatrader help for strategies and it doesn't help me much.

protected override void Initialize()
{
Add(Bollinger(2.3, 20));
SetProfitTarget("", CalculationMode.Ticks, 21);
SetStopLoss("", CalculationMode.Ticks, 12, false);

CalculateOnBarClose = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1

if (GetCurrentBid() < Bollinger(2.3, 20).Middle[0])
{
entryOrder = EnterLongLimit(DefaultQuantity, Bollinger(2.3, 20).Lower[0] + -1 * TickSize, "Long");

}
if (entryOrder != null && GetCurrentBid() > Bollinger(2.3, 20).Middle[0])
{

CancelOrder(entryOrder);
}


// Condition set 2

if (GetCurrentAsk() > Bollinger(2.3, 20).Middle[0])
{
entryOrder = EnterShortLimit(DefaultQuantity, Bollinger(2.3, 20).Upper[0] + 1 * TickSize, "Short");

}
if (entryOrder != null && GetCurrentBid() < Bollinger(2.3, 20).Middle[0])
{

CancelOrder(entryOrder);
}

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
Florida
 
Futures Experience: Intermediate
Platform: Ninjatrader
 
Posts: 12 since May 2010
Thanks: 34 given, 12 received


You need to be a little more specific on which order gets cancelled when.

Try this...

 
Code
// Bollinger_Band_Strategy

#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.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
	/// <summary>
	/// Simple moving average cross over strategy.
	/// </summary>
	[Description("Bollinger Band Strategy.")]
	public class Bollinger_Band_Strategy : Strategy
	{
		private	IOrder		entryOrder = null;
		private	double		numStdDev	= 2.3;
		private int			period		= 20;


		/// <summary>
		/// This method is used to configure the strategy and is called once before any strategy method is called.
		/// </summary>
		protected override void Initialize()
		{
			Add( Bollinger(numStdDev, period) );
			SetProfitTarget("", CalculationMode.Ticks, 21);
			SetStopLoss("", CalculationMode.Ticks, 12, false);

			CalculateOnBarClose = false;
		}

		/// <summary>
		/// Called on each bar update event (incoming tick).
		/// </summary>
		protected override void OnBarUpdate()
		{
			double bollinger_upper	= Bollinger(numStdDev, period).Upper[0];
			double bollinger_middle	= Bollinger(numStdDev, period).Middle[0];
			double bollinger_lower	= Bollinger(numStdDev, period).Lower[0];

			if (entryOrder == null)
			{
				if (GetCurrentBid() < bollinger_middle)
				{
					double entry_price = bollinger_lower - TickSize;
					entryOrder = EnterLongLimit( DefaultQuantity, entry_price, "Long" );
				}

				if (GetCurrentAsk() > bollinger_middle)
				{
					double entry_price = bollinger_upper + TickSize;
					entryOrder = EnterShortLimit( DefaultQuantity, entry_price, "Short" );
				}
			}
			else
			if (Position.MarketPosition == MarketPosition.Flat)
			{
				if (GetCurrentBid() > bollinger_middle)
				if (entryOrder.OrderAction == OrderAction.Buy)
					CancelOrder(entryOrder);

				if (GetCurrentAsk() < bollinger_middle)
				if (entryOrder.OrderAction == OrderAction.Sell)
					CancelOrder(entryOrder);
			}
		}

		#region Properties
		[Description("Number of standard deviations")]
		[GridCategory("Parameters")]
		[Gui.Design.DisplayNameAttribute("# of std. dev.")]
		public double NumStdDev
		{
			get { return numStdDev; }
			set { numStdDev = Math.Max(0, value); }
		}

		[Description("Numbers of bars used for calculations")]
		[GridCategory("Parameters")]
		public int Period
		{
			get { return period; }
			set { period = Math.Max(1, value); }
		}
		#endregion
	}
}


Last edited by pam421; February 22nd, 2011 at 10:35 AM. Reason: changed "Add" in Initialize to use symbolic values instead of numeric constants
Reply With Quote
The following user says Thank You to pam421 for this post:

Reply



futures io > > > > > Need Help with simple strategy on canceling orders

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strategy to monitor ALL account orders? SetFreeByTruth NinjaTrader Programming 18 November 14th, 2014 09:14 AM
Please help with simple strategy with SMA dimkrinichnyi NinjaTrader Programming 17 November 1st, 2011 02:25 PM
What is going on here (my strategy isn't producing orders) ???? jmejedi NinjaTrader Programming 5 June 7th, 2011 08:11 PM
Simple strategy vast NinjaTrader Programming 19 August 5th, 2010 06:39 PM
Strategy market orders zeller4 NinjaTrader Programming 5 August 27th, 2009 01:11 AM


All times are GMT -4. The time now is 07:06 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-13 in 0.07 seconds with 19 queries on phoenix via your IP 54.196.182.102