NexusFi: Find Your Edge


Home Menu

 





Coding Multi Time Frame (MTF) Indicators with NinjaTrader


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 180 posts (562 thanks)
    2. looks_two Zondor with 19 posts (29 thanks)
    3. looks_3 madLyfe with 16 posts (10 thanks)
    4. looks_4 BankRobberNT with 14 posts (16 thanks)
      Best Posters
    1. looks_one gomi with 3.7 thanks per post
    2. looks_two Fat Tails with 3.1 thanks per post
    3. looks_3 Zondor with 1.5 thanks per post
    4. looks_4 BankRobberNT with 1.1 thanks per post
    1. trending_up 189,841 views
    2. thumb_up 743 thanks given
    3. group 87 followers
    1. forum 424 posts
    2. attach_file 166 attachments




 
Search this Thread

Coding Multi Time Frame (MTF) Indicators with NinjaTrader

  #131 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


Braulio View Post
Is the CrossingArrowsMTF the simpler indicator you talk about?
I don't wanna be a party spoiler but I've already identified a situation where the CrossingArrowsMTF should be plotting a down arrow but there isn't one...yes, I'm that fast... see the pic, I also attached the template.

Please, do not use the VisualSMA for that purpose in VisualMode. You need to set it to StrategyMode (all other modes are repainting). Once set to StrategyMode you can decide whether it should plot an arrow or not.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Better Renko Gaps
The Elite Circle
 
  #132 (permalink)
 
Braulio's Avatar
 Braulio 
Portugal
 
Experience: Beginner
Platform: Ninjatrader, Multicharts
Broker: Amp Futures/Zen-Fire
Trading: ES, 6E
Posts: 229 since Aug 2009
Thanks Given: 407
Thanks Received: 217

Now you have me a bit more confused...the slope of the VisualSMA matches the same SMA(Typical,1) on the 8 and 10 ranges charts...but the CrossingArrowsMTF says they don't and that's why it doesn't plot an arrow?

If I set the VisualSMA in StrategyMode they are mostly horizontal and rarely they go down at the same time....and the CrossingArrowsMTF draws an arrow where they are flat.


Fat Tails View Post
Please, do not use the VisualSMA for that purpose in VisualMode. You need to set it to StrategyMode (all other modes are repainting). Once set to StrategyMode you can decide whether it should plot an arrow or not.


Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	246
Size:	148.8 KB
ID:	48323  
Visit my NexusFi Trade Journal Reply With Quote
  #133 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415


The esteemed vegasfoster and I have written an indicator adapted from the StochCycle indicator that currently works on 6R, 12R, 24R time frames. I want to be able to use it for tick charts and time charts as well as range, preferably based on the current chart bar type. NT Support says they won't (a) tell me how to access the current chart bar type and (b) they only support hard coding even though some NT users have conditionally coded to test and conditionally set the bar period but "I'm on my own". In other words, I would have to have a distinct indicator for each bar type... (back to the 50's in programming style?)

protected override void Initialize()
{
Add(PeriodType.Range, addBarPeriod1); //I WANT TO MAKE THIS TICK OR TIME-BASED CONDITIONALLY
Add(PeriodType.Range, addBarPeriod2); // DITTO
}

Is there a way to get and test the current charts BarsPeriod.Id value?

I doubt the following is correct, but just to show you what I'm trying to do.

if (BarsPeriod.Id == "Range") Add(PeriodType.Range, addBarPeriod1);
else if (BarsPeriod.Id == "Tick") Add(PeriodType.Tick, addBarPeriod1);
else if (BarsPeriod.Id == "Minute") Add(PeriodType.Minute, addBarPeriod1);
else <blah blah blah>;

I'd appreciate any help.

Saroj

Reply With Quote
  #134 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731

An example of the syntax for determining the type of chart that is in the main price panel can be found in the GomRecorderIndicator.


 
Code
if ((BarsPeriod.Id == PeriodType.Second && BarsPeriod.Value > 1) || BarsPeriod.Id == PeriodType.Minute)

After you type the period character after PeriodType, the Intellisense® code editor will helpfully give you a dropdown list of the valid values that you can select from.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #135 (permalink)
 
madLyfe's Avatar
 madLyfe 
Des Moines, Iowa
 
Experience: None
Platform: Ninja, TOS
Broker: AMP/CQG, TOS
Trading: CL, TF, GC
Posts: 1,641 since Feb 2011
Thanks Given: 9,220
Thanks Received: 1,020


