ATM Order Cancel Project - NinjaTrader Programming | futures io social day trading
futures io futures trading


ATM Order Cancel Project
Updated: Views / Replies:1,542 / 4
Created: by Baseheadz 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
 

ATM Order Cancel Project

  #1 (permalink)
Elite Member
Las Vegas, USA
 
Futures Experience: Master
Platform: Ninja, Multicharts, Proprietary
Favorite Futures: Energies
 
Posts: 48 since Jun 2011
Thanks: 1 given, 9 received

ATM Order Cancel Project

Hi Guys,

Does anybody know why this ATM strategy is outputting these types of errors?
**NT** GetAtmStrategyMarketPosition() method error: Missing atmStrategyId parameter
**NT** AtmStrategyCancelEntryOrder() method error: Missing orderId parameter




#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>
///
/// </summary>
[Description("")]
public class ATMTEST1: Strategy
{
#region Variables
private string atmStrategyIdLong = string.Empty;
private string orderIdLong = string.Empty;
private string atmStrategyIdShort = string.Empty;
private string orderIdShort = string.Empty;
private string atmStrategyName = "atmtest";
private int slipTicks = 1;
private int barNumberOfOrderLong = 0; //***
private int barNumberOfOrderShort = 0; //***

#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>



protected override void Initialize()
{

MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
CalculateOnBarClose = true;
BarsRequired = 10;

}

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

if (Historical)
return;



// Condition set LONG
if (
GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Flat
&& GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Flat
&& Low[0] < Low[1]
)

{
atmStrategyIdLong = GetAtmStrategyUniqueId();
orderIdLong = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, (Close[0] + SlipTicks * TickSize), 0, TimeInForce.Day, orderIdLong, AtmStrategyName, atmStrategyIdLong);
DrawText("Long1"+CurrentBar, "LL " + (Close[0] + SlipTicks * TickSize).ToString(), 0, Low[0] - 8*TickSize, Color.Cyan);
DrawArrowUp(CurrentBar.ToString(),0,Low[0] - 1*TickSize, Color.Cyan);
barNumberOfOrderLong = CurrentBar; //***

}

// Condition set SELL
if (
GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Flat
&& GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Flat
&& High[0] > High[1]
)

{
atmStrategyIdShort = GetAtmStrategyUniqueId();
orderIdShort = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Limit, (Close[0] - SlipTicks * TickSize), 0, TimeInForce.Day, orderIdShort, AtmStrategyName, atmStrategyIdShort);
DrawText("Short1"+CurrentBar,"SL " + (Close[0] - SlipTicks * TickSize).ToString(), 0, High[0] + 8*TickSize, Color.Cyan);
DrawArrowDown(CurrentBar.ToString(),0,High[0] + 1*TickSize, Color.Cyan);
barNumberOfOrderShort = CurrentBar; //***

}


//Cancels Limit order LONG************************************
if (CurrentBar > barNumberOfOrderLong && GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Long)
{
AtmStrategyCancelEntryOrder(orderIdLong);
orderIdLong = string.Empty;
Print("Cancelled LONG ENTRY Order from strategy");
}

//Cancels Long Limit if short strategy is short
if (GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Short)
{
AtmStrategyCancelEntryOrder(orderIdLong);
orderIdLong = string.Empty;
Print("Cancelled LONG ENTRY Order from strategy");
}

//Cancels Limit order Short************************************
if (CurrentBar > barNumberOfOrderShort && GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Short)
{
AtmStrategyCancelEntryOrder(orderIdShort);
orderIdShort = string.Empty;
Print("Cancelled SHORT ENTRY Order from strategy");
}

//Cancels Short Limit if strategy is long
if (GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Long)
{
AtmStrategyCancelEntryOrder(orderIdShort);
orderIdShort = string.Empty;
Print("Cancelled SHORT ENTRY Order from strategy");
}




// Check for a pending entry order LONG
if (orderIdLong.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderIdLong);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderIdLong = string.Empty;
}
}

else if (atmStrategyIdLong.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyIdLong) == Cbi.MarketPosition.Flat)
atmStrategyIdLong = string.Empty;


