![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
|
I would like to reference an indicator based on a different time frame from the primary time frame of the chart. By 'reference', I mean a simple "If >=" or "true/false" condition using that indicator and time frame. If I simply add an additional series, it ruins the chart due to the spacing problem. Is there a way to calculate an indicator using a different time frame without plotting it or otherwise affecting the chart?
Thanks. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,317
Thanks: 158
Thanked 206 times in 205 posts
|
Hello billr,
This would be possible by creating a new Indicator with some custom code. For example if you are using the SMA on the 5 minute chart you can start by creating a new indicator with the original code from another indicator. To do this go the Control Center -> Tools -> Edit NinjaScript -> Indicators. Then double left click on the indicator that you want to have the original code from for example the "SMA". It will then open up the source code for the indicator. Right click inside the window and select Save As. Type in a name of your choosing then press "Save". Press the "OK" button. Now you have a new indicator based off the system indicator code that you can modify to have a multi-time frame. For example to Add() a 1 minute time frame to a 5 minute chart: Code:
protected override void Initialize()
{
// Add a 1 minute Bars object: BarsInProgress index = 1
Add(PeriodType.Minute, 1);
}
protected override void OnBarUpdate()
{
// 1 minute chart.
// Do something within the context of the 1 minute Bars here
if(BarsInProgress ==1 )
{
//do something
}
}
http://www.ninjatrader.com/support/f...ead.php?t=3572 You may also read more on Multi-Time Frame and instruments on our online help guide at the following link. http://www.ninjatrader.com/support/h...nstruments.htm Please let me know if I can be of further assistance.
JC
NinjaTrader Customer Service
Last edited by NinjaTrader_JC; 07-13-2012 at 02:16 PM.
|
|
|
|
|
The following user says thank you to NinjaTrader_JC for this post: |
|
|
|
#3 |
|
Senior Member
Join Date: Oct 2007
Posts: 1,863
Thanks: 17
Thanked 100 times in 82 posts
|
There is a sample indicator here that calculates the SMA from a different bars than the bars shown on the chart. The primary reason that I have coded it, is to avoid spoiling the chart via non-equidistant bar spacing.
The indicator can be downloaded here (membership required): http://www.bigmiketrading.com/downlo...-download.html Or send me a private message with your e-mail and I will send it to you. It is not an easy piece of code and I have therefore locked the code. The indicator is available for free. |
|
|
|
|
The following user says thank you to Harry for this post: |
|
|
|
#4 |
|
Senior Member
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
|
Thanks Harry. I will take a look. I'm sure it will be quite helpful.
I am trying to do this for the same reasons you cite in your BMT post. I am a member of BMT, so I can access that section. Very kind of you to take the time to resond. Bill |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Oct 2007
Posts: 1,863
Thanks: 17
Thanked 100 times in 82 posts
|
Actually there are three different options to deal with the problem.
(1) add a secondary bar series via indicator, calculate values from the secondary bars and display indicators on chart for primary bars (2) calculate synthetic higher timeframe bars from the lower time frame bars, in this case you would collect the open, high, low and close from N consecutive bars and store them in an array, and then access the array to calculate indicator values (3) skip step (2) by tweaking the indicator values directly without creating those synthetic bars, for example if you code an SMA you can simply increase the indicator period by a factor N, if you code an EMA you can replace the smoothing constant k = 1/(2n+1) with a new smoothing constant k' = 1 - Math.Power(1-k, 1/N) and you are done. Both values give an excellent approximation, and at the same time you will be able to solve the problem of the unstable period, which covers up to N bars with the solution 2, but only 1 bar when you tweak the indicators Send me a private message via BigMike's (or here), if you have any further questions. Harry |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| code change affecting strategy with multiple entries? | richtobey | Strategy Development | 1 | 02-06-2012 12:37 PM |
| Multiple Time Frame Chart Spacing | DavidHP | Charting | 3 | 11-04-2011 05:58 AM |
| Multiple Time Frame help | safetrading | Strategy Development | 9 | 07-02-2011 01:07 PM |
| multiple time frame backtesting | daniel olofsson | Strategy Analyzer | 1 | 10-13-2010 04:16 PM |
| Strategy that includes multiple display panels and multiple time frame data | burrmann | Strategy Development | 1 | 08-03-2010 04:53 AM |