![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Sep 2006
Location: Rome, , Italy
Posts: 131
Thanks: 2
Thanked 1 time in 1 post
|
I'd like to plot and indicator for trend.
If a certain condition is met then the trend is up and the indicator plots 1, otherwise, if another condition is met the the trend is down and the indicator plots -1. Following is the code: if (CurrentBar < Barre1) return; if (Close[0] > MAX(High, Barre1)[1]) { Plot0.Set(1); } if (Close[0] < MIN(Low, Barre1)[1]) { Plot1.Set(-1); } The problem is that there are empty spaces but I'd like to have the previous value (1 or -1) until the trend does not change. How can I write the code to plot the previous value and have a continuous indicator? Thanks for any help. |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Usea variableto store the current trend value. Declare the variable under the variables section:
private double trend = 1; Then in the OnBarUpdate(): if (CurrentBar < Barre1) return; if (Close[0] > MAX(High, Barre1)[1]) trend = 1; else if (Close[0] < MIN(Low, Barre1)[1]) trend = -1; Plot1.Set(trend); Ray
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Sep 2006
Location: Rome, , Italy
Posts: 131
Thanks: 2
Thanked 1 time in 1 post
|
Perfect.
Now is working fine. Thanks very much. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|