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

Shared strategy on multiple instruments

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

    Shared strategy on multiple instruments

    I am not too sure how to handle a strategy with the following high-level behaviour.
    1. Same strategy on multiple instruments (about 20)
    2. Only 1 entry/exit per day all together (not per instrument).
    3. As soon as one of the instruments being looked at, trigger an entry it should not be possible for the other instruments to be traded on that day.
    4. The strategy relies on the same indicator applied to each instrument.
    Should I
    1. open 20 charts (one for each instrument) and apply an instance of the strategy to all of them? But then, how can l let know all strategy instances that an entry was already triggered by one of them.
    2. or have a single instance of the strategy trading the 20 instruments (i.e. SampleMultiInstrument). But then how can I ensure that the indicator are used and looked per instrument and not only for the main instrument.
    I am really not sure which path I should investigate. Thank you in advance for your guidance!

    #2
    Hello Logicwar, thanks for writing in.

    If you want to use 20 separate instances, you can have them all read a single .txt file that would write a flag to the file and on each bar, each script would check this file. If the file contains the flag, return from OnBarUpdate, if not, continue with OnBarUpdate.
    https://ninjatrader.com/support/help..._propertie.htm - File IO example

    If you use a single instance with 20+ instruments, you could set a boolean flag within the script at the class level e.g. bool myFlag. When one of the instruments initiates a trade, set the boolean to false do not trade the other instruments if the boolean is false. You will need to set up indicators for each instrument added to the script e.g.

    if (State == State.Historical)
    {
    mySma0 = SMA(BarsArray[0], 20);
    mySma1 = SMA(BarsArray[1], 20);
    // and so on.
    }

    You would then be able to check each SMA as they are updated e.g.

    OnBarUpdate()
    {

    if(BarsInProgress == 0)
    {
    Print(mySma1[0]);
    }

    if(BarsInProgress == 1)
    {
    Print(mySma1[0]);
    }


    }

    Best regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      Thank you very much for your feedback.

      Any pros and cons using 20 separate instances vs a single instance with 20 instrument? I understand with you rtips that both solutions would work (and how to do it) but stil not sure which one to go for.

      Regards,

      Comment


        #4
        Hello Logicwar, thanks for your reply.

        It depends on what you would rather do. If you use 20 separate instances the logistics problem to solve would be to have them read a single .txt file. With 1 instance with 20 added instruments, the logistics problem to solve would be to manage the position between the instruments added. One pro for the single instance would be that you don't have to set up a strategy 20 separate times. I would say the single instance would be the best route to take.

        Kind regards,
        -ChrisL

        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your feedback.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,265 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X