Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difference timing between 2 trades

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

    Difference timing between 2 trades

    Good afternoon,
    I have a strategy which open 2 trades when a condition is true like the code below.
    ================================================== ============
    if(mycondition==true)
    {
    if(BarsInProgress==1 && Positions[1].MarketPosition != MarketPosition.Long)
    {
    EnterLong(NbContratA, "B1");
    EntryPriceA=Close[0];
    }
    if(BarsInProgress==2 && Positions[2].MarketPosition != MarketPosition.Short)
    {
    EnterShort(NbContratB, "S1");
    EntryPriceB=Close[0];

    }
    }
    ================================================== ===========
    This code works but the orders for the 2 stocks aren't passed at the same hour.
    The strategy turns on a 10 minutes chart, and I had 10 minutes or 20 minutes of difference between the time where the stock A buy and the stock B sell.

    Could you explain the problem please?

    Thank's a lot for your answer.

    #2
    Hello neo-13,

    Thank you for your post.

    I cannot tell from the code posted what the cause of this matter is. However, I would like to test this item on my end. Please advise what the Instrument, PeriodType and Interval (Example: ES 06-13) is that you applied the indicator or chart to and what the secondary bar series Instrument, PeriodType and Interval are as well.

    In addition, is this in backtesting, Market Replay or real-time data?

    I look forward to your response.

    Comment


      #3
      In addition code there is:
      protected override void Initialize()
      {

      Add(instrumentA,PeriodType.Minute, timePeriod,MarketDataType.Last);
      Add(instrumentB,PeriodType.Minute, timePeriod,MarketDataType.Last);

      DeltaPairLog = new DataSeries(this);
      EntriesPerDirection = 2;
      EntryHandling = EntryHandling.UniqueEntries;
      ExitOnClose = false;
      CalculateOnBarClose = true;
      }

      InstrumentA="CMO"
      InstrumentB="NLY"
      Time Period= 10 minutes
      The condtion is based on a spread between the 2 stocks and if the spread cross above, the code of my first thread is executed.
      I use NT with a simulated account and real time account of IB with TWS.

      Thank's

      Comment


        #4
        Hello neo-13,

        Thank you for your response.

        This is happening because the incorrect bars in progress index is referenced. you will need to change the two conditions to the following:
        Code:
        if(BarsInProgress==0 && Positions[0].MarketPosition != MarketPosition.Long)
        Code:
        if(BarsInProgress==1 && Positions[1].MarketPosition != MarketPosition.Short)
        For information on working with multiple instruments and time frames please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

        Please let me know if I may be of further assistance.

        Comment


          #5
          Thank's,
          but if I add 2 instruments from a third instrument.
          My strategy is on chart of msft, I calculate the spread between CMO and NLY and I trade with CMO and NLY, I must use BarsInProgress 1 and 2 and not 0, 0 is for msft!! no?


          Thank's

          Comment


            #6
            Hello neo-13,

            Thank you for your response.

            I see, that would not work then and you have it set correctly in that case. Can you forward me the full code for this strategy so I may test on my end?
            If you prefer you can send the strategy to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 862125' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=58372

            I look forward to assisting you further.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cre8able, Today, 03:20 PM
            0 responses
            5 views
            0 likes
            Last Post cre8able  
            Started by Fran888, 02-16-2024, 10:48 AM
            3 responses
            47 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Started by martin70, 03-24-2023, 04:58 AM
            15 responses
            114 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by The_Sec, Today, 02:29 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by jeronymite, 04-12-2024, 04:26 PM
            2 responses
            31 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X