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

Help with exit strategy

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

    Help with exit strategy

    Hi,

    I am looking for some help on implementing my exit strategy. I am only using this in back-testing purposes and I do have access to historical data. This is on intra-day strategy. Basically, I enter the market on my signals with 3 orders of equal amount of shares, say 100 each of GOOG, for a total of 300. What I want to do, is the following:
    - Set a stop loss on the whole position of $X, if I get stopped out, I exit with everything.
    - When the market moves in my direction, and I reach my first arbitrary profit target, I exit with order (100 shares). Now I have some real profits and some unrealized.
    - Now what I want to do is set a stop loss on the rest of the position (200 shares) with a break even on the whole position (basically my stop is my entry price), then trailstop until I get stopped out.

    What I am struggling with is the SetStopLoss eliminates my ability to use SetTrailStop afterwards, as per documentation. What would be the best way to do this easily in my code?

    Thank you in advance!

    #2
    Roberto76,

    Thank you for your note.

    You can modify the SetStopLoss to act as a trailing stop or move the price as you want.

    You will want to take a look at the reference sample below on modifying your StopLoss and Profit Targets-
    http://www.ninjatrader.com/support/f...ead.php?t=3222

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Here is my challenge - how do I know when my profit target was reached? I can't see that in the OnBarUpdate method. So, I am not sure when to move a stop up. I am also not sure where I can get value of my initial order entry - what price did I get in on?

      Thank you!

      Comment


        #4
        Roberto,

        I mean't to add this second reference sample. It will show you how to monitor your stop loss and profit targets -
        http://www.ninjatrader.com/support/f...ead.php?t=5790
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hi - thanks for the info, I tried using those methods and was able to code the strategy, but I am still having an issue. I am backtesting on historical daily data - using daily bars. So, initial stop loss works just fine if market moves against me right after my entry. If it moves in my direction and I hit my first profit target - it gets executed fine. Then, I move my stop loss up to my first initial entry. Here is the odd part. Now, I get stopped out immediately at my initial entry price - which shouldn't be happening - as I already reached my profit target mid-day and prices continued to move up. So, I read forums further and saw that NT only uses OHLC data for backtesting - meaning, it doesn't not consider what happens within that bar. So, if prices go down first - or up first - it doesn't matter - it just stops you out. This is producing incorrect results for me... Has anyone else run into this? Is there a good workaround for it? (besides of running this on a minute bars - which would be extremely impractical for me).

          Thanks for your help,

          -roberto

          Comment


            #6
            Roberto,

            You will need to incorporate an Intrabar Granularity to have your strategy calculate on a tick by tick basis.
            http://www.ninjatrader.com/support/f...ead.php?t=6652
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Hi - thanks for that - I think we are getting closer. I believe adding a smaller series in my strategy should help hit appropriate stops more accurately if orders are submitted against them. Before I start mucking around, a few questions:

              1. I used to use SetProfitTarget and SetStoploss, but based on what I'm reading, to achieve more appropriate stops - I should be using ExitStopLoss. In a backtest - will the good until cancelled parameter work if set to true? Or will the order expire at the end of the bar and need to be re-submitted on the next more granular bar? Would I have to cancel them?

              2. If I use exit stop loss - can I stil use SetProfitTarget? I am fine if we exit at any bar..... Or am I required to switch to exit Stop Limit and Exit Stop loss - and fully drop the "set" methods?

              3. The example provided does not address when to submit orders. so, in my strategy, primary series is in a daily bar - which is where the entries are. Is it ok to then put exits in a secondary seriers? Or will this create a problem?

              4. What I am thinking of doing is this - can you see if it makes sense - or if it is along the right side of thinking (this is for back-testing):

              In Initialize():
              - Remove SetStopLoss completely from code....
              - Keep SetProfit for profit targets

              OnBarUpdate:
              - EnterLong or short according to my entries (where BIP ==0) for daily charts
              - Check to see if I'm flat - if so, cancel the ExitStopLoss order.....

              OnExecution:
              - I detect for on profit target execution, if so - move the stop up by placing the ExitStopLoss order on the more granular series (BIP==0)

              Am I thinking along the right lines? Or is there a better way to do it?

              Thanks,

              -robert

              Comment


                #8
                Roberto,

                will the good until cancelled parameter work if set to true? Or will the order expire at the end of the bar and need to be re-submitted on the next more granular bar? Would I have to cancel them?
                Yes, although with NinjaScript this is called Live until Cancelled. By default orders submitted by method Enter() or Exit() will be cancelled at the end of each bar unless resubmitted.

                If I use exit stop loss - can I stil use SetProfitTarget? I am fine if we exit at any bar..... Or am I required to switch to exit Stop Limit and Exit Stop loss - and fully drop the "set" methods?
                You will not be able to use both. You will need to use either Exit() or Set() methods.

                The example provided does not address when to submit orders. so, in my strategy, primary series is in a daily bar - which is where the entries are. Is it ok to then put exits in a secondary seriers? Or will this create a problem?
                You will need to place the exits on the same series as you submit the entry orders. You are using the Intrabar Granularity to calculate when you want to submit the orders in your logic.


                Your logic looks good. I would recommend testing it out and adjust any issues that you come across.

                Let me know if I can be of further assistance.
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by roberto76 View Post
                  In a backtest - will the good until cancelled parameter work if set to true? Or will the order expire at the end of the bar and need to be re-submitted on the next more granular bar? Would I have to cancel them?
                  Yes. Good till cancelled will work correctly on orders.
                  3. The example provided does not address when to submit orders. so, in my strategy, primary series is in a daily bar - which is where the entries are. Is it ok to then put exits in a secondary seriers? Or will this create a problem?
                  You can enter on one bar series and exit on another. In fact, the samples subForum has the very example that you seek.

                  ref: http://www.ninjatrader.com/support/f...ead.php?t=5787

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by mintos, 04-02-2024, 08:22 PM
                  7 responses
                  36 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by PaulMohn, 04-24-2024, 03:49 AM
                  5 responses
                  39 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by claxxical, 05-30-2017, 12:30 PM
                  38 responses
                  4,480 views
                  0 likes
                  Last Post alancurry  
                  Started by Felix Reichert, 04-26-2024, 02:12 PM
                  10 responses
                  70 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by lightsun47, Today, 11:37 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Zachary  
                  Working...
                  X