![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jan 2008
Posts: 130
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
if i do ADX(Input, 14) then I will get the ADX of the current bar. How do I get the ADX of the previous bar? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
NinjaCustomer, this code will get you the ADX of the current bar:
Code:
double current_ADX = ADX(Input, 14)[0]; Code:
double prev_ADX = ADX(Input, 14)[1];
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 2008
Posts: 130
Thanks: 0
Thanked 0 times in 0 posts
|
Here is the whole of my indicator (that I made to illustrate the problem):
The code that displays the fixed text "right" does not get executed I'm using 6.5 Code:
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class TestIndicator : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
DrawTextFixed("abc", "left", TextPosition.TopLeft);
double curWMA = WMA(Input, 100)[0];
double prevWMA = WMA(Input, 100)[1];
DrawTextFixed("def", "right", TextPosition.TopRight);
}
#region Properties
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private TestIndicator[] cacheTestIndicator = null;
private static TestIndicator checkTestIndicator = new TestIndicator();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public TestIndicator TestIndicator()
{
return TestIndicator(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public TestIndicator TestIndicator(Data.IDataSeries input)
{
if (cacheTestIndicator != null)
for (int idx = 0; idx < cacheTestIndicator.Length; idx++)
if (cacheTestIndicator[idx].EqualsInput(input))
return cacheTestIndicator[idx];
TestIndicator indicator = new TestIndicator();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.SetUp();
TestIndicator[] tmp = new TestIndicator[cacheTestIndicator == null ? 1 : cacheTestIndicator.Length + 1];
if (cacheTestIndicator != null)
cacheTestIndicator.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheTestIndicator = tmp;
Indicators.Add(indicator);
return indicator;
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.TestIndicator TestIndicator()
{
return _indicator.TestIndicator(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.TestIndicator TestIndicator(Data.IDataSeries input)
{
return _indicator.TestIndicator(input);
}
}
}
Last edited by NinjaCustomer; 02-07-2010 at 11:23 PM.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
You would need to make sure to not access any undefined bars at the OnBarUpdate() start -
http://www.ninjatrader-support2.com/...ead.php?t=3170 Your code below likely throws an error to the log tab....
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| if Target Profit reached on previous bar, dont trade current bar | paschall | Strategy Development | 4 | 09-02-2009 10:34 PM |
| Current Bar Open Equals Previous Bar Close | ramacan | Charting | 6 | 05-23-2009 11:07 AM |
| High and Low of previous bar and actual bar | Fernando | Miscellaneous Support | 1 | 03-18-2009 10:54 AM |
| Highest Bar of e.g. ADX | Tobias1985 | Strategy Development | 4 | 02-26-2009 02:04 PM |
| CrossBelow previous bar and omit current bar | ct | General Programming | 1 | 06-03-2007 02:54 AM |