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

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 Zeezee, Today, 12:45 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by tomasak, Today, 12:54 PM
      0 responses
      1 view
      0 likes
      Last Post tomasak
      by tomasak
       
      Started by swjake, Today, 12:04 PM
      2 responses
      9 views
      0 likes
      Last Post swjake
      by swjake
       
      Started by Richozzy38, Yesterday, 01:06 PM
      5 responses
      24 views
      0 likes
      Last Post Richozzy38  
      Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
      13 responses
      52 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X