I hope someone can help me. I am trying to develop a strategy which uses RSI in a multi time frame scenario. My situation is this. I want to go short whenever RSI crosses above let us say 65 in a 15 minute and a 5 minute chart.
I used your SampleMulti Time Frame strategy to develop my strategy. However this is not working. I can see the RSI cross over in both time periods however my stratey doesn't execute. Maybe I am doing something wrong.
Below is the code. If someone can tell me what I am doing wrong I will appreciate it.
Thanks
//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#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.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// This is a sample multi-time frame strategy.
/// </summary>
[Description("This is a sample multi-time frame strategy.")]
public class RSIMultiTimeFrame : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private int rSIPeriod = 14; // Default setting for RSIPeriod
private int rSISmooth = 3; // Default setting for RSISmooth
private int profitTarget = 13; // Default setting for ProfitTarget
private int stopLoss = 12; // Default setting for StopLoss
double crossoverValue = 65;
double crossoverValue2 = 65;
#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 a 5 minute Bars object to the strategy
Add(PeriodType.Minute, 5);
// Add a 15 minute Bars object to the strategy
Add(PeriodType.Minute, 15);
// Note: Bars are added to the BarsArray and can be accessed via an index value
// E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
// Add simple moving averages to the chart for display
// This only displays the SMA's for the primary Bars object on the chart
// Add(SMA(5));
// Add(SMA(50));
Add(RSI(14,3));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Historical)
return;
Print("" + Time[0] + " " + "RSI OUTSIDE IS NOW " + crossoverValue + RSI(BarsArray[2], 14,3));
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
// We only want to process events on our primary Bars object (index = 0) which is set when adding
// the strategy to a chart
//if (BarsInProgress != 0)
// return;
// Checks if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
if (CrossAbove(RSI(BarsArray[2], 14,3), crossoverValue,1))
Print("" + Time[0] + " " + "RSI IS NOW in 5 Min chart " + crossoverValue);
if (CrossAbove(RSI(BarsArray[1], 14,3), crossoverValue2,1))
Print("" + Time[0] + " " + "RSI IS NOW in 15 Min chart " + crossoverValue2);
// Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
//if (CrossAbove(RSI(RSIPeriod, RSISmooth),crossoverValue,1))
if (CrossAbove(RSI(BarsArray[2], 14,3), crossoverValue,1) && (CrossAbove(RSI(BarsArray[1], 14,3), crossoverValue2,1)))
EnterShort(2);
}
#region Properties
#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("Crossover value")]
[GridCategory("Parameters")]
public double CrossoverValue
{
get { return crossoverValue; }
set { crossoverValue = Math.Max(1, value); }
}
[Description("Crossover value 2")]
[GridCategory("Parameters")]
public double CrossoverValue2
{
get { return crossoverValue2; }
set { crossoverValue2 = Math.Max(1, value); }
}
#endregion
#endregion
}
}


Comment