Thanks
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
BarsAgo of MIN output
Collapse
X
-
BarsAgo of MIN output
I used the MIN method to find the double value between two points. How can I get a reference to the bar of that MIN price? I thought of using LowestBar but I can;t see how I can set it to find the lowest bar within a range.
ThanksTags: None
-
Hello b16_aln,
Are you specifically using a BarsAgo greater than 0 with the MIN method? If not, you can use LowestBar interchangeably:
Code:if(CurrentBar < 20) return; double value = MIN(Low, 20)[0]; int lowestBar = LowestBar(Low, 20); double lowestPrice = Low[lowestBar]; Print(value + " " +lowestPrice + " BarsAgo: " + lowestBar);
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
yes i used a lopp to find MIN as i'm looking for the value between 2 points. With MIN I could do it because i could set the start bar for the look back period using [square brackets] but I'm not sure how I can set the start Bar for the lkookback period on the LowestBar function?
Comment
-
Hello b16_aln,
it sounds like you should likely just use the loop you have and some conditions to find the MIN and then use the loops index from that point.
Using LowestBar wouldn't work in your use case because it expects not to be used in a loop in normal bar processing.
Using MIN would be one way to get the MIN however that is also not generally used in a loop but is used with the current bar processing. You can use a BarsAgo with this but for the described use case that is not likely the best way.
Because you already made a loop you can skip using MIN or LowestBar and just calculate the minimum yourself based on the prices seen in your loop. Once you find the minimum price, you could store the loops index at that point.
If you then needed to convert the index to a BarsAgo, that would use the CurrentBar: CurrentBar - foundIndex = BarsAgo
For an example of finding the minimum/maximum in a loop yourself you could see the following page: https://ninjatrader.com/support/help...ghlightsub=min
Assuming your loop is similar you would find the min and once you have also set a variable to the index of that iteration of the loop, going from the help guide sample that might look similar to the following:
Code:double newMin = Math.Min(tmpMin, plotValue); if(newMin != tmpMin) myIndex = index; tmpMin = newMin;
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello b16_aln,
I had explained about using the loop from the linked sample because you said you were using a loop. The page I linked this page has an example of a loop being used which makes it a good comparison. That sample also shows finding the min/max in the loop which is also what you are doing, so this sample matches what you want to do.
The concepts from that sample are the same as your requirements:
Finding the minimum
looping over a range of time
Because you didn't provide any sample, it would be up to you to learn from this code and apply it in your own situation. You said you are using a loop, so you could compare your loop with this loop to understand how you can calculate the minimum. I also explained one way you could store the index when the minimum is found and also provided a way to calculate BarsAgo from the index. You can use all of this information to apply toward your loop in your script, you would just need to review the sample further and make comparisons to see where that will fit with your existing loop.
Please let me know if may be of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello b16_aln,
The index would be your loops iterator, that depends on what you programmed as to what that would be called in your code. Most commonly you will see the index represented as "i" or "index" in a for loop. The sample I linked that would be "index".
Code:for ([B]int index [/B]= ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
If you can provide a sample of what you are actually coding that would be much more helpful so we can just talk about what you are doing in your logic. Without knowing specifically what you coded all I can really do is direct you to similar concepts which you can learn from. Because we are using C# and manually coding, you can review the syntax from other samples to understand concepts and then apply them to your code as needed.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Thanks Jesse,
Yes I was aware and using int "i" in loops but never put 2 and 2 together to use index over the NT8 Bar series . I only used it over a <list> up till now.
I'm very new to coding and c# so appreciate the assistance. I will look over it all over the weekend.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by timmbbo, Today, 08:59 AM
|
1 response
2 views
0 likes
|
Last Post Today, 09:16 AM | ||
Started by KennyK, 05-29-2017, 02:02 AM
|
2 responses
1,281 views
0 likes
|
Last Post
by marcus2300
Today, 09:13 AM
|
||
Started by fernandobr, Today, 09:11 AM
|
0 responses
3 views
0 likes
|
Last Post
by fernandobr
Today, 09:11 AM
|
||
Started by itrader46, Today, 09:04 AM
|
1 response
6 views
0 likes
|
Last Post Today, 09:10 AM | ||
Started by bmartz, 03-12-2024, 06:12 AM
|
5 responses
33 views
0 likes
|
Last Post Today, 08:34 AM |
Comment