Skip to content

Instantly share code, notes, and snippets.

@rymoore99
Last active September 6, 2016 18:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rymoore99/11176820 to your computer and use it in GitHub Desktop.
Save rymoore99/11176820 to your computer and use it in GitHub Desktop.
#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>
/// An example crossover strategy
/// </summary>
[Description("An example crossover strategy")]
public class DemoCrossoverStrategy : 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()
{
CalculateOnBarClose = true;
// we'll set the stop loss for our positions globally
SetStopLoss(CalculationMode.Percent, .1);
SetProfitTarget(CalculationMode.Percent, .2);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
var sma1 = SMA(10);
var sma2 = SMA(20);
if (CrossAbove(sma1, sma2, 1)) {
EnterLong();
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment