Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to set AnchorY to the same value as previous draw arrow
Collapse
X
-
How to set AnchorY to the same value as previous draw arrow
my indicator is calculateOnEachTick, i have it so when conditions are met and the bar is still open draw a transparent object with a colored outline, then after the candle closes if the conditions are true after close it draws a solid colored object on top of it, the problem is that when the confirmation draw object is ploted its y anchor is set the the current bar, how can i attach the y anchor to the previous draw object
Tags: None
-
Hello Kylemcfar57x,
Thank you for your post.
I recommend creating a double variable for the Y value that is set when the condition is triggered and you are drawing the transparent object with the colored outline. Then, when you draw the solid object for the condition when the bar closes, you may use the variable's value for the Y in the draw method which will match the y anchor from the previous object. For example, all of the options for Draw.ArrowUp() include "double y" and the variable may be used in that place:
Please let us know if we may be of further assistance.
-
you will have to forgive me im a bit of a noob when it comes to this, this is what im using now
ArrowUp myArrowUp = Draw.ArrowUp(this, Convert.ToString(CurrentBars[0]), true, 1, (Low[0] - .5), new SolidColorBrush(Colors.Black));
myArrowUp.OutlineBrush = Brushes.Aqua;
so if i use this method i wont have to use anchorY?
Comment
-
Hello Kylemcfar57x,
Thank you for your response.
No worries! I would be glad to provide a code snippet for a more thorough explanation/example. Please see below where a private variable yAnchorPrice is created and how it would be used in your conditions:
I appreciate your patience. Please feel free to reach out with any additional questions or concerns.Code:public class ExampleIndicator: Indicator { private double yAnchorPrice; protected override void OnBarUpdate() { if (// condition for transparent object) { yAnchorPrice = Low[0] - .5; // draw transparent object } if (// candle closes and condition is still true) { ArrowUp myArrowUp = Draw.ArrowUp(this, Convert.ToString(CurrentBars[0]), true, 1, yAnchorPrice, new SolidColorBrush(Colors.Black)); myArrowUp.OutlineBrush = Brushes.Aqua; } } }
Comment
-
-
Everything is working, i put it in a try catch block so its not crashing anymore but i keep getting this error, i have unique names for each plot could it be because of the way anchory moves the draw object it only happens every so often, using market replay haven't run it on live yet, just curious if you had any idea of what was happening and if its ok to ignore
Active drawing object tag names must be unique per drawing tool type, the tag '5373' is already in use by another active drawing tool of a different type and will be ignored.
1/18/2023 7:34:00 PM System.NullReferenceException: Object reference not set to an instance of an object.
at NinjaTrader.NinjaScript.Indicators.ABindicatorButt onMergeV1.OnBarUpdate()
yAnchorPrice = Low[0] - .5;
ArrowUp bullishArrowUnconfirmed = Draw.ArrowUp(this, Convert.ToString(CurrentBars[0]), true, 0, yAnchorPrice, BullishArrowUnconfirmed);
bullishArrowUnconfirmed.OutlineBrush = BullishArrowUnconfirmedOutlineBrush;
yAnchorPrice = High[0] + .5;
ArrowDown bearishArrowUnconfirmed = Draw.ArrowDown(this, Convert.ToString(CurrentBars[0]), true, 0, yAnchorPrice, BearishArrowUnconfirmed);
bearishArrowUnconfirmed.OutlineBrush = BearishArrowUnconfirmedOutlineBrush;
yAnchorPriceBullish = High[0] + .5;
Diamond bearishDiamondUnconfirmed = Draw.Diamond(this, Convert.ToString(CurrentBars[0]), true, 0, yAnchorPriceBullish, BearishDiamondUnconfirmed);
bearishDiamondUnconfirmed .OutlineBrush = BearishDiamondUnconfirmedOutlineBrush;
yAnchorPriceBearish = Low[0] - .5;
Diamond bullishDiamondUnconfirmed = Draw.Diamond(this, Convert.ToString(CurrentBars[0]), true, 0, yAnchorPriceBearish, BullishDiamondUnconfirmed);
bullishDiamondUnconfirmed.OutlineBrush = BullishDiamondUnconfirmedOutlineBrush;
should i have a unique name for the arrows? i made one for the diamonds since they were in the same block
Comment
-
Hello Kylemcfar57x,
Thanks for your note.
Yes, you will need to use a unique tag for each drawing object type. For example, rather than using "Convert.ToString(CurrentBars[0])" as the tag for all of the mentioned objects, you could include a string based on the type plus the CurrentBar number such as the following in your first ArrowUp:
ArrowUp bullishArrowUnconfirmed = Draw.ArrowUp(this, "bullArrow" + Convert.ToString(CurrentBars[0]), true, 0, yAnchorPrice, BullishArrowUnconfirmed);
bullishArrowUnconfirmed.OutlineBrush = BullishArrowUnconfirmedOutlineBrush;
Then for the others, the tags could be something like:
"bearArrow" + Convert.ToString(CurrentBars[0])
"bearDiamond" + Convert.ToString(CurrentBars[0])
"bullDiamond" + Convert.ToString(CurrentBars[0])
By making these adjustments, you should be able to avoid the error message that you were receiving.
Please let us know if we may be of further assistance.
Comment
-
Comment
-
Hello Kylemcfar57x,
Thank you for your reply.
As long as the tag names are unique, that will be okay. The number it is appending to the tag is the CurrentBars[0] index. This value is the number for the current bar in a series. If any of your drawing objects share the same number, it simply means that they were both drawn on the same bar. For more information about CurrentBars:
Please let us know if we may be of further assistance.
Comment
-
so should i just ignore the error as long as i use a try catch bolck and execute the rest with a finally it doesn't crash and still runs like it should
Comment
-
Hello Kylemcfar57x,
Thank you for your reply.
I did not realize you were still receiving errors. If you are receiving a message that "Active drawing object tag names must be unique per drawing tool type" this means that there are still two different drawing tools that are trying to share the same tag name. Please be sure to right-click and select Reload NinjaScript on any charts that are currently using your indicator to make sure the changes to the script are picked up. If you are still getting the error, you could Ctrl + F in your script for "CurrentBars" and review all parts of your script to make sure anywhere that is used in a tag, the tag is unique to that specific drawing object.
I appreciate your patience. Please feel free to reach out with any additional questions or concerns.
Comment
-
lol my bad and i should be thanking you for your patience, dumb mistake on my part I have several versions of the script im working on i had a chart in the background using the old one that was still tossing the errors
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
63 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
139 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment