If you have any questions about how OnBarUpdate and the Calculate setting works I would suggest reading the following two links. When using OnEachTick the Close price is the last price in realtime.
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
Decrease the size of the RegionHIghLightY on each tick when the price touches it
Collapse
X
-
Hello cmtjoancolmenero,
If you have any questions about how OnBarUpdate and the Calculate setting works I would suggest reading the following two links. When using OnEachTick the Close price is the last price in realtime.
This is at 15:30 but imagine I open Ninja at 17:30 and start the indicator and the price is now 1380 but at 16:30 the price went until 1650, I'd like to be the region 1700 to 1650, you got me now?
JesseNinjaTrader Customer Service
-
Hello Jesse,
Nice didn't know about that, but then I can not use Close[0] as the lastTop or lastBottom because I need the tail of the candle not the Close[0], is there anything I can do with this?
if (BarsInProgress == 0) or if (BarsInProgress == 1).
Because my code now works, but as I'm assigning the Close[0] when joining the if, it's not correct.
Code is like this
if (CrossBelow(Close, topPrice, 1))
{
highPrice = Close[0]; <-- this is the problem, I need the lowest price or the highest both but not the close.
Draw.RegionHighlightY(this, "Example", true, highPrice, bottomPrice, Brushes.Blue, Brushes.DodgerBlue, 25);
}
if (CrossBelow(Close, bottomPrice, 1))
{
RemoveDrawObject("Example");
}
I have a condition to check if the price is going topToBottom or bottomToTop so if it's topToBottom the important thing should be the highest of a green candle, if it's topToBottom it should be the lowest of a red candleLast edited by cmtjoancolmenero; 05-01-2024, 03:43 PM.
Comment
-
Hello cmtjoancolmenero,
The tail of the candle is the Low price, if you are unsure which price you may need you can use the data box in the chart and hover the mouse over a bar to see its values.
Regarding BarsInProgress, you can read about that concept here: https://ninjatrader.com/support/help...BarsInProgress
JesseNinjaTrader Customer Service
Comment
-
Hello Jesse,
but looking to my code, it's normal that the price it's not getting the low and high, right? I've tried with Low and High and did not work, any idea?
Comment
-
Hello Jesse,
What I expect is this code
if (CrossBelow(Close, topPrice, 1))
{
highPrice = Close[0]; <-- this is the problem, I need the lowest price or the highest both but not the close.
Draw.RegionHighlightY(this, "Example", true, highPrice, bottomPrice, Brushes.Blue, Brushes.DodgerBlue, 25);
}
if (CrossBelow(Close, bottomPrice, 1))
{
RemoveDrawObject("Example");
}
to the price if the low/high crosses the rectangle and keep pushing still changing the height but is not decreassing at all I guess is just taking into account the Close[0] and I need to check the Low if the price comes from topToBottom and the high if price comes bottomToTop and not is doing this.
I don't know what's missing the code works but I'm missing something about the Close and CrossBelow.
Remember I'm using Calculate = Calculate.OnEachTick; and I need to know the price every tick so in theory with Low/High will work, right?
This is what happens
It should reduce the region to the candle heigh maxLast edited by cmtjoancolmenero; 05-02-2024, 12:17 PM.
Comment
-
Hello cmtjoancolmenero,
If you want to use the high or low price with the cross methods or where you are setting the variable you would just use the High or Low series in place of Close.
You can read about the available series here: https://ninjatrader.com/support/help...riceseries.htm
JesseNinjaTrader Customer Service
Comment
-
Hello Jesse,
Unfurnately, I've tried it, and still doing the same, it stops on Close but is not taking into account the MAX/LOW price on each tick, is really that hard to get that value?
if (CrossBelow(Low, topPrice, 1))
{
highPrice = Low[0];
Draw.RegionHighlightY(this, "Example", true, highPrice, bottomPrice, Brushes.Blue, Brushes.DodgerBlue, 25);
}
if (CrossBelow(Low, bottomPrice, 1))
{
RemoveDrawObject("Example");
}
This is an example of what I'm doing when the price crosses from top to bottom.
And is like this
As you can see, from where it started is doing good, because that's the top the prices crosses from bot to top and is making the region smaller, but the only thing is missing is that I can not get these tails from the candle, the region should have the bottom on the last bigger tail from the red candle.
Comment
-
Hello cmtjoancolmenero,
If your current logic is not working as you expected you may need to use Prints to see what values the script is seeing and how that logic is being executed.
Keep in mind that in realtime the High and Low represent the current bars high and low prices which only get reset when the close breaches either price. The High and Low are set based on the market which is the Last price or Close.
The Tails or Wick of the candle are set by the High and Low price. You can hover the mouse over the bar with the data box open to see those prices.JesseNinjaTrader Customer Service
Comment
-
Hello Jesse, yes, true I decided to instead of using RegionHorizontalY use a Rectangle, but the thing is I need to update it, the thing is when I was doing with the RegionHorizontalY it was easy because it had not start and end, now I'f like to draw a Rectangle instead and the start should be the same moment is drawn that is on the first bar close I'd say, then I have the top and bot and it should work as expected because i'm only changing the object, but the thing is that I do not only know if I have to resize from top/bot I need to draw the end of the rectangle to the price, means this :
The end of the rectangle should be aligned with the the last onBarClose() so everytime onBarClose() is called I should resize all of the rectangles I have on my chart, so what's missing now is :
How to get the position where I need to draw the rectangle? I have a condition that I draw it the first bar of the day, so the start point should be that one, and then I need to set the end of the rectangle to the current price.
How can I do it?
Comment
-
Hello cmtjoancolmenero,
To update a drawing object you would need to call the drawing object method again with new values. Using 0 bars ago for the endBarsAgo will keep the rectangles right side with the current bar. If you wanted to keep its left side in place you would need to store the CurrentBar from when you initially draw the object to a variable and use CurrentBar - yourVariable to get a number of bars ago since the stored bar number, that will let you maintain the left side bars ago.
JesseNinjaTrader Customer Service
Comment
-
Hello Jesse,
What I'm doing is working in terms of top and bottom resize, the problem is that the size of the rectangle (horizontal) is not as expected, what I want is to be aligned with the last candle (second image attached) and from now is like this :
What I'm doing is :
Draw.Rectangle(this, regionTag, 0, topPrice, CurrentBar, bottomPrice, Brushes.Red);
Then I store in my Dictionary the CurrentBar and I assign it to that regionTag
Once I'm updating it I try to di this way
Draw.Rectangle(this, tag, 0, topPrice, CurrentBar - startBars[tag], bottomPrice, Brushes.Red);
But is not going fully to the last candle of the chart, what I'm missing? The expected behaviour should be the second image, and what happens is the first image, is only getting 1 candle of horizontal size.
And I'm looking for something like this
A rectangle that the end position is the last candle.
Last edited by cmtjoancolmenero; 05-03-2024, 07:40 AM.
Comment
-
Hello cmtjoancolmenero,
You would need to use a Print to see what values are being used in your dictionary when you are calling the drawing method later to update its values, You also likely should switch the bars ago you used, the first bars ago is the start bar which should be your stored bar number, the second bars ago is the end bar which should be 0 bars ago.
Draw.Rectangle(this, tag, CurrentBar - startBars[tag], topPrice, 0, bottomPrice, Brushes.Red);
JesseNinjaTrader Customer Service
Comment
-
Hello Jesse,
Yes, now using this :
Draw.Rectangle(this, tag, 0, topPrice, CurrentBar - startBars[tag], bottomPrice, Brushes.Red);
It does work, the thing is kinda laggy because I'm doing a forloop to get all drawingObjects to get mines and then update on each onBarClose() and I don't know if it's ineficcient this or is there any other way it should do this logic, because I need to update the size of the rectangle onEachCloseBar so I have to loop through all the bars I've drawn and update the size, any idea on how to do it faster and efficient?
Comment
-
Hello cmtjoancolmenero,
A for loop will cause extra cpu use as you are iterating over X number of times for each update. If you use OnEachTick that could easily create a laggy script if the collection being used has quite a few items.
One way to avoid that would be to only update the objects on the first tick of the bar or once per bar. If you are only trying to extend the most recent object then a loop is not needed, you can just store the Tag name of the current days rectangle to a variable and use that when you want to update that specific object. Calling the drawing method with that tag will update it.
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by trader_by_day, Today, 09:25 PM
|
1 response
5 views
0 likes
|
Last Post Today, 09:31 PM | ||
Started by quicksandatl, 05-09-2024, 11:11 AM
|
3 responses
25 views
0 likes
|
Last Post
by quicksandatl
Today, 07:12 PM
|
||
Started by morrnel, 05-12-2024, 06:07 PM
|
6 responses
68 views
1 like
|
Last Post Today, 06:52 PM | ||
Started by algospoke, 05-13-2024, 06:53 PM
|
2 responses
21 views
0 likes
|
Last Post
by algospoke
Today, 06:49 PM
|
||
Started by janio973, Yesterday, 07:24 PM
|
6 responses
30 views
0 likes
|
Last Post Today, 06:01 PM |
Comment