Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Modding Existing Indicator?
Collapse
X
-
Tags: None
-
Hello Bob-Habanai,
Thanks for your post.
Yes, you could use custom logic to calculate the range of ticks between the open price and close price of a bar, save that value to a variable, and use that variable when calling the Draw.Text() method to draw the value on the chart.
See this help guide page for more information about accessing the PriceSeries (Open and Close prices): https://ninjatrader.com/support/help...riceseries.htm
See this help guide page for more information about using the Draw.Text() method: https://ninjatrader.com/support/help.../draw_text.htm
Let me know if I may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Thank you for your reply Brandon.
I went to:
and
But I'm still unsure of what the string should look like, thank you for trying though.
Originally posted by NinjaTrader_BrandonH View PostHello Bob-Habanai,
Thanks for your post.
Yes, you could use custom logic to calculate the range of ticks between the open price and close price of a bar, save that value to a variable, and use that variable when calling the Draw.Text() method to draw the value on the chart.
See this help guide page for more information about accessing the PriceSeries (Open and Close prices): https://ninjatrader.com/support/help...riceseries.htm
See this help guide page for more information about using the Draw.Text() method: https://ninjatrader.com/support/help.../draw_text.htm
Let me know if I may assist further.
Comment
-
Hello Bob-Habanai,
Thanks for your note.
An example of finding the difference between the Open price and Close price and drawing that value as text on a chart could be seen below. Note that this is an example demonstrating a programming concept and is not a copy/paste solution.
Create a variable called something like MyDifference and assign the Open price - Close price to that variable. Then, call your Draw.Text() method and use that variable for the 'string text' property.
Draw.Text(NinjaScriptBase owner, string tag, string text, int barsAgo, double y, Brush textBrush)
Example code:
//class level variable
private double MyDifference;
//OnBarUpdate()
protected override void OnBarUpdate()
{
MyDifference = Open[0] - Close[0];
Draw.Text(this, "difference", MyDifference.ToString(), 0, High[0] + 10 * TickSize, Brushes.Pink);
}
Let me know if I may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Hi Brandon,
Because of your recent replies, I was able to do this one successfully and add several extra features,
but it's displaying the range in points, not ticks. i.e. instead of 1, it'll draw 0.25.
Any idea why that is?
Thanks again.
Originally posted by NinjaTrader_BrandonH View PostHello Bob-Habanai,
Thanks for your note.
An example of finding the difference between the Open price and Close price and drawing that value as text on a chart could be seen below. Note that this is an example demonstrating a programming concept and is not a copy/paste solution.
Create a variable called something like MyDifference and assign the Open price - Close price to that variable. Then, call your Draw.Text() method and use that variable for the 'string text' property.
Draw.Text(NinjaScriptBase owner, string tag, string text, int barsAgo, double y, Brush textBrush)
Example code:
//class level variable
private double MyDifference;
//OnBarUpdate()
protected override void OnBarUpdate()
{
MyDifference = Open[0] - Close[0];
Draw.Text(this, "difference", MyDifference.ToString(), 0, High[0] + 10 * TickSize, Brushes.Pink);
}
Let me know if I may assist further.
Comment
-
Without knowing Ninjascript properly, I found a quick workaround by going:
MyDifference = Close[0] - Open[0] + Close[0] - Open[0] +Close[0] - Open[0] +Close[0] - Open[0];
Then I did MyDifference = (Close[0] * 4) - (Open[0] * 4); which is much better.
But how do you write if (Close[0] = Open[0]) ?
i.e. a Doji candle? I tried and it wouldn't compile.
Ok, I did more research and found you have to write = twice.
Problem solved!Last edited by Bob-Habanai; 08-25-2022, 04:28 AM.
Comment
-
Hi Bob-Habanai,
Just a quick answer to your question about obtaining ticks rather than points. There's a property provided by Ninja Trader called TickSize. It represent the price value of 1 tick for the primary data series. That is...
For the MES, the tick is 0.25 points, so the TickSize is 0.25. This allows you to quickly get ticks from a difference in prices. For example,
Range Ticks = (High - Low) / TickSize
Range Ticks = (4148.75 - 4145.50) / 0.25 = 3.25 / 0.25 = 13 ticks
Hope that helps!
Matt
Comment
-
Thanks for the reply, Stealth.
Ninja keeps saying the name 'ticksize' does not exist in the current context.
Any idea why?
Much appreciated!
Originally posted by StealthM93 View PostHi Bob-Habanai,
Just a quick answer to your question about obtaining ticks rather than points. There's a property provided by Ninja Trader called TickSize. It represent the price value of 1 tick for the primary data series. That is...
For the MES, the tick is 0.25 points, so the TickSize is 0.25. This allows you to quickly get ticks from a difference in prices. For example,
Range Ticks = (High - Low) / TickSize
Range Ticks = (4148.75 - 4145.50) / 0.25 = 3.25 / 0.25 = 13 ticks
Hope that helps!
Matt
Comment
-
Hello Bob-Habanai,
Thanks for your note.
So that I may accurately assist, how is TickSize being used in the script?
Are you using TickSize within the OnBarUpdate() method of your script?
See this help guide page for information about TickSize and sample code: https://ninjatrader.com/support/help...8/ticksize.htm
I look forward to assisting further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
- Likes 1
Comment
-
Hi Brandon,
Here is the exact code.
If I try to changeCode:{ public class DrawDistance : Indicator { //class level variable private double MyDifferenceGreen; private double MyDifferenceRed; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "DrawDistance"; Calculate = Calculate.OnEachTick; 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) { } } protected override void OnBarUpdate() { //assign MyDifference MyDifferenceGreen = (Close[0] * 4) - (Open[0] * 4); MyDifferenceRed = (Open[0] * 4) - (Close[0] * 4); //green ticks if (Close[0] > Open[0]) Draw.Text(this, "does this matter" + CurrentBar, MyDifferenceGreen.ToString(), 0, Low[0] - 30 * TickSize, Brushes.ForestGreen); //red ticks if (Open[0] >= Close[0]) Draw.Text(this, "does this really matter" + CurrentBar, MyDifferenceRed.ToString(), 0, High[0] + 30 * TickSize, Brushes.Red); } } }
toCode:MyDifferenceGreen = (Close[0] * 4) - (Open[0] * 4); MyDifferenceRed = (Open[0] * 4) - (Close[0] * 4);
I get that error. I also get that error if I remove the MyDifferenceGreen & MyDifferenceRed,Code:MyDifferenceGreen = (Close[0] * Ticksize) - (Open[0] * Ticksize); MyDifferenceRed = (Open[0] * Ticksize) - (Close[0] * Ticksize);
and put it (Close[0] * ticksize) - (Open[0] * ticksize) into
Draw.Text(this, "does this really matter" + CurrentBar, (Open[0] * ticksize) - (Close[0] * ticksize).ToString(), 0, High[0] + 30 * TickSize, Brushes.Red);
Thanks for your help.
Comment
-
There's another issue Brandon that if the indicator is set to calculate on bar close it works fine,
but if it's set to calculate on tick, if the bar retraces, it will draw (for example) above the bar as a seller bar,
then if the bar reverses, instead of cancelling the drawing and only drawing the buyer distance,
it will keep the former on the screen.
Any idea why that is or how to stop that occurring?
Here's a picture of what I mean.
The red arrows are pointing at text that should've been cancelled when the conditions changed.
Thanks again!
Comment
-
Hi Bob-Habanai,
Allow me to assist...- Since you're checking for Close > Open in the if statements, you only need a single value for the difference: double MyDifferentTicks = Math.Abs(Close[0] - Open[0]) * TickSize;
- Also, I believe you want division by TickSize, not multiplication to get the number of ticks. (Corrected below)
- For TickSize, you must use "TickSize" and not "Ticksize" - variables are case sensitive; otherwise, you'll get the error you're seeing.
- The reason you're getting two labels on a bar is because you have two different text strings for each Draw statement. Use the same string when concatenating CurrentBar.
Here's an update on your code that might help.
Hope that helps! I'm sure Brandon will provide more insight.Code:protected override void OnBarUpdate() { //assign MyDifference int MyDifferenceTicks = (int)((Close[0] - Open[0]) / TickSize); //green ticks if (Close[0] > Open[0]) Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen); //red ticks if (Open[0] >= Close[0]) Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, High[0] + 30 * TickSize, Brushes.Red); }
Kind regards,
Matt
Comment
-
Thanks for those helpful tips Stealth.
Do you have any idea how to get rid of the DimGray outline around the text and make it transparent? in the code below?
Code:Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen);
Originally posted by StealthM93 View PostHi Bob-Habanai,
Allow me to assist...- Since you're checking for Close > Open in the if statements, you only need a single value for the difference: double MyDifferentTicks = Math.Abs(Close[0] - Open[0]) * TickSize;
- Also, I believe you want division by TickSize, not multiplication to get the number of ticks. (Corrected below)
- For TickSize, you must use "TickSize" and not "Ticksize" - variables are case sensitive; otherwise, you'll get the error you're seeing.
- The reason you're getting two labels on a bar is because you have two different text strings for each Draw statement. Use the same string when concatenating CurrentBar.
Here's an update on your code that might help.
Hope that helps! I'm sure Brandon will provide more insight.Code:protected override void OnBarUpdate() { //assign MyDifference int MyDifferenceTicks = (int)((Close[0] - Open[0]) / TickSize); //green ticks if (Close[0] > Open[0]) Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen); //red ticks if (Open[0] >= Close[0]) Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, High[0] + 30 * TickSize, Brushes.Red); }
Kind regards,
Matt
Comment
-
Hi Bob-Habanai,
See here for the different Draw.Text() method specifications.
For my scenarios, similar to yours, I'm using:
Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity);
As you can see, there are parameters that set the outline and area brushes and opacity.
Here's a sample from the strategy I'm currently developing.
Draw.Text(this, newChartMarker, true, pChartSymbol + pTradeCode, 0, pPrice, 0, pColor, ChartMarkerFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
Where newChartMarker, pChartSymbol, pTradeCode, pPrice, pColor, and ChartMarkerFont are variables defined elsewhere.
Kind regards,
Matt
Comment
-
Hi Matt,
Does this mean we must put in values for the in-betweens and there's no way to just skip them like:
Code:Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen),,,,,Brushes.Transparent);
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
661 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
375 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment