here's the code:
#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>
/// Enter the description of your strategy here
/// </summary>
[Description("Display the SMA200 from the 1 min chart on the 50 tick chart (or another time period)")]
[Gui.Design.DisplayName("DrawSMA200")]
public class DrawSMA200 : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private int tagNumber = 0;
private string tagName;
private double sma200Value_0;
private double sma200Value_1;
#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 the 1 minute chart
Add(Instrument.FullName, PeriodType.Minute, 1);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (BarsInProgress == 1) // 1 min
{
sma200Value_0 = SMA(200)[0];
sma200Value_1 = SMA(200)[1];
return;
}
if (BarsInProgress == 0) // 50 tick chart
{
tagNumber = tagNumber + 1;
tagName = "tag" + tagNumber.ToString();
// Draw the SMA 200 from the 1 minute chart on the 50 tick chart using draw tools
DrawLine(tagName, 1, sma200Value_1, 0, sma200Value_0, Color.DarkOrchid, DashStyle.Solid, 4);
return;
}
}
#region Properties
#endregion
}
}
Comment