![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
how can I implement this settlement " High since X bars" where X is a parameter ?
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
double myHigh = MAX(High, X)[0];
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
thanks for your answer
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
I have another question. I'm trying to code an indicator which plot a signal for 3 different periods x1,x2,x3 on the same window.
Here is the script i've coded so far : protected override void Initialize() { Add(new Plot(Color.Red, "repulse1")); Add(new Plot(Color.Black, "repulse2")); Add(new Plot(Color.Green, "repulse3")); Add(new Line(Color.Black,0, "Zero line")); } protected override void OnBarUpdate() { double myHigh1=Max(High,x1)[0]; double myLow1=MIN(Low,x1)[0]; double bullishthrust1=3*Close[0]-2*myLow1-Open[x1]; double bearishthrust1=Open[x1]+2*myhigh1-3*Close[0]; BEMA1.Set(EMA(bullishthrust, 5*x1)); BEMA2.Set(EMA(bullishthrust, 5*x1)); double repulse1=(BEMA1-BEMA2)/Close[0]*100; } How can I modify this script in order to avoid writing things 3 times ? Feel free to tell me if there are some mistakes (this is my first script) |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
not sure what you mean by three times...
You can not pass in a double to EMA() method. You need to store calculations in a DataSeries object and pass that in. See this reference - http://www.ninjatrader-support.com/v...ead.php?t=7299
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
What I mean is that each parameter is using the same formula.
In the script below I only wrote the code for x1 (for x2 and x3 I would have written the same thing ) |
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Then you write some sort of loop:
for (x = 1; x < 3, x++) { // Calculations here }
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
here is my script,can you tell me what is wrong or what can be done to shorten the code, please?
private int x1=1; private int x2=5; private int x3=15; private Dataseries EMAbull1; private Dataseries EMAbear1; private Dataseries EMAbull2; private Dataseries EMAbear2; private Dataseries EMAbull3; private Dataseries EMAbear3; protected override void Initialize() { Add(new Plot(Color.Red, "repulse x1")); Add(new Plot(Color.Black, "repulse x2")); Add(new Plot(Color.Green, "repulse x3")); Add(new Line(Color.Black,0, "Zero line")); EMAbull1 =new Dataseries(this); EMAbear1 =new Dataseries(this); EMAbull2 =new Dataseries(this); EMAbear2 =new Dataseries(this); EMAbull2 =new Dataseries(this); EMAbear2 =new Dataseries(this); } protected override void OnBarUpdate() { double myHigh1=Max(High,x1)[0]; double myLow1=MIN(Low,x1)[0]; double bullishthrust1=3*Close[0]-2*myLow1-Open[x1]; double bearishthrust1=Open[x1]+2*myhigh1-3*Close[0]; EMAbull1.Set(EMA(bullishthrust, 5*x1)); EMAbear1.Set(EMA(bearishthrust, 5*x1)); double repulse x1=(EMAbull1-EMAbear1)/Close[0]*100; double myHigh2=Max(High,x2)[0]; double myLow2=MIN(Low,x2)[0]; double bullishthrust1=3*Close[0]-2*myLow1-Open[x2]; double bearishthrust1=Open[x2]+2*myhigh1-3*Close[0]; EMAbull2.Set(EMA(bullishthrust, 5*x2)); EMAbear2.Set(EMA(bearishthrust, 5*x2)); double repulse x2=(EMAbull2-EMAbear2)/Close[0]*100; double myHigh3=Max(High,x3)[0]; double myLow3=MIN(Low,x3)[0]; double bullishthrust1=3*Close[0]-2*myLow1-Open[x3]; double bearishthrust1=Open[x3]+2*myhigh1-3*Close[0]; EMAbull3.Set(EMA(bullishthrust, 5*x3)); EMAbear3.Set(EMA(bearishthrust, 5*x3)); double repulse x3=(EMAbull2-EMAbear2)/Close[0]*100; } |
|
|
|
|
|
#9 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
We are happy to help if we can glance at the code and see anything that sticks out but what we don't do is provide support in debugging user generated code. You would have to debug on your own.
Here is a helpful resource - http://www.ninjatrader-support.com/v...ead.php?t=3418
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| EMA of High - Low | glenng | Indicator Development | 2 | 02-02-2008 07:45 PM |
| Bars are wrong on strategy performance (negative bars) | woodside | Historical NinjaTrader 6.5 Beta Threads | 2 | 01-13-2008 10:22 PM |
| CrossAbove(High, High, 1) | Lost Trader | Indicator Development | 4 | 01-11-2008 09:27 AM |
| High greater than Highest High of last 20 Bars | SamIam | Strategy Development | 1 | 08-19-2007 04:58 PM |
| Momentum bars or Price Range Bars | Akros | Indicator Development | 7 | 06-10-2007 04:55 AM |