Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom series price reference bars

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

    Custom series price reference bars

    Hello
    I am creating some custom series and I just want to make sure I am referencing the correct bar.

    As I understand, every series starts with bar 0, so in my code below am I right in thinking that, even if my calculation is on IsFirstTickOfBar, the first value of the HSwPrice series is [0], so with i = 1, the first value of the series would be [i - 1]?

    Also, am I synchronising correctly the HSwPrice series to the 5 minute series in DataLoaded?
    According to the help guide (SampleSyncSecondarySeries_NT8):
    " /* Syncs another DataSeries object to the secondary bar object.
    We use an arbitrary indicator overloaded with an ISeries<double> input to achieve the sync.
    The indicator can be any indicator. The Series<double> will be synced to whatever the
    BarsArray[] is provided.*/ "

    Thank you

    Code:
      secondarySeries = new Series<double>(SMA(BarsArray[1], 50)); // [URL="https://ninjatrader.com/support/helpGuides/nt8/samples/SampleSyncSecondarySeries_NT8.zip"]SampleSyncSecondarySeries_NT8[/URL] code
    Code:
    public class ATM2 : Strategy
     {    
        private Series<double>        HSwPrice;    // High price swing
    ......
    
    else if (State == State.Configure)                
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                    AddDataSeries(Data.BarsPeriodType.Minute, 5);                
                }
    
    else if (State == State.DataLoaded)
     {
         HSwPrice = new Series <double>(DMI(Closes[2], Convert.ToInt32(DmiPeriod)), MaximumBarsLookBack.TwoHundredFiftySix);
    .......
    
    if (IsFirstTickOfBar)
    {                        
        while (!DoneSearching)        
            {
    
     i = 1;
    
    if (Highs[2][i] < Highs[2][i+1] && Highs[2][i+1] > Highs[2][i+2])
        {
             HSwPrice[i - 1] = Highs[2][i + 1];  // Finding high price swings
             HSwPriceBar = CurrentBar - (i+1);
         }
    Last edited by itrader46; 11-28-2019, 09:57 AM.

    #2
    Hello itrader46,
    As I understand, every series starts with bar 0, so in my code below am I right in thinking that, even if my calculation is on IsFirstTickOfBar, the first value of the HSwPrice series is [0], so with i = 1, the first value of the series would be [i - 1]?
    The [0] at the end is a BarsAgo, this is a lookback from now in time. Each series does start with a bar 0 and processing does start on bar 0 however [0] represents zero BarsAgo or the Current bar.
    If you are currently processing bar 0 (CurrentBar 0) the [0] would represent CurrentBar 0. If we are now processing bar 5 (CurrentBar 5) the [0] represents bar 5, to access bar 0 from here you would need [5] or [CurrentBar].

    Also, am I synchronising correctly the HSwPrice series to the 5 minute series in DataLoaded?
    That appears to be similar to the sample yes.


    As a side note, OnBarUpdate is not shown in your sample so it looks like in this sample you are working with data in DataLoaded. If that is the case that is not suggested and you should instead work with data on bar 0 from OnBarUpdate or as the bars progress in OnBarUpdate. Properties like IsFirstTickOfBar specifically will not apply in DataLoaded, this is set during bar processing. If you are working In OnBarUpdate for the last part of the sample please ignore this comment.


    I look forward to being of further assistance.


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X