Thanks,
JoeMiller
[
#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
// ****************** ORIGINAL COPY FROM KOGONAM *****************
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// variable0 = +1 or -1 for current position = long or short or 0 = flat. Entry signal is red/green bar change confrirmed by a second red/green bar in the same direction.
/// </summary>
[Description("variable0 = +1 or -1 for current position = long or short or 0 = flat. Entry signal is red/green bar change confrirmed by a second red/green bar in the same direction.")]
public class Koganam : Strategy //WAS SwingRedBlueBars2
{
#region Variables
// Wizard generated variables
private int profitGoal = 16; // Default setting for ProfitGoal
private int stopLoss = 16; // Default setting for StopLoss
// User defined variables (add any user defined variables below)
private int calcIndex = 0; //we shall use this to adjust our bar references
#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("L", CalculationMode.Ticks, ProfitGoal);
SetStopLoss("L", CalculationMode.Ticks, StopLoss, false);
SetProfitTarget("S", CalculationMode.Ticks, ProfitGoal);
SetStopLoss("S", CalculationMode.Ticks, StopLoss, false);
CalculateOnBarClose = false;
}
protected override void OnStartUp()
{
if (Account.Name == "Backtest") //this means that we are in the Strategy Analyser
calcIndex = 0;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 2) return;
if (!Historical) calcIndex = 0;
else calcIndex = 1;
// Condition set 1
if (Close[1 - calcIndex] >= Open[1 - calcIndex]
&& Close[2 - calcIndex] >= Open[2 - calcIndex]
&& Variable0 == 0)
{
EnterLong(DefaultQuantity, "L");
Variable0 = 1;
}
// Condition set 2
if (Close[1 - calcIndex] <= Open[1 - calcIndex]
&& Close[2 - calcIndex] <= Open[2 - calcIndex]
&& Variable0 == 0)
{
EnterShort(DefaultQuantity, "S");
Variable0 = -1;
}
// Condition set 3
if (Position.MarketPosition == MarketPosition.Flat)
{
Variable0 = 0;
}
}
#region Properties
[Description("Profit Goal [ticks]")]
[GridCategory("Parameters")]
public int ProfitGoal
{
get { return profitGoal; }
set { profitGoal = Math.Max(1, value); }
}
[Description("Stop Loss [ticks]")]
[GridCategory("Parameters")]
public int StopLoss
{
get { return stopLoss; }
set { stopLoss = Math.Max(1, value); }
}
#endregion
}
}

Comment