Using IOrders and setting stops problems - NinjaTrader Programming | futures io social day trading
futures io futures trading


Using IOrders and setting stops problems
Updated: Views / Replies:894 / 4
Created: by spinnybobo 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 100,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

 
 
Thread Tools
 

Using IOrders and setting stops problems

 
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 175 since Aug 2009
Thanks: 102 given, 48 received

Using IOrders and setting stops problems

Hello Everyone

I have a Ninjascript question concerning a very simple IOrder strategy.
Basically I have a reason to get into the trade. I enter on an IOrder and then I set the stop.
I don't understand why when I run this very simple code, it always does ExitOnClose even though the price crosses where the stop should be.
The stop is simply not being set for some reason even though I am tagging it with the name "Long"

 
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
{

    [Description("Basic IOrder Strategy")]
    public class IOrderBasic : Strategy
    {
	#region Variables
		
	private int _stop = 10;
	private int _quantity = 1;
	private SMA _sma;
	private IOrder _entry = null;
	private IOrder _exit = null;
		
	#endregion

        protected override void Initialize()
        {
            CalculateOnBarClose = true;
	    this._sma = SMA(21);
	    Add(_sma);
        }
        protected override void OnBarUpdate()
        {
		//seek an exit
		if (_entry != null && _entry.OrderState == OrderState.Filled && Long)
		{
			if (_exit == null)
			    _exit = ExitLongStop(_quantity, _entry.AvgFillPrice-(_stop*TickSize), "Stop", "Long");
		}
		//seek an entry
		if (Flat)
		{
			if (High[0] >= _sma[0] && High[1] < _sma[1])
			{
				_entry = EnterLong(_quantity, "Long");
			}
		}
        }
	#region Helpers
		
	private bool Long{ get { return Position.MarketPosition == MarketPosition.Long; }}
	private bool Short{ get { return Position.MarketPosition == MarketPosition.Short; }}
	private bool Flat{ get { return Position.MarketPosition == MarketPosition.Flat; }}
		
	#endregion

        #region Properties
        [Description("Stop")]
        [GridCategory("Parameters")]
        public int Stop
        {
            get { return _stop; }
            set { _stop = Math.Max(1, value); }
        }
	[Description("Quantity")]
	[GridCategory("Parameters")]
	public int Quantity
	{
		get { return _quantity; }
		set { _quantity = Math.Max(1, value); }
	}
        #endregion
    }
}
Any help would be much appreciated
thanks
Spencer


Last edited by spinnybobo; June 6th, 2013 at 02:47 PM.
 
 
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.

 
 
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 835 received


Maybe...
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

 
 
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 175 since Aug 2009
Thanks: 102 given, 48 received

this might be working now

Hey

This might be working now. Perhaps before the template that I was using was interpreted incorrectly when I rewrote the code. I tried to make it as barbones as possible. At least now when I trace the orders I can see them working.

 
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
{

    [Description("Basic IOrder Strategy")]
    public class IOrderBasic : Strategy
    {
	#region Variables
		
	private int _stop = 10;
	private int _quantity = 1;
	private SMA _sma;
	private IOrder _entry = null;
	private IOrder _exit = null;
		
	#endregion

        protected override void Initialize()
        {
            CalculateOnBarClose = true;
	    EntryHandling = EntryHandling.UniqueEntries;
	    TraceOrders = true;
	    this._sma = SMA(21);
	    Add(_sma);
        }
        protected override void OnBarUpdate()
        {

		if (CurrentBar < 20) //not enough bars stop
			return;

		if (Flat) //get in a position
		{
			if (High[0] >= _sma[0] && High[1] < _sma[1])
			{
				_entry = EnterLong(_quantity, "Long");
			}
		}
		if (Long) //set stop if in a position
			_exit = ExitLongStop(_quantity, _entry.AvgFillPrice - (_stop*TickSize), "Stop", "Long");
        }
	#region Helpers
		
	private bool Long{ get { return Position.MarketPosition == MarketPosition.Long; }}
	private bool Short{ get { return Position.MarketPosition == MarketPosition.Short; }}
	private bool Flat{ get { return Position.MarketPosition == MarketPosition.Flat; }}
		
	#endregion

        #region Properties
        [Description("Stop")]
        [GridCategory("Parameters")]
        public int Stop
        {
            get { return _stop; }
            set { _stop = Math.Max(1, value); }
        }
	[Description("Quantity")]
	[GridCategory("Parameters")]
	public int Quantity
	{
		get { return _quantity; }
		set { _quantity = Math.Max(1, value); }
	}
        #endregion
    }
}
any other ideas would be appreciated
thanks
Spencer

 
 
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 175 since Aug 2009
Thanks: 102 given, 48 received

update

it seems like when I say

 
Code
     if (_entry == null)
         _entry = EnterLong(_quantity, "Long");
it seems to be having a problem when I call to see if it is null first before allowing it to be set.
it seems to be working as long as I don't ask
 
Code
if (_entry == null) 

//or

if(_entry != null)
anyway, it seems to be working now. Now I can at least program trailing stops.


 



futures io > > > > > Using IOrders and setting stops problems
Thread Tools



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

July Journal Challenge - $500 in Amazon Gift Cards!

July
 

Current Events in Commodity Markets: Influence & Crowd Psychology w/IQFeed

Jul 12

AXESS Trader: Powerful cloud Based Trading Platform w/GFF Brokers

Jul 17

TBA: FuturesTrader71 w/Morad Askar

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Catastrophic Stops tderrick Traders Hideout 5 February 26th, 2012 02:30 PM
IOrders TrailStop MXASJ NinjaTrader Programming 3 January 13th, 2012 07:58 AM
Monthly Stops crmtrade EasyLanguage Programming 4 December 5th, 2010 08:29 AM
Stops, trailing and breakeven stops jonc NinjaTrader 4 November 9th, 2010 12:06 AM
Targets + Stops max-td Psychology and Money Management 24 September 14th, 2009 05:41 PM


All times are GMT -4. The time now is 04:13 PM. (this page content is cached, log in for real-time version)

Copyright © 2018 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 2018-07-13 in 0.11 seconds with 14 queries on phoenix