• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sergey_z, Today, 02:56 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by samir, Today, 02:46 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by neoikon, Today, 02:24 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by XimoTrader, Today, 12:57 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by FxInception, Today, 12:27 PM
    2 responses
    14 views
    0 likes
    Last Post FxInception  
    Working...
    X