PDA

View Full Version : 2 instruments strategy


ninjamouse
03-09-2010, 04:09 PM
Hello there

Can this be done using C#?

I want a strategy based on 2 instruments i.e. YM/ES, chart type range chart, and I want to buy/sell based on a simple MACD crossover.

Thanking you in advance

NinjaTrader_RyanM
03-09-2010, 04:23 PM
Hello Ninjamouse,

NinjaTrader offers support for automated strategies with multiple instruments. The following two links should help get you started on implementing this:

Trading Crossovers (http://www.ninjatrader-support2.com/vb/showthread.php?t=3224)

Multi Time Frame and Instruments. (http://www.ninjatrader-support.com/HelpGuideV6/MultiTimeFrameInstruments.html)

ninjamouse
03-10-2010, 01:16 PM
Hello Ninjamouse,

NinjaTrader offers support for automated strategies with multiple instruments. The following two links should help get you started on implementing this:

Trading Crossovers (http://www.ninjatrader-support2.com/vb/showthread.php?t=3224)

Multi Time Frame and Instruments. (http://www.ninjatrader-support.com/HelpGuideV6/MultiTimeFrameInstruments.html)

I just wrote this:

protected override void Initialize()
{
Add(PeriodType.Range, 3);
Add("ES 03-10", PeriodType.Range, 3); // I can change this 04-10

CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{
if (ADX(14)[0] > 30 && ADX(BarsArray[2], 14)[0] > 30)
{
EnterLong(1, "Long");
}

and Im not getting any buy or sell signals, am I doing something wrong?
else

{
EnterShort(1, "Short");
}
}

NinjaTrader_RyanM
03-10-2010, 02:52 PM
Hello NinjaMouse,

You'll have to work with TraceOrders and debug the values you expect to be true.

Within the Initialize() method add:
TraceOrders = true;


Look at the tips below for help with this.

Debugging your NinjaScript Code (http://www.ninjatrader-support2.com/vb/showthread.php?t=3418)

TraceOrders (http://www.ninjatrader-support2.com/vb/showthread.php?t=3627)

ninjamouse
03-10-2010, 03:01 PM
Is this correct?

if (CrossAbove(RVI(14), 0, 1) && CrossBelow(RVI(BarsArray[1], 14), 0, 1))
{
// do something
}

So is this saying, if the current charts RVI is above and the RVI for ES is down do someting

NinjaTrader_RyanM
03-10-2010, 03:35 PM
A crossing event requires that the values cross, and is not necessarily the same as "less than" or "greater than".


CrossAbove(RVI(14), 0, 1)

This says if the primary series RVI crosses above 0 within the last bar.

CrossBelow(RVI(BarsArray[1], 14), 0, 1)

This says if the secondary series RVI crosses below 0 within the last bar.