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

    #16
    Hello Murali,

    I would not rely on something being time based. I would recommend that you check the position in OnPositionUpdate() or wait until the orders are filled or cancelled in OnOrderUpdate().

    The message is letting you know that orders are being ignored for violating the internal handling rules as I have previously advised.

    Calling an EnterShortLimit() when there is an exit order working for the opposite position is not allowed.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hi Chelsea,

      Thank you, will check and revert back with questions.

      in my strategy, I'm trying to add 2 dataseries

      1. 15 Min NQ with some indicator X
      2. 5 min NQ with some indicator Y

      Based on the Buy/sell signal from 15 Min chart indicator X, I want to enter the trade in my 5 min chart Indicator Y buy/sell alerts

      I'm able to add 2 dataseries, but not sure how to add indicators to each chart and capture the alerts from those indicators. Could you please give me some sample reference?


      Thankyou,
      Murali


      Comment


        #18
        Hello Murali,

        From the example in the help guide:
        " if (BarsInProgress == 1)
        return;

        // Pass in a Bars object as input for the simple moving average method
        // Evaluates if the 20 SMA of the primary Bars is greater than
        // the 20 SMA of the secondary Bars added above
        if (SMA(20)[0] > SMA(BarsArray[1], 20)[0])
        EnterLong();"


        Indicators can be added to a chart from a strategy from AddChartIndicator().


        Alert can be called with the Alert() method.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hi Chelsea ,

          Thankyou, I'm getting the following error when i'm trying to do back test in strategy analyzer.

          Strategy 'STScalperV3': Error on calling 'OnStateChange' method: NinjaScript 'STScalperV3': Please use the alternate method 'AddHeikenAshi()' instead of AddDataSeries()

          When I try to add my strategy to the chart and activate, I'm getting the following error.

          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.

          else if (State == State.Configure)
          {
          // Add a 15 minute Bars object to the strategy
          //AddDataSeries("NQ 03-22",Data.BarsPeriodType.HeikenAshi, 15); // BarsArray[1]
          AddHeikenAshi("NQ 03-22",Data.BarsPeriodType.HeikenAshi, 15, MarketDataType.Last);

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

          AddChartIndicator(RMSTIndicator(ATRPeriod,Multipli er));
          AddChartIndicator(RMheikinashi(Length));

          }

          Please check my strategy code attached. Not sure why i'm getting this error.

          Thanks,
          Murali
          Attached Files

          Comment


            #20
            Hello Murali,

            Indicators cannot be called until the data is loaded in State.DataLoaded.


            Move the call to RMSTIndicator and RMheikenashi() to State.DataLoaded.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Thankyou Chelsea. Issue got fixed now. But, In the cart, I see both the indicators are getting added to the default data series. I want Indicator X in 15min and Indicator Y in 7 min. Is it possible to add indicator to a particular chart alone?

              Thankyou,
              Murali
              Attached Files

              Comment


                #22
                Hello radhmu978,

                Supply BarsArray[1] or BarsArray[2] as the input series.


                AddChartIndicator(RMSTIndicator(BarsArray[1] ATRPeriod, Multiplier));
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Hi Chelsea ,

                  Thank you, it worked. But still I'm not able to do back test in strategy analyzer. Do i need to do something differently for backtesting?

                  Thanks,
                  Murali

                  Comment


                    #24
                    Hello Murali,

                    Is the same error occurring?

                    "Strategy 'STScalperV3': Error on calling 'OnStateChange' method: NinjaScript 'STScalperV3': Please use the alternate method 'AddHeikenAshi()' instead of AddDataSeries()"

                    Are there any calls to AddDataSeries() instead of AddHeikenAshi()?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #25
                      I commented those, removed it from the code after the error message. I'm not getting any error in output window when i run the strategy, but in backtest mode, it is not taking trades

                      Comment


                        #26
                        Hello radhmu978,

                        Debug the code using prints.

                        Start by printing the time of the bar outside of all conditions and ensure the data is being processed.

                        Then print all values used in the conditions to see if these are evaluating as true or false.

                        Enable TraceOrders to see if orders are being cancelled, ignored, rejected.

                        Below is a link to a forum post on using Print() to understand behavior.


                        I am happy to assist with analyzing the output from the prints.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          Hi Chelsea,

                          this is the error I get in my output window.

                          Made it to line 76 -
                          Made it to line 81 -
                          Made it to line 90 - add chart indicator
                          Strategy 'STScalperV3': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
                          OnStateChange 1 SetDefaults
                          OnStateChange 2 SetDefaults
                          OnStateChange 1 Terminated
                          OnStateChange 2 Terminated

                          When I comment the CurrentBars[0] check, I get the error. If i retain this check in strategy, then my backtest is not working.
                          //if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot)
                          //return;

                          Not printing anything in OnBarUpdate() function.
                          Attached Files

                          Comment


                            #28
                            Hello radhmu978,

                            BarsRequiredToPlot is generally used for Indicators, BarsRequiredToTrade is generally used for Strategies.


                            What is the size of the BarsArray collection? (BarsArray.Count)

                            Are you certain that code is causing the error?
                            If all other code is commented out and this code is uncommented, does the error occur?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Sorry, I was busy, I could not respond to your questions on time.

                              Yes, that is the line throwing error, the last line of the code I hit is 102. after that I have comparison of CurrentBars to BarsRequiredToTrade, this is where it fails

                              Print("Made it to line 102 - OnBarUpdate " );
                              if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < BarsRequiredToTrade )
                              return;

                              Print("Made it to line 106 - add chart indicator " );

                              this is the output when i try to enable the strategy

                              Made it to line 102 - OnBarUpdate

                              Enabling NinjaScript strategy 'STScalperV3/249316710' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes

                              OnStateChange 1 Terminated
                              OnStateChange 2 Terminated
                              Attached Files
                              Last edited by radhmu978; 01-27-2022, 09:19 AM.

                              Comment


                                #30
                                Hello radhmu978,

                                What is the size of the BarsArray collection? (BarsArray.Count)

                                Can you print CurrentBars[1] by itself?
                                Chelsea B.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by knowmad, Today, 03:52 AM
                                0 responses
                                13 views
                                0 likes
                                Last Post knowmad
                                by knowmad
                                 
                                Started by tradingnasdaqprueba, Today, 03:42 AM
                                0 responses
                                8 views
                                0 likes
                                Last Post tradingnasdaqprueba  
                                Started by Haiasi, 04-25-2024, 06:53 PM
                                4 responses
                                63 views
                                0 likes
                                Last Post effraenk  
                                Started by ccbiasi, 11-23-2017, 06:06 AM
                                5 responses
                                2,205 views
                                0 likes
                                Last Post leodavis  
                                Started by kujista, Yesterday, 12:39 AM
                                2 responses
                                14 views
                                0 likes
                                Last Post kujista
                                by kujista
                                 
                                Working...
                                X