Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting long and entering short with different quantity in the same bar

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

    Exiting long and entering short with different quantity in the same bar

    Hi,

    I am trying to develop a strategy where I may have to exit a previous long/short position with a certain quantity and enter
    in the other direction with a different quantity (the difference in quantities is because of position sizing).


    Currently I am doing something like this:
    quantity = get_quantity(); // for position sizing for both long and short
    if (enterLong) {
    EnterLong(quantity, "long");
    }
    else if (enterShort) {
    Entershort(quantity, "short");
    }
    else if (exitLong) {
    ExitLong("long");
    }
    else if (exitShort) {
    ExitShort("short");
    }

    Will this work when the long and short quantities are different ?

    Can you please provide me an example to do this correctly.

    Thanks.



    #2
    Hello ausgaef,

    Thank you for your post.

    Yes, that would work even if the value of your quantity variable changes. I've attached a quick Strategy Builder strategy I made that illustrates changing the quantity between short and long entries. I'd suggest unlocking the code and taking a look at how it works.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Hi Kate, thank you so much. Will try it out.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      77 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X