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


Multiple Time Frames
Updated: Views / Replies:7,033 / 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

  #11 (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


Trader Jeff View Post
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

Hey

you can try out this strategy

 
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.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /*
	Strategy by Spencer aka spinnybobo on futures.io (formerly BMT) 02/17/2015
	*/
    [Description("Strategy for 5 min entry and 1 min exit")]
    public class MM : Strategy
    {
       
		// IOrders
		private IOrder entryOrder, exitOrder;
		
        
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			
			// make it unmanaged because more work to code but better control and greater possibilities
			Unmanaged = true;
			
			//add the 1 minute.  Base chart is BarsInProgress of 0.  They get added in order starting from 0.  
			// therefore the 1 minute is BarsInProgress of 1.
			Add(PeriodType.Minute, 1);
			
			// add the EMA 21 for the base chart
			EMA(21).Plots[0].Pen.Width = 2;
			EMA(21).Plots[0].Pen.Color = Color.DodgerBlue;
			Add(EMA(21));
        }
        
        protected override void OnBarUpdate()
        {
			// debug stuff
			Print("");
			Print(Time[0]+ " | base value: " + EMA(BarsArray[0], 21)[0]);
			Print("");
			Print(Time[0]+ " | 1 minute value: " + EMA(BarsArray[1], 21)[0]);
			
			
			// Look for entries.  BarsInProgress == 0 refers to base chart (which in this case is 5 minute
			if (BarsInProgress == 0)
			{
				if (Flat && Close[0] > EMA(21)[0])
				{
					if (entryOrder == null) // always check if an object is null before using it
					{
						entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "Go Long");
					}
				}
			}
			// Look for exit.  BarsInProgress == 1 refers to the 1 minute chart
			if (BarsInProgress == 1)
			{
				if (Long && Closes[0][0] < EMA(21)[0]) // Closes[0][0] uses base chart inside of BIP == 1
				{
					if (exitOrder == null) // always check if an object is null before using it
					{
						exitOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, Position.Quantity, 0, 0, "", "Exit Long");
					}
				}
			}
			
        }
		protected override void OnOrderUpdate(IOrder order)
		{
			if (entryOrder != null && entryOrder == order)
			{
				if (order.OrderState == OrderState.Filled)
				{
					// if using targets and stops, enter that information here ----then at end, set entryOrder to null
					entryOrder = null;
				}
				if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
					entryOrder = null;
			}
			if (exitOrder != null && exitOrder == order)
			{
				if (order.OrderState == OrderState.Filled)
				{
					
					exitOrder = null;
				}
				if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
					exitOrder = null;
			}
		}
		// helper methods
		private bool Long { get { return (Position.MarketPosition == MarketPosition.Long);}}
		private bool Short { get { return (Position.MarketPosition == MarketPosition.Short);}}
		private bool Flat { get { return (Position.MarketPosition == MarketPosition.Flat);}}


        #region Properties
     
        #endregion
    }
}

Reply With Quote
The following 2 users say Thank You to spinnybobo for this post:
 
  #12 (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

Thank you...


spinnybobo View Post
Hey

you can try out this strategy

 
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.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /*
	Strategy by Spencer aka spinnybobo on futures.io (formerly BMT) 02/17/2015
	*/
    [Description("Strategy for 5 min entry and 1 min exit")]
    public class MM : Strategy
    {
       
		// IOrders
		private IOrder entryOrder, exitOrder;
		
        
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			
			// make it unmanaged because more work to code but better control and greater possibilities
			Unmanaged = true;
			
			//add the 1 minute.  Base chart is BarsInProgress of 0.  They get added in order starting from 0.  
			// therefore the 1 minute is BarsInProgress of 1.
			Add(PeriodType.Minute, 1);
			
			// add the EMA 21 for the base chart
			EMA(21).Plots[0].Pen.Width = 2;
			EMA(21).Plots[0].Pen.Color = Color.DodgerBlue;
			Add(EMA(21));
        }
        
        protected override void OnBarUpdate()
        {
			// debug stuff
			Print("");
			Print(Time[0]+ " | base value: " + EMA(BarsArray[0], 21)[0]);
			Print("");
			Print(Time[0]+ " | 1 minute value: " + EMA(BarsArray[1], 21)[0]);
			
			
			// Look for entries.  BarsInProgress == 0 refers to base chart (which in this case is 5 minute
			if (BarsInProgress == 0)
			{
				if (Flat && Close[0] > EMA(21)[0])
				{
					if (entryOrder == null) // always check if an object is null before using it
					{
						entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "Go Long");
					}
				}
			}
			// Look for exit.  BarsInProgress == 1 refers to the 1 minute chart
			if (BarsInProgress == 1)
			{
				if (Long && Closes[0][0] < EMA(21)[0]) // Closes[0][0] uses base chart inside of BIP == 1
				{
					if (exitOrder == null) // always check if an object is null before using it
					{
						exitOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, Position.Quantity, 0, 0, "", "Exit Long");
					}
				}
			}
			
        }
		protected override void OnOrderUpdate(IOrder order)
		{
			if (entryOrder != null && entryOrder == order)
			{
				if (order.OrderState == OrderState.Filled)
				{
					// if using targets and stops, enter that information here ----then at end, set entryOrder to null
					entryOrder = null;
				}
				if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
					entryOrder = null;
			}
			if (exitOrder != null && exitOrder == order)
			{
				if (order.OrderState == OrderState.Filled)
				{
					
					exitOrder = null;
				}
				if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
					exitOrder = null;
			}
		}
		// helper methods
		private bool Long { get { return (Position.MarketPosition == MarketPosition.Long);}}
		private bool Short { get { return (Position.MarketPosition == MarketPosition.Short);}}
		private bool Flat { get { return (Position.MarketPosition == MarketPosition.Flat);}}


        #region Properties
     
        #endregion
    }
}

Thanks a lot, I appreciate it.

Reply With Quote
 
  #13 (permalink)
Membership Temporarily Revoked
russia
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: FXCM
Favorite Futures: forex
 
mwamba123's Avatar
 
Posts: 9 since Mar 2015
Thanks: 1 given, 0 received

making the indicator multi time frame


hello guys know am a newbie
and i have only been trading for a month now
i use this indicator to look for spikes within spikes
just wanted to ask if anyone could help me turn this indicator into an multi-time frame indicator and also if possible add alert to it
big thanks in advance

Attached Files
Register to download File Type: zip Spike.zip (3.8 KB, 12 views)
Reply With Quote
 
  #14 (permalink)
Membership Temporarily Revoked
russia
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: FXCM
Favorite Futures: forex
 
mwamba123's Avatar
 
Posts: 9 since Mar 2015
Thanks: 1 given, 0 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");
            }                            
        } 

Hey i have only been trading for a month now
i use this indicator to look for spikes within spikes
just wanted to ask if you guys could help me turn this indicator into an multi-time frame indicator and also if possible add alert to it
big thanks in advance

Attached Files
Register to download File Type: zip Spike.zip (3.8 KB, 14 views)
Reply With Quote
 
  #15 (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


mwamba123 View Post
Hey i have only been trading for a month now
i use this indicator to look for spikes within spikes
just wanted to ask if you guys could help me turn this indicator into an multi-time frame indicator and also if possible add alert to it
big thanks in advance

Are you trying to turn this into an Indicator or a Strategy? The reason I ask is because you are have SetProfitTarget which is for trading using a Strategy

Reply With Quote
 
  #16 (permalink)
Membership Temporarily Revoked
russia
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: FXCM
Favorite Futures: forex
 
mwamba123's Avatar
 
Posts: 9 since Mar 2015
Thanks: 1 given, 0 received


spinnybobo View Post
Are you trying to turn this into an Indicator or a Strategy? The reason I ask is because you are have SetProfitTarget which is for trading using a Strategy

oh no sir no strategy just an indicator
i use it mostly for options

Reply With Quote
 
  #17 (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


mwamba123 View Post
oh no sir no strategy just an indicator
i use it mostly for options


ok so EnterLong(1, ....); and EnterShort(1, .....); and SetStops and SetProfitTarget, etc.. are all things you use in a Strategy.
It looks like you are correct how you added the multiple time frames

you can also use BarsInProgress


lets say you have it like

 
Code
protected override void Initialize()
{
      Add(PeriodType.Minute, 5); // index of 1
      Add(PeriodType.Minute, 15); // index of 2
}

protected override void OnBarUpdate()
{
     if (BarsInProgress == 0)
    {
         // anything in here is base chart
        if (Close[0] > Open[0])  // The Close and Open refers to the base chart
             // do something

        // if you want to refer to another chart inside of BIP == 0 then do it this way
        if (Close[1][0] > Open[1][0])
           // do something
    }
    if (BarsInProgress == 1)
    {
          // same as above  Close[0] refers to BIP == 1 and Close[0][0] refers to base chart 
         // and Close[2][0] refers to BIP == 2
    }

}
I believe how you have it with BarsArray is correct. You use BarsArray with premade indicators
let me know if anymore questions

Reply With Quote
The following user says Thank You to spinnybobo for this post:
 
  #18 (permalink)
Membership Temporarily Revoked
russia
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: FXCM
Favorite Futures: forex
 
mwamba123's Avatar
 
Posts: 9 since Mar 2015
Thanks: 1 given, 0 received


spinnybobo View Post
ok so EnterLong(1, ....); and EnterShort(1, .....); and SetStops and SetProfitTarget, etc.. are all things you use in a Strategy.
It looks like you are correct how you added the multiple time frames

you can also use BarsInProgress


lets say you have it like

 
Code
protected override void Initialize()
{
      Add(PeriodType.Minute, 5); // index of 1
      Add(PeriodType.Minute, 15); // index of 2
}

protected override void OnBarUpdate()
{
     if (BarsInProgress == 0)
    {
         // anything in here is base chart
        if (Close[0] > Open[0])  // The Close and Open refers to the base chart
             // do something

        // if you want to refer to another chart inside of BIP == 0 then do it this way
        if (Close[1][0] > Open[1][0])
           // do something
    }
    if (BarsInProgress == 1)
    {
          // same as above  Close[0] refers to BIP == 1 and Close[0][0] refers to base chart 
         // and Close[2][0] refers to BIP == 2
    }

}
I believe how you have it with BarsArray is correct. You use BarsArray with premade indicators
let me know if anymore questions

hey thank you very much for all of this
i barely understand what you have just explained to me
i have little to no knowledge of coding...
i just started trading and am still practicing on demo accounts.
i just have the basic knowledge of everything
and i just started reading about coding

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)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

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 10:52 PM.

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-11 in 0.12 seconds with 20 queries on phoenix via your IP 54.145.16.43