Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Placing long/short orders on multiple instruments

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

    Placing long/short orders on multiple instruments

    Hi,

    I would like to place different size positions long and short on multiple stocks. For example, let's assume the whole portfolio should be long $100 and short $100, and I have 5 stocks that I am trading. My algorithm computes a "weight" to put on each stock, with 1.0 being the total portfolio weight on each side long or short. Meaning, if I assign a weight of .5 to a stock, then it should have a position of long $50, or if I have a weight of -.25, then the position should be short $25. My algorithm ensures that each side (long or short) adds up to 1.0 (or -1.0 on the short side), so this way the long and short sides are the same size, so the portfolio always remains dollar-neutral (long and short same amount).

    Can you please show me some simple code that would take the weights for stocks that my algorithm produces (on a daily basis) and place the appropriate trade entries? For example, can I specify a dollar amount of stock to buy in my trade order? What should the NinjaScript command look like?

    Thanks!
    Protis

    #2
    Hey mate, are you performing trades on stocks, currency or futures?

    On currency the easiest way to control it is to auto fill with an amount equal to a dollar value you want invested. AUDJPY is a flat value, so 1000 = $1000, on the AUSUSD its 100000 = $1000.

    If it's stocks you'll need to determine the value / price before getting your entry amount, so if its $25 a stock you can only afford 1 if your trading 4 $25 stocks.

    You can adjust your account cash starting value. My startegy is currently testing with $10,000 starting over 6 forex trades and evenly splits based on 70% of that. So it assume if it's trading 6 in total that if can invest up to ~1160 each.

    Comment


      #3
      Thanks! I am actually working with stocks...could you please be more specific with some code snippets? Let's say I already know how I want to distribute the account's cash at each time step, according to "weights" that I give to each stock, where all the positive weights add up to 1.0 and all the negative weights add up to -1.0. Basically I want to end up with an equal amount of money long and short.
      Thanks again,
      Protis

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      639 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 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
      572 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X