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

Question regarding second data series

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

    Question regarding second data series

    Hi,
    I have a default data series (YM 144Tick) and a secondary data series (YM 1597 tick), and I want to find the average range of the 1597 tick series.

    I add the secondary data series as follows:

    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Tick, 1597);
    }

    and want to calculate the Range of the 1597 series as follows (this is just dummy code for testing):

    private void CalculateRange()
    {
    var range = 0.0;
    var count = 0;
    var maxNum = Math.Min(Highs[1].Count, 144);
    for (var i = 1; i < maxNum; i++)
    {
    if (!Highs[1].IsValidDataPoint(i))
    break;
    var high = Highs[1][i];
    var low = Lows[1][i];
    range += Math.Abs(high - low);
    count += 1;
    }

    var averageRange = range / count;
    Code.Output.Process("Range: " + averageRange, PrintTo.OutputTab2);
    }

    As seen in the picture, the Highs[1].Count gives me 452 bars, while I can only iterate through 14 of them before I receive an exception.
    The additional test of Highs[1].IsValidDataPoint() never returns false.


    Could you please tell me where the issue lies?

    Best regards,
    T

    #2
    Update:

    Problem is fixed by using
    if (CurrentBars[1] < 144)
    return;

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    938 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    3 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    1 view
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    27 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Working...
    X