Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Open Long and Short Positions

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

    Open Long and Short Positions

    Hello Forum Members: I wanted to ask a simple question.

    Is it possible to open a long position and a short position on two different instruments on NT8? For instance, is it possible to long the ES Dec 23 contract, and sell NQ Dec 23 contract at the same time? Similarly, buy a recent Corn contract and sell recent Oil contract. The reason I ask is that I was trying to develop a strategy, and my coder told me that it was not possible. He is asking me to contact support forums. I find it very strange. BTW, I can do it on a demo account.

    I am very confused. Please help!
    Last edited by cranky; 09-25-2023, 06:36 AM.

    #2
    Hello cranky,

    Thank you for the message.

    You are more than welcome to be Long on One Instrument while Short on another.
    • The issue would be if you were trying to be both Long and Short on the same instrument and contract.

    So, since you would be Long on the ES and short on the NQ, that is a totally viable option.


    Please let us know if we may provide any further assistance.

    Comment


      #3
      Thanks for all your help. Basically, I am trying to code a simple strategy where MES is the primary instrument and MNQ is the secondary instrument, which will always take the opposite direction of the main instrument. I have started coding it. Basically, it should open a position on every bar...nothing much. However, after compiling it, it doesn't seem to start. Here is the code:

      region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class MultiInstrumentTest : Strategy
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "MultiInstrumentTest";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      }
      else if (State == State.Configure)
      {
      AddDataSeries("MNQ DEC23", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
      }
      }

      protected override void OnBarUpdate()
      {
      if(Position.MarketPosition == MarketPosition.Flat)
      {
      EnterLong(0, 1, "MESENTRY");
      EnterShort(1, 1, "MNQENTRY");
      }
      }
      }
      }​

      Comment


        #4
        Hello cranky,

        Thank you for the update.

        If you have questions about creating or editing a NinjaScript Strategy, please make sure you are posting those within the correct location in the Forum.

        Please recreate your post and do it under the "Strategy Development" or "Indicator Development" section of the forum instead.


        This section of the forum is for General Platform or technical-related questions.

        Please let us know if we may provide any further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        77 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        45 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        27 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        63 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X