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 12-17-2009, 05:59 AM   #1
mfmsonic
Junior Member
 
Join Date: Dec 2009
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default multi-time frame strategy problem

Hi all,

I am just beginning to construct a multi time frame strategy and am having some trouble starting off.

I am just looking to set a series of doubles for certain time periods but no long position is opened.

As is usual, it is probably a simple error, but would appreciate any advice as to how to obtain the required trades so they can be utilised for the strategy.

The required code is written below.

PHP Code:
// 
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
#endregion


// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    
/// <summary>
    /// This is a sample multi-time frame strategy.
    /// </summary>
    
[Description("This is a sample multi-time frame strategy.")]
    public class 
SampleMultiTimeFrame_day Strategy
    
{
        
#region Variables
        // Wizard generated variables
        // 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>
        
protected override void Initialize()
        {
            
// Add a 5 minute Bars object to the strategy
            
Add(PeriodType.Day1);
            
            
// Add a 15 minute Bars object to the strategy
            
Add(PeriodType.Week1);
            
            
// Note: Bars are added to the BarsArray and can be accessed via an index value
            // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
            
            // Add simple moving averages to the chart for display
            // This only displays the SMA's for the primary Bars object on the chart
            
Add(SMA(5));
            
Add(SMA(50));
            
            
CalculateOnBarClose true;
        }

        
/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        
protected override void OnBarUpdate()
        {
            
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
            // We only want to process events on our primary Bars object (index = 0) which is set when adding
            // the strategy to a chart
            
if (BarsInProgress != 0)
                return;
            
            
// Checks  if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
            
if (SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 50)[0] && SMA(BarsArray[2], 5)[0] > SMA(BarsArray[2], 50)[0])
            {
                
// Checks for a cross above condition of the 5 and 50 period SMA on the primary Bars object and enters long
                
if (CrossAbove(SMA(5), SMA(50), 1))
                    
EnterLong(1000"SMA");
            }
            
            
// Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
            
if (CrossBelow(SMA(BarsArray[2], 5), SMA(BarsArray[2], 50), 1))
                
ExitLong(1000);
        }

        
#region Properties
        #endregion
    
}

Last edited by mfmsonic; 12-17-2009 at 06:08 AM.
mfmsonic is offline  
Reply With Quote
Old 12-17-2009, 07:39 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

mfmsonic,

Please ensure you have enough bars loaded. You need at least 20 on each bar series. 20 on weekly series would require a lot of days back to load.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-17-2009, 11:38 PM   #3
mfmsonic
Junior Member
 
Join Date: Dec 2009
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default

NinjaTrader_Josh,
Thank you for your reply. The bars are long enough from 1962 to 2009. Still no trades. Here are the snapshot from my backtesting. Please check it.
Attached Images
File Type: gif a1.png (42.7 KB, 14 views)
File Type: gif a2.png (39.2 KB, 12 views)
File Type: gif a3.png (12.4 KB, 11 views)
File Type: gif a4.png (36.3 KB, 13 views)
mfmsonic is offline  
Reply With Quote
Old 12-18-2009, 07:29 AM   #4
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

You will then need to debug your code with Print() statements and TraceOrders = true.

http://www.ninjatrader-support2.com/...ead.php?t=3418
http://www.ninjatrader-support2.com/...ead.php?t=3627
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-20-2009, 02:37 AM   #5
aviat72
Senior Member
 
Join Date: Jul 2009
Location: San Francisco Bay Area
Posts: 216
Thanks: 0
Thanked 4 times in 3 posts
Default

It might be an issue with update sequence. Try using the value 2 for the lookBackPeriod in the CrossAbove, Below tests.
aviat72 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
Multi time frame strategy? Hanko Strategy Analyzer 4 11-09-2012 03:34 PM
Problem Creating EMA for Multi-Time Frame on Highs RoyBoy Strategy Development 7 09-26-2012 11:22 AM
Multi-time frame strategy laparker Strategy Development 4 05-24-2009 10:03 PM
Multi-time frame strategy - Longer-term real-time calculations Shansen Strategy Development 1 04-19-2009 06:36 AM
Market Reply and Multi time frame Strategy problem kekkis Strategy Development 3 12-30-2008 05:26 AM


All times are GMT -6. The time now is 11:53 AM.