Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Want to trigger a stoploss only after a certain quantity of position

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

    Want to trigger a stoploss only after a certain quantity of position

    Hi,
    I am trying to place a stop loss after a certain number of contracts.

    E.g. if current position <=2
    no stoploss or whatsoever

    If current position >2
    SetStopLoss("EnterLong", CalculationMode.Price, Close[0] - (10 * TickSize), false);

    Then upon flat I want to cancel any stoploss for the next entry until again, position size has exceeded that same amount.

    The problem I face is that when there is a single stop set, every new entry from there onwards will inherit the stoploss from the previous entry and thus mix my strategy.

    Any ideas how I can solve this?

    Thanks

    #2
    Hello nikolaalx,

    Thanks for your post.

    Yes this can be solved by using a unique entry name for your orders after the first 2 and then using that name in the SetStopLoss. The unique name will work on and with any entry with the same name.

    Here is some sample code I used to test this and have attached a picture of the results. The first 2 orders are not named, the next three are named (each the same) and is the same in the SetStopLoss statement.

    In initialize I had: SetStopLoss ("gt2entry",CalculationMode.Ticks, 8, false);

    In the OnBarUpdate I had:

    if (Close[0] > Open[0]) // just to place orders
    {

    if (Position.Quantity < 2 )
    {
    EnterLong (); // these are the first two orders
    }
    else if (Position.Quantity > 1 && Position.Quantity < 5)
    {
    EnterLong ("gt2entry"); // these are the next 3, tied to SetStopLoss by the signal name.
    }
    }

    Using the simulated data feed, I ran the price up to fill the 5 orders, then ran price down and see that the last 3 order stops filled, then ran price back up and 3 more orders were placed, ran down again and the 3 named entry orders were again stopped out, leaving the original 2 in place. Please see the picture.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    571 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    330 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    548 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    549 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X