NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 05-07-2008, 01:52 PM   #1
kuroro13
Senior Member
 
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default High since x bars

how can I implement this settlement " High since X bars" where X is a parameter ?
kuroro13 is offline  
Reply With Quote
Old 05-07-2008, 02:08 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

double myHigh = MAX(High, X)[0];
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-07-2008, 02:20 PM   #3
kuroro13
Senior Member
 
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default

thanks for your answer
kuroro13 is offline  
Reply With Quote
Old 05-07-2008, 03:19 PM   #4
kuroro13
Senior Member
 
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default

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)
kuroro13 is offline  
Reply With Quote
Old 05-07-2008, 03:26 PM   #5
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-07-2008, 03:36 PM   #6
kuroro13
Senior Member
 
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default

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 )
kuroro13 is offline  
Reply With Quote
Old 05-07-2008, 03:47 PM   #7
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Then you write some sort of loop:

for (x = 1; x < 3, x++)
{
// Calculations here
}
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-07-2008, 04:52 PM   #8
kuroro13
Senior Member
 
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default

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;
}
kuroro13 is offline  
Reply With Quote
Old 05-07-2008, 06:30 PM   #9
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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
NinjaTrader_Ray 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
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


All times are GMT -6. The time now is 02:10 AM.