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

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 GLFX005, Today, 03:23 AM
            0 responses
            1 view
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            11 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            6 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            12 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Working...
            X