Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stoploss, takeprofit and trailing stop in one strategy

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

    stoploss, takeprofit and trailing stop in one strategy

    Dear friends.
    I want to use take profit for order and stop loss at the same time. But I have read at manual that it is impossible.
    I try to use such code to close profitable position when thay more profitable then set up in variable myInput0.
    if (Position.MarketPosition == MarketPosition.Long&&Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)>myInput0)
    {
    ExitLong("exit for profit");
    }
    //////////////
    if (Position.MarketPosition == MarketPosition.Short&&Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)>myInput0)
    {
    ExitShort("exit for Short");
    }


    But it does not give result. I try to optimize it, and changing variable myInput0, does not give result.
    I also download sample of trailing stop, but they does not move stop loss and only close order's when profit reduced. And those mechanism do not work well on bactesting.

    #2
    Hi daglas,

    To track what your strategy is doing, you can use Print() statements to check values. Print your performance value to verify it's what you expect.

    Print(Position.GetProfitLoss(Close[0], PerformanceUnit.Currency));

    I want to use take profit for order and stop loss at the same time. But I have read at manual that it is impossible.
    Where did you read this in the manual? You can have profit target order and stop loss active at the same time.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post

      Where did you read this in the manual? You can have profit target order and stop loss active at the same time.
      If a stop loss or trail stop order is generated in addition to a profit target order, they are submitted as OCO (one cancels other)

      I use take profit
      SetProfitTarget("",CalculationMode.Percent,myInput 0);
      But it does not work.

      Comment


        #4
        OCO means that if one of the orders (either target or stop loss) is filled, it cancels the remaining one. The idea is that once your position is closed, you don't want outstanding orders that will enter the market in the opposite directions.

        What is your myInput0? If you're using CalculationMode.Percent, this should be a double, and the decimal equivalent for the percent you're going for.
        50% = .5
        1% = .01
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        157 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        91 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        143 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        131 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X