![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
how would I go about creating a strategy where... say for example
if ES is up from 9:30am to 10:00am, enterlong YM at 11am and if ES is down from 9:30am to 10:00am, entershort YM at 11am I'm assuming I would run a backtest on YM, but how do I call upon the instrument ES. Thanks in advance |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Here is a great start for Multi-Instrument strategies.
http://www.ninjatrader-support.com/H...struments.html
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
I looked at the below code and was not sure...
if I want to know if ES is up between 9:30am and 10:00am... if so, Enterlong in YM at 11am do I have to first place the below code in Initialize() Add("ES 12-07", PeriodType.Minute, 1); and then how do I call upon it? Sorry if I mangled it up. Still new at programming if ("ES 12-07".ToTime(93000)<=ToTime(100000)) Enterlong(1).ToTime(110000); Quote:
|
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Right z32000. First place Add("ES 12-07", PeriodType.Minute, 1); into the Initialize() method. Then in the OnBarUpdate() you want to run your checks on the BarsInProgress = 1 and place your trades in the context of BarsInProgress = 0 (when you load your strategy run it on the YM not the ES).
Code:
if (BarsInProgress == 1)
{
if (ToTime(Time[0]) == 93000)
esOpen = Open[0];
else if (ToTime(Time[0]) == 100000)
esClose = Close[0];
if (esClose > esOpen)
tradeYM = true;
}
if (BarsInProgress == 0)
{
if (tradeYM == true)
EnterLong();
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks Josh! You're a genius
![]() I'm not sure if Ninjatrader takes this into account but some instruments... such as hong kong futures where the market opens the night before... So say if I wanted to know if the hong kong market was up between 10pm and 2am and if so, go long on ES the next day... does this make things much more tricker? I would think NT only compares two instruments within the same time period. Quote:
|
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Add the HK instrument like you did the ES instrument.
Code:
if (BarsInProgress == 1)
{
if (ToTime(Time[0]) == 93000 && ToDay(Time[0]) == (ToDay(DateTime.Now) - 1))
hkOpen = Open[0];
else if (ToTime(Time[0]) == 100000 && ToDay(Time[0]) == (ToDay(DateTime.Now) - 1))
hkClose = Close[0];
if (hkClose > hkOpen)
tradeHK = true;
}
if (BarsInProgress == 0)
{
if (tradeHK == true && ToDay(Time[0]) == ToDay(DateTime.Now))
EnterLong();
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
I'm not quite sure what do you mean by save some time variables...
I am doing this for backtesting first and foremost, so it's rather tough not being able to use the DateTime.Now... Quote:
|
|
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Code:
if (BarsInProgress == 1)
{
if (ToTime(Time[0]) == 93000)
hkOpen = Open[0];
else if (ToTime(Time[0]) == 100000)
{
hkClose = Close[0];
if (hkClose > hkOpen)
{
tradeHK = true;
hkDay = ToDay(Time[0]);
}
}
}
if (BarsInProgress == 0)
{
if (tradeHK == true && ToDay(Time[0]) == (hkDay + 1))
{
EnterLong();
tradeHK = false;
hkDay = 0;
hkOpen = 0;
hkClose = 0;
}
}
Josh
NinjaTrader Customer Service
Last edited by NinjaTrader_Josh; 11-19-2007 at 11:22 PM.
|
|
|
|
|
|
#9 | |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
thanks Josh again
I see you used the time from 9:30am to 10:00am..but instead if it was 9:30am to 1:00am (the next day)... is this possible? Quote:
|
|
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
All time comparisons are possible. You will just need to work out various techniques through the use of Time[0], ToTime(), and ToDay().
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
|
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Right. I provided you with different techniques you can use. You don't necessarily need to use the exact technique I've outlined under all circumstances.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
hi Josh, I just gave the code a try, but I don't think it works...
{ if (tradeHK == true && ToDay(Time[0]) == (hkDay + 1)) { EnterLong(); tradeHK = false; hkDay = 0; hkOpen = 0; hkClose = 0; } } You wrote the above... but I don't see how this long position can ever be executed since your condition states... Enter long "if current date is equal to current date plus 1"... I gave it a try and unfortunately it did not work...any ideas? Thanks ![]() |
|
|
|
|
|
#14 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
The technique shown there is suppose to say "if the current date is the previous date + 1 (aka if current date is current date)". The hkDay variable is set in the BarsInProgress = 1. When your strategy goes through the historical data of the previous date and it evalutes to true it will set the variable to that date. I see what you mean it will never evalute to true. You will need to add a condition to prevent it from updating on the latest date.
The code I posted are just pseudocodes and have never been tested. They are to demonstrate theoretical techniques, but you will need to develop it to your exact needs on your own. The idea behind what I posted is this. On timeframe 1 store the previous day's up/down trend in the opening hour. On timeframe 0 check to see if timeframe1 was up or down on the previous day and do something accordingly.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exporting Instruments | Rollins | Suggestions And Feedback | 1 | 10-31-2007 05:47 AM |
| Linking different instruments | Rollins | Charting | 2 | 10-08-2007 02:03 PM |
| Not able to chart certain instruments | pipperjack | Charting | 1 | 09-20-2007 12:39 PM |
| Same Strategy Only Runs on Part of Instruments | rabidturtle | Strategy Development | 4 | 09-14-2007 02:36 PM |
| What Instruments do You Trade??? | chipper338 | ATM Strategies (Discretionary Trading) | 5 | 11-30-2004 04:30 AM |