Unfortunately, I cannot get it to work. As soon as I compile a strategy that looks at two instruments, things get screwy in Strategy Analyzer.
Let's pretend I have a multi instrument strategy called "multi" and I have a normal strategy called "buylowsellhigh"
If I'm in Strategy Analyzer and backtest buylowsellhigh, everything works as expected. If I then grab "multi" from the backtest pulldown selection, it does not update the parameters. I mean, all the parameters I have from "buylowsellhigh" stick, even though the parameters in "multi" should be completely different.
It's almost as if Analyzer is not updating. If I hit the Run Backtest button, it actually runs the previously selected (buylowsellhigh in this case) strategy. Basically, it is impossible to backtest "multi".
===
Maybe something is strange with my code? This is my first try at using multi instruments. I've stripped down something I've been working on. This won't work on my end. Hopefully you can tell me why.
// sameColorTest
//
//
// DESCRIPTION:
//
//
//
// CHANGELOG:
// 10/28/10
#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>
///
/// </summary>
[Description("No name for this strategy yet.")]
public class sameColorTest : Strategy
{
#region Variables
private int contracts = 1;
private bool a_goLong = true;
private bool a_goShort = true;
private int _tradeTimeBegin = 630; // Default setting for TradeTimeBegin
private int _tradeTimeEnd = 1250; // Default setting for TradeTimeEnd
private bool addIndicators = true; // Default setting for AddIndicators
private bool condition1 = false;
#endregion
/// <summary>
///
/// </summary>
protected override void Initialize()
{
if (AddIndicators == true)
{
}
CalculateOnBarClose = true;
TraceOrders = false;
Unmanaged = false;
Add("DX", PeriodType.Minute, 1);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (TimeToTrade)
{
if (Position.MarketPosition == MarketPosition.Flat && condition1 == false)
LookForCondition1();
if (Position.MarketPosition == MarketPosition.Flat && condition1 == true)
condition1 = false;
}
else FlattenPosition();
}
private void LookForCondition1()
{
SetStopLoss("Long", CalculationMode.Price, 1, false);
SetProfitTarget("Long", CalculationMode.Price, 10000);
SetStopLoss("Short", CalculationMode.Price, 10000, false);
SetProfitTarget("Short", CalculationMode.Price, 1);
if (
Close[0] > Open[0]
&& Closes[1][0] < Opens[1][0]
)
{
EnterLong(contracts, "Long");
SetProfitTarget("Long", CalculationMode.Ticks, 1);
SetStopLoss("Long", CalculationMode.Price, Low[1], false);
condition1 = true;
}
}
private void FlattenPosition()
{
if (Position.MarketPosition != MarketPosition.Flat)
{
if (Position.MarketPosition == MarketPosition.Long)
ExitLong();
else if (Position.MarketPosition == MarketPosition.Short)
ExitShort();
} else
{
}
}
private bool TimeToTrade
{
get
{
if (_tradeTimeBegin == 0 || _tradeTimeEnd == 0)
return true;
else
{
if (_tradeTimeBegin > _tradeTimeEnd)
return ToTime(Time[0]) >= _tradeTimeBegin*100 || ToTime(Time[0]) <= _tradeTimeEnd*100;
else
return ToTime(Time[0]) >= _tradeTimeBegin*100 && ToTime(Time[0]) <= _tradeTimeEnd*100;
}
}
}
#region Properties
[Description("Go long ?")]
[Category("Parameters")]
public bool A_goLong
{
get { return a_goLong; }
set { a_goLong = value; }
}
[Description("Go short")]
[Category("Parameters")]
public bool A_goShort
{
get { return a_goShort; }
set { a_goShort = value; }
}
[Description("The time to begin trading in HHMM format.")]
[Category("Parameters")]
public int TradeTimeBegin
{
get { return _tradeTimeBegin; }
set { _tradeTimeBegin = Math.Max(0, value); }
}
[Description("The time to end trading in HHMM format")]
[Category("Parameters")]
public int TradeTimeEnd
{
get { return _tradeTimeEnd; }
set { _tradeTimeEnd = Math.Max(0, value); }
}
[Description("Add indicators to current chart?")]
[Category("Parameters")]
public bool AddIndicators
{
get { return addIndicators; }
set { addIndicators = value; }
}
[Description("Number of contracts to trade.")]
[Category("Parameters")]
public int Contracts
{
get { return contracts; }
set { contracts = Math.Max(1, value); }
}
#endregion
}
}

Comment