Braulio View Post
Now you have me a bit more confused...the slope of the VisualSMA matches the same SMA(Typical,1) on the 8 and 10 ranges charts...but the CrossingArrowsMTF says they don't and that's why it doesn't plot an arrow?

If I set the VisualSMA in StrategyMode they are mostly horizontal and rarely they go down at the same time....and the CrossingArrowsMTF draws an arrow where they are flat.

braulio, ive kinda read into what you are doing here but not following 100%. are you trying to replace the visualSMA indie with arrows of the crosses or are you saying that the visualSMA indie is off?

dont believe anything you hear and only half of what you see

¯\_(ツ)_/¯

(╯°□°)╯︵ ┻━┻
Visit my NexusFi Trade Journal Reply With Quote
  #136 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


Braulio View Post
Now you have me a bit more confused...the slope of the VisualSMA matches the same SMA(Typical,1) on the 8 and 10 ranges charts...but the CrossingArrowsMTF says they don't and that's why it doesn't plot an arrow?

If I set the VisualSMA in StrategyMode they are mostly horizontal and rarely they go down at the same time....and the CrossingArrowsMTF draws an arrow where they are flat.

If the VisualSMA is horizontal, this simply means that no new 8-range bar has been completed, so the indicator sticks with the value of the prior 8-range bar.

The confusion about the slope occurs, because there are two bar series. The slope relative to the 8-range bar series it not the same as the slope relative to the 4-range bar series. The VisualSMA would show the slope relative to the 4-range bars, which is often flat in StrategyMode. What you need is the slope of the 8-range bars. Or better, you just want to check whether the Typical[0] was greater or smaller than Typical[1] on the 8-range bars.

You cannot get the slope from the 8-range bars by using the VisualSMA.

Started this thread Reply With Quote
Thanked by:
  #137 (permalink)
 
Braulio's Avatar
 Braulio 
Portugal
 
Experience: Beginner
Platform: Ninjatrader, Multicharts
Broker: Amp Futures/Zen-Fire
Trading: ES, 6E
Posts: 229 since Aug 2009
Thanks Given: 407
Thanks Received: 217

Ok,


Fat Tails View Post
You cannot get the slope from the 8-range bars by using the VisualSMA.

So the first conclusion I draw from your quote is that I cannot trust the slope of the VisualSMA indicator.

