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 JonesJoker, 04-22-2024, 12:23 PM
    8 responses
    41 views
    0 likes
    Last Post JonesJoker  
    Started by timko, Today, 06:45 AM
    0 responses
    3 views
    0 likes
    Last Post timko
    by timko
     
    Started by Waxavi, 04-19-2024, 02:10 AM
    2 responses
    39 views
    0 likes
    Last Post poeds
    by poeds
     
    Started by chbruno, Yesterday, 04:10 PM
    1 response
    44 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by Max238, Today, 01:28 AM
    1 response
    25 views
    0 likes
    Last Post CactusMan  
    Working...
    X