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

Passing a Period.Type into the Indicator for Additional Instrument

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

    Passing a Period.Type into the Indicator for Additional Instrument

    I know I can pass through a symbol for an additional instrument into an indicator by:

    declaring a string input variable
    eg. private string symbol = @"SPY"

    and then adding the new instrument in Initialize
    eg. Add(symbol, Period.Type.Day, 1)

    And that way I can manually change what additional instrument I add into the indicator every time I set my parameters for an indicator.

    But how do I change the Period.Type? It's not a string, so I can't just enter in another string parameter/variable.

    #2
    im sure there is a more convenient way but what u can do is to use(depending on how many periodtypes u acutally wanna have) either a bool or a list.

    if for example ur only interested in alternating between day and minute bars u could just use a bool that u would set in the parameters to true (for minute) and false for day. and then use a simple if(bool) then add period.minute and if(bool==false) add period.day statment or something like that. the actual value for the periodtype can then be inserted by a simple int parameter.

    for a list dropdown u would use something like this

    public enum PeriodTypes
    {
    Day,
    Minute,
    Range
    }
    and this for you parameters
    [NinjaTrader.Gui.Design.DisplayName("Periodypes"), GridCategory("Parameters")]
    public PeriodTypes PeriodTypes
    {
    get
    {
    return this.periodtypes;
    }
    set
    {
    this.periodtypes = value;
    }
    }
    and then again use simple if statements.

    if(PeriodTypes== PeriodTypes.Day)
    Add()
    make sure to use
    using System.Collections.Generic;
    declaration (first region) when using a list.
    Last edited by BigRo; 11-17-2015, 06:25 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    1 view
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    238 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    383 views
    1 like
    Last Post Gavini
    by Gavini
     
    Started by oviejo, Today, 12:28 AM
    0 responses
    1 view
    0 likes
    Last Post oviejo
    by oviejo
     
    Started by pechtri, 06-22-2023, 02:31 AM
    10 responses
    125 views
    0 likes
    Last Post Leeroy_Jenkins  
    Working...
    X