Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ChartTrader addon - how to make permanent?

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

    #16
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello focus333,

    That became SampleWPFModifications.
    https://ninjatrader.com/support/foru...07#post1124507

    With placing orders through an indicator, this would have to be done using the Addon approach noted in post #2.

    I have some recent demos you might like I've attached. Something I'm working on for a larger picture project I have in the works to organize our support suggestions over the years for all the developers out there.

    These demonstrate placing orders from button clicks with 3 approaches in both strategies and indicators using the addon approach:
    1. Placing a market order immediately when clicked
    2. Submitting a limit order with limit price updated to indicator plot value
    3. Setting a trigger to submit a market order after conditions are met

    Similar to the ProfitChaseStopTrail demos, these are ideas implemented in different types of scripts to convey it's an idea and the code is how you decide to tackle it.

    The ProfitChaseStopTrail demos in case you were not familiar with these:
    https://ninjatrader.com/support/foru...269#post802269

    And Strategy Builder versions:
    https://ninjatrader.com/support/foru...596#post806596
    Chelsea B

    I have taken you example of using Indicator for buttons (very nice, thanks)

    I am try to use the Case 3 to have a condition set in place of you SMA cross

    compiied without errors, when I apply the button, it shows enabled, but when I get to the trigger part, the Buttons go away and the indicator I assume is disabled and I have and error in my Log tab

    Error on Calling OnBarUpdate method on bar 1507. Object reference not se to an instance of an object

    i try to add a BarsInProgress !=0 in the OnBarUpdate region but then got the error on click of the button, after removed, the error still occurs as soon as i click the button

    THE OTHER ON MARKET BUTTON AND LIMIT ORDER BUTTONS STILL FUNCTION PROPERLY

    Thanks
    Last edited by DTSSTS; 02-24-2021, 09:21 AM.

    Comment


      #17
      Hello DTSSTS,

      Use prints to identify the variable that has a null value.

      Below is a link to a forum post that demonstrates using prints to understand behavior.


      Add a print after each line of code in OnBarUpdate.

      What is the last print that appears before the error?

      What is the line of code below that print?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        the first time i tryed to enable the button it did enable and waited uptil it triggered to send the error, but after that i get the error as soon as i click the button, that really confused me as I do not think at this point anything to do with the logic is even getting started that would then create the prints

        so a print might be needed for just the Click of the button

        so as you know how to define that print is always outside my knowledge if it requires details

        example from you link



        Print(string.Format("{0} | SMA(7)[1]: {1} < SMA(14)[1]: {2} & SMA(7)[0]: {3} > SMA(14)[0]: {4}", Time[0], SMA(7)[1], SMA(14)[1], SMA(7)[0], SMA(14)[0]));

        a couple of examples of my variables

        if (longConditionTriggerEnabled

        think need a print for this first

        other variables examples

        && (ATSConsolidationTrader1.Inthebox_plot[2] == 1)


        && (ATSLongTradeBiasSignalZERO.ATSLongTradeBiasSignal plot0[2] > SMALongZERO[2])


        Print(string.Format("{0} | ATSLongTradeBiasSignalZERO.ATSLongTradeBiasSignalp lot0[2]: {1}", Time[0]));

        i know the above is not correct, i tried several modification but onlyl have errors in the programming errors at the bottom on script editior

        Thanka

        Comment


          #19
          Hello,

          I recommend you just print letters or numbers to identify which line is causing the error. This is described in the forum post I have linked on using prints to understand behavior.

          Print("1");
          // line of code here

          Print("2");
          // line of code here

          Print("3");
          // line of code here.


          If you have compile errors, what are the compile errors, and on what lines? May we have a screenshot of the errors?

          Your print has a {1} in the string.Format() but there is no second object supplied. This will cause an error as that index does not exist.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            i just found that at some other forum post and tryed

            Print("step 1");
            && (ATSLongTradeBiasSignalZERO.ATSLongTradeBiasSignal plot0[2] > SMALongZERO[2])
            Print("step 2");
            && (ATSShortTradeBiasSignalZERO.ATSShortTradeBiasSign alplot0[2] <= SMAShortZERO[2])


            i just get tons of errors regarding _ && ;


            Invalid expression term '&&' CS1525
            ; expected CS1002
            Invalid expression term '&&' CS1525
            ; expected CS1002
            Invalid expression term ')' CS1525
            ;
            Last edited by DTSSTS; 02-24-2021, 11:15 AM.

            Comment


              #21
              Hello DTSSTS,

              The if condition is considered one line of code. Prints cannot go inside of the if condition (the branching command).

              Print("1");

              if (Close[0] > Open[0]
              && Open[0] > Open[1]
              && Open[1] > Open[2])
              {
              Print(Time[0] + " condition true");
              }

              Print("2");

              myVal = 100;

              Print("3");

              MyMethodCall();

              Print("4");
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                ok so i have the print before the IF, how will i know which is causing the error

                also I now only get the error when we trigger the trade after I added

                if (CurrentBar == 0)

                inthe OnBarUpdate Region, the button clicks to enabled, but now just stays enabled and does not trigger or create error

                ok added print step one as shown below, it start showing up even if longConditionTriggerEnablled has NOT be clicked, so I do not believe we are getting past that point

                i did add print for condition true and print for order submitted





                #region Use case 3, setting a trigger to submit a market order after conditions are met
                Print("step 1");
                if (longConditionTriggerEnabled
                // your custom conditions for entering the trade can go here. I'll use the price crossing the SMA as an example.

                //ref && (ATSConsolidationTrader1.Inthebox_plot[1] == 1)
                //ref && (ATSLongTradeBiasSignalZERO.ATSLongTradeBiasSignal plot0[1] > SMALongZERO[1])
                //ref && (ATSShortTradeBiasSignalZERO.ATSShortTradeBiasSign alplot0[1] <= SMAShortZERO[1]))

                //ref only && (ATSConsolidationTrader1.Inthebox_plot[1] == 1)
                // && (ATSLongTradeBiasSignalZERO.ATSLongTradeBiasSignal plot0[2] > SMALongZERO[2])
                // && (ATSShortTradeBiasSignalZERO.ATSShortTradeBiasSign alplot0[2] <= SMAShortZERO[2])

                // && (ATSLongTradeBiasSignalZERO.ATSLongTradeBiasSignal plot0[1] > SMALongZERO[1])
                // && (ATSShortTradeBiasSignalZERO.ATSShortTradeBiasSign alplot0[1] <= SMAShortZERO[1])


                // && (Position.MarketPosition != MarketPosition.Long)// HAD TO BLOCK BECAUSE OF ERRORS
                // && (Position.Quantity == 0)// HAD TO BLOCK BECAUSE OF ERRORS
                // In the Box Primary

                && (ATSConsolidationTrader1.Inthebox_plot[2] == 1)

                && (Close[2] < ATSConsolidationTrader1.upperboundary_plot[1])
                && (Close[2] > ATSConsolidationTrader1.lowerboundary_plot[1])
                && (Close[1] > ATSConsolidationTrader1.upperboundary_plot[1])
                && (Close[1] == ATSConsolidationTrader1.breakupbarvalue_plot[1])
                && (ATSConsolidationTrader1.breakupbarvalue_plot[3] != ATSConsolidationTrader1.breakupbarvalue_plot[1])
                && (ATSConsolidationTrader1.breakupbarvalue_plot[1] > ATSConsolidationTrader1.upperboundary_plot[1])

                // && (LongSetZERO == 1)
                // || (LongSetONE == 1)
                // || (LongSetTWO == 1)



                && (Close[0] > Close[1]))


                // && (CrossAbove(sma1, Close, 1) || CrossBelow(sma1, Close, 1)))// blocked from original script
                {
                Print(Time[0] + " condition true");

                longConditionTriggerEnabled = false;

                Print(Time[0] + " Long condition trigger NOT enabled false");


                Order mar****rder = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, 1, 0, 0, string.Empty, "Long conditional", new DateTime(), null);
                account.Submit(new Order[] { mar****rder });
                Print(Time[0] + " order submitted");



                Last edited by DTSSTS; 02-24-2021, 12:14 PM.

                Comment


                  #23
                  Hello DTSSTS,

                  Once you have identified which line is causing the error, you will need to check every nullable variable on that line for null.

                  I am assuming longConditionTriggerEnabled is a non nullable bool.

                  if (ATSConsolidationTrader1 == null)
                  {
                  Print("ATSConsolidationTrader1 is null");
                  }
                  else
                  {
                  Print("ATSConsolidationTrader1 is not null");
                  }

                  if (ATSConsolidationTrader1 != null)
                  {
                  Print("ATSConsolidationTrader1.Inthebox_plot.Count : " + ATSConsolidationTrader1.Inthebox_plot.Count.ToStri ng());
                  }

                  etc
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    I GOT IT TO WORK!!!! removed current bar == 0

                    also found 1 indicator needing additional line of code was my original error

                    NOW a couple items i would like to add needing information about Cbi.Position.MarketPosition.get

                    // && (Position.MarketPosition != MarketPosition.Long)// HAD TO BLOCK BECAUSE OF ERRORS
                    // && (Position.Quantity == 0)// HAD TO BLOCK BECAUSE OF ERRORS

                    ALSO how do i change your example code to trade the account selected in the Chart Trader menu

                    i believe from this region

                    else if (State == State.DataLoaded)
                    {
                    account = Account.All.FirstOrDefault(a => a.Name == "Sim101");// need modified

                    if (account != null)
                    account.OrderUpdate += Account_OrderUpdate;

                    if (ChartControl != null)
                    CreateWPFControls();



                    thanks


                    ALSO i plan to remove the market order and limt order on indicator from the code (anything special i need to avoid ie clean up area)

                    then I plan to added the Short Sale Button
                    Last edited by DTSSTS; 02-24-2021, 12:53 PM.

                    Comment


                      #25
                      Hello DTSSTS,

                      Is this is a NinjaScript Strategy that has a Position and not an Indicator or other type of script which does not have a Position?


                      Are you trying to get the Position of an account for a specific instrument?


                      Below is a link to an example that finds the AccountSelector by the automation ID.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        It is an indicator from you example, I do not want a strategy, just wanting to have a level of safety in the indicator that the quanitity traded is from the chart trader on the chart and that if there is already a position that no trade will be made.

                        just want the postition of the account we are trading and the insturment on the chart with the indicator. that is selected from the chart trader, ie you have sim101 built into the strategy, just need to be able to change that to the appropriate/desired account


                        I got you example of Account selector, but figuring out what lines of the code are needed AND SWITCH ones to remove is not clear

                        Comment


                          #27
                          Hello DTSSTS,

                          Look for chartTraderAccountSelector and see how this is assigned an object and where this is used to print the account name.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #28
                            so where in the previous example code that we have been working with today would this be inserted

                            protected void ButtonClick(object sender, RoutedEventArgs rea)
                            {
                            NinjaTrader.Gui.Tools.AccountSelector chartTraderAccountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;

                            message = "Account selector null or no account selected";

                            if (chartTraderAccountSelector != null && chartTraderAccountSelector.SelectedAccount != null)
                            message = string.Format("Selected account DisplayName: {1} \r\n (Full) Name: {2}", DateTime.Now, chartTraderAccountSelector.SelectedAccount.Display Name, chartTraderAccountSelector.SelectedAccount.Name);

                            Print(string.Format("{0} | {1}", DateTime.Now, message));
                            Draw.TextFixed(this, "infobox", message, TextPosition.BottomLeft, Brushes.MediumTurquoise, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Transparent, ChartControl.Properties.ChartBackground, 100);
                            ForceRefresh();
                            }


                            ************************

                            seems we would need some chart control as well

                            Comment


                              #29
                              Hello DTSSTS,

                              This would be in place of where the account variable is being set in State.DataLoaded.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                i really cannot figure out why the example (being something so many would be interested in ) would be NOT easy to set account to

                                I have tried to add that code, but seems other items need to be included NO luck so far

                                do I need to block what you have in there

                                account = Account.All.FirstOrDefault(a => a.Name == "Sim104");// need modified


                                // account = Account.All.FirstOrDefault(a => a.Name == "");// need modified
                                if (account != null)
                                account.OrderUpdate += Account_OrderUpdate;

                                if (ChartControl != null)
                                CreateWPFControls();

                                also what about the terminate area

                                thanks

                                i place this down in the ondata load region


                                // ************************************************** ************************************************** ****************
                                protected void ButtonClick(object sender, RoutedEventArgs rea)
                                {
                                NinjaTrader.Gui.Tools.AccountSelector chartTraderAccountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;

                                // message = "Account selector null or no account selected";

                                if (chartTraderAccountSelector != null && chartTraderAccountSelector.SelectedAccount != null)
                                // message = string.Format("Selected account DisplayName: {1} \r\n (Full) Name: {2}", DateTime.Now, chartTraderAccountSelector.SelectedAccount.Display Name, chartTraderAccountSelector.SelectedAccount.Name);

                                // Print(string.Format("{0} | {1}", DateTime.Now, message));
                                // Draw.TextFixed(this, "infobox", message, TextPosition.BottomLeft, Brushes.MediumTurquoise, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Transparent, ChartControl.Properties.ChartBackground, 100);
                                ForceRefresh();
                                }




                                // ************************************************** ************************************************** ****************
                                should i have that near the top

                                got render errors if i remember correct when actually testing

                                i moved it upward and got 30 lines of errors
                                Last edited by DTSSTS; 02-24-2021, 03:37 PM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                579 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                334 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                101 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                554 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                551 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X