NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 09-12-2008, 05:37 AM   #1
julen
Junior Member
 
Join Date: Sep 2008
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default Multitimeframe strategy

Hi, I am devoloping an estrategy that make entrymarket position long/short in 30min bars, according MACD daily position.

If Macd daily fast period value is below 0 it only take short position.

If Macd daily fast period value is above 0 it only take long position.

I try the estrategy on charts and it makes trades during a period but suddenly it doesn't works for the rest of the chart

I try it on AIG chart from january the first, and the mistake appears on may the nineth, is the first day daily macd falls below 0, and appears an stoplongentry order on the chart that coincide with 16:00bar max of the nineth.

Here I let you the code, do you see what is going wrong?




// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
///<summary>
/// Enter the description of your strategy here
///</summary>
[Description("Enter the description of your strategy here")]
publicclass RotRangH : Strategy
{
#region Variables
// Wizard generated variables
privatedouble stoploss = 0.030; // Default setting for Stoploss
// User defined variables (add any user defined variables below)
#endregion
///<summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
///</summary>
protectedoverridevoid Initialize()
{
Add (PeriodType.Day, 1);

SetStopLoss("", CalculationMode.Percent, Stoploss, false);
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
if (BarsInProgress != 0)
return;

// Checks if the macd daily fast period is above 0 and time in 30min bars is 16:00,
//then gives variable0 value= high 16:00(30minbar) and enter a stop longposition at value0
if (MACD(BarsArray[1], 12, 26, 9)[0] > 0 && ToTime(Time[0]) == 160000)
Variable0 = High[0] + 1*TickSize;
EnterLongStop(DefaultQuantity, Variable0, "");

// Checks if the macd daily fast period is below 0 and time in 30min bars is 16:00,
//then gives variable1 value= Low 16:00(30minbar) and enter a stop shortposition at value1
if (MACD(BarsArray[1], 12, 26, 9)[0] < 0 && ToTime(Time[0]) == 160000)
Variable1 = Low[0] - 1*TickSize;
EnterShortStop(DefaultQuantity, Variable1, "");


}
Last edited by julen; 09-12-2008 at 06:18 AM.
julen is offline  
Reply With Quote
Old 09-12-2008, 08:18 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

I am not sure what you exactly you mean, but first try this. Swap the bars objects. So run your strategy on a daily chart and change your Add(PeriodType.Day, 1) to Add(PeriodType.Minute, 30). Be sure you change up the logic inside to reflect this change too.

Reason to make this change is to ensure that the bar sequence fires correctly during backtesting.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-13-2008, 07:45 AM   #3
julen
Junior Member
 
Join Date: Sep 2008
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default

First Of all thanks for your reply, and I understand what you propose, but I will try to explain you with my terrible english what I'm trying, I want to enter in market long or short if 30minbar that finishes at 16:00( Spanish hour, I think it's 10AM in USA) High or Low is crossed. I introduce a filter: If daily Macd Fast line is above 0, enter long if 30minbar High is broken;
If daily Macd Fast line is below 0, enter short if 30minbar Low is crossed.

I will try like you propose, but how can I refer 30minbar High or Low? is this correct?

High(BarsArray[1])[0]
Low(BarsArray[1])[0]

And to tell that 30minbar That I'm refering is that wich ends at 16:00?

Totime(BarsArray[1], Time[0]) == 160000

or better:

BarTimer(BarsArray[1])[0] == 160000

Thank you very much for your attention.
julen is offline  
Reply With Quote
Old 09-13-2008, 10:24 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Maybe this reference sample can provide some guidance.

http://www.ninjatrader-support.com/v...ead.php?t=8600
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-09-2008, 01:00 AM   #5
boboinuk
Junior Member
 
Join Date: Feb 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default muti-time frame

Quote:
Originally Posted by julen View Post
First Of all thanks for your reply, and I understand what you propose, but I will try to explain you with my terrible english what I'm trying, I want to enter in market long or short if 30minbar that finishes at 16:00( Spanish hour, I think it's 10AM in USA) High or Low is crossed. I introduce a filter: If daily Macd Fast line is above 0, enter long if 30minbar High is broken;
If daily Macd Fast line is below 0, enter short if 30minbar Low is crossed.

I will try like you propose, but how can I refer 30minbar High or Low? is this correct?

High(BarsArray[1])[0]
Low(BarsArray[1])[0]

And to tell that 30minbar That I'm refering is that wich ends at 16:00?

Totime(BarsArray[1], Time[0]) == 160000

or better:

BarTimer(BarsArray[1])[0] == 160000

Thank you very much for your attention.
Hi Julien,
I think ninja cannot handle more than one time frame. Have you found a way to go round this problem....they promised it will be sorted in NT7.
If you are ahead of the game....let us in.
Cheers.
boboinuk is offline  
Reply With Quote
Old 10-09-2008, 03:25 AM   #6
NinjaTrader_Jason
NinjaTrader Customer Service
 
NinjaTrader_Jason's Avatar
 
Join Date: Aug 2007
Location: Breda, Netherlands
Posts: 11,236
Thanks: 83
Thanked 336 times in 328 posts
Default

Hello boboinuk,

Multi time frame strategies are supported. Please see the link below.
http://www.ninjatrader-support.com/H...struments.html
NinjaTrader_Jason is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Introducing Daily filter (Multitimeframe) to an existing strategy stefy Strategy Development 3 09-03-2008 09:45 AM
MultiTimeframe syntax nico_p General Programming 6 04-29-2008 08:59 AM


All times are GMT -6. The time now is 04:19 AM.