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

Price discrepancy calculating SMA-5 on 1440 minute series

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

    Price discrepancy calculating SMA-5 on 1440 minute series

    Hello,

    I am new to NinjaScript and am developing an indicator that displays the 1440 minute 5-day SMA on all charts of an asset. In my code, I add a data series in State.Configure with BarsPeriodType = Minute and the period = 1440 minute bars. The problem is that the SMA-5 price displays differently when I display the indicator on the 1440 minute chart vs the 60min chart. Given that I am specifying in the code to use the 1440 minute series, I would expect the calculation to be the same on the 1440 min chart and the 60 min chart.

    Could someone provide insight into why this discrepancy exists and if possible, suggest a solution? Here is the code for where I add the series and calculate the 5-SMA:


    else if (State == State.Configure)
    {
    // Add a 1440 min series
    if (BarsArray.Length == 1)
    AddDataSeries(Data.BarsPeriodType.Minute, 1440);
    }

    else if (State == State.DataLoaded)
    {
    // Initialize SMA series
    smaValue = SMA(BarsArray[1], 5);
    }


    Edit:

    Here is the indicator on the 1440 min chart:

    Click image for larger version

Name:	image.png
Views:	46
Size:	4.4 KB
ID:	1282847


    Here is the indicator on the 60 min chart:

    Click image for larger version

Name:	image.png
Views:	42
Size:	7.1 KB
ID:	1282846



    Thank you in advance!
    Attached Files
    Last edited by tsliepen; 12-19-2023, 01:03 PM. Reason: Edited to include screenshots

    #2
    Hello tsliepen,

    The Calculation setting, TickReplay, the State, and when this is calling Draw.TextFixed() will be a factor here.

    I would recommend printing the BarsInProgress, date, State, and bar time, which will help clarify.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Karado58, 11-26-2012, 02:57 PM
    8 responses
    14,828 views
    0 likes
    Last Post Option Whisperer  
    Started by Option Whisperer, Today, 09:05 AM
    0 responses
    1 view
    0 likes
    Last Post Option Whisperer  
    Started by cre8able, Yesterday, 01:16 PM
    3 responses
    11 views
    0 likes
    Last Post cre8able  
    Started by Harry, 05-02-2018, 01:54 PM
    10 responses
    3,204 views
    0 likes
    Last Post tharton3  
    Started by ChartTourist, Today, 08:22 AM
    0 responses
    6 views
    0 likes
    Last Post ChartTourist  
    Working...
    X