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 NISNOS69, Today, 03:16 PM
    0 responses
    3 views
    0 likes
    Last Post NISNOS69  
    Started by massgainstradingwi, Today, 03:05 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by stafe, 03-10-2025, 12:09 PM
    7 responses
    36 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by IanS00, Today, 01:55 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Marble, Today, 05:00 AM
    2 responses
    20 views
    0 likes
    Last Post Marble
    by Marble
     
    Working...
    X