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:771 / 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 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
 

Using IOrders and setting stops problems

  #1 (permalink)
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: 171 since Aug 2009
Thanks: 99 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 03:47 PM.
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
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 received


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

Reply With Quote
 
  #4 (permalink)
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: 171 since Aug 2009
Thanks: 99 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

Reply With Quote
 
  #5 (permalink)
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: 171 since Aug 2009
Thanks: 99 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.

Reply With Quote

Reply



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

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
Catastrophic Stops tderrick Traders Hideout 5 February 26th, 2012 03:30 PM
IOrders TrailStop MXASJ NinjaTrader Programming 3 January 13th, 2012 08:58 AM
Monthly Stops crmtrade EasyLanguage Programming 4 December 5th, 2010 09:29 AM
Stops, trailing and breakeven stops jonc NinjaTrader 4 November 9th, 2010 01:06 AM
Targets + Stops max-td Psychology and Money Management 24 September 14th, 2009 06:41 PM


All times are GMT -4. The time now is 01:29 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.07 seconds with 19 queries on phoenix via your IP 54.145.16.43