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,147 / 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 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
 3  
 
Thread Tools Search this Thread
 

VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy

  #51 (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,

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

Spencer, I'm at work right now so won't be able to test it till later. Thank you for the help Spencer!

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

hmmm, just realized

hmm, actually I am still new to Ninjascript. It seems like Position.AvgPrice is the average representation of the fill price. from the documentation

 
Code
{
    // Raise stop loss to breakeven when there is at least 10 ticks in profit
    if (Close[0] >= Position.AvgPrice + 10 * TickSize)
         ExitLongStop(Position.Quantity, Position.AvgPrice);
}
So, we probably don't need IOrder, but I hear that most professionals will only use them with real live strategies. We can always take IOrder out and replace _entry.AvgFillPrice with Position.AvgPrice and just add a simple SMA cross strategy or something.

Reply With Quote
 
  #53 (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
hmm, actually I am still new to Ninjascript. It seems like Position.AvgPrice is the average representation of the fill price. from the documentation

 
Code
{
    // Raise stop loss to breakeven when there is at least 10 ticks in profit
    if (Close[0] >= Position.AvgPrice + 10 * TickSize)
         ExitLongStop(Position.Quantity, Position.AvgPrice);
}
So, we probably don't need IOrder, but I hear that most professionals will only use them with real live strategies. We can always take IOrder out and replace _entry.AvgFillPrice with Position.AvgPrice and just add a simple SMA cross strategy or something.


you're correct about position.avgprice

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

Think this is it

Hey calhawk01

I think this code pretty much works.
I did not use IOrders. You can always take out the reason to get long or short. You can also play with the drawLine things.
However, I believe it works or at least it is a general outline to what you were looking for

