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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X