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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X