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 cmtjoancolmenero, Yesterday, 03:58 PM
        11 responses
        39 views
        0 likes
        Last Post cmtjoancolmenero  
        Started by FrazMann, Today, 11:21 AM
        0 responses
        5 views
        0 likes
        Last Post FrazMann  
        Started by geddyisodin, Yesterday, 05:20 AM
        8 responses
        52 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by DayTradingDEMON, Today, 09:28 AM
        4 responses
        26 views
        0 likes
        Last Post DayTradingDEMON  
        Started by George21, Today, 10:07 AM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X