Stuttgart+Germany
Experience: Intermediate
Platform: NinjaTrader
Trading: ES
Posts: 2 since Jun 2012
Thanks Given: 0
Thanks Received: 0
|
Hi
I was wondering if someone can help me with Ninja code. I am new in the programming and trying to create my first strategy and have following issue. I want to set as Trailing Stop and exit condition, respectively "Chandelier Stop" but it does not react at all. What is wrong with this code? Would appreciate any help.
#region Variables
// Wizard generated variables
private double multi = 1.75; // ATR Multiplier
private int period = 1; // ATR Period
private double ch_Mulit = 3; // Chandelier Multiplier
private int ch_Period = 10; // Chandelier Period
private int stop_Loss = 25; // Initial Stop Loss
// 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()
{
Add(Bollinger(2, 20));
Add(Bollinger(2, 20));
Add(ATR(Period));
Add(Bollinger(2, 20));
Add(Bollinger(2, 20));
Add(ATR(Period));
SetStopLoss("", CalculationMode.Ticks, Stop_Loss, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Bollinger(2, 20).Upper[0] - Bollinger(2, 20).Lower[0]
< Multi * ATR(Period)[0]
&& CrossAbove(Close, Bollinger(2, 20).Upper, 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (Bollinger(2, 20).Upper[0] - Bollinger(2, 20).Lower[0]
< Multi * ATR(Period)[0]
&& CrossBelow(Close, Bollinger(2, 20).Lower, 1))
{
EnterShort(DefaultQuantity, "");
}
// Condition set 3
if (CrossBelow(Close, ChandelierStop(Ch_Period, Multi).ChandelierLo, 1))
{
ExitLong("", "");
}
// Condition set 4
if (CrossAbove(Close, ChandelierStop(Ch_Period, Multi).ChandelierHi, 1))
{
ExitShort("", "");
}
}
#region Properties
[Description("ATR Multiplier for Entry Signal")]
[GridCategory("Parameters")]
public double Multi
{
get { return multi; }
set { multi = Math.Max(1, value); }
}
[Description("ATR Period for Entry Signal")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
[Description("Chandelier Mulitplier for Trailing Stop")]
[GridCategory("Parameters")]
public double Ch_Mulit
{
get { return ch_Mulit; }
set { ch_Mulit = Math.Max(1, value); }
}
[Description("Chandelier Period for Trailing Stop")]
[GridCategory("Parameters")]
public int Ch_Period
{
get { return ch_Period; }
set { ch_Period = Math.Max(1, value); }
}
[Description("Initial Stop Loss")]
[GridCategory("Parameters")]
public int Stop_Loss
{
get { return stop_Loss; }
set { stop_Loss = Math.Max(1, value); }
}
#endregion
}
}
|