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 kinfxhk, 07-14-2026, 09:39 AM
        0 responses
        125 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 07-13-2026, 10:18 AM
        0 responses
        105 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 07-13-2026, 09:50 AM
        0 responses
        85 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 07-13-2026, 07:21 AM
        0 responses
        105 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 07-11-2026, 02:11 AM
        0 responses
        84 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X