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
Highest / Lowest Price within a certain Range; MIN(), MAX() Issue
Collapse
X
-
Hello elliot5,
I would suggest adding a 60 minute data series, and then in BarsInProgress 1 (or the BarsInProgress associated with your 60 minute data series) to check Bars.IsFirstBarOfSession. You can then save the High[0] and Low[0] to variables and use them throughout your script.
Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm
We look forward to assisting.
-
Using 1 minute time series need the first hour of session high/low... ideas anyone?
Leave a comment:
-
Hello asmmbillah,
ChartBars.ToIndex is the index of the last bar that is visible on the chart. As it is relative to what is visible, I would not suggest using it to see what is the highest/lowest price of the session. I would instead suggest using it in OnBarUpdate which would be based on incoming data.
You can save the CurrentBar index to a private variable on Bars.IsFirstBarOfSession, and then loop from that saved index to CurrentBar. Within the loop, you can use Math.Min and Math.Max like you are to track the highest high and lowest low.
We look forward to assisting.
Leave a comment:
-
Hi,
I am using
double highPrice = 0;
double lowPrice = double.MaxValue;
int lastBar = ChartBars.ToIndex;
int firstBar = firstBarIdxToPaint; // this is the first bar of the session.
for (int idx = firstBar; idx <= lastBar && idx >= firstBar; idx++)
{
highPrice = Math.Max(highPrice, Bars.GetHigh(idx));
lowPrice = Math.Min(lowPrice, Bars.GetLow(idx));
}
but when I am printing the highPrice and lowPrice, it is printing some wrong prices. Any idea why that might happen? I am just trying to print the highest and lowest price for the session.
Leave a comment:
-
Hello JMont1,
When calling Draw.HorizontalLine(), you can specify a the same drawing tag to update the drawing object to a new location so another drawing object is not created. For example:
Code:bool firstbar = true; protected override void OnBarUpdate() { if(State == State.Historical) return; if (firstbar) { Draw.HorizontalLine(this, "MyTag", Close[0], Brushes.Red); firstbar = false; } else Draw.HorizontalLine(this, "MyTag", High[0], Brushes.Green); }
Drawing (Important notes at the bottom of the page - https://ninjatrader.com/support/help...us/drawing.htm
Draw.HoriozontalLine() - https://ninjatrader.com/support/help...zontalline.htm
Let us know if you have any additional questions.
Leave a comment:
-
Releasing drawn lines prior to writing new ones. Is there a recommended method to release drawn lines for Min Max when using Draw Horizontal Line before drawing new ones so they do not build up in the history?
Leave a comment:
-
Hello abctrader,
The levels where the lines are drawn are going to be based entirely off of what is sent to the RenderTarget.DrawLine() methods. The coordinates should be back traced to where they are assigned using ChartControl.GetXByBarIndex and ChartScale.GetYByValue.
The sample code linked in my previous message (I did not include the full link and updated my post. Link here) demonstrates setting your own plot values and drawing your own lines in OnRender(). I would recommend setting up this test code in a new script and then modify the plots so you can verify that you are able to create your own custom plots and draw them appropriately.
Once you can confirm that you are getting the results you expect, I would then recommend testing the same with your indicator. After you are able to draw custom plots appropriately in these two steps, it should not be difficult to correct the existing lines so they behave the same.
Let us know if there is anything else we can do to help.
Leave a comment:
-
Hi Jim
Thanx for your time and help. I figured the issue must be within the OnRender logic ...
I'm now using the exact same code like the one used within the standard Pivot indicator, since I basically want it to behave the same way. HOWEVER, it is still displaying incorrect values and not adjusting them properly once the calculated values change. It's still displaying the wrong lines, even though the data in the DataBox is different. Any help would be appreciated. Thanks
Leave a comment:
-
Hello abctrader,
This script is using SharpDX for custom rendering, correct? The plots in the data box and the chart should be correct for the plot values, but the drawing of the lines does not look the same.
We have some example SharpDX code that loops through all plots that are added and customizing the rendering similar to what you are trying to accomplish. I would recommend testing with that code and if you need to debug it, you could look into printing what plotValue is being used in the loop for each plot that you want to look into.
For example:
Code:protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // get the starting and ending bars from what is rendered on the chart float startX = chartControl.GetXByBarIndex(ChartBars, ChartBars.FromIndex); float endX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex); // Loop through each Plot Values on the chart for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++) { // get the value at the last bar on the chart (if it has been set) if (Values[seriesCount].IsValidDataPointAt(ChartBars.ToIndex)) { double plotValue = Values[seriesCount].GetValueAt(ChartBars.ToIndex); [B] if(seriesCount == 1)Print(plotValue);[/B] ...
Please let us know if there is anything else we can do to help.Last edited by NinjaTrader_Jim; 11-15-2018, 09:05 AM.
Leave a comment:
-
One more issue I'm facing is the chart not displaying the lines like they are calculated by the script.
I've attached 2 pictures: the 6B chart with the (incorrect) lines and the DataBox which has the correct values for the lines.
I've tried to refresh the chart, reload the NinjaScript (F5), however the lines aren't updating to the correct values, even though the values on the right-hand axis are correct!!!
Thanks for your help
2 Photos
Leave a comment:
-
Hello abctrader
I am interested in your code as well, if it is possible to share it.
Thanks
Leave a comment:
-
Ok thx 4 everything - looks like I've got it all figured out - Have a great weekend
Leave a comment:
-
Hello abctrader,
You could use FormatPriceMarker to reformat the appearance of values in the Price Marker.
FormatPriceMarker - https://ninjatrader.com/support/help...ricemarker.htm
More information on formatting strings in C# can be found here - https://docs.microsoft.com/en-us/dot...format-strings
Let us know if there is anything else we can do to help.
Leave a comment:
-
Ok - Thx much; seem to have the MIN() MAX() solved; If I could get the Price to now also print with the full decimal places I'd be happy ...
E.g. in Euro the price marker for the lines printed shows as 1.14, when in fact I'd like to see it as 1.13720 ... not sure what I need to do there. Any clue? Thx again
Leave a comment:
-
Hello abctrader,
In the video I am printing the CurrentBar when MAX is called, and then I am looking for that Bar Index on the Chart when I have the Data Box open.
From there, I check the highest value of that bar and I go check 3 more bars back since I am testing with a period of 4. The High of that bar (Bar Index 4131) was 1228 and the high of the 3 bars prior were 1227.9. Since, I was testing with a period of 4 for MAX, and 1228 is greater than the 1227.9 value from the previous bars, 1228 was the MAX.
Please let me know if you have any questions.
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by frankthearm, Today, 09:08 AM
|
10 responses
35 views
0 likes
|
Last Post
by frankthearm
Today, 02:54 PM
|
||
Started by GwFutures1988, Today, 02:48 PM
|
0 responses
2 views
0 likes
|
Last Post Today, 02:48 PM | ||
Started by mmenigma, Today, 02:22 PM
|
1 response
3 views
0 likes
|
Last Post Today, 02:34 PM | ||
Started by NRITV, Today, 01:15 PM
|
2 responses
9 views
0 likes
|
Last Post
by NRITV
Today, 01:51 PM
|
||
Started by maybeimnotrader, Yesterday, 05:46 PM
|
5 responses
28 views
0 likes
|
Last Post Today, 01:19 PM |
Leave a comment: