I have prepared simple code based on below sample:
http://www.ninjatrader.com/support/f...ead.php?t=3222
The code is as follows:
#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>
///
/// </summary>
[Description("Stop Loss, Breakeven, Take Profit")]
public class SLBETP : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private int ryzyko = 100;
private double Psize;
#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()
{
// !!! SetStopLoss(CalculationMode.Ticks, stoplossticks);
SetStopLoss(100);
SetProfitTarget(300);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(100);
}
// If a long position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 100)
{
SetStopLoss(100);
}
}
// Entry Condition
if (DonchianChannel(2).Upper[0] == DonchianChannel(2).Upper[1]
&& Close[0] < Close[1]
&& High[1] == DonchianChannel(2).Upper[1])
{
Pozycja();
EnterShort((int)Psize, "PKU-Open");
}
// Exit Condition
if (DonchianChannel(2).Upper[0] > DonchianChannel(2).Upper[1])
{
ExitShort("PKU-Close", "PKU-Open");
}
}
#region PozycjaFunction
void Pozycja()
{
Psize = (ryzyko/((DonchianChannel(2).Upper[0]-Close[0])*10000))/10*100000;
}
#endregion
#region Properties
/// <summary>
/// </summary>
[Description("Ryzyko w USD - 1R")]
[Category("Parameters")]
public int Ryzyko
{
get { return ryzyko; }
set { ryzyko = Math.Max(0, value); }
}
#endregion
}
}

Please support.

Comment