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 trilliantrader, Today, 03:01 PM
    2 responses
    17 views
    0 likes
    Last Post helpwanted  
    Started by ScottWalsh, Today, 06:52 PM
    2 responses
    17 views
    0 likes
    Last Post ScottWalsh  
    Started by cre8able, Today, 07:24 PM
    0 responses
    1 view
    0 likes
    Last Post cre8able  
    Started by Haiasi, Today, 06:53 PM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by ScottW, Today, 06:09 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X