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 dadarara, Today, 03:21 AM
    0 responses
    6 views
    0 likes
    Last Post dadarara  
    Started by rajeshks1988, 01-13-2021, 12:00 PM
    10 responses
    1,261 views
    0 likes
    Last Post konganda  
    Started by M_ichel, 04-22-2025, 02:21 PM
    7 responses
    60 views
    1 like
    Last Post brucerobinson  
    Started by michelz, 02-18-2025, 08:30 AM
    33 responses
    1,062 views
    0 likes
    Last Post MiCe1999  
    Started by volIQ, 04-23-2025, 05:43 PM
    4 responses
    38 views
    0 likes
    Last Post volIQ
    by volIQ
     
    Working...
    X