Thank you
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
Compare of Indicator values
Collapse
X
-
Compare of Indicator values
How do I compare latest value of an indicator with it's values during previous time period? F. ex. if I need to know on a 1 minute chart is DM+ value now highest during period of time from now, and back to the moment when DM+ has touched DM- last time.
Thank youTags: None
-
Hello,
You would need to know the bar index for when you are wanting to check or hold the value based on when certain conditions occur. For example you could create a double variable that holds the value of the DMI+ when the DMI+ is equal to the DMI-. For example:
if (DM(14).DiPlus[0] == DM(14).DiMinus[0])
{
MyDouble = DM(14).DiPlus;
}
You can get the current bar's DMI+ by using a value of 0 for the index for DM(period).DiPlius[int barsAgo]
For more information on the Directional Movement indicator please see the following link: http://ninjatrader.com/support/helpG...ovement_dm.htmCody B.NinjaTrader Customer Service
-
Good morning Cody B and Thank You for reply. I'm not advanced much with programming, but let me do what you recommend and come back to you?
Great day
MichaelLast edited by 2014Michael; 07-11-2016, 08:38 AM.
Comment
-
Hi, Cody B.
Just wanted to clarify. What you suggested “create a double variable that holds the value of the DMI+ when the DMI+ is equal to the DMI-” will define the first point in that time period between the point when DI+ was equal to DI- and second point is value of DI+ now. Right? And this will work, thank you.
Now, if you’ll be so kind, what I originally wanted is to compare this ‘now DI+’ value with every values of DI+ between those two points, and only signal (or open position) if ‘now DI+’ is highest.
Is it too much? Appreciate your help anyway.
Sincerely
Michael
Comment
-
Originally posted by 2014Michael View Post...
... what I originally wanted is to compare this ‘now DI+’ value with every values of DI+ between those two points, and only signal (or open position) if ‘now DI+’ is highest.
Sincerely
Michael
That being said, what you have to do is keep a running evaluation after the initial condition is met, and store the value of DI+ until the current value is less than the stored value, which would imply the the immediate past value of DI+ is a local maximum. You can make a decision on that.
Comment
-
Hello,
I have provided an example below of how you could find the highest value of the DMI Plus in the period from when the DMI Plus crosses the DMI Minus to the Current Bar.
Code:#region Variables private int myCurrentBar; private double diPlusHi; #endregion protected override void Initialize() { Overlay = false; Add(new Plot(Color.Green,"DiPlus"));//Plot to visualize the DiPlus Add(new Plot(Color.Red, "diPlusHi"));//Plot to visulize the high of the DiPlus } protected override void OnBarUpdate() { Value.Set(DM(14).DiPlus[0]);//Sets the first plot to the value of the DMI Plus if(CrossAbove(DM(14).DiPlus, DM(14).DiMinus, 1) || CrossBelow(DM(14).DiPlus, DM(14).DiMinus, 1))//Checks when the DiPlus Crosses the DiMinus { myCurrentBar = CurrentBar;//When the cross occurs we will set this value to be how we check back to when this occurred } diPlusHi = MAX(DM(14).DiPlus, CurrentBar - myCurrentBar)[0];//Using the MAX method we are able to check the maximum value of the DiPlus from the number of bars back from the current bar to the cross Values[1].Set(diPlusHi);//set the second plot so we can see the hi DrawVerticalLine("myCurrentBar", CurrentBar - myCurrentBar, Color.Red, DashStyle.Solid, 1);//draws a line at the time that the cross occurs DrawVerticalLine("CurrentBar", 0, Color.Blue, DashStyle.Solid, 1);//draws a line at the current bar so we can see when the area that is being checked }
Cody B.NinjaTrader Customer Service
Comment
-
-
Cody B., obviously genius. Let me see how it works, and I let you know. Have a great evening.
Michael
Comment
-
To Cody B.
Thanks. I didn't know about MAX method. It's great!
Three questions.
First. I see two lines in the second plot of the chart, and two vertical lines in the first plot, with bars, and it shows right. But it's show nowhere the diPlusHi point. Something little missing in the code?
Second. Is it posible to put in another condition for DI+ be biger than 25? So a result will be that DM is biger than 25, and bigest for our time period.
Third. Since we looking for highest DM+, we don't need 'CrosBelow' part (it will be later for DI- by analogy).
Appreciate your help
MichaelLast edited by 2014Michael; 07-12-2016, 04:17 PM.
Comment
-
Hello,
The DiPlusHi plot will be the highest DiPlus value. This will appear as the red plot in the sample I provided. You can remove the crossbelow. I provided a sample to get you started on your indicator as I believe this may have been the best method to show you how you can use the MAX indicator to accomplish this. You would be able to add a check for when the DiPlus is great than 25. You could add this to the Cross check or nest it as its own if statement.Cody B.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_CodyB View PostHello,
The DiPlusHi plot will be the highest DiPlus value. This will appear as the red plot in the sample I provided. You can remove the crossbelow. I provided a sample to get you started on your indicator as I believe this may have been the best method to show you how you can use the MAX indicator to accomplish this. You would be able to add a check for when the DiPlus is great than 25. You could add this to the Cross check or nest it as its own if statement.
Now, if you’ll be so kind, what I originally wanted is to compare this ‘now DI+’ value with every values of DI+ between those two points, and only signal (or open position) if ‘now DI+’ is highest.
How does processing the MAX() value in a fixed sliding window achieve that? Assume for the sake of argument, that after the initial condition. DI+ monotonically increases for 5 bars (say), in which case on each bar the MAX() will move. On which bar is he to make the entry then? After all, we have a new MAX on each bar. Entries cannot be made in hindsight. How does he make entries in real time, in a streaming chart, using the code that you have given him?
Just curious.
Comment
-
Hello,
You could create a conditon to compare the current DMI Plus to the value of the variable diPlusHi and if its greater you could set this as the signal.
For example:
Code:if(DM(14).DiPlus[0] > diPlusHi) //DoSomething
Cody B.NinjaTrader Customer Service
Comment
-
Thanks, Cody B.
Hopfully this all will work. I just not beeng professional need some time to process your information.
Michael
Comment
-
Hi, koganam.
Appreciate your attention. May be you have more elegant decision? I'll be happy to learn!
Just for clarity, allow me to say for example: when DI+ touched DI- last time it was 17. Than it's grew to 30, then it went back to 25. At this point I need to know if this value biggest on the time period from now and back to the point it was 17. So I want it to signal me only when DI+ will come to 31 or never until next touch with DI-.
It's great talking to you guys!
MichaelLast edited by 2014Michael; 07-13-2016, 04:10 PM.
Comment
-
Originally posted by 2014Michael View PostHi, koganam.
Appreciate your attention. May be you have more elegant decision? I'll be happy to learn!
Just for clarity, allow me to say for example: when DI+ touched DI- last time it was 17. Than it's grew to 30, then it went back to 25. At this point I need to know if this value biggest on the time period from now and back to the point it was 17. So I want it to signal me only when DI+ will come to 31 or never until next touch with DI-.
It's great talking to you guys!
Michael
Code:Store the state of the initial setup when it occurs: ---------------------------------------------------------------------- Process this block if we are not currently in a setup. DI+ must cross above Di- when both are less than 20 (or is 17 your limit). Update a bool to tell us that we are in a setup. Store the bar number and DI+. (I am not sure why we would store the bar number, unless you are placing an upper limit of a maximum number of bars how many bars within which the setup must complete, in which case, you simply add that as another processing condition).
Code:Process all next bars until the setup is invalid or DI+ rises to 31 or more: ------------------------------------------------------------------------------------------ On the next bar[LIST=1][*]If we are in a setup and[*]If DI+ has crossed below DI- reset the bool to tell us that we are not in a setup anymore.[*]Otherwise. if DI+ is 30 or more, we have a completed setup. Make the entry.[*]Otherwise, if DI+ is greater than the stored value of DI+, replace the stored value with the new value.[/LIST]
Everyone of those is a simple statement that is easily coded. That is how you write code. First you clearly state what you want to write, which serves to clarify your thinking, then you just write simple code statements. You can see that because I wrote down first what we want to do, the actual code will achieve your objective without having to do the convoluted dance that your initial description seemed to imply.
Now, just so that we are clear, I am not scolding you. I am just pointing out that writing the process flow makes coding much easier and clearer. When I first started, like most of my colleagues, I just wanted to jump in and write the code, thinking that I knew what to do. It soon dawned on me that the person who was finishing the assignments first and usually had the cleanest code, was not even coding after the assignment was given: he was writing the process flow. We all thought that we were ahead, until he handed in his paper early. Time after time. After a while, a large number of us were writing down our program flow first. It took up the most time, and often made the actual coding writing a simple throwaway exercise. OK. Off the soapbox now.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
Comment