Announcement

Collapse
No announcement yet.

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.

    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

        Comment


          #5
          Thank you for your feedback.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          23 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          120 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          63 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          45 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X