I was reading the following sample script
Question : Does this example have two time frames namely 5 minutes and 15 minute time frames
or
are there three time frames in the example below ?
copy of script is here below
SampleMultiTimeFrameOrders : Strategy
//
// Copyright (C) 2008, 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>
/// Reference sample demonstrating how to submit orders to different bars arrays.
/// </summary>
[Description("Reference sample demonstrating how to submit orders to different bars arrays.")]
public class SampleMultiTimeFrameOrders : Strategy
{
#region Variables
// Wizard generated variables
// 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 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);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
/* OnBarUpdate() method will execute this portion of the code when incoming ticks are on the
primary bar object. */
if (BarsInProgress == 1)
{
/* Checks if the 5 period SMA is decreasing in the secondary bar series (5min) and if it is below the 10
period SMA in the tertiary bar series (15min). */
if (SMA(5)[0] < SMA(5)[1] && SMA(5)[0] < SMA(BarsArray[2], 10)[0])
{
/* Exit the long position entered from the 15min bar object on a more granular time period.
This allows for more control in the management of your positions and can be used to improve
exit timing of your trades. */
ExitLong("Exit Long from 5min", "Enter Long from 15min");
}
}
/* OnBarUpdate() method will execute this portion of the code when incoming ticks are on the
tertiary bar object (15min). */
if (BarsInProgress == 2)
{
// Checks if the 25 period SMA is greater than the 50 period SMA on the 15min.
if (SMA(25)[0] > SMA(50)[0])
{
/* Enter long for 1 contract on the 15min bar object based on the barsInProgress parameter.
A value of 0=primary bars, 1=secondary bars, 2=tertiary bars */
EnterLong(2, 1, "Enter Long from 15min");
}
}
}
#region Properties
#endregion
}
}
Comment