View Full Version : Multi-Instrument Strategy
Loukas
06-23-2011, 05:06 AM
Hi,
My aim is to built a strategy which make few calculations on an instrument and based on few conditions enter Long to 2th instrument and enter Short to a 3th instrument( Actually I want to go Short in a basket of instruments).
To be more understandable lets say
Condition: EMA(5) > EMA(13) on EURUSD
Order: Enter Long on EURGBP
Condition EMA(5)< EMA(13) on EURUSD
Order: Close Long position and Enter Short on USDJPY
I have already made a code but when I going to back test it is not giving me any results. A part of my code is below
#region Variables
// Wizard generated variables
private string shortInst = @"USDJPY"; // Default setting for ShortInst
private string longInst = @"EURGBP"; // Default setting for LongInst
private string signalInst = @"EURUSD"; // Default setting for SignalInst
// User defined variables (add any user defined variables below)
#endregion
if (EMA(5)[0]>EMA(13)[0])
{
//Enter a long position on a basket of EM currencies
EnterShort(1,shortInst);
}
//Check if the momentum Fast EMA is lower than Slow EMA, change in trend
if ( EMA(5)[0]< EMA(13)[0])
{
ExitShort();
EnterLong(1,longInst);
}
Do you have any thoughs why this is not working? Thanks
NinjaTrader_Bertrand
06-23-2011, 05:37 AM
Loukas, I'm seeing you adding any instruments to your strategies first in the Initialize() - to get a working sample for this process it would best to start off by reviewing the SampleMultiInstrument installed per default with NT.
More documentation on MultiSeries work is also located here:
http://www.ninjatrader.com/support/helpGuides/nt7/multi_time_frame__instruments.htm
Loukas
06-23-2011, 06:20 AM
Thanks for the reply.
I made few changes but is still doesnt submit any trades. My concerns are around the EnterLong() statment.
Initialize()
index value of 0
// Add("USDGBP",PeriodTypr.Day,1);
// index value of 1
Add("USDMXN",PeriodType.Day,1);
// index value of 2
Add("EURUSD",PeriodType.Day,1);
OnBarUpdate()
if (CrossAbove(RSI(14, 0), 30, 1))
{
//Enter a long position on a basket of currencies. It is applied on Index Value 1
EnterShort(1,shortInst);
}
In English it means : Enter a short position on USDMXN when RSI of USDGBP cross above 30?
NinjaTrader_Bertrand
06-23-2011, 06:31 AM
Any errors in the log tab, this should be the first place to check if you run into any unexpected issues?
Please try with a $ sign in front of your FX spot symbols, so :
// Add("$USDGBP",PeriodTypr.Day,1);
// index value of 1
Add("$USDMXN",PeriodType.Day,1);
// index value of 2
Add("$EURUSD",PeriodType.Day,1);
Please also use this EnterLong overload for MultiSeries use, so you can specify to which BIP to submit:
EnterLong(int barsInProgressIndex, int quantity, string signalName)
Loukas
06-23-2011, 07:19 AM
At the Logs tab the message is that
"The strategy has called the Add[] method with an invalid instrument. The USDMXN does not exist..."
I made the adjustment this the symple "$". The is not any compile error but is still not making any trades.
I am not sure about EnterLong() if has the correct structure
if (CrossAbove(RSI(14, 0), 30, 1))
{
//Enter a long position on a basket of EM currencies. It is applied on Index Value 1
EnterShort(1,1,shortInst);
}
It checks the Cross of RSI on USDGBP( index 0) and enter a Short on USDMXN(index 1). EnterShort( index number, quantity, signal name)
Shall I send you the strategy to file to have a better view?
Thanks
NinjaTrader_Bertrand
06-23-2011, 07:27 AM
Did you reload the strategy fresh after making the needed code change to correctly call the added series? Yes, if you can attach the code that would help as I can then give it a run here for testing.
Thanks,
Loukas
06-24-2011, 10:26 AM
Please have a look at the attachement
NinjaTrader_Austin
06-24-2011, 01:50 PM
Loukas, your entry conditions are too restrictive. I ran your strategy on $EURCHF as the main instrument, $EURUSD as secondary, and $USDCAD as tertiary instrument (because we don't have USDMXN access) over a 2 year backtest and the conditions for entry were not triggered at all.
I placed some print statements in the code to help you see what is actually going on. Did you look at the SampleMultiInstrument strategy Bertrand referenced? None of your code is in a BarsInProgress, so the main conditions are checked for every series on every bar, which would make debugging extremely difficult.
Please take a look at the re-attached strategy, especially the comments I've revised.
Let me know if you have questions.
Loukas
06-27-2011, 07:59 AM
I didnt manage to solve the problem. I have entered the BarInProgress statment but I didnt understand which is the correct way to send an order for other instruments. I have attached an update of the strategy. Thanks
NinjaTrader_Bertrand
06-27-2011, 08:36 AM
In my testing here on a daily chart I see trades for your added instrument - your conditions run off BIP0, so the primary series and send then trades to index 1 and 2 - what issues are you seeing? The added series are used internally only and are not visualized if your run for example from your primary chart or Strategy Analyzer backtest.
Loukas
06-27-2011, 10:10 AM
Sorry it was my mistake. I would like to make the following changes, instead of going long a single currency I want to going Long a basket of cuurencies. Do you have any ideas about it?
NinjaTrader_Bertrand
06-27-2011, 10:23 AM
No worries, if you would like to execute in several symbols you could issue multiple Enter() calls to different series.
Loukas
06-27-2011, 10:40 AM
Is there a multiple Enter() statment or I have to enter one by one ?
e.g
Add("$USDCAD",PeriodType.Day,1);
Add("$USDJPY",PeriodType.Day,1);
.....
.....
EnterShort(1,1,shortInst);
EnterShort(2,1,shortInst);
NinjaTrader_Bertrand
06-27-2011, 10:45 AM
Is there a multiple Enter() statment or I have to enter one by one ?
e.g
Add("$USDCAD",PeriodType.Day,1);
Add("$USDJPY",PeriodType.Day,1);
.....
.....
EnterShort(1,1,shortInst);
EnterShort(2,1,shortInst);
This would be the way to go here Loukas.
Loukas
06-28-2011, 08:37 AM
I have tried the way below to enter a multiple Enter() statment but it send only an order for the first bar object only (USDCAD) . I tried to connect the EnterShort() statments with "&&" but it is not working neither. Do you have any ideas about it?
NinjaTrader_Bertrand
06-28-2011, 08:44 AM
You likely need to run with a higher EntriesPerDirection here or set EntryHandling to use UniqueEntries:
http://www.ninjatrader.com/support/helpGuides/nt7/entryhandling.htm
Loukas
06-28-2011, 10:08 AM
Thanks Bertrand, it is working good with the enter. However, with the ExitLong() or ExitShort statement are working. Every enter position is closing only with profit target level instead of closing when I am opening a new position in the opposine direction.
Initialize()
EntriesPerDirection = 4;
EntryHandling = EntryHandling.AllEntries;
OnBarUpdate()
if .........something
{
EnterShort(1,quantityOrder,"short1");
EnterShort(2,quantityOrder,"short2");
EnterShort(3,quantityOrder,"short3");
ExitLong("long");
}
else if ....something
{
EnterLong(5,quantityOrder,"long");
ExitShort("short1");
ExitShort("short2");
ExitShort("short3");
}
It is entering new positions but is not exiting the latest one....it close only when meet the profit target.
NinjaTrader_Austin
06-28-2011, 10:41 AM
Loukas, please try exiting the position before opening a position in the other direction:
exitshort1
exitshort2
exitshort3
enterlong5
instead of
enterlong5
exitshort1
exitshort2
exitshort3