Based on the CrossingArrowsMTF I wrote the attached indicator to try and better understand what's going on and here's what I found (please correct me if I'm wrong) :

It basically plots :
. green - when the slope of 8range SMA(Typical,1) + 10range SMA(Typical,1) are both going up
. red - when the slope of 8range SMA(Typical,1) + 10range SMA(Typical,1) are both going down
. nothing - when they are not going in the same direction

I've applied it to a 4range chart along with the VisualSMA's (see the pic) and I can see the following:

1. the slope of both SMA(Typical,1) are going up but the VisualSMA's lying and going down.
2. both SMA(Typical,1) are NOT going in the same direction but VisualSMA's are lying and plot the opposite.

Have I got it right this time?

Thanks

Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	349
Size:	152.9 KB
ID:	48333  
Attached Files
Elite Membership required to download: aMerda.zip
Visit my NexusFi Trade Journal Reply With Quote
  #138 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


Braulio View Post
Ok,
So the first conclusion I draw from your quote is that I cannot trust the slope of the VisualSMA indicator.

You can trust the slope of a VisualSMA, but you need to understand what it does. The slope is painted backwards from the last value calculated from the 8-range bars to the prior value calculated from the 8-range bars. The slope is only known, once that last 8-range bar has closed. However, you already try to use it before it is known.

You have to understand what repainting means. I do not code repainting indicators in general, but the VisualSMA is an exception. It does not repaint relative to the 8-range bars - it simply connects two data-points - , but it repaints relative to the 4-range bars, as the connection of two data points from the 8-range bars may include many data points from the 4-range bars.

Therefore you should only use the VisualSMA in StrategyMode if you want to use it for calculating other indicators.


Braulio View Post
Based on the CrossingArrowsMTF I wrote the attached indicator to try and better understand what's going on and here's what I found (please correct me if I'm wrong) :

It basically plots :
. green - when the slope of 8range SMA(Typical,1) + 10range SMA(Typical,1) are both going up
. red - when the slope of 8range SMA(Typical,1) + 10range SMA(Typical,1) are both going down
. nothing - when they are not going in the same direction

I've applied it to a 4range chart along with the VisualSMA's (see the pic) and I can see the following:

1. the slope of both SMA(Typical,1) are going up but the VisualSMA's lying and going down.
2. both SMA(Typical,1) are NOT going in the same direction but VisualSMA's are lying and plot the opposite.

Have I got it right this time?

Thanks

Yes, you have got the trend filter right. Let us have a look at the last green box. Historical data is made up of 1-tick bars. So the trendfilter collects the information from the previous bars of the secondary bar series (BarsInProgress ==1 and BarsInProgress==2). It does not have the information yet that the Typical Price of the secondary bar series has moved down. If you compare with the VisualEMAs, you will notice that the previous close of the secondary bar series was one candle back - aligned to the second but the last green box of your trend filter. So the trendfilter simply remains grreen in that state, because the next tick of the secondary bar series has not been registered.

The VisualSMA has a negative slope, it already uses the information from the next tick and then paints the slope back. The lag is compensated, but this is achieved through repainting the connection between two consecutive 8-range or 10-range bars. The VisualSMA does not lie, it just seems to look into the future. If you use the VisualSMA in StrategyMode it will be in harmony with your trend filter.

Real-Time data would be different

If you use real-time data, the picture will be different. Each tick registered will temporarily change the value of the 4-range, the 8-range and the 10-range bars. So in real-time your trendfilter will not be green but already red, because it will collect the last value from the secondary bars at that stage when the bar 1 on your chart closes. This is in line with the CalculateOnBarClose = false settings for the primary bars. The current value of an indicator is shown, even if the bar has not closed. In real-time those current values from the secondary bars are used to calculate the trendfilter. When the bar is closed it will use the last known value, which is an intrabar value and no longer available with historical data.

This mean that your trendfilter will also show different values, once you have loaded historical (1-tick -per-bar) data.

Started this thread Reply With Quote
Thanked by:
  #139 (permalink)
 
Braulio's Avatar
 Braulio 
Portugal
 
Experience: Beginner
Platform: Ninjatrader, Multicharts
Broker: Amp Futures/Zen-Fire
Trading: ES, 6E
Posts: 229 since Aug 2009
Thanks Given: 407
Thanks Received: 217

Could you zip a file with the part of your brain that understands all this and send it over? Thanks....

. that means the CrossingArrowsMTF indicator will also show different results in real time, right?

. could this historical/real-time "problem" with indicators that have different dataseries be solved if they used tick information from the gomrecorder framework?

. does that also mean that this a common problem with all MTF indicators? That is, there will always be a difference between historical and real-time calculus?

Visit my NexusFi Trade Journal Reply With Quote
  #140 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103



Braulio View Post
Could you zip a file with the part of your brain that understands all this and send it over? Thanks....

That means the CrossingArrowsMTF indicator will also show different results in real time, right?

Does that also mean that this a common problem with all MTF indicators? That is, there will always be a difference between historical and real-time calculus?

There is a common problem with all MTF indicators, which is linked to the way OnBarUpdate() works.

OnBarUpdate() will always run the primary Bars [BarsInProgress == 0] first. It will then call the added bar series [BarsInProgress == 1, BarsInProgress == 2, etc.].

Now imagine that both your primary bar and your secondary bar close at 5:10 PM. The primary bar is run first and the indicator values are set for that bar. Then OnBarUpdate() will run the secondary bar and calculate the values for the 5:10 PM bar close of the secondary bars. But you can no more use them for setting the indicator values, because the indicator values were already set for the 5:10 PM bar, when OnBarUpdate() had called the primary bar.

This means that you will always come 1 tick late. All MTF indicators lag by at least 1 tick.

Now note the difference between historical and real-time data. Historical bars are 1-tick bars. Coming 1 tick late means that you will be 1 bar late. Real-time bars are less of a problem, because the 5:10 PM indicator value will have been calculated from the second-but-the-last tick of the 5:10 secondary bar. On historical data there is no second-but-the-last-tick, so the close from the previous bar will be used.

To solve this problem visually, you can simply repaint 1 tick back. This is the reason that the VisualSMA indicator has a 1-tick-repaint option, the FirstTickMode. But if you want to execute a strategy you can not repaint, because you would use information that is not yet made available by NinjaTrader - a case of the hindsight bias.

Started this thread Reply With Quote
Thanked by:




Last Updated on April 19, 2022


© 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