NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 11-11-2008, 01:24 PM   #1
ActiveHawk
Junior Member
 
Join Date: Feb 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default How to access another indicators configurable properties

I have indicatorA with several properties that are user configurable via its indicator panel. I have another indicatorB that wants to use some of the same settings and I don't want the user to have to set the properties in both places.

From indicatorB, when I code IndicatorA().PropertyName from within onbarupdate(), I get the original default value as set in indicatorA variable section and not the value the user set via indicatorA's dialog.

I use configurable properties all the time and the work great when only reference by the indicator that set them.

Is there a way to get the value the user has set in the dialog from another indicator?


Code:
 
///****IndicatorA
 
private int propertyTest = 2;
 
// Initialize has nothing related
 
// OnBarUpdate has nothing related
 
#region Properties
[Category("Whatever")]
[Description("Sets the whatever")]
[NinjaTrader.Gui.Design.DisplayName("Whatever Property)")]
public int PropertyTest
{
  get { return propertyTest ; }
  set { propertyTest = value; }
}
#endregion
Then user changes PropertTest to a 10 in the indicator dialog.

Code:
 
//**** IndicatorB
 
...OnBarUpdate()
{
  Print("Test: " + IndicatorA().PropertTest)  <----- always prints "2"
}
When I add a Print() of the property to OnBarUpdate() on IndicatorA, for each bar I get...

Code:
 
Test: 2
Test: 10
ActiveHawk is offline  
Reply With Quote
Old 11-11-2008, 02:28 PM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Hi ActiveHawk,

Thanks for your post.

Please review those two links here -

1. http://www.ninjatrader-support2.com/...ead.php?t=4991

2. http://www.ninjatrader-support.com/H...V6/Update.html

It is important that you use the Update() method to force an update of the embedded indicator values.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 11-11-2008, 04:17 PM   #3
ActiveHawk
Junior Member
 
Join Date: Feb 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default Not related to Update()

Thanks for the reply. I'm familier with the use of Update() but this doesn't seem to be a problem with calling Update(). It fails with or without the call to Update() in the property getter. It has to do with variables that are changed by the user not being available to other indicators.

I've included two simple test indicators. TestIndB calls TestIndA to get the value of A's user configurable property (ExposedVariable) but can only ever get the default and not the value set by the user.

The ExposedVariable can be changed all you want in the dialog of TestIndA and the output window will always show "Exposed Variable: 2".

See simple test code below...

TestIndA.cs
Code:
 
public class TestIndA : Indicator
{
  private int exposedVariable = 2;
 
  protected override void Initialize()
  {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
  }
 
  protected override void OnBarUpdate()
  {
    Plot0.Set(Close[0] + (10*TickSize));
  }
 
  [Browsable(false)]
  [XmlIgnore()]
  public DataSeries Plot0
  {
    get { return Values[0]; }
  }
 
  // [Browsable(false)] // user configurable property
  // [XmlIgnore()] // user configurable property
  public int ExposedVariable
  {
  get { Update(); return exposedVariable; } // Update() doesn't matter here.
  set { exposedVariable = value; }
  }
}
TestIndB.cs
Code:
 
public class TestIndB : Indicator
{
 
  protected override void Initialize()
  {
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot0"));
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
  }
 
  protected override void OnBarUpdate()
  {
    Print("Exposed variable from TestIndB: " + TestIndA().ExposedVariable);
  }
 
  [Browsable(false)]
  [XmlIgnore()]
  public DataSeries Plot0
  {
    get { return Values[0]; }
  }
}
ActiveHawk is offline  
Reply With Quote
Old 11-11-2008, 05:05 PM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Hi ActiveHawk,

Thanks for posting the test indicators.

You cannot make a user defined input variable directly available to other indicators.

For that matter please create another variable that tracks the user defined input one and expose that to access it from the other study.
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add indicator line with configurable level RandyT General Programming 5 10-14-2008 09:16 PM
Access to values of some indicators lgarcia3 Miscellaneous Support 6 04-15-2008 09:45 AM
Beta bug? Strategy Analyzer backtest properties window showing wrong properties OregonSun Historical NinjaTrader 6.5 Beta Threads 2 01-27-2008 05:42 PM
Bugs with DrawTextFixed and saving templates with configurable fonts Wizard Historical NinjaTrader 6.5 Beta Threads 4 12-12-2007 07:57 AM
Programmatic Access to all Power Volume Indicators Forex Ninja Suggestions And Feedback 1 05-21-2007 08:24 AM


All times are GMT -6. The time now is 10:13 PM.