![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Oct 2008
Posts: 60
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I was just wondering why this code doesn't work - I have the strategy and the indicator added to a chart. From the Print() statement I can tell the variable is getting set in the indicator, but the plot is just plotting 1's. Code:
public class MyCustomStrategy : Strategy {
#region Variables
int myValue = 0;
#endregion
protected override void Initialize(){
CalculateOnBarClose = true;
}
protected override void OnBarUpdate(){
myValue++;
MyCustomIndicator().TestValue = myValue;
if(myValue == 10)
myValue = 0;
}
}
}
Code:
public class MyCustomIndicator : Indicator
{
#region Variables
private int testValue = 0;
#endregion
protected override void Initialize() {
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
CalculateOnBarClose = true;
}
protected override void OnBarUpdate() {
Print(testValue);
Values[0].Set(testValue);
}
#region Properties
public int TestValue {
get { return testValue; }
set { testValue = Math.Max(1, value); }
}
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Hi spinalwiz,
Please take a look at your indicator region properties and use this snippet: Code:
public int TestValue
{
get { return testValue; }
set { testValue = Math.Max(0, value); }
}
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Oct 2008
Posts: 60
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Bertrand,
Good spot, although I dont think I explained myself very well. Ignoring the rest of the code, this is the part I can't get to work: In the Strategy: Code:
MyCustomIndicator().TestValue = 5; Code:
Values[0].Set(testValue); Code:
Print(testValue); 0 5 0 5 0 5 0 5 This is the code I have in Properties: Code:
public int TestValue {
get { return testValue; }
set { testValue = Math.Max(0, value); }
}
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Hi spinalwiz,
Thanks, please take a look then at the following reference sample - http://www.ninjatrader-support2.com/...ead.php?t=4991 You want to use a DataSeries class to have up-to-date values... Have a great day!
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Oct 2008
Posts: 60
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
Thank you for your reply. I am now using a DataSeries although it unfortunately still does not work. The example you gave was for getting an indicator variable from a strategy. I need to set an indicator variable from a strategy. The code I have in my strategy is: Code:
MyCustomIndicator().MyData.Set(5); MyCustomIndicator().Update(); Code:
Values[0].Set(myData[0]); Code:
public DataSeries MyData
{
set { myData = value; }
get { return myData; }
}
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Hi spinalwiz, unfortunately this is not supported.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Color variable not being initialized if Indicator is included in a Template | GaryAlbers | Suggestions And Feedback | 3 | 04-15-2008 07:10 AM |
| Strategy with a variable that is not plotted | ssierra | Strategy Analyzer | 1 | 03-08-2008 07:17 PM |
| externally accessible custom indicator variable? | Lost Trader | General Programming | 5 | 01-12-2008 02:27 AM |
| Setting Swing to a variable? | Burga1 | Strategy Development | 15 | 12-24-2007 03:25 AM |
| Using a formula or variable as an input to an Indicator | nolantx | Indicator Development | 5 | 05-24-2007 03:58 PM |