VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy - NinjaTrader | futures io social day trading
futures io futures trading


VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy
Updated: Views / Replies:54,155 / 63
Created: by Big Mike Attachments:3

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 dont 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
 3  
 
Thread Tools Search this Thread
 

VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy

  #41 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


calhawk01 View Post
Thank you for the reply.

Now I have:

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			
			EnterLong("target1");

		}


		
		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
				
				if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
			
			}
This still does not seem to work. It exits at profit target1

Hi,

I couldn't find a description of what you were trying to do, but that seems correct with a single target.

Can you describe what it is you are trying to do?

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
 
  #42 (permalink)
Elite Member
baltimore marylnd
 
Futures Experience: Beginner
Platform: ninja
Favorite Futures: es
 
Posts: 69 since May 2013
Thanks: 1 given, 6 received


NJAMC View Post
Hi,

I couldn't find a description of what you were trying to do, but that seems correct with a single target.

Can you describe what it is you are trying to do?

hi NJAMC, apolgs for the late reply [went on a vaca ]

what i'm trying to do is:

buy one contract when my buy conditions are true, set my initial stoploss 12 ticks away, and have three targets, once target1 is hit, I want to move my initial stoploss to my purchase price, once target2 is hit, i want to move my stoploss to target1 and once target 3 is hit, i want to exit. i thought that is what this script did but it's a bit different :/

Reply With Quote
 
  #43 (permalink)
Elite Member
baltimore marylnd
 
Futures Experience: Beginner
Platform: ninja
Favorite Futures: es
 
Posts: 69 since May 2013
Thanks: 1 given, 6 received


 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
		
			EnterLong("target1");
			
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				
				if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
				
			}
when t1 is hit, it moves to stoploss to average price, but when t2 is hit, the stoploss isn't moved to t1

Reply With Quote
 
  #44 (permalink)
Elite Member
desert CA
 
Futures Experience: Intermediate
Platform: NT7, TOS
Broker/Data: AMP/wCQG, TDA
Favorite Futures: CL,YM
 
Posts: 2,027 since Jul 2011
Thanks: 2,211 given, 1,551 received

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
		
			EnterLong("target1");
			
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
                                else if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
                                else if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				
			}
                }

Just an idea. Reversing the order of the statements and using "else" so that "SetStopLoss" is not set multiple times in the loop. I don't have a strategy setup currently to test it.


Last edited by Cloudy; May 25th, 2013 at 03:43 AM.
Reply With Quote
 
  #45 (permalink)
Elite Member
baltimore marylnd
 
Futures Experience: Beginner
Platform: ninja
Favorite Futures: es
 
Posts: 69 since May 2013
Thanks: 1 given, 6 received

Cloudy, thank you for trying. Still no luck though :/

here is the complete code to the strategy:

 
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>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")]
    public class TargetES930 : Strategy
    {
        //#region Variables
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		
		private int		stop			= 12;
		
		private bool	be2				= true;
		private bool	be3				= true;
		
		
		//#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()
        {
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
			
			
        }
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
		
			EnterLong("target1");
			
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
                                else if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
                                else if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				
			}
                
			
		}

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;

ManageOrders();

if (CrossBelow(CCI(14), 250, 1))
EnterLong();
}

        //#region Properties
		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE2
        {
            get { return be2; }
            set { be2 = value; }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE3
        {
            get { return be3; }
            set { be3 = value; }
        }
		
		
        //#endregion
    }
}

Reply With Quote
The following user says Thank You to calhawk01 for this post:
 
  #46 (permalink)
Elite Member
baltimore marylnd
 
Futures Experience: Beginner
Platform: ninja
Favorite Futures: es
 
Posts: 69 since May 2013
Thanks: 1 given, 6 received

Alright i'm going to give up on this unless someone helps me lol

I've tried to play around with this for the past several days but it does not seem to work properly

Current code I have, does not seem to call the "manage order();" properly.

It enters the positions, but the stoploss only changes ONCE when target1 is hit, the stoploss moves to avg price, but when target2 is hit, stoploss is never moved to target1 and so on..

Thanks in advance for looking at the code:

 
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>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")]
    public class TargetES930 : Strategy
    {
        //#region Variables
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		
		private int		stop			= 12;
		
		private bool	be2				= true;
		private bool	be3				= true;
		
		
		//#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()
        {
            CalculateOnBarClose = false;
			EntryHandling		= EntryHandling.UniqueEntries;
			
		}
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target2*TickSize));	
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
			
			}
                
			
		}

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

            EntryHandling		= EntryHandling.UniqueEntries;
			
			GoLong();
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			if (........ENTER ANY TRADING LOGIC.................))
				EnterLong("target1");
				GoLong();
			if (ToTime(Time[0]) == ToTime(15, 56, 0))
				ExitLong("", "");			
        }

        //#region Properties
		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE2
        {
            get { return be2; }
            set { be2 = value; }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE3
        {
            get { return be3; }
            set { be3 = value; }
        }
		
		
        //#endregion
    }
}

Reply With Quote
 
  #47 (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


calhawk01 View Post
Alright i'm going to give up on this unless someone helps me lol

I've tried to play around with this for the past several days but it does not seem to work properly

Current code I have, does not seem to call the "manage order();" properly.

It enters the positions, but the stoploss only changes ONCE when target1 is hit, the stoploss moves to avg price, but when target2 is hit, stoploss is never moved to target1 and so on..

Thanks in advance for looking at the code:

 
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>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")]
    public class TargetES930 : Strategy
    {
        //#region Variables
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		
		private int		stop			= 12;
		
		private bool	be2				= true;
		private bool	be3				= true;
		
		
		//#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()
        {
            CalculateOnBarClose = false;
			EntryHandling		= EntryHandling.UniqueEntries;
			
		}
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target2*TickSize));	
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
			
			}
                
			
		}

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

            EntryHandling		= EntryHandling.UniqueEntries;
			
			GoLong();
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			if (........ENTER ANY TRADING LOGIC.................))
				EnterLong("target1");
				GoLong();
			if (ToTime(Time[0]) == ToTime(15, 56, 0))
				ExitLong("", "");			
        }

        //#region Properties
		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE2
        {
            get { return be2; }
            set { be2 = value; }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE3
        {
            get { return be3; }
            set { be3 = value; }
        }
		
		
        //#endregion
    }
}

Hey Calhawk01

it looks like in the method GoLong() you only have SetProfitTarget for "target1" and did not set it for "target2 and "target3. If you don't set them, then they don't exist.
or you are setting them the manageorders and bugs are then happening. Make sure when you first GoLong, you have Stops and all Profit Targets set. then when they are set, you can properly call manageorders. otherwise weird things happen and hard to trace. make a step by step list, then program it that way. It will take care of most of your problems.

actually, now that I look at it, if you are using 3 positions you need to call SetStopLoss 3 times.
here is the code you should start with as a template. It has been stripped down. If not using the optimizer, then you don't need B/E, if you are not going short, then you don't need short logic.

 
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>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")] //modified by Spencer Davis as a simple template 05/30/2013.  
    public class MyMoneyMaker_BigMike : Strategy
    {
        
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		private int		stop			= 12;
		
		
		
        protected override void Initialize()
        {
            
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
			
			
        }
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");
			EnterLong("target2");
			EnterLong("target3");
			
		}
		
		private void ManageOrders()
		{
			if (Position.MarketPosition == MarketPosition.Long)
			{
				//Enter Trade management logic here for stop tightening
			}
		}

        protected override void OnBarUpdate()
        {
            EntryHandling		= EntryHandling.UniqueEntries;
			
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			//if ( enter reason for going long here ) 
			//	GoLong();
			
        }

		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
    }
}
hope this helps.
can you please describe your management strategy?

Spencer


Last edited by spinnybobo; May 30th, 2013 at 11:31 AM.
Reply With Quote
 
  #48 (permalink)
Elite Member
baltimore marylnd
 
Futures Experience: Beginner
Platform: ninja
Favorite Futures: es
 
Posts: 69 since May 2013
Thanks: 1 given, 6 received


spinnybobo View Post
Hey Calhawk01

it looks like in the method GoLong() you only have SetProfitTarget for "target1" and did not set it for "target2 and "target3. If you don't set them, then they don't exist.
or you are setting them the manageorders and bugs are then happening. Make sure when you first GoLong, you have Stops and all Profit Targets set. then when they are set, you can properly call manageorders. otherwise weird things happen and hard to trace. make a step by step list, then program it that way. It will take care of most of your problems.

actually, now that I look at it, if you are using 3 positions you need to call SetStopLoss 3 times.
here is the code you should start with as a template. It has been stripped down. If not using the optimizer, then you don't need B/E, if you are not going short, then you don't need short logic.

 
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>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")] //modified by Spencer Davis as a simple template 05/30/2013.  
    public class MyMoneyMaker_BigMike : Strategy
    {
        
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		private int		stop			= 12;
		
		
		
        protected override void Initialize()
        {
            
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
			
			
        }
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");
			EnterLong("target2");
			EnterLong("target3");
			
		}
		
		private void ManageOrders()
		{
			if (Position.MarketPosition == MarketPosition.Long)
			{
				//Enter Trade management logic here for stop tightening
			}
		}

        protected override void OnBarUpdate()
        {
            EntryHandling		= EntryHandling.UniqueEntries;
			
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			//if ( enter reason for going long here ) 
			//	GoLong();
			
        }

		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
    }
}
hope this helps.
can you please describe your management strategy?

Spencer

Hello Spencer, the above code enters three different positions. that's what i'm trying to change. the original code posted by bigmike also enters three different positions. I want to enter one position (one contract) with three different profit targets and stoplosses that move once profit targets are hit. initial stoploss 12 ticks, if target1 is hit then stoploss= avg price, if target2 is hit, then stoploss=target1, if target3 is hit, then stoploss= target2

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");
			EnterLong("target2");
			EnterLong("target3");
			
		}
the above creates three different positions/ buys three contracts

i figured the below would set the stoploss and target1 when the trade is first entered, but once target1 is hit, ManageOrder() would kick in and move the stoplosses. Ya know?

 
Code

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);

			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));

			
			EnterLong("target1");

			
		}

Reply With Quote
 
  #49 (permalink)
Elite Member
baltimore marylnd
 
Futures Experience: Beginner
Platform: ninja
Favorite Futures: es
 
Posts: 69 since May 2013
Thanks: 1 given, 6 received

anyone? maybe I can paypal you some cash?? i really dont feel like dropping hundreds of dollars to one of the indicator creating companies! b/c i feel like i already have the correct code.. just needs some additional coding or move some parts around. need:

buy ONE contract when trade logic becomes true with the following trade management settings: initial stoploss 12 ticks, if target1 is hit then stoploss= avg price, if target2 is hit, then stoploss=target1, if target3 is hit, then stoploss= target2

thank you in advance for taking the time

Reply With Quote
 
  #50 (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

off the top of my head


Hey,

Ok, I know what you mean now. So, I think in order to access the entry price, you need to create an IOrder object.

 
Code
private IOrder _entry = null;

//then you can do this
_entry = EnterLong("tag you want to give");

//then later you can do this
if (High[0] >= (target1 * TickSize))
SetStopLoss(CaculationMode.Price, (_entry.AvgFillPrice);
I did not try it out yet. Look at Scott Shodsons Ninja Trader webinars. He uses IOrders a lot.
He has 2 webinars. They are very good.

 
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>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")] //modified by Spencer Davis as a simple template 05/30/2013.  
    public class MyMoneyMaker_BigMike : Strategy
    {
        
		
		private int		_target1			= 12;
		private int		_target2			= 10;
		private int		_target3			= 24;
		private int		_stop			= 12;
		
		private IOrder _entry = null;
		
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
        }
		
		private void GoLong()
		{
			SetStopLoss("Enter_Position", CalculationMode.Price, Close[0] - (Stop*TickSize), false);

			_entry = EnterLong("Enter_Position");
		}
		
		private void ManageOrders()
		{
			if (Position.MarketPosition == MarketPosition.Long)
			{
				if(High[0] >= (_target1 * TickSize))
					SetStopLoss(CalculationMode.Price, _entry.AvgFillPrice);
				else if (High[0] >= (_target2 * TickSize))
					SetStopLoss(CalculationMode.Price, (_entry.AvgFillPrice + (_target1 * TickSize)));
				else if (High[0] >= (_target3 * TickSize))
					SetStopLoss(CalculationMode.Price, (_entry.AvgFillPrice + (_target2 * TickSize)));
			}
		}

        protected override void OnBarUpdate()
        {
            EntryHandling		= EntryHandling.UniqueEntries;
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			//if ( enter reason for going long here ) 
			//	GoLong();
			
        }

		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return _target1; }
            set { _target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return _target2; }
            set { _target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return _target3; }
            set { _target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return _stop; }
            set { _stop = Math.Max(1, value); }
        }
    }
}
hope this helps

I will code something later and test it.
Spencer

Reply With Quote

Reply



futures io > > > > VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy Big Mike MultiCharts 39 November 9th, 2017 04:35 AM
VIDEO: MultiCharts vs. NinjaTrader strategy backtesting and optimization Big Mike MultiCharts 53 June 12th, 2016 02:34 PM
Anyone know of good video tutorial for C# language? whoisthere48 NinjaTrader Programming 11 April 1st, 2012 06:33 PM
Is there a video tutorial on creating a NT indicator (in 6.5)? Thanks. aquarian1 NinjaTrader 9 May 16th, 2011 06:56 PM
VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy Big Mike NinjaTrader Programming 0 January 26th, 2010 06:22 AM


All times are GMT -4. The time now is 01:13 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-14 in 0.14 seconds with 20 queries on phoenix via your IP 54.234.255.29