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

Strategy Builder - how to set strategy to run every day not just day it is added?

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

    #16
    Hi Chelsea,

    Thanks for the reply.

    So to avoid the OCO ID error, I should Buy at one tick above the ask and Sell at one tick below the bid? I am printing all the information, so I can definitely check that, but is that how I could avoid it? Or was that just an example?

    Thanks for the link to the error for OnBar Update. I am using On price change instead of on bar close, I assume that has no relation to it? And I should still ensure that I am not calling anything from a previous bar?

    Thanks a lot! This is very helpful!

    David

    Comment


      #17
      Hello David,

      The OCO ID error can be ignored, if this is due to a paired order being rejected. The rejection of the first order being resolved, will resolve the OCO error as well.

      The price chosen for the order type, must be on the correct side of the market. The logic could calculate a price, then check to see which is lower, the calculated price or the ask minus 1 tick (for buys or bid minus 1 tick for sells), and place the order with the valid price.

      Viewing the prints would tell you what the issue is causing the rejected order due to an invalid price. You can compare the price chosen, with the current ask or bid to see if it is less than or greater than.


      The link to the post about indexing errors, is to address the error: "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". This is caused by invalid indexes. CurrentBar must be greater than any bars ago value used.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hi Chelsea,

        Apologies for the late reply to this.

        I think I managed to fix everything, but the indexing error. Is there a way to see what is being called? I am not looking at other indexes, nor calling out other instruments, it is a very simple strategy. Profit target and trailing stop seem to work. The strategy enters Buy and Sell orders, but I keep getting that error that then disable the strategy after the Profit or Stop loss is reached, as expected. I am printing the relevant parameters in the Output window and I have enabled "Trace Orders". Is it possible to identify which command is calling what to fix it? Is the information available somewhere?

        It always happens after the strategy enters a trade. I have included the .txt of the Output window. One example is on Apr 20, 2021 at 17:12. I was actually watching this as it happened: it entered the trade, set the stop loss and profit target, then started following it and when I checked the strategy it had turned "White". Then I checked the Output window and saw the message.

        See attached screenshot of the Output window (this one was on Apr 20, 2021 at 8:32 am).

        Thanks
        David

        Attached Files

        Comment


          #19
          Hello david196,

          Use prints to find the exact line causing the error. Add a print one line before any action or any condition. The last print to appear is likely one line above the error.

          Indexes use brackets. Close[0] is using an index of 0 as the barsAgo index.

          Once the line is identified, look at all brackets. Ensure that any index used is less than the size of the collection. If the value is a barsAgo value, it must be less than CurrentBar.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hi Chelsea,

            Thanks for the reply, I opened the code and the only thing that I found as far as "OnBarUpdate" is the attached. Do you know what that is? It is between the Inputs and Variables and Conditions and Actions...

            Thanks
            David

            Attached Files

            Comment


              #21
              Hello david196,

              OnBarUpdate is the method that runs when the bar updates. This will be when the bar closes if Calculate is OnBarClose, when a tick is received with Calculate.OnEachTick, or when the price changes with Calculate.OnPriceChange. This is where the logic of the script is processed.

              Below I am providing a link to a forum post with helpful information about getting started with NinjaScript and C#. Please watch the Strategy Builder 301 and NinjaScript Editor 401 training videos.


              May I test this script on my end to see if I am able to reproduce this error?
              ​​​​​​​
              To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
              1. Click Tools -> Export -> NinjaScript...
              2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
              3. Click the 'Export' button
              4. Enter a unique name for the file in the value for 'File name:'
              5. Choose a save location -> click Save
              6. Click OK to clear the export location message
              By default your exported file will be in the following location:
              • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
              Below is a link to the help guide on Exporting NinjaScripts.
              http://ninjatrader.com/support/helpG...-us/export.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hi Chelsea,

                Thank you very much, that would be great!

                Please find the export attached.

                I use it on ES 06-21 with a 1 min chart.
                It updates on price change.

                Thanks!
                David
                Attached Files

                Comment


                  #23
                  Hello david196,

                  Are you certain you have provided the correct script?

                  I have tested and I did not receive any error.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hi Chelsea,

                    Thanks for sharing the video.

                    Yes, I am sure it is the right one.There are a couple of interesting things though: the strategy performed very differently in your test! See attached screenshots from mine and yours.
                    The ORB High/Low values are different and the PnL is also different. Yours executed fewer trades and was profitable, whereas mine was negative (in the same time span), and executed more trades. I am trying to find a way to record the screen so I can share the full sequence like you did.

                    I did not get the error message when applying the script on the instrument, only when running it live (still on a Sim account). I had it running all day today and I had to restart it after each trade that it took. Same error message in the Output window. Are there different settings in Ninja Trader (between your machine and mine) that could be causing this? Or is everything embedded in the script so we should be in the same conditions?

                    I really do not understand why we get different results...

                    Thanks
                    David
                    Attached Files

                    Comment


                      #25
                      Hello david196,

                      Thanks for your reply.

                      What data feed do you connect to?

                      On your chart, please right mouse click and select "Reload all historical data" and then rerun your strategy to verify your strategy results.


                      Paul H.NinjaTrader Customer Service

                      Comment


                        #26
                        HI Paul,

                        Thanks for the reply.

                        I use My Rithmic for Ninja Trader Brokerage.

                        I reloaded all historical data and there was no change. I still have the same trades as shown in the previous message. Aside from that, any idea why I do not get an error message when I apply it on the Chart or run a backtest, but when I run it live (on the Sim) it always prompts that error message after entering a trade and disable the strategy soon after? So it is basically a one trade strategy...

                        Thanks
                        David

                        Comment


                          #27
                          Hello david196,

                          Thanks for your reply.

                          Chelsea's video was to show that he was not seeing an error, he was not trying to compare results. The reason the values are different was because of the time differences between CST and MST.

                          Can you clarify what specific error messages you get that are disabling the strategy?
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #28
                            Hi Paul,

                            I apologize for the late reply, I have been very busy at work and had to put NJ on the side for a few weeks.

                            I managed to fix the strategy, it now runs continuously! I had to put a time filter in the set with the print command also. That's the only thing that I have changed, it runs like a Swiss clock now!

                            I have a couple more questions:

                            1)
                            I understand that the commands are in order, meaning that the script tries to execute Set 1 before Set 2, etc.

                            In the same strategy I am opening a Long Position in Set 2 under certain conditions and a Short position in Set 3 other different conditions (that are mutually exclusive, they cannot both be right at the same time). Is that a correct way of doing it? It seems so, since it is performing well and it executes the trades correctly (as it should). Just wondering about coding etiquette and if there is a better way of doing it.

                            2)
                            Another question is about the lines. In Set 1 I add lines to the chart, but they are only visible when I apply the strategy on the chart, not when I do it from the Strategy TAB in the Control Center. Is that normal? Is there a way to add lines to a chart when launching the Strategy from the Strategy tab in the control center?

                            Thank you very much!
                            Cheers
                            David

                            Comment


                              #29
                              Hello david196,

                              Thanks for your reply.

                              Congratulations on the working strategy!

                              1) If your strategy is working and performing as expected then that is really the best answer.
                              2) That would be expected, when you apply the strategy in the strategy tab, there is no chart associated with the strategy. When you apply the strategy to a chart then the strategy can display on that chart.

                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              435 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              9 responses
                              126 views
                              1 like
                              Last Post caryc123  
                              Started by selu72, Today, 02:01 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Working...
                              X