Coding Multi Time Frame (MTF) Indicators with NinjaTrader - NinjaTrader | futures io social day trading
futures io futures trading


Coding Multi Time Frame (MTF) Indicators with NinjaTrader
Updated: Views / Replies:103,133 / 411
Created: by Fat Tails Attachments:161

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
 161  
 
Thread Tools Search this Thread
 

Coding Multi Time Frame (MTF) Indicators with NinjaTrader

  #391 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received


deltason View Post
Great thread. Hard for me to phrase this question. Is there a way to create an alert or chart marker when an indicator or bar value on one time frame equals an indicator or bar value on another time frame? For example, can there be an alert/chart marker when the 5 period SMA of a 10 minute chart equals the 5 period SMA of a 20 minute chart (rounded if necessary)? Another example would be an alert/chart marker when the high/low of a 30 minute bar equals the high/low of a 20 minute bar.

Use something like this:

 
Code
// in variables region

int alertBar;

// in Initialize ()

Add (PeriodType.Minute, 10);
Add (PeriodType.Minute, 20);

CalculateOnBarClose = false;


// in OnBarUpdate

if (BarsInProgress != 0)        // all series get the update so we'll use the original chart one only
    return;

if ((int)(SMA(Closes[1],5)[0]) == (int)(SMA(Closes[2],10)[0]))
{
    if (CurrentBar != alertBar)
    {
        // draw or make a sound here

        alertBar = CurrentBar;
    }
}
That's a rough idea, you might want to use less rounding (e.g. use the Round2TickSize function) or run with different event settings but something like that should do enough. There are other ways but I like simple. (Do excuse any spelling/syntax/sematic errors, I'm only on a ChromeBook.)

ed: Just a thought, I think there are CrossAbove/CrossBelow/etc functions that could be useful in this area

Travel Well

Last edited by ratfink; April 18th, 2014 at 01:09 PM. Reason: ca/cb/etc
Reply With Quote
The following user says Thank You to ratfink for this post:
 
  #392 (permalink)
Elite Member
Memphis, Tennessee
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: ES, EUR/USD
 
deltason's Avatar
 
Posts: 133 since Jul 2009
Thanks: 1,552 given, 118 received


ratfink View Post
Use something like this:

That's a rough idea, you might want to use less rounding (e.g. use the Round2TickSize function) or run with different event settings but something like that should do enough. There are other ways but I like simple. (Do excuse any spelling/syntax/sematic errors, I'm only on a ChromeBook.)

ed: Just a thought, I think there are CrossAbove/CrossBelow/etc functions that could be useful in this area

Thanks for taking the time to put that together. I am just now seeing this and will give it a go. Thanks again.

Reply With Quote
The following user says Thank You to deltason for this post:
 
  #393 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary



deltason View Post
Great thread. Hard for me to phrase this question. Is there a way to create an alert or chart marker when an indicator or bar value on one time frame equals an indicator or bar value on another time frame? For example, can there be an alert/chart marker when the 5 period SMA of a 10 minute chart equals the 5 period SMA of a 20 minute chart (rounded if necessary)? Another example would be an alert/chart marker when the high/low of a 30 minute bar equals the high/low of a 20 minute bar.


For every multitimeframe question there are 3 different approaches. Please see link below for a detailed explanation.

https://futures.io/ninjatrader-programming/28037-essentials-multiple-time-frames-multi-time-frame-indicators.html#post343553

Your first example: In the case of an SMA, you can simply tweak the indicator by adapting the period. The 5-period SMA of a 20 minute chart comes very close to a 10-period SMA of a 10-minute chart. Therefore for your first example you do not need to create any indicator that loads multiple bar series.

Your second example: This question is not clearly put, because if you use 20 min and 30 min bars, they will sometimes have a common close and they will sometimes not have a common close. In this case I would use a 10 min chart and compare the 3-bar high to the 2-bar high, or the 3-bar low to the 2-bar low. This approach beats any approach using 20 and 30 min bars.


Below is a sample chart of what can be done without adding a secondary bar series.

-> the first chart shows genuine MACDs which are calculated from composite bars (composite bars are created from primary bars, something which is possible for minute, tick and volume bars)
-> the second chart shows tweaked MACDs, which have the timeframe problem resolved by adapting the indicator lookback periods

Of course there is a small difference between the genuine and the tweaked indicators. Which one would you prefer?


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following 7 users say Thank You to Fat Tails for this post:
 
  #394 (permalink)
Elite Member
Memphis, Tennessee
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: ES, EUR/USD
 
deltason's Avatar
 
Posts: 133 since Jul 2009
Thanks: 1,552 given, 118 received

