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

How to create a breakeven strategy that works well :)

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

    How to create a breakeven strategy that works well :)

    Hello Team,

    Looking for some support on how to create a proper breakeven strategy that eventually trails with the market.

    Currently the strategy submits an order once it notices the market is 5 points from a specific entry price. I use the following to submit the order:
    EnterLongLimit(2, entryarea, "TradeArea"); {
    SetProfitTarget(CalculationMode.Ticks, 40);
    SetStopLoss(CalculationMode.Ticks, 40); }



    Now once market is in a long position I want to be able to move just the stop loss once we have been in the market for 5 bars and we see that the close price of market is greater than our entry price. I am using the following to try and do this:
    else if (numberofbarssinceentry > 5 && Close[0] > entryarea) {
    SetStopLoss(CalculationMode.Price, entryarea); }

    Instead of moving stop loss to breakeven it just exits me out of the position. Can someone please shed some light on this please? What do I need to do to adjust stop loss to breakeven once market is in a favourable position. Thank you!


    #2
    Hello Shodasi99,

    Thank you for your post.

    The following reference sample demonstrates how to modify the price of stop/target orders:


    For example, it uses Position.AveragePrice for the entry price to use for the breakeven modification:
    Code:
                    // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
                    if (Close[0] > Position.AveragePrice + 50 * TickSize)
                    {
                        SetStopLoss(CalculationMode.Price, Position.AveragePrice);
                    }
    ​
    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3

      Hello Emily,

      Thanks for writing back to us. I have tried the following insert:
      SetStopLoss(CalculationMode.Price, Position.AveragePrice);

      However this does not allow me to change the stop loss to breakeven, instead it exits me out of the position completely? Any idea why this is? Thanks!​

      Comment


        #4
        Originally posted by Shodasi99 View Post
        Hello Emily,

        Thanks for writing back to us. I have tried the following insert:
        SetStopLoss(CalculationMode.Price, Position.AveragePrice);

        However this does not allow me to change the stop loss to breakeven, instead it exits me out of the position completely? Any idea why this is? Thanks!​
        Is this happening during real-time testing or during historical/backtest results? If possible, please provide a screenshot showing where you are seeing that it exits you out of the position after the breakeven.
        • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
        • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
        ​I look forward to your reply.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hello Emily,

          Please see screenshots attached. The first image is when market has entered our order at 4151. It will set stop loss and profit accordingly. Next image will show how it will just close us out.
          Attached Files

          Comment


            #6
            Hello SHodasi99,

            Thank you for your reply.

            I suggest adding Print() statements as well as enabling Trace Orders in order to debug and better understand your strategy's behavior. You could print out the price of your stop loss and profit target orders and add a print every time you call SetStopLoss() and SetProfitTarget() to see when exactly the prices are being set and what the prices are being set to. TraceOrders may be set to true in State.SetDefaults and will also supply useful details regarding orders and when they are submitted, changed, canceled, ignored, etc to the NinjaScript Output window. For more information on using these tools for debugging, please see the links below:If you do not understand the output from your prints and trace orders, you could save it to a text file by right-clicking the NinjaScript Output window and selecting Save as, then attach the .txt file to your reply so I may better assist you.

            Please feel free to reach out with any additional questions or concerns.
            Emily C.NinjaTrader Customer Service

            Comment


              #7

              Hello Emily,

              Will definitely try that. In the meantime I had a question. If I use EnterLongLimit(int quantity, double limitPrice, string signalName) with SetProfitTarget(string fromEntrySignal, CalculationMode mode, double value) and SetStopLoss(CalculationMode mode, double value) when I first submit order, can I later update the profit target and stop loss later as market moves? If I can how would i do this, I see in the example you submit the order with enterlong() function

              Comment


                #8
                Hello Shodasi99,

                Thank you for your reply.

                Updating the price of SetStopLoss() and SetProfitTarget() would still be done in the same way, whether you are calling EnterLong() or EnterLongLimit() for the entry order. You could try this by modifying the example to submit an EnterLongLimit() order instead and observe the behavior of the stop and target orders:


                Please let us know if we may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Emily,

                  Thank you for all your support, with some tweaking and the sample code you provided. I can now adjust SetStopLoss() and SetProfitTarget() freely

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by llanqui, Today, 03:53 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post llanqui
                  by llanqui
                   
                  Started by burtoninlondon, Today, 12:38 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post burtoninlondon  
                  Started by AaronKoRn, Yesterday, 09:49 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post AaronKoRn  
                  Started by carnitron, Yesterday, 08:42 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post carnitron  
                  Started by strategist007, Yesterday, 07:51 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post strategist007  
                  Working...
                  X