Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
High since x bars
Collapse
X
-
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)
Comment
-
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=7299RayNinjaTrader Customer Service
Comment
-
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;
}
Comment
-
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=3418RayNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by terofs, Yesterday, 04:18 PM
|
1 response
21 views
0 likes
|
Last Post
by terofs
Today, 10:14 AM
|
||
Started by CommonWhale, Today, 09:55 AM
|
1 response
3 views
0 likes
|
Last Post Today, 10:11 AM | ||
Started by Gerik, Today, 09:40 AM
|
2 responses
7 views
0 likes
|
Last Post
by Gerik
Today, 10:04 AM
|
||
Started by RookieTrader, Today, 09:37 AM
|
2 responses
12 views
0 likes
|
Last Post
by RookieTrader
Today, 10:02 AM
|
||
Started by alifarahani, Today, 09:40 AM
|
1 response
7 views
0 likes
|
Last Post Today, 10:01 AM |
Comment