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

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.


    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rdtdale, Yesterday, 01:02 PM
    2 responses
    15 views
    0 likes
    Last Post rdtdale
    by rdtdale
     
    Started by TradeSaber, Today, 07:18 AM
    0 responses
    7 views
    0 likes
    Last Post TradeSaber  
    Started by PaulMohn, Today, 05:00 AM
    0 responses
    9 views
    0 likes
    Last Post PaulMohn  
    Started by ZenCortexAuCost, Today, 04:24 AM
    0 responses
    6 views
    0 likes
    Last Post ZenCortexAuCost  
    Started by ZenCortexAuCost, Today, 04:22 AM
    0 responses
    3 views
    0 likes
    Last Post ZenCortexAuCost  
    Working...
    X