take care
Spencer

 
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
{
    /*
	Author:  Spencer Davis
	This is an outline Trade Management strategy for using dynamic stops and targets
	*/
    [Description("A strategy that trails the stops")]
    public class sdTM : Strategy
    {
		//periods
		private int fastPeriod = 8;
		private int slowPeriod = 34;
		
		//trade management
		private int stopLoss = 18;
		private int target1 = 10;
		private int target2 = 20;
		private int target3 = 30;
		private SMA fastSMA;
		private SMA slowSMA;
		
		private bool drawStop = false;
		
        
        protected override void Initialize()
        {
		CalculateOnBarClose = true;
		EntryHandling = EntryHandling.UniqueEntries;
		fastSMA = SMA(FastPeriod);
		slowSMA = SMA(SlowPeriod);
		Add(slowSMA);
		Add(fastSMA);
		fastSMA.Plots[0].Pen.Width = 2;
		fastSMA.Plots[0].Pen.Color = Color.Green;
		slowSMA.Plots[0].Pen.Width = 2;
		slowSMA.Plots[0].Pen.Color = Color.Red;
			
        }

        protected override void OnBarUpdate()
        {
		if (CurrentBar < 20) return; //make sure there is enough data

		//buy conditions
		if (CrossAbove(SMA(FastPeriod), SMA(SlowPeriod), 1)&& Flat)
			GoLong();
		else if (CrossBelow(SMA(FastPeriod),SMA(SlowPeriod),1) && Flat)
			GoShort();			
		ManageTrade();
        }
	private void ManageTrade()
	{
		if(Long)
		{
			if (!drawStop)
				this.DrawLine("StopLine"+CurrentBar, true, 0, (Position.AvgPrice - StopLoss*TickSize), -8, (Position.AvgPrice -StopLoss*TickSize), Color.Red, DashStyle.Dash, 2);				
				
			if (High[0] >= (Position.AvgPrice + Target1*TickSize) && High[0] < (Position.AvgPrice + Target2*TickSize))
			{
				SetStopLoss("EntryLong", CalculationMode.Price, Position.AvgPrice, false);
				this.DrawLine("BreakEvenLong"+CurrentBar,true,0,(Position.AvgPrice + Target1*TickSize), -8, (Position.AvgPrice + Target1*TickSize), Color.Gray, DashStyle.Dash, 2);
			}
			if (High[0] >= (Position.AvgPrice + Target2*TickSize)&& High[0] < (Position.AvgPrice + Target3*TickSize))
			{
				SetStopLoss("EntryLong", CalculationMode.Price, Position.AvgPrice + Target1*TickSize, false);
				this.DrawLine("Target1Long"+CurrentBar,true,0,(Position.AvgPrice + Target2*TickSize), -8, (Position.AvgPrice + Target2*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			if (High[0] >= (Position.AvgPrice + Target3*TickSize))
			{
				ExitLong(1, "Exiting Long", "EntryLong");
				this.DrawLine("Target2Long"+CurrentBar,true,0,(Position.AvgPrice + Target3*TickSize), -8, (Position.AvgPrice + Target3*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			drawStop = true;	
		}
		if(Short)
		{
			if (!drawStop)
				this.DrawLine("StopLine"+CurrentBar, true, 0, (Position.AvgPrice + StopLoss*TickSize), -8, (Position.AvgPrice + StopLoss*TickSize), Color.Red, DashStyle.Dash, 2);				

			if (Low[0] <= (Position.AvgPrice - Target1*TickSize)&& Low[0] > (Position.AvgPrice - Target2*TickSize))
			{
				SetStopLoss("EntryShort", CalculationMode.Price, Position.AvgPrice, false);
				this.DrawLine("BreakEvenShort"+CurrentBar,true,0,(Position.AvgPrice - Target1*TickSize), -8, (Position.AvgPrice - Target1*TickSize), Color.Gray, DashStyle.Dash, 2);
			}
			if (Low[0] <= (Position.AvgPrice - Target2*TickSize)&& Low[0] > (Position.AvgPrice - Target3*TickSize))
			{
				SetStopLoss("EntryShort", CalculationMode.Price, Position.AvgPrice - Target1*TickSize, false);
				this.DrawLine("Target1Long"+CurrentBar,true,0,(Position.AvgPrice - Target2*TickSize), -8, (Position.AvgPrice - Target2*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			if (Low[0] <= (Position.AvgPrice - Target3*TickSize))
			{
				ExitShort(1, "Exiting Short", "EntryShort");
				this.DrawLine("Target2Long"+CurrentBar,true,0,(Position.AvgPrice - Target3*TickSize), -8, (Position.AvgPrice - Target3*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			drawStop = true;
		}
	}
	private void GoLong()
	{
		SetStopLoss("EntryLong", CalculationMode.Ticks, StopLoss, false);
		EnterLong(1, "EntryLong");
		drawStop = false;
	}
	private void GoShort()
	{
		SetStopLoss("EntryShort", CalculationMode.Ticks, StopLoss, false);
		EnterShort(1, "EntryShort");
		drawStop = false;
	}
	//returns current state of Flat, Long, or Short
	#region TradeState
	private bool Flat { get{ return Position.MarketPosition == MarketPosition.Flat; } }
	private bool Long { get{ return Position.MarketPosition == MarketPosition.Long; } }
	private bool Short { get{ return Position.MarketPosition == MarketPosition.Short; } }
	#endregion

        #region Properties
        [Description("Fast Period")]
        [GridCategory("Parameters")]
        public int FastPeriod
        {
            get { return fastPeriod; }
            set { fastPeriod = Math.Max(1, value); }
        }
		[Description("Slow Period")]
        [GridCategory("Parameters")]
        public int SlowPeriod
        {
            get { return slowPeriod; }
            set { slowPeriod = Math.Max(1, value); }
        }
		[Description("Stop Loss")]
        [GridCategory("Parameters")]
        public int StopLoss
        {
            get { return stopLoss; }
            set { stopLoss = Math.Max(1, value); }
        }
		[Description("1st Target")]
        [GridCategory("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("2nd Target")]
        [GridCategory("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("3rd Target")]
        [GridCategory("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		
        #endregion
    }
}


Last edited by spinnybobo; August 13th, 2013 at 09:33 PM.
Reply With Quote
The following user says Thank You to spinnybobo for this post:
 
  #55 (permalink)
Market Wizard
Houston, Texas
 
Futures Experience: Advanced
Platform: NinjaTrader; BloodHound
Broker/Data: NinjaTrader Brokerage, Kinetick, Rithmic
Favorite Futures: ES, CL, 6E, UB, 6J, 6B, ZS
 
Posts: 921 since Oct 2012
Thanks: 672 given, 877 received


Big Mike View Post
In this video tutorial I show how to create a strategy from scratch (not using the wizard, which I never use).

The strategy contains a few optimizable parameters such as SMA length, EMA length, HMA length, three different targets with custom tick settings on each, a stop size, and the option to move target 2 to breakeven after target 1 is hit, as well as move target 3 to breakeven after target 2 is hit.

[Mike

I got the following Recursive Property error when I compiled the strategy (see code below):
Your strategy likely holds one or more recursive properties which could cause NinjaTrader to crash: EMAlength HMALENGTH TARGET1 TARGET2 TARGET3 BE2 BE3

Do you want to edit these properties?
I have attached the code I created. Please note I did not use the SMA. Can anyone please point out what I typed in wrong?

Thank you.


JLW

#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>
/// Enter the description of your strategy here
/// </summary>
[Description("Create a strategy with optimizable variables")]
public class testbmt : Strategy
{
private int emalength = 20;
private int hmalength = 10;

private int target1 = 12;
private int target2 = 10;
private int target3 = 18;

private int stop = 12;

private bool be2 = false;
private bool be3 = false;

/// <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);
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("target1", CalculationMode.Price, Close(0) + (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1+Target2+Target3*TickSize));

EnterLong("target1");
EnterLong("target2");
EnterLong("target3");
)

private void GoShort()
(
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("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

)

private void ManageOrders()
(
if (Position.MarketPosition == MarketPosition.Long)
(
if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)

if (Position.MarketPosition == MarketPosition.Short)
(
if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)
)
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;

EMA emav = EMA(EMAlength);
HMA hmav = HMA(HMAlength);

ManageOrders();

if (Position.MarketPosition != MarketPosition.Flat) return;

if (Rising(emav) && Rising(hmav));
GoLong();
else if (Falling(emav) && Falling(hmav));
GoShort;
}

#region Properties
[Description("")]
[GridCategory("Parameters")]
public int EMAlength
{
get { return EMAlength; }
set { EMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int HMAlength
{
get { return HMAlength; }
set { HMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target1;
{
get { return target1; }
set { target1 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target2;
{
get { return target2; }
set { target2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target3;
{
get { return target3; }
set { target3 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Stop;
{
get { return stop; }
set { stop = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be2;
{
get { return be2; }
set { be2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be3;
{
get { return be3; }
set { be2 = Math.Max(1, value); }
}
#endregion
}
}

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


jlwade123 View Post
I got the following Recursive Property error when I compiled the strategy (see code below):
Your strategy likely holds one or more recursive properties which could cause NinjaTrader to crash: EMAlength HMALENGTH TARGET1 TARGET2 TARGET3 BE2 BE3

Do you want to edit these properties?
I have attached the code I created. Please note I did not use the SMA. Can anyone please point out what I typed in wrong?

Thank you.


JLW

#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>
/// Enter the description of your strategy here
/// </summary>
[Description("Create a strategy with optimizable variables")]
public class testbmt : Strategy
{
private int emalength = 20;
private int hmalength = 10;

private int target1 = 12;
private int target2 = 10;
private int target3 = 18;

private int stop = 12;

private bool be2 = false;
private bool be3 = false;

/// <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);
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("target1", CalculationMode.Price, Close(0) + (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1+Target2+Target3*TickSize));

EnterLong("target1");
EnterLong("target2");
EnterLong("target3");
)

private void GoShort()
(
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("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

)

private void ManageOrders()
(
if (Position.MarketPosition == MarketPosition.Long)
(
if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)

if (Position.MarketPosition == MarketPosition.Short)
(
if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)
)
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;

EMA emav = EMA(EMAlength);
HMA hmav = HMA(HMAlength);

ManageOrders();

if (Position.MarketPosition != MarketPosition.Flat) return;

if (Rising(emav) && Rising(hmav));
GoLong();
else if (Falling(emav) && Falling(hmav));
GoShort;
}

#region Properties
[Description("")]
[GridCategory("Parameters")]
public int EMAlength
{
get { return EMAlength; }
set { EMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int HMAlength
{
get { return HMAlength; }
set { HMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target1;
{
get { return target1; }
set { target1 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target2;
{
get { return target2; }
set { target2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target3;
{
get { return target3; }
set { target3 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Stop;
{
get { return stop; }
set { stop = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be2;
{
get { return be2; }
set { be2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be3;
{
get { return be3; }
set { be2 = Math.Max(1, value); }
}
#endregion
}
}

Hey JLW,

just to let you know, if you use

 
Code
  

//write code here
makes it look more readable.
It looks like you used () in places you should use {}

you wrote:

 
Code
private void GoShort()
(
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("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

)
it should be:

 
Code
private void GoShort()
{
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("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

}
This will probably give you a bunch of errors.
(....) are for functions and arguments
{....} is for blocks of code --- everything that goes inside of a method, class, namespace

Spencer

Reply With Quote
The following user says Thank You to spinnybobo for this post:
 
  #57 (permalink)
Trading Apprentice
Boston, Massachusetts
 
Futures Experience: Advanced
Platform: Ninjatrader,Tradestation
Favorite Futures: Oil
 
Posts: 7 since Mar 2013
Thanks: 1 given, 1 received

Question on Video

Big Mike

You mention in the video your running ninja on a virtual machine. Could you amplify on this. I guess more specifically
I am wondering if this gives some enhanced level of security for your code etc. From who, Ninja, Hackers etc.
and what virtual machine do you recommend?

Thanks
Jerry

Reply With Quote
 
  #58 (permalink)
Trading Apprentice
Wiesbaden
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 2 since Mar 2014
Thanks: 1 given, 0 received


Wazoo View Post
Big Mike

You mention in the video your running ninja on a virtual machine. Could you amplify on this. I guess more specifically
I am wondering if this gives some enhanced level of security for your code etc. From who, Ninja, Hackers etc.
and what virtual machine do you recommend?

Thanks
Jerry

I am not sure if those are the reasons Big Mike does it, but the following advantages come to my mind when running it on a Virtual Machine:
1. You can run a 2. instance of NinjaTrader
2. Assuming you are connecting to a demo account on your VM: Your testing of strategies etc. won't interfere with your live trading accounts (depending on how you test this could happen if you test it on your primary NT connected to your live accounts)
Hence: you completely keep your live trading and your research separated

Reply With Quote
 
  #59 (permalink)
Market Wizard
Houston, Texas
 
Futures Experience: Advanced
Platform: NinjaTrader; BloodHound
Broker/Data: NinjaTrader Brokerage, Kinetick, Rithmic
Favorite Futures: ES, CL, 6E, UB, 6J, 6B, ZS
 
Posts: 921 since Oct 2012
Thanks: 672 given, 877 received


Wazoo View Post
Big Mike

You mention in the video your running ninja on a virtual machine. Could you amplify on this. I guess more specifically
I am wondering if this gives some enhanced level of security for your code etc. From who, Ninja, Hackers etc.
and what virtual machine do you recommend?

Thanks
Jerry

I use Amazon S3 for free to house my Ninja data backup. I have been thinking increasing storage/memory from Amazon to use as a sandbox for my strategy development. Amazon is pretty cheap.

Reply With Quote
 
  #60 (permalink)
Trading Apprentice
kansas city, ks
 
Futures Experience: Intermediate
Platform: ninjatrader
Favorite Futures: stocks
 
Posts: 16 since Jun 2014
Thanks: 0 given, 5 received


great video, thanks

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 06:22 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-14 in 0.21 seconds with 20 queries on phoenix via your IP 54.160.245.121