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 Shansen, 08-30-2019, 10:18 PM
    24 responses
    939 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    8 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    4 views
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    28 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    33 views
    0 likes
    Last Post wzgy0920  
    Working...
    X