Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Select indicator through [NinjaScriptProperty]

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

    Select indicator through [NinjaScriptProperty]

    Can I let the user select an indicator for input to a strategy using the [NinjaScriptProperty]?

    Thanks.

    #2
    Hello cstangor, and thank you for your question.

    This is not directly possible. The attached script will demonstrate why. While it will compile correctly, if you type "SMA(14)" in as its input parameter, it will still fail. Even if NinjaTrader were modified so this succeeds we would still be in a difficult position, as the 14 hard-coded into OnBarUpdate was an arbitrary choice, and if typing SMA(14) were made to work, typing SMA(50) would also be made to work, and you as a coder do not have a view into this input.

    The best option currently available is to take an integer, string, or similar supported input, and use a switch statement based on this input to set up an indicator based on the user's selection, i.e.

    Code:
    [FONT=Courier New]switch inputvar
    {
        case 1 :
            myIndicator = MACD(1, 2, 3);
        case 2 :
            myIndicator = SMA(14);
        default :
            myIndicator = EMA(12);
    }[/FONT]
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    60 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    39 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    21 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    23 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    51 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X