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
-
Unfortunately there's no sound on your last video and I couldn't figure out what you were trying to communicate - Sorry
-
Hello abctrader,
I've created another demonstration showing how MAX could be analyzed by looking at the debug output.
Demo - https://drive.google.com/file/d/1vIu...w?usp=drivesdk
Print: Print(string.Format("highestPrice: {0} index: {1} range: {2}", highestPrice, CurrentBar, li_LookBack));
As for your condition: if((Count - CurrentBar) > 2) return;
This will compare the number of bars available in the script to the number of bars it has processed and if it is greater than 2. This is essentially checking if you are processing historical data since Count will not increase until Realtime data is processed and new bars are built. I typically would not recommend this type of check involving Count and would suggest to use Bars.Count or BarsArray[0].Count so the reference is valid with Multi Time Frame NinjaScripts. Checking if (State == State.Historical) return; would be a close parallel to this condition.
Please let me know if we can be of further assistance.
Leave a comment:
-
Thanks for your response Jim
I've attached the complete file - If you attach it e.g to the current GC contract, you'll see that the output is not correct since it's calculating the wrong low and high values for the given period. You can see in the Ninjascript Output what values are calculated.
Then look for the following line:
// if((Count - CurrentBar) > 2) return;
un-comment it and you'll see now that the values are calculated correctly, however the plots are not processed any longer.
Thanks for your help - really no idea what I'm doing wrong
Last edited by abctrader; 11-08-2018, 04:48 PM.
Leave a comment:
-
Thanks for your post abctrader,
MIN will return the lowest price from a Series looking back a certain number of bars. MAX will return the highest price in a Series looking back a certain number of bars.
Demo - https://drive.google.com/file/d/1FVm...w?usp=drivesdk
When you test the same on your end, are you seeing something different? What values are you getting when you test the same and what are you expecting to get?
I look forward to being of any further assistance.
Leave a comment:
-
Highest / Lowest Price within a certain Range; MIN(), MAX() Issue
I'm trying to get the highest / lowest price for a certain range - so far so good, here's my code (an excerpt of it):
namespace NinjaTrader.NinjaScript.Indicators
{
// [TypeConverter("NinjaTrader.NinjaScript.Indicators. PivotsTypeConverter")]
public class HighLowRange: Indicator
{
private double sum, lowestPrice, highestPrice, fractal;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Plot High / Low of a certain range";
Name = "HighLowRange";
Calculate = Calculate.OnBarClose;
DisplayInDataBox = false;
DrawOnPricePanel = false;
IsAutoScale = false;
IsOverlay = true;
PaintPriceMarkers = true;
ScaleJustification = ScaleJustification.Right;
iLookBackPeriodBars = 64;
AddPlot(Brushes.Red, "H88");
AddPlot(Brushes.Green, "L08");
}
}
protected override void OnBarUpdate()
{
lowestPrice = MIN(Low, li_LookBack)[0];
highestPrice = MAX(High, li_LookBack)[0];
}
}
}
This gives completely false values.
I also tried it with determining of the index
lowestPrice = Low[LowestBar(Low, li_LookBack)];
highestPrice = High[HighestBar(High, li_LookBack)];
However this also is not retrieving the correct values
Only if I determine the values when processing just the last Bar and putting in the condition
if(Count - CurrentBar > 2)
before the calculation does it retrieve the correct value, however this messes up the plots and everything else that comes afterwards.
Please advice. Thank you
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by volIQ, Yesterday, 04:28 PM
|
2 responses
16 views
0 likes
|
Last Post
by volIQ
Today, 01:42 PM
|
||
Started by adeelshahzad, Today, 11:49 AM
|
5 responses
16 views
0 likes
|
Last Post Today, 01:27 PM | ||
Started by spottysallrite, Today, 11:31 AM
|
5 responses
13 views
0 likes
|
Last Post Today, 01:20 PM | ||
Started by yaniv, Today, 12:50 PM
|
1 response
2 views
0 likes
|
Last Post Today, 01:15 PM | ||
Started by Lele2k24, Yesterday, 11:24 AM
|
10 responses
33 views
0 likes
|
Last Post Today, 01:04 PM |
Leave a comment: