Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Instrument/Time Frame Query

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

    Multi Instrument/Time Frame Query

    Hi NT Support guys!

    I am programming a strategy that trades more than 1 instrument at the time, I was wondering if the following code makes sense or has programming issues:

    Code:
    					
    if (Positions[1].MarketPosition == MarketPosition.Long 
    && BarsSinceEntry(BarsArray[1]) >= nBarsInTrade 
    &&  Position.GetProfitLoss(BarsArray[1],Closes[1][0], PerformanceUnit.Points) >= 0)
    	SetStopLoss(...);
    in particular what I am trying to figure out is:

    1. if it makes sense to use:
    BarsSinceEntry(BarsArray[1])

    to calculate the bars since entry on my secondary instrument;


    2.1. if it makes sense to use:
    Position.GetProfitLoss(BarsArray[1],Closes[1][0], PerformanceUnit.Points) >= 0)

    to calculate the profit on the secondary instrument;

    Thanks for your advise

    #2
    Hello sburtt,

    Thank you for your post.

    Using Bars.SinceEntry() for multiple series will need to use the following syntax:
    Code:
    BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo)
    There is no need for BarsArray in Position.GetProfitLoss(), simply use Closes[1][0]:
    Code:
    Position.GetProfitLoss(Closes[1][0], PerformanceUnit.Points)
    For information on using multiple instruments and time frames in your code 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


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello sburtt,

      Thank you for your post.

      Using Bars.SinceEntry() for multiple series will need to use the following syntax:
      Code:
      BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo)
      There is no need for BarsArray in Position.GetProfitLoss(), simply use Closes[1][0]:
      Code:
      Position.GetProfitLoss(Closes[1][0], PerformanceUnit.Points)
      For information on using multiple instruments and time frames in your code please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

      Please let me know if I may be of further assistance.
      Hi Patrick, please correct me if I am wrong, but I think that what you suggest above doesn't work for my case, I am refering to:
      Code:
      Position.GetProfitLoss(Closes[1][0], PerformanceUnit.Points)
      Within the same strategy I am trading multiple instruments at the same time. what i am trying to achieve is GetProfitLoss() only for the specific instrument I am interested in, therefore I think I must somehow link this code to the specific barsInProgressIndex or a specific signalName. I hope I've been clear in my explanation, if not below is an example, I would appreciate if you could give me some advise on how to achieve this.

      e.i. Assume I am trading instrument "A" and "B" at the same time within the same strategy, meaning "A" = BarsArray[0], my primary instrument and "B" = BarsArray[1], my secondary instrument. Now assume I have both a Long position in "A" and "B", and that I want to check if the position in "B" is in profit to move my stoploss to breakeven. Do you think this code would work? How exactly does this code identify if the long position in "B" is in profit or loss?

      Code:
      if (Positions[1].MarketPosition == MarketPosition.Long 
      && BarsSinceEntry(1,"",0) >= nBarsInTrade 
      &&  Position.GetProfitLoss(Closes[1][0], PerformanceUnit.Points) >= 0)
      	SetStopLoss(...);

      Comment


        #4
        Hello sburtt,

        Thank you for your response.

        The [1] in Closes[1][0] references the secondary bar series ("B" in your example). your code example will work to find the profit of the second bar series.

        For information on Closes please visit the following link: http://www.ninjatrader.com/support/h...nt7/closes.htm

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

        Comment


          #5
          ok cool it looks like it works fine, thx.

          the need for this comes from the fact that in this way i can actually see the real MaxDD of myequity curve. I assume the Cumulative Result is simply an average, therefore the MaxDD is not correct, please correct me if wrong

          Comment


            #6
            Hello sburtt,

            Thank you for your response.

            GetProfitLoss() is not a cumulative PnL but the Unrealized PnL of the open position.

            There is a AvgProfit and CumProfit at the following link that you may be looking for: http://www.ninjatrader.com/support/h...ancevalues.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            646 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            367 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X