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

Closes[0][0] and Closes[1][0] returns the same value

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

    Closes[0][0] and Closes[1][0] returns the same value

    Hi,
    Futures Daily Chart "ES".
    I want to show the Price 30 minutes before real candle close.

    So I've created a new trading hour and set each day end time to 15:30 (instead of 16:00), called this custom trading hour as "US Equities RTH - NIMA".

    I've added a data series using new trading hour:
    Code:
    AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, "US Equities RTH - NIMA");
    Now I've tried to show close price at 15:30 on the chart as bellow but all Closes[1][0] are showing the same value of Close[0]:

    Code:
    protected override void OnBarUpdate()
    {[INDENT]if (BarsInProgress == 1)[/INDENT][INDENT=2]return;[/INDENT][INDENT]
    if (CurrentBar < ATR_Length)[/INDENT][INDENT=2]return;[/INDENT][INDENT]
    
    DrawPlus.Diamondp(this, "Close - " + CurrentBar, false, 0, Closes[1][0], Brushes.Violet, true, 0.8f, Brushes.Violet); 
    
    
    DrawPlus.Dotp(this, "ATR_H - " + CurrentBar, false, -1, Close[0] + _ATR[0], Brushes.Red, true, 0.7f, Brushes.Black);
    DrawPlus.Dotp(this, "ATR_L - " + CurrentBar, false, -1, Close[0] - _ATR[0], Brushes.Red, true, 0.7f, Brushes.Black);
    
    DrawPlus.Dotp(this, "STD_H - " + CurrentBar, false, -1, Close[0] + _StdDev[0], Brushes.Green, true, 0.7f, Brushes.Black);
    DrawPlus.Dotp(this, "STD_L - " + CurrentBar, false, -1, Close[0] - _StdDev[0], Brushes.Green, true, 0.7f, Brushes.Black);[/INDENT]
     
    }
    Can you please advise what I'm missing ?
    Thanks.

    #2
    Hello njafarynia,

    First, drawing objects are only attached to the primary chart bars, BarsInProgress 0. So you must use prices and times from the primary series and draw during BarsInProgress 0 if you plan on using draw methods.

    Second, print the values if you are uncertain what these are. What does Print(Times[1][0]); print? Is this the bar you expect?
    https://ninjatrader.com/support/foru...121#post791121

    Further, a negative value for bars ago (or for any indexes) is not supported. Meaning this could cause undesired behavior as we don't support doing this.

    Last, if you want the end of the session time use a sessionIterator with the BarsArray[1] object.
    https://ninjatrader.com/support/help...oniterator.htm

    Below is a link to an example that uses a sessionIterator to get the end time of the session and subtract seconds from the session end time. You could subtract 30 minutes instead.
    https://ninjatrader.com/support/foru...ose#post100666
    Last edited by NinjaTrader_ChelseaB; 08-30-2022, 03:54 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Dear Chelsea,
      Thanks for your reply, actually I'm trying to have some information on chart for studding a strategy that I'm working on.

      Point 1 , Noted.
      I've modified the code as attached.

      Point 2 , print is giving the correct time but not the correct value !
      For instance MES Yesterday 29th Aug. at 15:30 is printing :
      29/08/2022 20:30:00 --> 4031,25 (I'm in Italy so you will see 20:30)
      While the correct value should be 4030,25

      Actually negative for bars ago function well and is not creating any problem, my only problem is with the value of Closes[1][0] which I should see to be different than Closes[0][0] but unfortunately they are the same.

      I've seen the provided example but it is not what I'm looking for, I need the value at 30 minutes before close.

      My primary chart is Daily, also other data series are dailies so I need to have the indication of:
      1- Where Price was 30 minutes before close. -- 1st AddDataSeries
      2- Price of Close (It is chart bar close) -- Primary Chart
      3- Price of extended hours closed. --- 2nd AddDataSeries
      PS) please note that in Italy the US Futures Market cash will close @ 10:00PM and extended hour @ 11:00PM
      Can you help me whit this.
      Thanks
      Attached Files

      Comment


        #4
        Hello njafarynia,

        print is giving the correct time but not the correct value
        Please provide the output text file. The output should have labels so we know what each value is and how it is being compared.


        I've seen the provided example but it is not what I'm looking for, I need the value at 30 minutes before close.
        Can you clarify how this example is not exactly what you need? To get the time 30 minutes before the close of a session, get the close of the session and add negative 30 minutes..

        The example demonstrates getting the close of a session and subtracting seconds. Subtract minutes instead..


        Actually negative for bars ago function well and is not creating any problem, my only problem is with the value of Closes[1][0] which I should see to be different than Closes[0][0] but unfortunately they are the same.
        Please provide output that shows this.
        Code:
        if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
        return;
        
        Print(string.Format("\r\nTimes[{0}][0]: {1} | Closes[{0}][0]: {2}, {3}, BarsInProgress: {0}, " +
        "BarsArray[{0}].BarsPeriod.BarsPeriodType: {4}, BarsArray[{0}].BarsPeriod.Value: {5}\r\n" +
        "Times[0][0]: {6}, Closes[0][0]: {7}, {8}, BarsArray[0].BarsPeriod.BarsPeriodType: {9}, BarsArray[0].BarsPeriod.Value: {10}\r\n",
        BarsInProgress, Times[BarsInProgress][0], Closes[BarsInProgress][0], BarsArray[BarsInProgress].Instrument.FullName,
        BarsArray[BarsInProgress].BarsPeriod.BarsPeriodType, BarsArray[BarsInProgress].BarsPeriod.Value,
        Times[0][0], Closes[0][0], BarsArray[0].Instrument.FullName, BarsArray[0].BarsPeriod.BarsPeriodType, BarsArray[0].BarsPeriod.Value));
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ageeholdings, Today, 07:43 AM
        0 responses
        6 views
        0 likes
        Last Post ageeholdings  
        Started by pibrew, Today, 06:37 AM
        0 responses
        4 views
        0 likes
        Last Post pibrew
        by pibrew
         
        Started by rbeckmann05, Yesterday, 06:48 PM
        1 response
        14 views
        0 likes
        Last Post bltdavid  
        Started by llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        12 views
        0 likes
        Last Post burtoninlondon  
        Working...
        X