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!
See more
See less

Partner 728x90

Collapse

Highest / Lowest Price within a certain Range; MIN(), MAX() Issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • abctrader
    replied
    Unfortunately there's no sound on your last video and I couldn't figure out what you were trying to communicate - Sorry

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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:


  • abctrader
    replied
    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:


  • NinjaTrader_Jim
    replied
    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




Latest Posts

Collapse

Topics Statistics Last Post
Started by rhyminkevin, Today, 04:58 PM
3 responses
48 views
0 likes
Last Post Anfedport  
Started by iceman2018, Today, 05:07 PM
0 responses
5 views
0 likes
Last Post iceman2018  
Started by lightsun47, Today, 03:51 PM
0 responses
7 views
0 likes
Last Post lightsun47  
Started by 00nevest, Today, 02:27 PM
1 response
14 views
0 likes
Last Post 00nevest  
Started by futtrader, 04-21-2024, 01:50 AM
4 responses
50 views
0 likes
Last Post futtrader  
Working...
X