Multiple Time Frames - NinjaTrader Programming | futures io social day trading
futures io futures trading


Multiple Time Frames
Updated: Views / Replies:7,051 / 17
Created: by jkinneberg Attachments:2

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 2  
 
Thread Tools Search this Thread
 

Multiple Time Frames

  #1 (permalink)
Just starting out...
Vancouver, BC, Canada
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Mirus Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 1 since Aug 2009
Thanks: 0 given, 1 received

Multiple Time Frames

Have started coding in NinjaTrader. I know this is a very newbie question, and am an experienced coder just not coded algo systems.

How does one confirm logic in multiple time frames?
Want to only execute a trade if the longer timeframes, trend following indicators indicate the trade is being executed in the direction of the trend. For example the MACD on the daily and the 60 minute time frame is above a signal line, although the trade is being executed on a 5 minute time frame.

Thanks

Reply With Quote
The following user says Thank You to jkinneberg for this post:
 
  #2 (permalink)
Administrator: Retired Backtester
 Vendor: speedytradingservers.com 
Rennes France
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB/Kinetick
Favorite Futures: Futures
 
sam028's Avatar
 
Posts: 3,366 since Jun 2009
Thanks: 3,572 given, 3,982 received

It's quite simple, just check the example below, which is using 3 timeframes:
 
Code
                            
        protected override void Initialize(){
            
SetProfitTarget(""CalculationMode.TicksstopWin);
            
SetStopLoss(""CalculationMode.TicksstopLossfalse);
            
// Add a 5 minute Bars object to the strategy
            
Add(PeriodType.Minute5); //BarsArray[1]
            // Add a 15 minute Bars object to the strategy
            
Add(PeriodType.Minute15); //BarsArray[2]            
            // 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(StochasticMomentumIndex(3,5));
            
CalculateOnBarClose true;
        }

        protected 
override void OnBarUpdate()
        {
            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 (StochasticMomentumIndex(BarsArray[2],3,5)[0] > maxL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] > maxL15 &&
                
StochasticMomentumIndex(3,5)[0] > MaxL1)                
            {
                
EnterShort(1"STO Short");
            }
            if (
StochasticMomentumIndex(BarsArray[2],3,5)[0] < minL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] < minL15 &&
                
StochasticMomentumIndex(3,5)[0] < minL1)                
            {
                
EnterLong(1"STO Long");
            }                            
        } 

Reply With Quote
The following user says Thank You to sam028 for this post:
 
  #3 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 48 received



sam028 View Post
It's quite simple, just check the example below, which is using 3 timeframes:
 
Code
                            
        protected override void Initialize(){
            
SetProfitTarget(""CalculationMode.TicksstopWin);
            
SetStopLoss(""CalculationMode.TicksstopLossfalse);
            
// Add a 5 minute Bars object to the strategy
            
Add(PeriodType.Minute5); //BarsArray[1]
            // Add a 15 minute Bars object to the strategy
            
Add(PeriodType.Minute15); //BarsArray[2]            
            // 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(StochasticMomentumIndex(3,5));
            
CalculateOnBarClose true;
        }
 
        protected 
override void OnBarUpdate()
        {
            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 (StochasticMomentumIndex(BarsArray[2],3,5)[0] > maxL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] > maxL15 &&
                
StochasticMomentumIndex(3,5)[0] > MaxL1)                
            {
                
EnterShort(1"STO Short");
            }
            if (
StochasticMomentumIndex(BarsArray[2],3,5)[0] < minL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] < minL15 &&
                
StochasticMomentumIndex(3,5)[0] < minL1)                
            {
                
EnterLong(1"STO Long");
            }                            
        } 


Hi Sam

just wanted to say that I enjoyed your webinar. you should do another one on multiple time frames:-)

I was wondering if you could perhaps post all of this code? I am not sure if minL5 is something you made up or part of the Ninja library----would like to see your private variables as well as public.

I am really wanting to learn how to deal with multiple time frames on Ninja Trader. Perhaps you can post more examples as they are extremely helpful.

I am looking on specifically wanting to do the following:
Entry is based on a cross of the SMA (simple moving averages) the 5 period and 21 period on the Daily chart, AND the current price is > than the 8 period moving average of the monthly chart. If this is true, GoLong

Then, I would want my exit to be based on price so it would be intrabar for the daily, so I would have to use the 1 minute for exit-----say, if it goes up 30 ticks, then out and set stop at 30 ticks.

I actually have a more complex exit plan than this, but just want to know how to enter based on the daily/monthly-----and exit on the 1 minute or even the tick chart---maybe like a 100 tick or something.

Any information about this would be greatly appreciated. I am writing a paper for my school in computer science, and wanted to do some complex programming. Just need to know how to incorporate multiple time frames.

thank you

Spencer

Reply With Quote
 
  #4 (permalink)
Administrator: Retired Backtester
 Vendor: speedytradingservers.com 
Rennes France
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB/Kinetick
Favorite Futures: Futures
 
sam028's Avatar
 
Posts: 3,366 since Jun 2009
Thanks: 3,572 given, 3,982 received

Hi @spinnybobo,

Here is the code:

 
Code
                            

#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


namespace NinjaTrader.Strategy
{

    [
Description("SMI multi frame.")]
    public class 
SMI_mtf Strategy
    
{
        
#region Variables
        
private int stopWin 20;     // Default setting for StopWin
        
private int stopLoss 20;     // Default setting for StopLoss
        
private int minL1 = -70;         // Default setting for Min Limit 1 min
        
private int maxL1 70;         // Default setting for Max Limit 1 min
        
private int minL5 = -20;         // Default setting for Min Limit 5 min
        
private int maxL5 20;         // Default setting for Max Limit 5 min
        
private int minL15 = -10;         // Default setting for Min Limit 15 min
        
private int maxL15 10;         // Default setting for Max Limit 15 min
      
        #endregion

        
protected override void Initialize(){

            
SetProfitTarget(""CalculationMode.TicksstopWin);
            
SetStopLoss(""CalculationMode.TicksstopLossfalse);

            
// Add a 5 minute Bars object to the strategy
            
Add(PeriodType.Minute5); //BarsArray[1]
                       
            
Add(PeriodType.Minute15); //BarsArray[2]
            
Add(StochasticMomentumIndex(3,5));
            
CalculateOnBarClose true;
        }

        protected 
override void OnBarUpdate()
        {
            if (
BarsInProgress != 0)
                return;
                        
            if (
StochasticMomentumIndex(BarsArray[2],3,5)[0] > maxL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] > maxL15 &&
                
StochasticMomentumIndex(3,5)[0] > MaxL1)                
            {
                
EnterShort(1"STO Short");
            }
            if (
StochasticMomentumIndex(BarsArray[2],3,5)[0] < minL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] < minL15 &&
                
StochasticMomentumIndex(3,5)[0] < minL1)                
            {
                
EnterLong(1"STO Long");
            }                            
        }

        
#region Properties
        
[Description("")]
        [
Category("Parameters")]
        public 
int StopWin
        
{
            
get { return stopWin; }
            
set stopWin Math.Max(1value); }
        }
        [
Description("")]
        [
Category("Parameters")]
        public 
int StopLoss
        
{
            
get { return stopLoss; }
            
set stopLoss Math.Max(1value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MaxL1
        
{
            
get { return maxL1; }
            
set maxL1 Math.Max(0value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MinL1
        
{
            
get { return minL1; }
            
set minL1 Math.Min(0value); }
        }    
        [
Description("")]
        [
Category("Parameters")]
        public 
int MaxL5
        
{
            
get { return maxL5; }
            
set maxL5 Math.Max(0value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MinL5
        
{
            
get { return minL5; }
            
set minL5 Math.Min(0value); }
        }    
        [
Description("")]
        [
Category("Parameters")]
        public 
int MaxL15
        
{
            
get { return maxL15; }
            
set maxL15 Math.Max(0value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MinL15
        
{
            
get { return minL15; }
            
set minL15 Math.Min(0value); }
        }    
        
#endregion
    
}


Success requires no deodorant! (Sun Tzu)
Reply With Quote
The following 3 users say Thank You to sam028 for this post:
 
  #5 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 48 received


sam028 View Post
Hi @spinnybobo,

Here is the code:

 
Code
                            


#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


namespace NinjaTrader.Strategy
{

    [
Description("SMI multi frame.")]
    public class 
SMI_mtf Strategy
    
{
        
#region Variables
        
private int stopWin 20;     // Default setting for StopWin
        
private int stopLoss 20;     // Default setting for StopLoss
        
private int minL1 = -70;         // Default setting for Min Limit 1 min
        
private int maxL1 70;         // Default setting for Max Limit 1 min
        
private int minL5 = -20;         // Default setting for Min Limit 5 min
        
private int maxL5 20;         // Default setting for Max Limit 5 min
        
private int minL15 = -10;         // Default setting for Min Limit 15 min
        
private int maxL15 10;         // Default setting for Max Limit 15 min
      
        #endregion

        
protected override void Initialize(){

            
SetProfitTarget(""CalculationMode.TicksstopWin);
            
SetStopLoss(""CalculationMode.TicksstopLossfalse);

            
// Add a 5 minute Bars object to the strategy
            
Add(PeriodType.Minute5); //BarsArray[1]
                       
            
Add(PeriodType.Minute15); //BarsArray[2]
            
Add(StochasticMomentumIndex(3,5));
            
CalculateOnBarClose true;
        }

        protected 
override void OnBarUpdate()
        {
            if (
BarsInProgress != 0)
                return;
                        
            if (
StochasticMomentumIndex(BarsArray[2],3,5)[0] > maxL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] > maxL15 &&
                
StochasticMomentumIndex(3,5)[0] > MaxL1)                
            {
                
EnterShort(1"STO Short");
            }
            if (
StochasticMomentumIndex(BarsArray[2],3,5)[0] < minL5 &&
                
StochasticMomentumIndex(BarsArray[1],3,5)[0] < minL15 &&
                
StochasticMomentumIndex(3,5)[0] < minL1)                
            {
                
EnterLong(1"STO Long");
            }                            
        }

        
#region Properties
        
[Description("")]
        [
Category("Parameters")]
        public 
int StopWin
        
{
            
get { return stopWin; }
            
set stopWin Math.Max(1value); }
        }
        [
Description("")]
        [
Category("Parameters")]
        public 
int StopLoss
        
{
            
get { return stopLoss; }
            
set stopLoss Math.Max(1value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MaxL1
        
{
            
get { return maxL1; }
            
set maxL1 Math.Max(0value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MinL1
        
{
            
get { return minL1; }
            
set minL1 Math.Min(0value); }
        }    
        [
Description("")]
        [
Category("Parameters")]
        public 
int MaxL5
        
{
            
get { return maxL5; }
            
set maxL5 Math.Max(0value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MinL5
        
{
            
get { return minL5; }
            
set minL5 Math.Min(0value); }
        }    
        [
Description("")]
        [
Category("Parameters")]
        public 
int MaxL15
        
{
            
get { return maxL15; }
            
set maxL15 Math.Max(0value); }
        }
        
        [
Description("")]
        [
Category("Parameters")]
        public 
int MinL15
        
{
            
get { return minL15; }
            
set minL15 Math.Min(0value); }
        }    
        
#endregion
    
}


Hi Sam

thanks for the code? you are awesome. Quick question rather than starting a new thread: Is it possible to backtest a strategy with 2 time frames? Like the ES entry on 5min and exit on 1min or tick and to backtest everything and get a chart printout?

I ask because it is not very intuitive. On the regular chart, it has a spot for entering multiple data series and bars back and everything, then adding the strategy. But on the backtesting engine, I dont see a spot for entering another data series?

The only other thing I can think of is hard coding the exact name of the data series and time frame in the actual strategy------not sure how to do this?

thanks as always

take care
Spencer

Reply With Quote
The following user says Thank You to spinnybobo for this post:
 
  #6 (permalink)
Administrator: Retired Backtester
 Vendor: speedytradingservers.com 
Rennes France
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB/Kinetick
Favorite Futures: Futures
 
sam028's Avatar
 
Posts: 3,366 since Jun 2009
Thanks: 3,572 given, 3,982 received

Sorry, but I don't see where is the problem.
Of course, MTF strategies are backtestable.
The logic for your idea is simple:
- check on which time frame you're in
->if it's the main TF, and flat, look for an entry
->if it's the other TF, and not flat, look for an exit

But I've maybe not understood your questions .

Success requires no deodorant! (Sun Tzu)
Reply With Quote
The following user says Thank You to sam028 for this post:
 
  #7 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


spinnybobo View Post
Hi Sam

thanks for the code? you are awesome. Quick question rather than starting a new thread: Is it possible to backtest a strategy with 2 time frames? Like the ES entry on 5min and exit on 1min or tick and to backtest everything and get a chart printout?

I ask because it is not very intuitive. On the regular chart, it has a spot for entering multiple data series and bars back and everything, then adding the strategy. But on the backtesting engine, I dont see a spot for entering another data series?

The only other thing I can think of is hard coding the exact name of the data series and time frame in the actual strategy------not sure how to do this?

thanks as always

take care
Spencer

Hi @spinnybobo

Be sure to keep an eye on BarsInProgress. Also, when you use the EnterLong function, you may need to use the following format:

EnterLong(int barsInProgressIndex, int quantity, string signalName)

This will let you fire orders against different Instruments in your strategy based upon the BarsInProgress. By default is is 0 and fires upon your main chart/instrument.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
The following 3 users say Thank You to NJAMC for this post:
 
  #8 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 48 received


sam028 View Post
Sorry, but I don't see where is the problem.
Of course, MTF strategies are backtestable.
The logic for your idea is simple:
- check on which time frame you're in
->if it's the main TF, and flat, look for an entry
->if it's the other TF, and not flat, look for an exit

But I've maybe not understood your questions .

thanks Sam. I am confusing the act of starting a new chart and adding multiple data series to the chart with the strategy analyzer. In Tradestation, for example, I always had to add a data series the strategy was using to the chart in order for it to work. It seems that Ninja can add it to the base chart through the code. Just a mis-understanding of how everything works:-)

I did have one question though: Let's say I wanted to open a new 1 min chart on the ES. Lets say I wanted my code to add an SMA(8) of the 10 min ES chart so I can see it. So, it would have 1 min bars with a ES 10 min SMA(8) all done programmatically.

it seems like anything we want to add to the chart has to be done through the Add() method like Add(SMA(5)) in the Initialize(){} field. However, we cannot use BarsArray in this field----and I think we can only access multiple time frames through BarsArray---correct? ---and this field is the area where we would Add indicators to the chart.

Is it possible to add an indicator of the ES SMA(5) 10 min chart of ES 1min programmatically?
I would think this would be essential for debugging to make sure everything is written correctly from a visual perspective.

thanks
Spencer


Last edited by spinnybobo; March 5th, 2012 at 07:27 PM.
Reply With Quote
 
  #9 (permalink)
Elite Member
OH
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 6 since Apr 2010
Thanks: 3 given, 9 received

This has already been discussed:
Coding Multi Time Frame (MTF) Indicators with NinjaTrader

You can also just download the indicator:
Visual EMA Multi-Timeframe

In summary, basic coding causes "stair-stepping" of higher time-frame indicators but that's actually what you want if you are designing a strategy. There is a MTF stochastic available too.

Reply With Quote
The following 2 users say Thank You to cyrussujar for this post:
 
  #10 (permalink)
Elite Member
Chicago, IL United States
 
Futures Experience: Advanced
Platform: Ninja Trader, Trader Work Station, Think or Swim
Broker/Data: Ninja Trader, Interactive Brokers, TD Ameritrade
Favorite Futures: ES
 
Posts: 27 since Nov 2014
Thanks: 7 given, 8 received



spinnybobo View Post
Hi Sam

thanks for the code? you are awesome. Quick question rather than starting a new thread: Is it possible to backtest a strategy with 2 time frames? Like the ES entry on 5min and exit on 1min or tick and to backtest everything and get a chart printout?

I ask because it is not very intuitive. On the regular chart, it has a spot for entering multiple data series and bars back and everything, then adding the strategy. But on the backtesting engine, I dont see a spot for entering another data series?

The only other thing I can think of is hard coding the exact name of the data series and time frame in the actual strategy------not sure how to do this?

thanks as always

take care
Spencer

Hi there,

I was curious to know if you were able to setup a strategy to backtest the 5 minute for entry and use the 1 minute for exiting using ema? I came across this thread since I am trying to accomplish a similar strategy.

Thanks,
Jeff

Reply With Quote

Reply



futures io > > > > > Multiple Time Frames

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Powerlanguage and Multi time frames Laurent EasyLanguage Programming 10 December 2nd, 2016 03:54 AM
Time frames and charts spikoloco Traders Hideout 10 February 22nd, 2012 08:49 PM
ninja 7 info on multiple time frames for indicators jrs659 NinjaTrader 6 August 16th, 2011 02:16 PM
Webinar: Multiple Time Frames - Trading with Trend Big Mike The Elite Circle 40 August 9th, 2011 08:21 PM
Queue a backtest in multicharts same symbol on multiple time frames? crbucks MultiCharts 4 June 23rd, 2011 11:33 AM


All times are GMT -4. The time now is 11:09 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-13 in 0.16 seconds with 20 queries on phoenix via your IP 54.227.51.103