I couldn't use LowestBar() method since it by default takes into account starting index as 0. Please suggest which method can be used in this situation ?
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
How to find Lowest Bar value within a range of bars ?
Collapse
X
-
How to find Lowest Bar value within a range of bars ?
I need to find the lowest bar within a range for ex: from index 2 to index 8 and current bar index is 0.
I couldn't use LowestBar() method since it by default takes into account starting index as 0. Please suggest which method can be used in this situation ?
1 PhotoLast edited by sachin shetty; 07-11-2020, 08:51 PM. -
Hello sachin shetty,
Thanks for your post and welcome to the NinjaTrader forums!
If you are looking for the lowest price I would suggest using the MIN() method where you can specify the Low data series, the number of bars to process and the start bar (Bars ago index). Using your example would be: myLowPrice = MIN(Low, 6)[2].
If you need the lowest bars ago then I would suggest a for loop to interate over the range of bars and compare the low price. Something like:
Code:double lowprice = double.MaxValue; // set initally to highest double type value double lowbarsAgo = 0; for (int i = 2; i < 9; i++) { if (Low[i] < lowprice) // is low is less than previous low price { lowprice = Low[i]; // save new lower price lowbarsAgo = i; // save the bars ago value } }
Paul H.NinjaTrader Customer Service
- Likes 2
-
Hello Paul,
How would I modify your recommendation to plot a brush color on each bar meeting this criteria?
It should color each bar which low is the lowest price over the past 4 bars.
For example:
If
Low[0] = 0.70 // CurrentBar = 555
Low[1] = 0.99 // CurrentBar = 554
Low[2] = 0.92 // CurrentBar = 553
Low[3] = 0.85 // CurrentBar = 552
Low[4] = 0.96 // CurrentBar = 551
then color CurrentBar's low in gold.
...
If
Low[0] = 0.69 // CurrentBar = 455
Low[1] = 0.94 // CurrentBar = 454
Low[2] = 0.92 // CurrentBar = 453
Low[3] = 0.83 // CurrentBar = 452
Low[4] = 0.96 // CurrentBar = 451
then color CurrentBar's low in gold.
...
If
Low[0] = 1.0 // CurrentBar = 355
Low[1] = 0.66 // CurrentBar = 354
Low[2] = 0.97 // CurrentBar = 353
Low[3] = 0.85 // CurrentBar = 352
Low[4] = 0.96 // CurrentBar = 351
then do not color CurrentBar's low.
I tested this but it seems not to be working.
Code:double lowprice = double.MaxValue; // set initally to highest double type value double lowbarsAgo = 0; for (int i = 1; i < 19; i++) { if (Low[i] < lowprice) // is low is less than previous low price { lowprice = Low[i]; // save new lower price lowbarsAgo = i; // save the bars ago value } } if( lowprice == Low[0] ) { BarBrush = Brushes.Gold; }
Last edited by PaulMohn; 01-04-2024, 12:21 PM.
Comment
-
Hello PaulMohn,
You would need to use a print to see why that is not working in your specific use case. To color a bar you can use BarBrush. One problem with the code you provided is that checking if two prices are equal will fail, that is not valid. you would need to check if the price is lesser equal or greater equal for it to be true, to check if a price is directly equal you would need to use math as described on the following page: https://ninjatrader.com/support/help...arithmetic.htmJesseNinjaTrader Customer Service
- Likes 1
Comment
-
Originally posted by NinjaTrader_Jesse View PostHello PaulMohn,
You would need to use a print to see why that is not working in your specific use case. To color a bar you can use BarBrush. One problem with the code you provided is that checking if two prices are equal will fail, that is not valid. you would need to check if the price is lesser equal or greater equal for it to be true, to check if a price is directly equal you would need to use math as described on the following page: https://ninjatrader.com/support/help...arithmetic.htm
I'll reformulate and simplify my query.
How would I use prints to color any bar/every bars which are preceded by 4 bars with higher lows?
The criteria is the bar must have four bars or more which lows are all higher than its low.
Color the '1' bars in screenshot below:
Last edited by PaulMohn; 01-05-2024, 12:17 AM.
Comment
-
Hello PaulMohn,
Prints are not use to color the chart, that is a way for you to output data to the output window. You would use prints to output the values you are trying to compare in your condition to check if the condition should or should not be true. Also as mentioned checking equality is not valid you need to see the tip page that I linked in the previous post whch explains both why that is not valid and how to check equality on double numbers.
JesseNinjaTrader Customer Service
Comment
-
How would I use prints to check how to color any bar/every bars which are preceded by 4 bars with higher lows?
What prints statement?
The criteria is the bar must have four bars or more which lows are all higher than its low.
Color the '1' bars in screenshot below:
Comment
-
Hello PaulMohn,
How you color bars would be based on the conditions you make in your code. To know if a bar should or should not be colored you would need to check if your condition is true or not. To know if the condition as true or not you would need to Print the values that condition is using.
You can read about using prints in the following link: https://ninjatrader.com/support/help.../nt8/print.htm
JesseNinjaTrader Customer Service
Comment
-
-
Hello PaulMohn,
No that would not be possible but you can use prints to identify how that code is working. Prints are an important part of your development process, that will let you explore code that may not be your own. If you want to find out how something is working or why it is not working using prints is the first step in that process.
Keep in mind the code you posted is not exactly what was originally posted so when you make modifications prints are going to be a very important tool for you to use. Please also refer to the help guide link that I had posted as that is relevant to the condition you made, checking if two numbers are equal will not work and the link I provided explains why and how to check that.
JesseNinjaTrader Customer Service
Comment
-
Why wouldn't @NinjaTrader_PaulH be able to respond?
Again, what prints statement?
The reference you provided isn't helpful, as is your comment, for finding what prints/values to check the logic for. At best it states equality of doubles isn't derived from straight equality, which is useless to find out what print statement would be of use to meet the requested criteria.
Comment
-
Hello PaulMohn,
You would need to make a custom print statement that outputs the values you are using in your condition. If you are unsure how to use print statements I would suggest to refer to the help guide for some samples of how to use prints.
A print statement would be useful for your use case to print out and see if both values were the same value. If they are and the condition is not true then the help guide link is exactly the solution, you would need to use math instead of == which will not work for that type of use case.
You can also contact a professional NinjaScript Consultant who would be eager to assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational/debugging services.
JesseNinjaTrader Customer Service
Comment
-
NinjaTrader_Brett isn't NinjaTrader_Jesse comment misleading and unhelpful for the case at hand?
Why would a technician not provide examples of prints they argue would help in a case other than to purposely mislead?
Comment
-
Example of non purposely misleading reply and good customer service effort from reputable technician would have been:
Code:bool b = true; for (int i = 1; i < 5; i++) { // In two lines for being clear, but it's possible just in one b = b && Low[i] > Low[0]; // You could speed it up this way. if(!b) break; } if (b) { //something to happen here ONCE! BarBrush = Brushes.Magenta; }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Shansen, 08-30-2019, 10:18 PM
|
24 responses
939 views
0 likes
|
Last Post
by spwizard
Today, 01:29 AM
|
||
Started by Max238, Today, 01:28 AM
|
0 responses
6 views
0 likes
|
Last Post
by Max238
Today, 01:28 AM
|
||
Started by rocketman7, Today, 01:00 AM
|
0 responses
4 views
0 likes
|
Last Post
by rocketman7
Today, 01:00 AM
|
||
Started by wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
28 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:43 PM
|
||
Started by wzgy0920, 02-22-2024, 01:11 AM
|
5 responses
33 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:33 PM
|
Comment