Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Instrument Strategy

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

    Multi-Instrument Strategy

    Hello,
    I am trying to write a strategy that goes long on instrument A and short on instrument B when the price of instrument B has diverged by a certain amount from instrument A. When I try to run the strategy, I get no results and the chart of the instrument won't show.

    if(Position.MarketPosition == MarketPosition.Flat && Close[0] > 2*Closes[1][0])
    {
    EnterShort(0, 1, "ENTRY");
    EnterLong(1, 1, "ENTRY");
    }​

    Thank you

    #2
    Hello samish18,

    Have you tried using a Print to make sure that your condition is becoming true? You would need to print the values you are using to see if Close[0] is becoming greater than Closes[1][0] * 2.

    Comment


      #3
      I did, and nothing was printed. I edited the statement to execute if there is any difference in price between the two and it still did not execute. The code above it is as follows:

      else if (State == State.Configure)
      {
      AddDataSeries("MSFT", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 30 || CurrentBars[1] < 30)
      return;​

      Comment


        #4
        Hello samish18,

        Do you have tick data for MSFT? If you do not that would prevent the script from loading. Your script should otherwise only execute on the primary series due to the BarsInProgress condition. It would also require 30 bars for both series, if the primary is a large series like a daily series you would need to load at least 30 days, otherwise 30 bars for the series being used as the primary.

        Comment


          #5
          I don't think that is the issue. I have tried changing the timeframe and instrument to no avail. I've also been backtesting over a 2 year period without hitting a single occurrence.

          Comment


            #6
            Hello samish18,

            You could add a print before your conditions to check what data was loaded. For example:
            Code:
            protected override void OnBarUpdate()
            {​
            Print(BarsInProgress + " " + CurrentBar);

            Comment


              #7
              The BarsInProgress was 0 and only 0 for each iteration (never 1). What does this mean?

              Comment


                #8
                Hello samish18,

                That would indicate no data was loaded for the MSFT instrument. When you added the AddDataSeries statement did you remove and re apply the script to where you are testing it?

                Are you able to open a chart of MSFT and view a 1 tick chart for the amount of days that you are trying to test?

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                66 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                141 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                76 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                47 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                51 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X