PDA

View Full Version : Multy Instrument Strategy: deals are not opening


fx.practic
08-20-2010, 12:47 PM
Hello. I made simple multy-instrument strategy ( $AUDJPY, $CHFJPY, $EURJPY, $GBPJPY - 60 Min).

It must unconditional open positions on all instruments at 02:00 and close all at 22:00 every day.

I backtest it on 04.06.2010 - 20.08.2010 an get only 1 deal.

My history is OK - It clear on chart screenshot.

Help me, please, to let this strategy work correct.

namespace NinjaTrader.Strategy
{
/// <summary>
/// GBPJPY only
/// </summary>
[Description("USDJPY only")]
public class sMultuCurrencySimple : Strategy
{
#region Variables
#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("$AUDJPY", BarsPeriod.Id, BarsPeriods[0].Value);
Add("$CHFJPY", BarsPeriod.Id, BarsPeriods[0].Value);
Add("$EURJPY", BarsPeriod.Id, BarsPeriods[0].Value);
Add("$GBPJPY", BarsPeriod.Id, BarsPeriods[0].Value);

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// ------------------ Open positions -----------------------------------------------------------
//
if (BarsInProgress == 1 || Time[0].Hour == 2 ) { EnterLong(DefaultQuantity, ""); return; }
if (BarsInProgress == 2 || Time[0].Hour == 2 ) { EnterLong(DefaultQuantity, ""); return; }
if (BarsInProgress == 3 || Time[0].Hour == 2 ) { EnterLong(DefaultQuantity, ""); return; }
if (BarsInProgress == 4 || Time[0].Hour == 2 ) { EnterLong(DefaultQuantity, ""); return; }
if ( Time[0].Hour == 2 ) EnterLong(DefaultQuantity, "");
// ---------------------------------------------------------------------------------------------

// ------------------------------------ Close positions---------------------
//
if ( Time[0].Hour == 22)
{
ExitLong( "", ""); ExitShort( "", "");
ExitLong(1, "", ""); ExitShort(1, DefaultQuantity, "", "");
ExitLong(2, "", ""); ExitShort(2, DefaultQuantity, "", "");
ExitLong(3, "", ""); ExitShort(3, DefaultQuantity, "", "");
ExitLong(4, "", ""); ExitShort(4, DefaultQuantity, "", "");
}
// --------------------------------------------------------------------------
}

#region Properties
#endregion
}
}

NinjaTrader_RyanM
08-20-2010, 01:21 PM
Hello fx.practic,

All your orders are submitted to the primary series. You will need to use the advanced overload that supports entering on a specific BarsInProgress.

EnterLong(int barsInProgressIndex, int quantity,string signalName) (http://www.ninjatrader-support.com/HelpGuideV6/EnterLong.html)

You also are defining your conditions with ||. Most likely you will want to use && and also refer to the Time object of the specific series you want to enter on.

This is accessed with Times (http://www.ninjatrader-support.com/HelpGuideV6/Times.html)

Example submitting on second series.

if (BarsInProgress == 1 && Times[1][0].Hour == 2)
EnterLong(1, DefaultQuantity, "");

Your exit statements also need to use the advanced overload.
ExitLong(int barsInProgressIndex, int quantity,string signalName,string fromEntrySignal) (http://www.ninjatrader-support.com/HelpGuideV6/ExitLong.html)

fx.practic
08-21-2010, 07:41 AM
Everything works now.

If "Entries Per Dials" = 1, deals are opening only on primary instrument.
If "Entries Per Dials" = 5, deals are opening on all 5 instruments.

Thank You very march!

P.S. About "&&" and "||" - may be, I need to sleep more :)