NexusFi: Find Your Edge


Home Menu

 





Multiple Time Frames


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one spinnybobo with 6 posts (4 thanks)
    2. looks_two mwamba123 with 4 posts (0 thanks)
    3. looks_3 sam028 with 3 posts (5 thanks)
    4. looks_4 Trader Jeff with 2 posts (0 thanks)
      Best Posters
    1. looks_one NJAMC with 3 thanks per post
    2. looks_two cyrussujar with 2 thanks per post
    3. looks_3 sam028 with 1.7 thanks per post
    4. looks_4 spinnybobo with 0.7 thanks per post
    1. trending_up 12,840 views
    2. thumb_up 15 thanks given
    3. group 11 followers
    1. forum 17 posts
    2. attach_file 2 attachments




 
Search this Thread

Multiple Time Frames

  #11 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


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
    }
}

Follow me on Twitter Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
Exit Strategy
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
60 thanks
Funded Trader platforms
43 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #12 (permalink)
 Trader Jeff 
Chicago, IL United States
 
Experience: Advanced
Platform: Ninja Trader, Trader Work Station, Think or Swim
Broker: Ninja Trader, Interactive Brokers, TD Ameritrade
Trading: ES
Posts: 27 since Nov 2014
Thanks Given: 7
Thanks Received: 10


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)
 mwamba123 
russia
 
Posts: 9 since Mar 2015


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
Elite Membership required to download: Spike.zip
Reply With Quote
  #14 (permalink)
 mwamba123 
russia
 
Posts: 9 since Mar 2015


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
Elite Membership required to download: Spike.zip
Reply With Quote
  #15 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


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

Follow me on Twitter Reply With Quote
  #16 (permalink)
 mwamba123 
russia
 
Posts: 9 since Mar 2015


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)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


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

Follow me on Twitter Reply With Quote
Thanked by:
  #18 (permalink)
 mwamba123 
russia
 
Posts: 9 since Mar 2015


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




Last Updated on March 21, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts