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>
/// This strategy tries to maintain position on the direction of the price indication.
/// </summary>
[Description("This strategy tries to maintain position on the direction of the price indication.")]
public class Line : Strategy
{
#region Variables
// Wizard generated variables
private double pricepivot = 1920.00;
private int starttime = 83000;
private int stoptime = 155500;
private int startdate = 20160412;
private int stopdate = 20160413;
private int tickprofit = 16;
private int protectivestop = 8;// Default setting for Pricepivot
// 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()
{
SetProfitTarget("", CalculationMode.Ticks, tickprofit);
SetStopLoss("", CalculationMode.Ticks, protectivestop, false);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (ToDay(Time[0])>= startdate && ToDay(Time[0]) <= stopdate)
{
if ((ToTime(Time[0]) >= starttime && ToTime(Time[0]) <= stoptime))
{
// Condition set 1
if (CrossAbove(Close, Pricepivot, 1))
{
EnterLong(DefaultQuantity, "long");
}
// Condition set 2
if (CrossBelow(Close, Pricepivot, 1))
{
EnterShort(DefaultQuantity, "short");
}
}
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int Tickprofit
{
get { return tickprofit; }
set { tickprofit = Math.Max(1, value); }
}
#endregion
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int Protectivestop
{
get { return protectivestop; }
set { protectivestop = Math.Max(1, value); }
}
#endregion
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int Startdate
{
get { return startdate; }
set { startdate = Math.Max(1, value); }
}
#endregion
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int Stoptdate
{
get { return stopdate; }
set { stopdate = Math.Max(1, value); }
}
#endregion
#region Properties
[Description("")]
[GridCategory("Parameters")]
public double Pricepivot
{
get { return pricepivot; }
set { pricepivot = Math.Max(1, value); }
}
#endregion
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int Starttime
{
get { return starttime;}
set { starttime = Math.Max(1, value); }
}
#endregion
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int Stoptime
{
get { return stoptime; }
set { stoptime = Math.Max(1, value); }
}
#endregion
}
}
Last edited by a moderator: