Last active
September 6, 2016 18:14
-
-
Save rymoore99/79c3b146b186206d200c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 DemoCrossoverStrategy2 : Strategy | |
{ | |
#region Variables | |
private int sma1Val = 10; | |
private int sma2Val = 20; | |
private int profitTarget = 10; | |
private int stopLoss = 20; | |
#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, Convert.ToDouble(this.stopLoss) / 100); | |
SetProfitTarget(CalculationMode.Percent, Convert.ToDouble(this.profitTarget) / 100); | |
} | |
/// <summary> | |
/// Called on each bar update event (incoming tick) | |
/// </summary> | |
protected override void OnBarUpdate() | |
{ | |
var sma1 = SMA(this.sma1Val); | |
var sma2 = SMA(this.sma2Val); | |
if (CrossAbove(sma1, sma2, 1)) { | |
EnterLong(); | |
} | |
} | |
#region Properties | |
[Description("First SMA Value")] | |
[GridCategory("SMA Parameters")] | |
public int SMA1 | |
{ | |
get { return sma1Val; } | |
set { sma1Val = Math.Max(1, value); } | |
} | |
[Description("Second SMA Value")] | |
[GridCategory("SMA Parameters")] | |
public int SMA2 | |
{ | |
get { return sma2Val; } | |
set { sma2Val = Math.Max(1, value); } | |
} | |
[Description("Stop Loss %")] | |
[GridCategory("Target Parameters")] | |
public int StopLoss | |
{ | |
get { return stopLoss; } | |
set { stopLoss = Math.Max(1, value); } | |
} | |
[Description("Profit Target %")] | |
[GridCategory("Target Parameters")] | |
public int ProfitTarget | |
{ | |
get { return profitTarget; } | |
set { profitTarget = Math.Max(1, value); } | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment