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 cmoran13, 04-16-2026, 01:02 PM
            0 responses
            76 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            45 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            168 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            101 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            165 views
            2 likes
            Last Post CaptainJack  
            Working...
            X