Ninja Strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


Ninja Strategy
Updated: Views / Replies:1,014 / 4
Created: by 432860Steve 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 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
 
Thread Tools Search this Thread
 

Ninja Strategy

  #1 (permalink)
Trading Apprentice
Australia
 
Futures Experience: Beginner
Platform: Ninja & MT4
Broker/Data: GFT
Favorite Futures: Forex
 
432860Steve's Avatar
 
Posts: 2 since May 2011
Thanks: 1 given, 0 received

Ninja Strategy

Hi..I am trying to write my first Ninja strategy..a simple SMA cross one ...but cant get it to work. Is there anyone who can point me to some site/forum where I can learn the basics.

What I have so far.....
#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>
/// Test SMA 5,13
/// </summary>
[Description("Test SMA 5,13")]
public class MyCustomStrategy1 : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#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()
{
// Add a 5 minute Bars object to the strategy
Add(PeriodType.Minute, 5);

// Add a 15 minute Bars object to the strategy
Add(PeriodType.Minute, 15);

// Note: Bars are added to the BarsArray and can be accessed via an index value
// E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above

// Add simple moving averages to the chart for display
// This only displays the SMA's for the primary Bars object on the chart
Add(SMA(5));
Add(SMA(13));

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
// We only want to process events on our primary Bars object (index = 0) which is set when adding
// the strategy to a chart
if (BarsInProgress != 0)
return;

// Checks if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
if (SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 13)[0] && SMA(BarsArray[2], 5)[0] > SMA(BarsArray[2], 13)[0])
{
// Checks for a cross above condition of the 5 and 50 period SMA on the primary Bars object and enters long
if (CrossAbove(SMA(5), SMA(13), 1))
EnterLong(1000, "SMA");
SendMail("NinjaTest", "mcaullays@hotmail.com", "SMA Test", "SMA Test");

}

// Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
if (CrossBelow(SMA(BarsArray[2], 5), SMA(BarsArray[2], 13), 1))
ExitLong(1000);
SendMail("NinjaTest", "mcaullays@hotmail.com", "SMA Test", "SMA Test");

#region Properties
#endregion
}
}}


Last edited by 432860Steve; May 4th, 2011 at 09:54 AM. Reason: added extra detail
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
Melbourne, Australia
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG Markets
Favorite Futures: EUR?USD,AU/USD
 
sinisa's Avatar
 
Posts: 38 since Apr 2011
Thanks: 10 given, 41 received

Here we go


Firstly, make sure you have at lease .NET 2.0 or greater installed.
MS Kind of has had fun with this one, but first thing you are missing under declarations is

using syste.web.mail

Then in you strategy where you wish to send an e-mail you need this code

System.Web.Mail.MailMessage myMessage=new System.Web.Mail.MailMessage();

//Provide information for server authetication, as by default MS has assumed that you do not need to authenticate
//to your mail server, funny that

myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1 );
myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername","SmtpHostUserName" );
myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","SmtpHostPassword" );

myMessage.From="from e-mail";
myMessage.To="to e-mail";
myMessage.Subject="Message Subject";
myMessage.Body="Message Body";

System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(myMessage);

I would recommend putting above code into seprate method like

bool SendMeAMailNotification () {
System.Web.Mail.MailMessage myMessage=new System.Web.Mail.MailMessage();

//Provide information for server authetication, as by default MS has assumed that you do not need to authenticate
//to your mail server, funny that

myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1 );
myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername","SmtpHostUserName" );
myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","SmtpHostPassword" );

myMessage.From="from e-mail";
myMessage.To="to e-mail";
myMessage.Subject="Message Subject";
myMessage.Body="Message Body";

System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(myMessage);
}

And then at the places where you wish to call this just call this method, i did not put try and catch into this, but as you Working with the system resources would be recommended to place some error handling.

Regards

Markets are logical and
Reply With Quote
The following user says Thank You to sinisa for this post:
 
  #4 (permalink)
Elite Member
Melbourne, Australia
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG Markets
Favorite Futures: EUR?USD,AU/USD
 
sinisa's Avatar
 
Posts: 38 since Apr 2011
Thanks: 10 given, 41 received

Slightlly modified with the method and try catch

#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>
/// Test SMA 5,13
/// </summary>
[Description("Test SMA 5,13")]
public class MyCustomStrategy1 : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#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()
{
// Add a 5 minute Bars object to the strategy
Add(PeriodType.Minute, 5);

// Add a 15 minute Bars object to the strategy
Add(PeriodType.Minute, 15);

// Note: Bars are added to the BarsArray and can be accessed via an index value
// E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above

// Add simple moving averages to the chart for display
// This only displays the SMA's for the primary Bars object on the chart
Add(SMA(5));
Add(SMA(13));

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
// We only want to process events on our primary Bars object (index = 0) which is set when adding
// the strategy to a chart
if (BarsInProgress != 0) return;
bool msgSent = false;
// Checks if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
if (SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 13)[0] && SMA(BarsArray[2], 5)[0] > SMA(BarsArray[2], 13)[0]) {
// Checks for a cross above condition of the 5 and 50 period SMA on the primary Bars object and enters long
if (CrossAbove(SMA(5), SMA(13), 1)) EnterLong(1000, "SMA");
//SendMail("NinjaTest", "mcaullays@hotmail.com", "SMA Test", "SMA Test");
msgSent = SendMeAMessage();
}

// Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
if (CrossBelow(SMA(BarsArray[2], 5), SMA(BarsArray[2], 13), 1)) {
ExitLong(1000);
//SendMail("NinjaTest", "mcaullays@hotmail.com", "SMA Test", "SMA Test");
msgSent = SendMeAMessage();
}
}

private bool SendMeAMessage() {
try {
System.Web.Mail.MailMessage myMessage=new System.Web.Mail.MailMessage();

//Provide information for server authetication, as by default MS has assumed that you do not need to authenticate
//to your mail server, funny that

myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1 );
myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername","SmtpHostUserName" );
myMessage.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","SmtpHostPassword" );

myMessage.From="from e-mail";
myMessage.To="to e-mail";
myMessage.Subject="Message Subject";
myMessage.Body="Message Body";

System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(myMessage);

} catch ( Exception ex ) {
//do something when error
return false;
}
return true;


}

Hope it helps

Markets are logical and
Reply With Quote
The following 2 users say Thank You to sinisa for this post:
 
  #5 (permalink)
Trading Apprentice
Australia
 
Futures Experience: Beginner
Platform: Ninja & MT4
Broker/Data: GFT
Favorite Futures: Forex
 
432860Steve's Avatar
 
Posts: 2 since May 2011
Thanks: 1 given, 0 received

Still having trouble Sinisa.

Get error message
The type or namespace name 'system' could not be found (are you missing a using directive or an assembly reference?) CS0246 - click for info 8 7

Reply With Quote

Reply



futures io > > > > > Ninja Strategy

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
Ninja Indicator to Ninja Strategy emini_Holy_Grail NinjaTrader Programming 10 March 10th, 2013 12:23 AM
Converting TOS Study to Ninja Strategy cjcornelius ThinkOrSwim 1 August 12th, 2011 07:10 PM
Ninjatrader7 ATM Strategy combine with Strategy Wizard Ninja Script schuster21 NinjaTrader Programming 4 July 4th, 2011 05:39 PM
Ninja Strategy multi-timeframe issue/Strategy to indicator nw123 NinjaTrader Programming 2 December 20th, 2009 07:24 PM
Ninja Strategy gives diff results emini_Holy_Grail NinjaTrader 3 December 8th, 2009 06:52 AM


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