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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X