I'm new to NT, and I'm following the tutorial.
While testing the example "RSI with Stop Loss and Profit Target", I've encountered an issue that may be a bug.
Setup:
Version = NT 7.0.0.19
.NET/CLR Version = 2.0.50727.3603
Datafeed = Yahoo (builtin)
Ticker = BP (British Petroleum)
With this setup, I run a backtest in the Strategy Analyzer, on ticker BP, with the script below,
which is a slight modification of the script in the tutorial.
#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>
/// RSI with Stop Loss and Profit Target
/// </summary>
[Description("RSI with Stop Loss and Profit Target")]
public class Tutorial2 : Strategy
{
#region Variables
// Wizard generated variables
private int rSIPeriod = 13; // Default setting for RSIPeriod
private int rSISmooth = 10; // Default setting for RSISmooth
private int profitTarget = 10; // Default setting for ProfitTarget
private int stopLoss = 10; // Default setting for StopLoss
private CalculationMode calcMode = CalculationMode.Percent;
// 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()
{
CalculateOnBarClose = true;
// This will add the RSI indicator to the chart for visualization
Add(RSI(rSIPeriod, rSISmooth));
// Add stop loss and profit target orders
SetStopLoss(calcMode, stopLoss);
SetProfitTarget(calcMode, profitTarget);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < RSIPeriod)
return;
if (CrossAbove(RSI(RSIPeriod, RSISmooth), 30, 1))
{
EnterLong();
}
}
#region Properties
[Description("RSI Period")]
[GridCategory("Parameters")]
public int RSIPeriod
{
get { return rSIPeriod; }
set { rSIPeriod = Math.Max(1, value); }
}
[Description("RSI Smooth")]
[GridCategory("Parameters")]
public int RSISmooth
{
get { return rSISmooth; }
set { rSISmooth = Math.Max(1, value); }
}
[Description("Profit Target Offset")]
[GridCategory("Parameters")]
public int ProfitTarget
{
get { return profitTarget; }
set { profitTarget = Math.Max(1, value); }
}
[Description("Stop Loss Offset")]
[GridCategory("Parameters")]
public int StopLoss
{
get { return stopLoss; }
set { stopLoss = Math.Max(1, value); }
}
[Description("Calculation Mode")]
[GridCategory("Parameters")]
public CalculationMode CalcMode
{
get { return calcMode; }
set { calcMode = value; }
}
#endregion
}
}
Issue 1: Signal acts on RSI instead of Smoothed RSI.
My code says to enter Long if (CrossAbove(RSI(RSIPeriod, RSISmooth), 30, 1))
For this test, RSIPeriod = 13, and RSISmooth = 10.
The data for RSI(BP(Daily),13,10) in the Data Box on the chart is:
- On 12/02/2000:
- RSI = 26,9
- Avg = 27,37
- On 15/02/2000:
- RSI = 31,01
- Avg = 28,03
- On 16/02/2000:
- RSI = 30,87
- Avg = 28,55
Now, my expectation is that this crossover should be triggered on the Smoothed data (Avg).
In that case, there would be no crossing above 30 on 15/02/2000.
Else, what's the point in using the smooth parameter in the formula?
Is this a bug?
Issue 2: SetStopLoss and SetProfitTarget don't work
My SetStopLoss and SetProfitTarget seem to get triggered.
I only get 2 trades with this script:
The first is on 16/02/2000 (see issue 1 above)
And the second is on the last bar (exit on close)
I don't suppose this is a bug, but something that I'm missing...


Comment