Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I enable my custom strategy from my indicator button?

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

    Can I enable my custom strategy from my indicator button?

    I have a strategy that is semi-automatic -- I enable it when the chart is forming an opportunity.

    I've created an indicator with a button, so that I can enable that strategy with the button (instead of going into the strategies dialog every time). However, I cannot figure out how to enable the strategy from within my NinjaScript code. In fact, I can only get a reference to the strategy if it is already enabled on the account. Is there a way to accomplish this?

    Here is the code snippet where I am trying to accomplish this:

    Code:
    private void enableKingJTrader(object sender, RoutedEventArgs e) {
        Print("Enabling King J Trader");
        NinjaTrader.Gui.Tools.AccountSelector xAlselector;
        bool kingJStratEnabled = false;
    
        ChartControl.Dispatcher.InvokeAsync((Action)(() =>
        {
            xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
            Print(xAlselector.SelectedAccount.ToString());
    
            foreach (StrategyBase strat in xAlselector.SelectedAccount.Strategies) {
                  Print("In a Strat");
                  Print(strat.Name);
                  if (strat.Name == "KingJ Zone Scale") {
                     kingJStratEnabled = true;
                 }
             }
    
              if (kingJStratEnabled == false) {
               //SOMEHOW ENABLE THE STRATEGY I WANT
             }
        }));
    
    }​

    #2
    Hello KingJTrader,

    Unfortunately, it is not supported to enable a NinjaScript Strategy programmatically through code.

    These must be manually enabled by a user with a conscious decision to do so.

    You could choose to leave the strategy always enabled and then use a bool changed from a button click to turn on and off the logic being evaluated.

    You could choose to not use a strategy and code the logic into the indicator using the Addon approach to send orders.
    Or your button click could launch an Addon window that sends orders using the Addon approach.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by raysinred, 04-06-2025, 01:52 PM
    16 responses
    139 views
    0 likes
    Last Post raysinred  
    Started by iantriestrading, Yesterday, 01:39 PM
    5 responses
    28 views
    0 likes
    Last Post iantriestrading  
    Started by trendisyourfriend, 05-25-2023, 09:54 AM
    10 responses
    169 views
    0 likes
    Last Post Curerious  
    Started by iantriestrading, Today, 04:12 PM
    0 responses
    17 views
    0 likes
    Last Post iantriestrading  
    Started by Adamel, Today, 03:47 PM
    0 responses
    13 views
    0 likes
    Last Post Adamel
    by Adamel
     
    Working...
    X