Thanks Fat Tails. The time periods were just examples to see what could be done and to make it a bit easier for me to ask the questions. I also have an interest in comparing different fractals on charts that are not time based.

Reply With Quote
The following user says Thank You to deltason for this post:
 
  #395 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

When FirstTickOfBar means LastTickOfBar

One of the reasons that coding multi timeframe indicators is so confusing is that, for historical data, only one tick is provided per bar. Let's see how this plays out in an example with a multi time frame indicator on a one minute chart. The primary price series, Bars[0], is a one minute bar series that prints to the chart, and the Added secondary price series, Bars[1], is a one second price series of the same instrument. As shorthand, the BarsInProgress property will be abbreviated BIP.

Once per minute, a bar of the primary series will print to the chart. When that bar prints, BIP equals zero and FirstTickOfBar will be true for the primary bar series. However, the fact that the bar has a high, low and close as well as an open, clearly shows that the appearance of this bar was actually triggered by its completion, not its commencement. So, for historical data, what is called "FirstTickOfBar" is actually the LAST tick of the bar.

The very next price tick will be from the secondary series, BIP will be 1, and Closes[1][0] and Times[1][0] will be the same as the most recent Closes[0][0] and Times[0][0], since this is the last one second period within the primary bar, Bars[0][N]. Anything calculated from this tick will correctly plot at the same place in the horizontal scale as CurrentBars[0][N].

Now the problems begin. Bars[0][N] is FINISHED. The next 60 ticks of the secondary series belong to Bars[0][N+1], not to Bars[0][N]. However, Bars[0][N], is THE Current Bar as far as the chart is concerned; Bars[0][N+1] does not even exist yet. It won't show up for one more minute, until it ENDS. So any data derived from these ticks will erroneously be plotted to the most recent bar on the chart, Bars[0][N].

Understanding how to correct for this is one of the major requirements for properly coding multi time frame, or multi instrument, indicators.

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett

Last edited by Zondor; May 13th, 2014 at 06:13 PM.
Reply With Quote
The following 8 users say Thank You to Zondor for this post:
 
  #396 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

MTF + DSP =????

Here is a post about Ehlers indicators based on time frames other than those of the Master Instrument

https://futures.io/ninjatrader/2175-thoughts-ehlers-indicators-2.html#post414249

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #397 (permalink)
Elite Member
Mérida, Mexico
 
Futures Experience: Intermediate
Platform: NinjaTrader 8
Broker/Data: looking
Favorite Futures: CL
 
michaelf's Avatar
 
Posts: 508 since Mar 2011
Thanks: 1,153 given, 512 received


Fat Tails View Post
I just want to explain another time, how the indicators work and can be correctly accessed. The explanation refers to the VisualSMA but also applies to the VisualEMA


Strategy mode

Indicator collects data from secondary bar series. When a bar of the secondary bar series is complete, the value is displayed on the chart. This typically results in a step function.


One-Tick Repaint Mode

This mode corrects a weakness of the multi-barseries concept of NinjaTrader. OnBarUpdate() will be triggered for the primary bars and then for the secondary bars. Now imagine that you have a 15 min chart and want to display an hourly SMA. Then t the full hour NinjaTrader will first run the primary bars (allowing to write values to the chart) and then the secondary bars calculating the values from the hourly bars, which it should have written to the primary 15 min bars during the prior run of OnBarUpdate(). This mean that for the bar close of the 15 min bar, the last tick of the 60 min bar cannot be taken into account, because it is not available.

The solution adopted is to repaint the value to the prior bar with the first tick of the new 15 minute bar. The indicator therefore repaints the prior bar a single time, but only uses information from the prior 60 minute bar, which is unfortunately processed after the 15 min bar.

The result also is a step function, but the lag of 1 bar is eliminated when real-time data is processed.


Visual Mode

With each incoming tick the distance between the last node - in the example above that would be the close of the hourly bar - and the current value of the indicator is repainted by using a linear interpolation. In COBC = false mode you can see the last leg moving up and down.


Accessing the indicator

In strategy mode it is pretty easy to access the indicator via another indicator or a strategy. This is possible because the indicator does not repaint. However, there is a limitation. Any multi-timeframe indicator that loads range bars, cannot be properly accessed via another indicator or strategy. Sometimes the indicator values will be vertically shifted, that is the indicator values would be false.

Therefore the VisualSMA cannot be accessed when the period type selected via the indicator parameters is set to "Range".

If you want to access the VisualSMA in One-Tick Repaint or Visual mode you would need to take into account that the indicator repaints. When the indicator is accessed in One-Tick Repaint mode, you need to access the last 2 values for your strategy and let it recalculate. When you access the indicator in Visual mode, things are more complicated, as the indicator repaints over the last swinging leg. Here you would need to call all indicator values that cover this period.

