Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

question on set profit target

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

    question on set profit target

    how do I set a profit target which takes the order price and adds a profit factor * ATR(20)?

    SetProfitTarget(CalculationMode.Price, ProfitFactor * (ATR(20)[0]));

    is the above correct?

    this createed some really bad results?? am I missing something? shouldnt I have order price in there somewhere??

    Thanks!

    #2
    Hello James377,

    Position.AvgPrice will return 0 when you're not in a position. Most likely you will want to add a check that only submits when you are not flat.

    if (Position.MarketPosition != MarketPosition.Flat)
    SetProfitTarget(CalculationMode.Price, ProfitFactor * (ATR(20)[0]));

    This also means you would want to set it to an initial value when you are flat. The following reference sample can help with modifying target orders dynamically:
    Modifying the price of stop loss and profit target orders
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      so where do I add in this position.avgprice?

      if (Position.MarketPosition != MarketPosition.Flat)
      SetProfitTarget(CalculationMode.Price, Position.AvgPrice + (ProfitFactor * (ATR(20)[0])));

      in bold??
      Last edited by james377; 09-30-2010, 03:01 PM.

      Comment


        #4
        Yes, that would be where. I misread your profit factor for Position.AvgPrice.

        You should print the value of this expression so you can verify that it's what you expect.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          how do I print the value of my profit target?

          Comment


            #6
            Print ((Position.AvgPrice + (ProfitFactor * (ATR(20)[0]))));

            You then view output through Tools > Output window. Additional debugging help is available here:
            Debugging your NinjaScript Code
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CaptainJack, 05-29-2026, 05:09 AM
            0 responses
            476 views
            0 likes
            Last Post CaptainJack  
            Started by CaptainJack, 05-29-2026, 12:02 AM
            0 responses
            317 views
            0 likes
            Last Post CaptainJack  
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            254 views
            1 like
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            340 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            306 views
            0 likes
            Last Post CarlTrading  
            Working...
            X