Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 DanielSanMartin, Yesterday, 02:37 PM
    2 responses
    12 views
    0 likes
    Last Post DanielSanMartin  
    Started by DJ888, 04-16-2024, 06:09 PM
    4 responses
    12 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by terofs, Today, 04:18 PM
    0 responses
    11 views
    0 likes
    Last Post terofs
    by terofs
     
    Started by nandhumca, Today, 03:41 PM
    0 responses
    7 views
    0 likes
    Last Post nandhumca  
    Started by The_Sec, Today, 03:37 PM
    0 responses
    3 views
    0 likes
    Last Post The_Sec
    by The_Sec
     
    Working...
    X