The indicator offers you a Public IntSeries, which can be accessed and which tells you how many bars it paints back for the currennt value. The IntSeries can be accessed as VisualSMA(period, false, false, thisCalcMode, thisPeriodType, thisPeriodValue, thisPriceType).Repaint[0] and then used to collect the last indicator values. You can then use the integer to loop through the bars back to the last node, which is used as anchor point.

For those who are interested I have attached a model indicator that accesses the VisualSMA and plots the values on a chart. Please copy the model indicator into the directory NinjaTrader 7 -> bin -> custom -> Indicator and compile. It will only compile, if you have the VisualSMA installed.

In case that you have installed the model indicator or any other indicator or strategy that accesses the VisualSMA, do not forget to remove those indicators/strategies first before you uninstall the assembly.

Hi @Fat Tails

A question, I try to use the VisualEMA in a strategy, build with the Strategy Wizard and I would like that the VisualEMA under "Rissing" paints the background. Right now it paint's only some single lines, what do I have to do, that it paints correctly?

Thanks for any help
Michael

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-visual.jpg  

Last edited by michaelf; October 15th, 2014 at 10:11 AM. Reason: grammar
Reply With Quote
 
  #398 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary


michaelf View Post
Hi @Fat Tails

A question, I try to use the VisualEMA in a strategy, build with the Strategy Wizard and I would like that the VisualEMA under "Rissing" paints the background. Right now it paint's only some single lines, what do I have to do, that it paints correctly?

Thanks for any help
Michael

The VisualEMA calculates node values according to the selected period for its internal bars and then interpolates the distance between the current value and the node. Interpolating means that it is repainting back to the last node. Repainting indicators cannot be accessed via a strategy created with the strategy wizard. However, it could be accessed via a manually coded strategy, as the number of bars that are currently repainted are exposed and can be accessed.

If you wish to access it with the strategy wizard, then you need to use the indicator in strategy mode (NOT: visual mode). In strategy mode the indicator paints a step function. Everytime a secondary bar closes the VisualEMA follows with a new value. I do not know whether you can define a rising state and a falling state for a step function with the strategy wizard. It is definitely easy to achieve, if you code manually.

Please be aware that the Visual EMA repaints in visual mode - it repaints back to the prior node - and therefore the slope derived from a new value will only be available in real time when the secondary bar has closed.

Reply With Quote
The following 3 users say Thank You to Fat Tails for this post:
 
  #399 (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

To use in a strategy for an entry of one timeframe & exit of another?

Hi,

I am setting up a strategy that uses an EMA/Cross for an entry of one timeframe and uses an EMA/Cross of another timeframe reversing for my exit/stop. Could this indicator be used in a strategy for this? And if not, would you kindly point me in the right direction of another Ninja indicator that can accomplish this if you know of one.

I guess I am basically looking for an alternative option of the general stop/loss by using another EMA Cross on a different timeframe than the primary entry for my exit.

Thanks for providing this indicator!

Jeff


Last edited by Trader Jeff; February 16th, 2015 at 11:17 AM. Reason: Wanted to add more content.
Reply With Quote
 
  #400 (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

Here is an image of what I am trying to do, thanks!


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Trader Jeff View Post
Hi,

I am setting up a strategy that uses an EMA/Cross for an entry of one timeframe and uses an EMA/Cross of another timeframe reversing for my exit/stop. Could this indicator be used in a strategy for this? And if not, would you kindly point me in the right direction of another Ninja indicator that can accomplish this if you know of one.

I guess I am basically looking for an alternative option of the general stop/loss by using another EMA Cross on a different timeframe than the primary entry for my exit.

Thanks for providing this indicator!

Jeff


Reply With Quote

Reply



futures io > > > > Coding Multi Time Frame (MTF) Indicators with NinjaTrader

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
Multi Time Frame Strategy Cancellation jthom NinjaTrader Programming 2 October 9th, 2014 12:00 PM
Close bar recognization in multi time frame strategy pinto552 NinjaTrader Programming 6 September 6th, 2011 10:07 AM
Multi-time frame strategy with periods of different size pequemec NinjaTrader Programming 2 February 24th, 2010 01:41 PM
visual multi-time frame scoring system. benbrooke Traders Hideout 1 October 4th, 2009 06:49 PM
Multi Volume/Time Frame Trading wh The Elite Circle 7 September 15th, 2009 05:55 PM


All times are GMT -4. The time now is 08:54 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.17 seconds with 20 queries on phoenix via your IP 54.83.122.227