Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-instrument script problem

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

    Multi-instrument script problem

    I have single instrument scripts I have programmed (not from the wizard, but by hand). They work just as I expect. I then created a multi-instrument script. This works just as I expect, but only for certain trading combinations. I have 3 instruments:
    1) The base instrument - BarsArray[0]
    2) The long instrument - BarsArray[1]
    3) The short instrument - BarsArray[2]

    This configuration works just as expected. The base is used just for signals, the long is for going long, the short for going short. Note that I exit the long and go short at the same bar (and vice/versa).

    Then I wanted to have this configuration:
    1) The base instrument - BarsArray[0]
    2) The long instrument - BarsArray[1]
    3) The 2nd long instrument - BarsArray[2]

    So I used the same code but changed the EnterShort for the BarsArray[2] instrument to an EnterLong. The same for the exit. In that case I never can enter the BarsArray[1] instrument long! I speculate that it is not until the bar actually closes that I get the buy/sell so it thinks there are two positions long at the same time? I believe it is something like this. Any thoughts?

    If I change in the strategies window under "Order Handling", "entries per direction" from 1 to 2, it appears to work. Why is this?

    #2
    tradetree, in the future, please post only one new thread for a question. I'll answer your query here, and let the other thread go.

    If your script works once you change the entries per direction to a larger number, that implies your script is trying to enter long/short with two contracts at once.

    Can you post the code you're using so we can see what could be going on?
    AustinNinjaTrader Customer Service

    Comment


      #3
      I didn't try and create multiple threads, must be when I tried to edit the message it posted a new thread. Anyway, I have proprietary code but I think I can strip it down to the raw trading actions. My issue has to do with the basics of long/short/flat with 3 instruments involved. Maybe I'll create a simple strategy for test purposes.

      Comment


        #4
        Hello,

        Also, you may If you add TraceOrders = True in the Initialize Method you will be able to trace the orders to see what is happening.



        If an orders getting rejected due to the EntriedPerDirectionCap it will be listed here.

        Let me know if I can be of further assistance.

        Comment


          #5
          I created a simple EMA crossing file and added my instruments. I created a chart with 6E 12-10 for Daily, 400 days. I put parameters into my strategy of ExitOnClose=false, Dual_long_instrument=6E12-10, Dual_short_instrument=ES 12-10. All else defaults. This does what I expect, I think.

          If I enter "URTY" for the Dual_long_instrument, there are no transactions. Now this may be because I have trade access to futures like 6E, but not equities like URTY? I am using Kinteticks free EOD for URTY data. If this is the problem, why is there no error output?
          Attached Files

          Comment


            #6
            tradetree,

            To see what data you actually have available, please pull up a chart of URTY separately and take a look. I suggest you add debugging prints to see where exactly your code is running into. Adding a generic Print() line at the top of OnBarUpdate() will help you see what is processed.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Ok, that was helpful. I discovered I had different trading hours for the two, so I put them both to Equities RTH. URTY also only goes back for 290 days. Yet I still don't get any trades. There is another strange thing that has now come up. If you look at the code I posted, the "Add" uses the BarsPeriod.BasePeriodType for the Interval. I print this out and it is set to "Minute" even though all instruments are set to "Day" in the chart. I even went into the debugger and checked it manually, and it is "Minute." Right on the chart the instruments are printed out as "Daily". How does this make sense?

              Comment


                #8
                I overrode BarsPeriod.BasePeriodType to be PeriodType.Day, and I got the trades. So is this a bug?

                Comment


                  #9
                  Hello,

                  Thanks for your note.

                  This is expected Unfortunately is that during Initialize BarsPeriod.BasePeriodType is not populated with a value at this point as the Initialize is just running.



                  There is a note on this page not to use this in Initialize.

                  As of currently The only way to do this would be to add a parameter to your strategy and set this manually.

                  Let me know if I can be of further assistance.

                  Comment


                    #10
                    Well if I access this after initialize will it work? Do I have to perform the Add only in Initialize? If that is the case then I clearly can't do it after Initialize. Is this true for BarsPeriod.Value as well? I could swear it worked for the Value field...

                    Comment


                      #11
                      tradetree, unfortunately dynamic Add()ing is not supported, it may or may not work - the Add() is done in Initialize() only, so adding an input to set it manually as Brett suggested would be a good approach.
                      BertrandNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by gravdigaz6, Today, 11:40 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post gravdigaz6  
                      Started by MarianApalaghiei, Today, 10:49 PM
                      3 responses
                      9 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by XXtrader, Today, 11:30 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post XXtrader  
                      Started by love2code2trade, Yesterday, 01:45 PM
                      4 responses
                      28 views
                      0 likes
                      Last Post love2code2trade  
                      Started by funk10101, Today, 09:43 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post funk10101  
                      Working...
                      X