// Check for a pending entry order Short
if (orderIdShort.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderIdShort);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderIdShort = string.Empty;
}
}

else if (atmStrategyIdShort.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyIdShort) == Cbi.MarketPosition.Flat)
atmStrategyIdShort = string.Empty;




}



#region Properties

[Description("Slippage Ticks for Entry")]
[GridCategory("Parameters")]
public int SlipTicks
{
get { return slipTicks; }
set { slipTicks = Math.Max(1, value); }
}





[Description("Name for the ATM Strategy")]
[GridCategory("Parameters")]

public string AtmStrategyName
{
get { return atmStrategyName; }
set { atmStrategyName = value; }
}


#endregion
}
}

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
Calcutta, India
 
Futures Experience: Intermediate
Platform: ArthaChitra
 
Posts: 278 since Jun 2009
Thanks: 161 given, 259 received


the atm strategy ids are string.empty and thus the error. you got to check

if (atmstrategyId.Length > 0 && .....)



Baseheadz View Post
Hi Guys,

Does anybody know why this ATM strategy is outputting these types of errors?
**NT** GetAtmStrategyMarketPosition() method error: Missing atmStrategyId parameter
**NT** AtmStrategyCancelEntryOrder() method error: Missing orderId parameter




#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>
///
/// </summary>
[Description("")]
public class ATMTEST1: Strategy
{
#region Variables
private string atmStrategyIdLong = string.Empty;
private string orderIdLong = string.Empty;
private string atmStrategyIdShort = string.Empty;
private string orderIdShort = string.Empty;
private string atmStrategyName = "atmtest";
private int slipTicks = 1;
private int barNumberOfOrderLong = 0; //***
private int barNumberOfOrderShort = 0; //***

#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>



protected override void Initialize()
{

MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
CalculateOnBarClose = true;
BarsRequired = 10;

}

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

if (Historical)
return;



// Condition set LONG
if (
GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Flat
&& GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Flat
&& Low[0] < Low[1]
)

{
atmStrategyIdLong = GetAtmStrategyUniqueId();
orderIdLong = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, (Close[0] + SlipTicks * TickSize), 0, TimeInForce.Day, orderIdLong, AtmStrategyName, atmStrategyIdLong);
DrawText("Long1"+CurrentBar, "LL " + (Close[0] + SlipTicks * TickSize).ToString(), 0, Low[0] - 8*TickSize, Color.Cyan);
DrawArrowUp(CurrentBar.ToString(),0,Low[0] - 1*TickSize, Color.Cyan);
barNumberOfOrderLong = CurrentBar; //***

}

// Condition set SELL
if (
GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Flat
&& GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Flat
&& High[0] > High[1]
)

{
atmStrategyIdShort = GetAtmStrategyUniqueId();
orderIdShort = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Limit, (Close[0] - SlipTicks * TickSize), 0, TimeInForce.Day, orderIdShort, AtmStrategyName, atmStrategyIdShort);
DrawText("Short1"+CurrentBar,"SL " + (Close[0] - SlipTicks * TickSize).ToString(), 0, High[0] + 8*TickSize, Color.Cyan);
DrawArrowDown(CurrentBar.ToString(),0,High[0] + 1*TickSize, Color.Cyan);
barNumberOfOrderShort = CurrentBar; //***

}


//Cancels Limit order LONG************************************
if (CurrentBar > barNumberOfOrderLong && GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Long)
{
AtmStrategyCancelEntryOrder(orderIdLong);
orderIdLong = string.Empty;
Print("Cancelled LONG ENTRY Order from strategy");
}

//Cancels Long Limit if short strategy is short
if (GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Short)
{
AtmStrategyCancelEntryOrder(orderIdLong);
orderIdLong = string.Empty;
Print("Cancelled LONG ENTRY Order from strategy");
}

//Cancels Limit order Short************************************
if (CurrentBar > barNumberOfOrderShort && GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Short)
{
AtmStrategyCancelEntryOrder(orderIdShort);
orderIdShort = string.Empty;
Print("Cancelled SHORT ENTRY Order from strategy");
}

