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 fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      160 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X