Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code using different PrimaryDataSeries

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

    Code using different PrimaryDataSeries

    Hi.
    A coding question for NT7. I have a 5Min chart which I sometimes switch to 15Min and back. Depending on which of the two timeframes is in use I want a certain EMA to show. Let's say when I am using the 5min chart I want to see an EMA40, when I switch it to 15Min I do not want to see the EMA40 but an EMA80. Is there a way to put this into the code? Perhaps something like this:

    protected override void OnBarUpdate()

    if (PrimaryDataSeries=5min)
    {
    show EMA 40
    remove EMA80
    ​}

    else ​if (PrimaryDataSeries=15min)
    {
    show EMA 80
    remove EMA40
    ​}

    My question is how to express the parts in bold in correct coding language.

    sandman


    #2
    Hello sandman,

    Yes, this is possible.

    The BarsPeriod holds information about the bars object.


    For example
    if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value == 5)
    {
    Value.Set( EMA(40)[0] );
    }

    else if (BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value == 15)
    {
    Value.Set( EMA(80)[0] );
    }

    You could choose to have two plots and set the Values instead, but I think if only one plot line is going to show, you could just use the one plot.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea. Exactly what I was looking for
      Thank you - and have a great day. sandman

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      128 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      73 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      116 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      109 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      88 views
      0 likes
      Last Post CarlTrading  
      Working...
      X