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

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 futtrader, 04-21-2024, 01:50 AM
        5 responses
        56 views
        0 likes
        Last Post NinjaTrader_Eduardo  
        Started by PeakTry, Today, 10:49 AM
        0 responses
        2 views
        0 likes
        Last Post PeakTry
        by PeakTry
         
        Started by llanqui, Today, 10:32 AM
        0 responses
        5 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by StockTrader88, 03-06-2021, 08:58 AM
        45 responses
        3,992 views
        3 likes
        Last Post johntraderuser2  
        Started by TAJTrades, Today, 09:46 AM
        0 responses
        8 views
        0 likes
        Last Post TAJTrades  
        Working...
        X