TRADING SYSTEMS

Pair Trading

Developing A Multilevel Strategy

by Vladimir Vladimirovich Voznjuk

Code not included in the print version of the magazine

multiGBP.cs


#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.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class multiGBP : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
		private string s1="1-m";
		private string s5="5-m";
		private string s15="15-m";
		private string s30="30-m";
		private string s60="60-m ";
		private string sd="daily  trend";
		private double z,bp,ch;
		private double x;
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Add(new Plot(Color.Black,  "Plot0"));

            Overlay				= false;
						Add(new Line(System.Drawing.Color.DarkViolet, 3, "Lower"));
			Add(new Line(System.Drawing.Color.YellowGreen, -3, "Upper"));
				
					Add("6B 06-11", PeriodType.Minute, 1);
					Add("6B 06-11", PeriodType.Minute, 5);
					Add("6B 06-11", PeriodType.Minute, 15);
					Add("6B 06-11", PeriodType.Minute, 30);
					Add("6B 06-11", PeriodType.Minute, 60);


        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			//DrawTextFixed("tag1", s1+"\n"+s5+"\n"+s15+"\n"+s30+"\n"+s60+"\n"+sd, TextPosition.TopLeft);
			//DrawTextFixed("tag2", "Text to draw", TextPosition.TopLeft);
		//	DrawTextFixed("tag3", "Text to draw", TextPosition.TopLeft);
		//	DrawTextFixed("tag4", "Text to draw", TextPosition.TopLeft);
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
			//BarsArray[0].MarketData.
			z=0;
			//if (CurrentBars[0]>4)
			if (CurrentBars[0]<4)
			{
		           Plot0.Set(0);

			}
			else
			{
			
			//-----------------------------------------------
						if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==1) {	 z=(Close[0]-Open[0])+(Closes[1][0]-Opens[1][0])*10000;DrawTextFixed("tag2", s1, TextPosition.TopLeft);}
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==5) 	{    z=(Close[0]-Open[0])+(Closes[2][0]-Opens[2][0])*10000; DrawTextFixed("tag2", s5, TextPosition.TopLeft);  }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==15) {	 z=(Close[0]-Open[0])+(Closes[3][0]-Opens[3][0])*10000; DrawTextFixed("tag2", s15, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==30) {	 z=(Close[0]-Open[0])+(Closes[4][0]-Opens[4][0])*10000; DrawTextFixed("tag2", s30, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==60) {	 z=(Close[0]-Open[0])+(Closes[5][0]-Opens[5][0])*10000;  DrawTextFixed("tag2", s60, TextPosition.TopLeft);  }
			///---------------------------
			
			
       
			
			Plot1.Set(z);
			
			}
        }

        #region Properties
        [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        public DataSeries Plot0
        {
            get { return Values[0]; }
        }
        public DataSeries Plot1
        {
            get { return Values[0]; }
        }
		        public DataSeries Plot2
        {
            get { return Values[0]; }
        }
        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public partial class Indicator : IndicatorBase
    {
        private multiGBP[] cachemultiGBP = null;

        private static multiGBP checkmultiGBP = new multiGBP();

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public multiGBP multiGBP(int myInput0)
        {
            return multiGBP(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public multiGBP multiGBP(Data.IDataSeries input, int myInput0)
        {
            if (cachemultiGBP != null)
                for (int idx = 0; idx < cachemultiGBP.Length; idx++)
                    if (cachemultiGBP[idx].MyInput0 == myInput0 && cachemultiGBP[idx].EqualsInput(input))
                        return cachemultiGBP[idx];

            lock (checkmultiGBP)
            {
                checkmultiGBP.MyInput0 = myInput0;
                myInput0 = checkmultiGBP.MyInput0;

                if (cachemultiGBP != null)
                    for (int idx = 0; idx < cachemultiGBP.Length; idx++)
                        if (cachemultiGBP[idx].MyInput0 == myInput0 && cachemultiGBP[idx].EqualsInput(input))
                            return cachemultiGBP[idx];

                multiGBP indicator = new multiGBP();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.MyInput0 = myInput0;
                Indicators.Add(indicator);
                indicator.SetUp();

                multiGBP[] tmp = new multiGBP[cachemultiGBP == null ? 1 : cachemultiGBP.Length + 1];
                if (cachemultiGBP != null)
                    cachemultiGBP.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cachemultiGBP = tmp;
                return indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public partial class Column : ColumnBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.multiGBP multiGBP(int myInput0)
        {
            return _indicator.multiGBP(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.multiGBP multiGBP(Data.IDataSeries input, int myInput0)
        {
            return _indicator.multiGBP(input, myInput0);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.multiGBP multiGBP(int myInput0)
        {
            return _indicator.multiGBP(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.multiGBP multiGBP(Data.IDataSeries input, int myInput0)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.multiGBP(input, myInput0);
        }
    }
}
#endregion




multiJPY.cs

#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.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class multiJPY : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
		private string s1="1-m";
		private string s5="5-m";
		private string s15="15-m";
		private string s30="30-m";
		private string s60="60-m ";
		private string sd="daily  trend";
		private double z,bp,ch;
		private double x;
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Add(new Plot(Color.Black,  "Plot0"));

            Overlay				= false;
						Add(new Line(System.Drawing.Color.DarkViolet, -0.02, "Lower"));
			Add(new Line(System.Drawing.Color.YellowGreen, 0.02, "Upper"));
					Add("6J 06-11", PeriodType.Minute, 1);
					Add("6J 06-11", PeriodType.Minute, 5);
					Add("6J 06-11", PeriodType.Minute, 15);
					Add("6J 06-11", PeriodType.Minute, 30);
					Add("6J 06-11", PeriodType.Minute, 60);
			// 					
					Add("6B 06-11", PeriodType.Minute, 1);
					Add("6B 06-11", PeriodType.Minute, 5);
					Add("6B 06-11", PeriodType.Minute, 15);
					Add("6B 06-11", PeriodType.Minute, 30);
					Add("6B 06-11", PeriodType.Minute, 60);
			//
					Add("6S 06-11", PeriodType.Minute, 1);
					Add("6S 06-11", PeriodType.Minute, 5);
					Add("6S 06-11", PeriodType.Minute, 15);
					Add("6S 06-11", PeriodType.Minute, 30);
					Add("6S 06-11", PeriodType.Minute, 60);
					
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			//DrawTextFixed("tag1", s1+"\n"+s5+"\n"+s15+"\n"+s30+"\n"+s60+"\n"+sd, TextPosition.TopLeft);
			//DrawTextFixed("tag2", "Text to draw", TextPosition.TopLeft);
		//	DrawTextFixed("tag3", "Text to draw", TextPosition.TopLeft);
		//	DrawTextFixed("tag4", "Text to draw", TextPosition.TopLeft);
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
			//BarsArray[0].MarketData.
			z=0;
			//if (CurrentBars[0]>4)
			if (CurrentBars[0]<4)
			{
		           Plot0.Set(0);
			Plot1.Set(0);
			Plot2.Set(0);
			}
			else
			{
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==1) {	 z=(Close[0]-Open[0])-(Closes[1][0]-Opens[1][0])*10000;DrawTextFixed("tag2", s1, TextPosition.TopLeft);}
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==5) 	{    z=(Close[0]-Open[0])-(Closes[2][0]-Opens[2][0])*10000; DrawTextFixed("tag2", s5, TextPosition.TopLeft);  }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==15) {	 z=(Close[0]-Open[0])-(Closes[3][0]-Opens[3][0])*10000; DrawTextFixed("tag2", s15, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==30) {	 z=(Close[0]-Open[0])-(Closes[4][0]-Opens[4][0])*10000; DrawTextFixed("tag2", s30, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==60) {	 z=(Close[0]-Open[0])-(Closes[5][0]-Opens[5][0])*10000;  DrawTextFixed("tag2", s60, TextPosition.TopLeft);  }
			//-----------------------------------------------
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==1) {	 bp=(Close[0]-Open[0])+(Closes[6][0]-Opens[6][0])*10000;DrawTextFixed("tag2", s1, TextPosition.TopLeft);}
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==5) 	{    bp=(Close[0]-Open[0])+(Closes[7][0]-Opens[7][0])*10000; DrawTextFixed("tag2", s5, TextPosition.TopLeft);  }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==15) {	 bp=(Close[0]-Open[0])+(Closes[8][0]-Opens[8][0])*10000; DrawTextFixed("tag2", s15, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==30) {	 bp=(Close[0]-Open[0])+(Closes[9][0]-Opens[9][0])*10000; DrawTextFixed("tag2", s30, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==60) {	 bp=(Close[0]-Open[0])+(Closes[10][0]-Opens[10][0])*10000;  DrawTextFixed("tag2", s60, TextPosition.TopLeft);  }
			///---------------------------
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==1) {	 bp=(Close[0]-Open[0])-(Closes[11][0]-Opens[11][0])*10000;DrawTextFixed("tag2", s1, TextPosition.TopLeft);}
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==5) 	{    bp=(Close[0]-Open[0])-(Closes[12][0]-Opens[12][0])*10000; DrawTextFixed("tag2", s5, TextPosition.TopLeft);  }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==15) {	 bp=(Close[0]-Open[0])-(Closes[13][0]-Opens[13][0])*10000; DrawTextFixed("tag2", s15, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==30) {	 bp=(Close[0]-Open[0])-(Closes[14][0]-Opens[14][0])*10000; DrawTextFixed("tag2", s30, TextPosition.TopLeft);   }
			if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==60) {	 bp=(Close[0]-Open[0])-(Closes[15][0]-Opens[15][0])*10000;  DrawTextFixed("tag2", s60, TextPosition.TopLeft);  }
			
           Plot0.Set(z);
			
			Plot1.Set(bp);
			Plot2.Set(ch);
			}
        }

        #region Properties
        [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        public DataSeries Plot0
        {
            get { return Values[0]; }
        }
        public DataSeries Plot1
        {
            get { return Values[0]; }
        }
		        public DataSeries Plot2
        {
            get { return Values[0]; }
        }
        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public partial class Indicator : IndicatorBase
    {
        private multiJPY[] cachemultiJPY = null;

        private static multiJPY checkmultiJPY = new multiJPY();

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public multiJPY multiJPY(int myInput0)
        {
            return multiJPY(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public multiJPY multiJPY(Data.IDataSeries input, int myInput0)
        {
            if (cachemultiJPY != null)
                for (int idx = 0; idx < cachemultiJPY.Length; idx++)
                    if (cachemultiJPY[idx].MyInput0 == myInput0 && cachemultiJPY[idx].EqualsInput(input))
                        return cachemultiJPY[idx];

            lock (checkmultiJPY)
            {
                checkmultiJPY.MyInput0 = myInput0;
                myInput0 = checkmultiJPY.MyInput0;

                if (cachemultiJPY != null)
                    for (int idx = 0; idx < cachemultiJPY.Length; idx++)
                        if (cachemultiJPY[idx].MyInput0 == myInput0 && cachemultiJPY[idx].EqualsInput(input))
                            return cachemultiJPY[idx];

                multiJPY indicator = new multiJPY();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.MyInput0 = myInput0;
                Indicators.Add(indicator);
                indicator.SetUp();

                multiJPY[] tmp = new multiJPY[cachemultiJPY == null ? 1 : cachemultiJPY.Length + 1];
                if (cachemultiJPY != null)
                    cachemultiJPY.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cachemultiJPY = tmp;
                return indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public partial class Column : ColumnBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.multiJPY multiJPY(int myInput0)
        {
            return _indicator.multiJPY(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.multiJPY multiJPY(Data.IDataSeries input, int myInput0)
        {
            return _indicator.multiJPY(input, myInput0);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.multiJPY multiJPY(int myInput0)
        {
            return _indicator.multiJPY(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.multiJPY multiJPY(Data.IDataSeries input, int myInput0)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.multiJPY(input, myInput0);
        }
    }
}
#endregion



MultiCurrencyIndicator.cs


#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.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class MultiCurrencyIndicator : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
		private string s1="1-m";
		private string s5="5-m";
		private string s15="15-m";
		private string s30="30-m";
		private string s60="60-m ";
		private string sd="daily  trend";
		private double z;
		private double x;
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
            Overlay				= false;
						Add(new Line(System.Drawing.Color.DarkViolet, -0.02, "Lower"));
			Add(new Line(System.Drawing.Color.YellowGreen, 0.02, "Upper"));
					Add("6J 06-11", PeriodType.Minute, 1);
					Add("6C 06-11", PeriodType.Minute, 1);
					Add("6B 06-11", PeriodType.Minute, 1);
					Add("6S 06-11", PeriodType.Minute, 1);
				//	Add("6J 06-11", PeriodType.Minute, 1);
					
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			//DrawTextFixed("tag1", s1+"\n"+s5+"\n"+s15+"\n"+s30+"\n"+s60+"\n"+sd, TextPosition.TopLeft);
			//DrawTextFixed("tag2", "Text to draw", TextPosition.TopLeft);
		//	DrawTextFixed("tag3", "Text to draw", TextPosition.TopLeft);
		//	DrawTextFixed("tag4", "Text to draw", TextPosition.TopLeft);
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
			//BarsArray[0].MarketData.
			z=0;
		//	if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==1) {	 z=(Close[0]-Open[0])-(Closes[1][0]-Opens[1][0])*10000;DrawTextFixed("tag2", s1, TextPosition.TopLeft);}
			//if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==5) 	{    z=(Close[0]-Open[0])-(Closes[2][0]-Opens[2][0])*10000; DrawTextFixed("tag2", s5, TextPosition.TopLeft);  }
			//if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==15) {	 z=(Close[0]-Open[0])-(Closes[3][0]-Opens[3][0])*10000; DrawTextFixed("tag2", s15, TextPosition.TopLeft);   }
			//if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==30) {	 z=(Close[0]-Open[0])-(Closes[4][0]-Opens[4][0])*10000; DrawTextFixed("tag2", s30, TextPosition.TopLeft);   }
			//if (BarsPeriod.BasePeriodType==PeriodType.Minute&&BarsPeriod.Value==60) {	 z=(Close[0]-Open[0])-(Closes[5][0]-Opens[5][0])*10000;  DrawTextFixed("tag2", s60, TextPosition.TopLeft);  }
z=(Close[0]-Open[0])/0.0001-(Closes[1][0]-Opens[1][0])/0.000001+(Closes[3][0]-Opens[3][0])/0.0001-(Closes[4][0]-Opens[4][0])/0.0001-(Closes[2][0]-Opens[2][0])/0.0001;
			//*1000;
			//DrawTextFixed("tag2", s1, TextPosition.TopLeft);}			
            Plot0.Set(z);
        }

        #region Properties
        [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        public DataSeries Plot0
        {
            get { return Values[0]; }
        }

        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public partial class Indicator : IndicatorBase
    {
        private MultiCurrencyIndicator[] cacheMultiCurrencyIndicator = null;

        private static MultiCurrencyIndicator checkMultiCurrencyIndicator = new MultiCurrencyIndicator();

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public MultiCurrencyIndicator MultiCurrencyIndicator(int myInput0)
        {
            return MultiCurrencyIndicator(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public MultiCurrencyIndicator MultiCurrencyIndicator(Data.IDataSeries input, int myInput0)
        {
            if (cacheMultiCurrencyIndicator != null)
                for (int idx = 0; idx < cacheMultiCurrencyIndicator.Length; idx++)
                    if (cacheMultiCurrencyIndicator[idx].MyInput0 == myInput0 && cacheMultiCurrencyIndicator[idx].EqualsInput(input))
                        return cacheMultiCurrencyIndicator[idx];

            lock (checkMultiCurrencyIndicator)
            {
                checkMultiCurrencyIndicator.MyInput0 = myInput0;
                myInput0 = checkMultiCurrencyIndicator.MyInput0;

                if (cacheMultiCurrencyIndicator != null)
                    for (int idx = 0; idx < cacheMultiCurrencyIndicator.Length; idx++)
                        if (cacheMultiCurrencyIndicator[idx].MyInput0 == myInput0 && cacheMultiCurrencyIndicator[idx].EqualsInput(input))
                            return cacheMultiCurrencyIndicator[idx];

                MultiCurrencyIndicator indicator = new MultiCurrencyIndicator();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.MyInput0 = myInput0;
                Indicators.Add(indicator);
                indicator.SetUp();

                MultiCurrencyIndicator[] tmp = new MultiCurrencyIndicator[cacheMultiCurrencyIndicator == null ? 1 : cacheMultiCurrencyIndicator.Length + 1];
                if (cacheMultiCurrencyIndicator != null)
                    cacheMultiCurrencyIndicator.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheMultiCurrencyIndicator = tmp;
                return indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public partial class Column : ColumnBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.MultiCurrencyIndicator MultiCurrencyIndicator(int myInput0)
        {
            return _indicator.MultiCurrencyIndicator(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.MultiCurrencyIndicator MultiCurrencyIndicator(Data.IDataSeries input, int myInput0)
        {
            return _indicator.MultiCurrencyIndicator(input, myInput0);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.MultiCurrencyIndicator MultiCurrencyIndicator(int myInput0)
        {
            return _indicator.MultiCurrencyIndicator(Input, myInput0);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.MultiCurrencyIndicator MultiCurrencyIndicator(Data.IDataSeries input, int myInput0)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.MultiCurrencyIndicator(input, myInput0);
        }
    }
}
#endregion



Continued from an article originally published in the September 2012 issue of Technical Analysis of Stocks & Commodities magazine. All rights reserved. © Copyright 2012, Technical Analysis, Inc.