Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

market order and limit order

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

    #31
    Not sure how to print BarsArray.Count

    Print("Made it to line 102 - OnBarUpdate " + CurrentBars[1]);
    Made it to line 102 - OnBarUpdate -1

    CurrentBars[1] value is -1

    Comment


      #32
      Hello radhmu978,

      Print(BarsArray.Count);

      If CurrentBars[1] is -1 then it hasn't processed any bars. Are you certain this has loaded?

      Chelsea B.NinjaTrader Customer Service

      Comment


        #33
        Should i load 2 charts, not sure if i get your question. How to find that? I'm testing using strategy analyzer, I tried to enable the strategy in chart as well. I used 15 min chart for testing, but i have 2 different dataseries - 15min and 7 min

        Comment


          #34
          Hello radhmu978,

          If you print BarsInProgress and the Time of the bar do you see BarsInProgress updating in OnBarUpdate()?

          Can you load a separate chart with the instrument, bar type, interval, and date range?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #35
            please check the attachement. All bars are loaded. attached the code as well. Could you please check and let me know what is the issue with the CurrentBars?

            1/27/2022 11:50:00 AM
            Made it to line 102 - CurrentBars -1
            Made it to line 116 - BarsInProgress 0
            1/27/2022 11:57:00 AM
            Made it to line 102 - CurrentBars -1
            Made it to line 116 - BarsInProgress 0
            Attached Files
            Last edited by radhmu978; 01-27-2022, 12:48 PM.

            Comment


              #36
              Hello radhmu978,

              The print of the BarsInProgress and time is not at the top of OnBarUpdate. It's below the code
              if (BarsInProgress != 0)
              return;

              This means we cannot see if BarsInProgres is reaching 1 and processing the first added series, and reaching 2 for the second added series.

              We need information about BarsInProgress 1 and 2. Please move the print above that.

              protected override void OnBarUpdate()
              {
              Print(string.Format("{0} | BarsArray.Count: {1}, BarsInProgres: {2}, CurrentBar: {3}", Time[0], BarsArray.Count, BarsInProgress, CurrentBar));
              if (BarsInProgress != 0)
              return;

              Was this run in the Strategy Analyzer as a backtest?

              Where is the error message in this output?

              Chelsea B.NinjaTrader Customer Service

              Comment


                #37
                Is the print stamenet correct? I'm getting compilation error in print. Could you please check the screenshot attached?

                Print(string.Format("{0} | BarsArray.Count: {1}, BarsInProgres: {2}, CurrentBar: {3}", Time[0], BarsArray.Count, BarsInProgress, CurrentBars[0]));

                Attached Files

                Comment


                  #38
                  Was this run in the Strategy Analyzer as a backtest?

                  Where is the error message in this output?

                  I tried it in both chart and strategy analyzer. if i run it from stratagy analyzer or add to chart, by commenting out the CurrentBars check, I get the following error

                  //if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < BarsRequiredToTrade )
                  //return;

                  Made it to line 76 -
                  Made it to line 81 -
                  Made it to line 76 -
                  Made it to line 81 -
                  Made it to line 90 - add chart indicator
                  12/27/2021 11:15:00 PM
                  Made it to line 102 - CurrentBars -1
                  Made it to line 116 - BarsInProgress 0
                  Made it to line 106 - OnBarUpdate
                  Strategy 'STScalperV3': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                  error is in this line = > if(RMheikinashi(BarsArray[1],Length).BUY[0] == 1)// BarsArray[1] refers to 15 min HA chart with HA indicator of length 55
                  Last edited by radhmu978; 01-27-2022, 02:47 PM.

                  Comment


                    #39
                    Hello radhmu978,

                    And the error does not occur when you don't uncommented the current bars check?

                    Previously, in post #29, you have confirmed that the current bars check is causing an error, is this still the case?
                    Dear NT8 support team, I have a simple strategy to perform reversal trading based on opposite signal. I have included a signalname for my entry orders and trying to exit the particula orders based on the signal name. My default entries per direction is 1. I did backtesting with market order and functionality worked perfectly.

                    Dear NT8 support team, I have a simple strategy to perform reversal trading based on opposite signal. I have included a signalname for my entry orders and trying to exit the particula orders based on the signal name. My default entries per direction is 1. I did backtesting with market order and functionality worked perfectly.


                    All other code is commented out except for the current bars check and the error is occurring, is this correct?

                    The code below that wouldn't be causing the error because its commented out, correct?


                    Further, why would the currentbar check be commented out and not the code below it, which needs that currentbar check to ensure all indexes used are less than the size of the collection (meaning BarsArray indexes must be less than BarsArray.Count, and BarsAgo indexes must be below CurrentBar)'
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #40
                      Hi Chelsea ,

                      I'm able to narrow down the issue. I took the SampleMultiTimeFrameOrders from the support forum and tried to replace the AddDataSeries() with AddHeikenAshi(), then the strategy stopped working.

                      the SampleMultiTimeFrameOrders order strategy is working with AddDataSeries() but not working with AddHeikenAshi

                      Is this AddHeikenAshi() function working in NT8? Do you have any examplePlease check the sample code attached.

                      // Add a 5 minute Bars object to the strategy
                      AddDataSeries(Data.BarsPeriodType.Minute, 5); // BarsArray[1]
                      // AddHeikenAshi("ES 03-22",Data.BarsPeriodType.HeikenAshi, 15, MarketDataType.Last);

                      // Add a 15 minute Bars object to the strategy
                      AddDataSeries(Data.BarsPeriodType.Minute, 15); // BarsArray[2]
                      //AddHeikenAshi("ES 03-22",Data.BarsPeriodType.HeikenAshi, 7, MarketDataType.Last);

                      thankyou,
                      Murali
                      Attached Files

                      Comment


                        #41
                        Hello Murali,

                        Attached is a simple working example of calling AddHeikenAshi().
                        Attached Files
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #42
                          thank you, it is working now.

                          Comment


                            #43
                            Hi Chelsea,

                            I want to set 2 different quantity for entry and exit. Take half profit and continue other order as runner. Is it possible to do based on order quantity or should i use a unique signal names for Entry orders?

                            //Illustration

                            EntryQuantity = 2;
                            ExitQuantity = 1;

                            EnterLong(EntryQuantity, "longEntryHA1");

                            //First profit target
                            ExitLongLimit(1, true, ExitQuantity, currentPtPrice, "Long profit target", "longEntryHA1")

                            //Second profit target
                            ExitLongLimit(1, true, ExitQuantity, currentPtPrice, "Long profit target", "longEntryHA1")

                            Thankyou,
                            Murali

                            Comment


                              #44
                              Hello Murali,

                              I would recommend using unique signal names for each quantity and an exit tied to that entry with a fromEntrySignal.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #45
                                Ok, I have the same approach, but it is not working, only if i change the EntriesPerDirection = 2, my second entry is getting accepted. Should i consider some unque names list "Salper", Runner etc., instead of adding 1,2 etc., at the end?

                                EnterLong(quantity, "longEntryHA1");
                                EnterLong(quantity, "longEntryHA2");

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Spiderbird, Today, 12:15 PM
                                1 response
                                6 views
                                0 likes
                                Last Post NinjaTrader_ChristopherJ  
                                Started by FrazMann, Today, 11:21 AM
                                1 response
                                6 views
                                0 likes
                                Last Post FrazMann  
                                Started by lorem, Yesterday, 09:18 AM
                                5 responses
                                18 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                                12 responses
                                42 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by geddyisodin, Yesterday, 05:20 AM
                                8 responses
                                52 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X