How do I calculate the barsAgo from 1 series to another? Compare timestamps on the bars Could be a heavy processing cost....
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
Drawing a rectangle from another series bar type.
Collapse
X
-
Drawing a rectangle from another series bar type.
So as long as my BarsArray[0] is the same as my BarsArray[1], the rectangle plots correctly but that defeats the purpose of the multiple timeframes. I want to be able to change my DataSeries Type to tick, etc. and be able to plot the rectangle based upon the 1 min BarsArray[1] series.
How do I calculate the barsAgo from 1 series to another? Compare timestamps on the bars Could be a heavy processing cost....Tags: None
-
Hello jalley,
Thanks for your post.
I would suggest using the Draw.Rectangle method overload where you specify the DateTime rather than the bars ago. That is how global draw objects are able to draw from one chart to another regardless of the bar-type/size, by using the price data and the date/time of the anchor points.
Reference: https://ninjatrader.com/support/help..._rectangle.htmPaul H.NinjaTrader Customer Service
-
Hello jalley,
Thanks for your reply.
That does not sound right.
Here is an example you can copy and test with:
public class DrawrectanglebyTime : Indicator
{
private bool doitonce = true;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "DrawrectanglebyTime";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 1);
}
}
protected override void OnBarUpdate()
{
if (State != State.Realtime) // wait for first real time bar close
return;
if (BarsInProgress != 0) return; // draw on the chart bars
// draw a 3 minute long rectangle, once.
if (doitonce)
{
Draw.Rectangle(this, "Test", Times[1][3], Lows[1][3], Times[1][0], Highs[1][0], Brushes.Gold);
doitonce = false;
}
}
With the code above I can draw a rectangle on any non-time based bars, such as tick, volume, range. See the screenshot below. I opened the rectangle property so you can see it is a 3 minute rectangle and if you look at where it starts and stops it does not line up with the center of the bar like it normally would when drawn using those chart bars.
Paul H.NinjaTrader Customer Service
- Likes 1
Comment
-
So it is working great when the data series is not using tick replay. Only change that causes it to break but not display any errors (just doesn't show the rectangle) is to click tick replay on the dataseries. The code line:
Draw.Rectangle(this, "IBRect" + DayofYear.ToString(), true, Times[1][x], DayIBLowPrice, Times[1][y], DayIBHighPrice, Brushes.Gray, Brushes.Gray, 30);
What could be causing it not to paint this rectangle when tick replay is checked? The lines and text I plot are working fine with or without tick replay.
Comment
-
Hello jalley,
Thanks for your reply.
I would suggest debugging the code to find out why.
You can add print statements to print out the conditions that would tell the draw statement to draw and then print statements to print out the values used by the draw statement to see if they align with your expectations.
Please see the help guide debugging tips here: https://ninjatrader.com/support/help...script_cod.htm
Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by adeelshahzad, Today, 03:54 AM
|
4 responses
22 views
0 likes
|
Last Post
by adeelshahzad
Today, 10:51 AM
|
||
Started by merzo, 06-25-2023, 02:19 AM
|
10 responses
823 views
1 like
|
Last Post Today, 10:38 AM | ||
Started by frankthearm, Today, 09:08 AM
|
5 responses
15 views
0 likes
|
Last Post Today, 10:19 AM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
43 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
||
Started by yertle, Today, 08:38 AM
|
5 responses
16 views
0 likes
|
Last Post Today, 09:45 AM |
Comment