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 SetProfitTarget

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

    Question on SetProfitTarget

    I'm familiar with how SetProfitTarget works on a 1 unit (or all in, all out) strategy. However, I'm wondering if there is a simple way to use this command when a strategy enters 1 unit and then adds more units when certain conditions are met.

    What I'd like to do is use SetProfitTarget(100.00), but I'm guessing that will give me a $100 target for each unit entered, whereas I want $100 target on the whole position.

    Any advice for the simplest way to approach this?

    #2
    Originally posted by coolmoss View Post
    I'm familiar with how SetProfitTarget works on a 1 unit (or all in, all out) strategy. However, I'm wondering if there is a simple way to use this command when a strategy enters 1 unit and then adds more units when certain conditions are met.

    What I'd like to do is use SetProfitTarget(100.00), but I'm guessing that will give me a $100 target for each unit entered, whereas I want $100 target on the whole position.

    Any advice for the simplest way to approach this?
    Essentially the same question: pretty much the same answer. Use CalculationMode.Price and the average entry price.

    ref: http://www.ninjatrader.com/support/f...ad.php?t=57470

    Comment


      #3
      Hey Koganam!

      Thank you for about the 7,000th time. Is there any way you could do a sort of vulcan mind meld and inject me with your programming saavy?

      Comment


        #4
        Hello coolmoss,

        Thanks for your note.

        Just to be sure I fully understand your inquiry, does this mean you would like to set the profit target to the combined profit of the entry quanity.

        So on the ES each tick of profit is worth $12.50 (tick size * point value).

        This means that $100 of profit would be 8 ticks (profit desired / (tick size * point value)). Spread across a quantity of 2, this would be 4 ticks, correct ( profit desired / (tick size * point value * quantity)).

        So if the current price is $1589, the profit target would be set at $1590.

        So to calculate this, I wrote the following:

        Code:
        int quantity = 2;
        double profitWanted = Instrument.MasterInstrument.Round2TickSize(100);
        double addTicks = (profitWanted / (TickSize * Instrument.MasterInstrument.PointValue * quantity));
        
        if (Position.MarketPosition == MarketPosition.Flat)
        {
        EnterLong(quantity, "myLong");
        }
        else
        {
        SetProfitTarget("myLong", CalculationMode.Price, Position.AvgPrice + addTicks * TickSize);
        }

        Please let me know if this is not what you where looking for.
        Last edited by NinjaTrader_ChelseaB; 04-29-2013, 10:56 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea. I think that will do it, but was thinking the SetProfitTarget needed to go in the Initialize() area, not OnBarUpdate(). My thinking was that if SetProfitTarget was in OnBarUpdate(), it would need to be after the entry order (so the correct average price could be calculated considering the most recently added position). I wasn't sure how SetProfitTarget would work if it appeared in the code AFTER the entry order. Perhaps it should be updated in OnExecution().

          That seems ideal, can I use SetProfitTarget() in OnExecution()?

          Comment


            #6
            Hi coolmoss,

            Yes, you can set the profit target in the OnExecution. Also yes, this would be the ideal place to set the profit target.

            Also, you may set the profit target after an order has been submitted.

            Let me know if this does not resolve your inquiry.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              I have a follow up question. I employed your coding suggestion, and in real time it seems to work very nicely. On historical backtesting, I get some odd results, and it dawned on me that if I use OnExecution(), that probably won't work for backtesting. Is that a correct assumption.

              To clarify what's happening, let me give you an example: I observed a real time trade sequence which involved an initial entry and two subsequent averaging in entries, then the exit at the fixed dollar target. I then hit F5 to refresh script, and I ended up with very different looking results. The trades weren't even the same trades. But again, it seems like in historical mode, OnExecution has no way to execute according to the exact same chronology as in real time.

              Do I have this correct? Thanks much.

              Comment


                #8
                Hi coolmoss,

                You are correct, there is a subtle difference with OnExecution. During backtesting the OnExecution is processed with historical data and is run instantly without delay.

                Another difference about backtesting is how it places orders. With real-time data orders are placed according to the volume of bid and ask information. In backtesting orders are placed according to the open, high, low, close information only.

                You may end up with better results if you use the Market Replay to do your testing.

                Below is a link to the help guide on Real-Time vs Backtest Discrepancies.
                http://www.ninjatrader.com/support/h...ime_vs_bac.htm


                Please let me know if this does not resolve your inquiry.
                Last edited by NinjaTrader_ChelseaB; 04-30-2013, 10:51 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you so much for a very educational and complete answer. It is much appreciated.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Segwin, 05-07-2018, 02:15 PM
                  14 responses
                  1,788 views
                  0 likes
                  Last Post aligator  
                  Started by Jimmyk, 01-26-2018, 05:19 AM
                  6 responses
                  837 views
                  0 likes
                  Last Post emuns
                  by emuns
                   
                  Started by jxs_xrj, 01-12-2020, 09:49 AM
                  6 responses
                  3,293 views
                  1 like
                  Last Post jgualdronc  
                  Started by Touch-Ups, Today, 10:36 AM
                  0 responses
                  12 views
                  0 likes
                  Last Post Touch-Ups  
                  Started by geddyisodin, 04-25-2024, 05:20 AM
                  11 responses
                  62 views
                  0 likes
                  Last Post halgo_boulder  
                  Working...
                  X