//Cancels Short Limit if strategy is long
if (GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Long)
{
AtmStrategyCancelEntryOrder(orderIdShort);
orderIdShort = string.Empty;
Print("Cancelled SHORT ENTRY Order from strategy");
}




// Check for a pending entry order LONG
if (orderIdLong.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderIdLong);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderIdLong = string.Empty;
}
}

else if (atmStrategyIdLong.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyIdLong) == Cbi.MarketPosition.Flat)
atmStrategyIdLong = string.Empty;


// Check for a pending entry order Short
if (orderIdShort.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderIdShort);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderIdShort = string.Empty;
}
}

else if (atmStrategyIdShort.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyIdShort) == Cbi.MarketPosition.Flat)
atmStrategyIdShort = string.Empty;




}



#region Properties

[Description("Slippage Ticks for Entry")]
[GridCategory("Parameters")]
public int SlipTicks
{
get { return slipTicks; }
set { slipTicks = Math.Max(1, value); }
}





[Description("Name for the ATM Strategy")]
[GridCategory("Parameters")]

public string AtmStrategyName
{
get { return atmStrategyName; }
set { atmStrategyName = value; }
}


#endregion
}
}


Reply With Quote
 
  #4 (permalink)
Elite Member
Las Vegas, USA
 
Futures Experience: Master
Platform: Ninja, Multicharts, Proprietary
Favorite Futures: Energies
 
Posts: 48 since Jun 2011
Thanks: 1 given, 9 received

Thanks Bukkan,

I'm using these strings so that I can have a long and short ATM strategy. How would I check these?

private string atmStrategyIdLong = string.Empty;
private string orderIdLong = string.Empty;
private string atmStrategyIdShort = string.Empty;
private string orderIdShort = string.Empty;

Something like this?

if (orderIdLong.Length == 0 && atmStrategyIdLong.Length == 0
&& orderIdShort.Length == 0 && atmStrategyIdShort.Length == 0
&& GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Flat
&& GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Flat

Reply With Quote
 
  #5 (permalink)
Elite Member
Calcutta, India
 
Futures Experience: Intermediate
Platform: ArthaChitra
 
Posts: 278 since Jun 2009
Thanks: 161 given, 259 received

Baseheadz,
I would have used one string Id instead of two as one cannot be both long and short at the same time. this would make life much easier.

yes you have to just check the length of the id

like

 
Code
if (atmId.Length > 0 && GetAtmStrategyMarketPosition(atmId) == MarketPosition.Long)
{
  //do stuff
}

Baseheadz View Post
Thanks Bukkan,

I'm using these strings so that I can have a long and short ATM strategy. How would I check these?

private string atmStrategyIdLong = string.Empty;
private string orderIdLong = string.Empty;
private string atmStrategyIdShort = string.Empty;
private string orderIdShort = string.Empty;

Something like this?

if (orderIdLong.Length == 0 && atmStrategyIdLong.Length == 0
&& orderIdShort.Length == 0 && atmStrategyIdShort.Length == 0
&& GetAtmStrategyMarketPosition(atmStrategyIdLong) == MarketPosition.Flat
&& GetAtmStrategyMarketPosition(atmStrategyIdShort) == MarketPosition.Flat


Reply With Quote

Reply



futures io > > > > > ATM Order Cancel Project

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
cancel last order terratec NinjaTrader Programming 16 September 1st, 2011 02:17 PM
IOG causing my limit order to cancel and replace intrabar tradersheldon EasyLanguage Programming 10 August 2nd, 2011 10:03 AM
How to cancel my subscription to all threads trendisyourfriend Tech Support 2 May 24th, 2011 07:30 PM
Help wanted! Long/short strategy with cancel order and trail stop mrticks NinjaTrader Programming 9 October 26th, 2010 05:15 PM
Project Natal Big Mike Off-Topic 0 August 22nd, 2009 07:58 AM


All times are GMT -4. The time now is 03:18 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-11 in 0.15 seconds with 19 queries on phoenix via your IP 54.226.172.30