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

Trailing stop not working on backtest

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

    #46
    Originally posted by Baruch View Post
    Stephen,
    Do you write in NT script or in wizard?
    If you write in Wizard, I can't help.
    If in script then you need private IOrder, that way this variable will hold your entry it you will be able to query it.
    Also you need VS. Thats the olny way I see how to debug!

    Baruch
    I don't use the Wizard. My programming skills are almost non-existent as you know.
    I will look at the 'private IOrder' stuff tonight and post with the something or nothing
    I come up with on Saturday. It's hard to tell sometimes, will my abilities, when I need
    to use this or that in NinjaScript, so thanks again.

    I get the impression from support that I am the first person to ever need such coding
    (ie. change stoploss, to breakeven, then to trailing).

    Comment


      #47
      stephen,

      What we are trying to say is you can do all of that with a single stop loss order. Just modify the price of it when you deem necessary to breakeven and to become a trailing stop when that needs to be done too. You don't need two separate orders to accomplish this.
      Josh P.NinjaTrader Customer Service

      Comment


        #48
        Originally posted by NinjaTrader_Josh View Post
        stephen,

        What we are trying to say is you can do all of that with a single stop loss order. Just modify the price of it when you deem necessary to breakeven and to become a trailing stop when that needs to be done too. You don't need two separate orders to accomplish this.
        I think you and Baruch understand by now how difficult all this is.

        Anyway, you wrote:





        As far as one or two orders...well, nothing has come close to working, regardless
        of how I've approached this so far.

        (trying not to be snotty about it to you)

        - Stephen
        Last edited by stephenszpak; 12-25-2009, 07:58 PM.

        Comment


          #49
          Originally posted by NinjaTrader_Josh View Post
          stephen,

          What we are trying to say is you can do all of that with a single stop loss order. Just modify the price of it when you deem necessary to breakeven and to become a trailing stop when that needs to be done too. You don't need two separate orders to accomplish this.
          I was trying to do this by modifying the stop loss order. Some code
          was posted by me. Either it's not written correctly or NT isn't seeing it
          according to Baruch:

          comment by Baruch here:
          ================================================== ===========
          The problem is that you are not in a position, so you don't have Position.AvgPrice.
          You execute EnterLong(), but it takes time to enter a position and its not on OnBarUpdate() of a current bar.
          ================================================== ============

          Comment


            #50
            Hello,

            I will have someone reply to you on Monday. Thank you for your patience.
            DenNinjaTrader Customer Service

            Comment


              #51
              I have contacted someone who plans to assist me
              in this coding, for a fee. I hope it works out.

              Comment


                #52
                Sorry to say it didn't.

                Comment


                  #53
                  Trying IOrder stuff now. After a couple hours I got this below.
                  I tried, and am still trying to exit the long position but something
                  isn't right in that as yet. Need to add a 5 point stop loss before
                  I do the other two stops (breakeven, then trailing)


                  ================================================== ========

                  private IOrder bullOrderentry=null;


                  protected override void OnBarUpdate()
                  {
                  {
                  {
                  if (Close[0]>Close[1]&& Median [0]>Median[1]&& bullOrderentry==null)
                  EnterLong("bullOrderentry");

                  Comment


                    #54
                    I thought that what I wrote below would begin to approach
                    being right. I wasn't sure if the stop would be triggered
                    in real time or at the close of a bar. Unfortunately the stop is never triggered at all.

                    ================================================== =============

                    #region Variables
                    private double Stop=0;


                    #endregion

                    private IOrder bullOrderentry=null;
                    private IOrder bullOrderexit=null;

                    protected override void OnBarUpdate()
                    {
                    {
                    {
                    if (Close[0]>Close[1]&& Median [0]>Median[1]&& bullOrderentry==null)
                    EnterLong("bullOrderentry");

                    Stop=Position.AvgPrice-5*TickSize;
                    if (("bullOrderentry"!=null)&&(Close[0]<=(Stop))&& (bullOrderexit==null));
                    ExitLong("bullOrderexit");

                    Comment


                      #55
                      Code causes exits if price moves up or down. Hmmm.
                      ==================================================

                      if (Close[0]>Close[1]&& Median [0]>Median[1]&& (Position.MarketPosition == MarketPosition.Flat))
                      EnterLong();
                      if (Position.MarketPosition == MarketPosition.Long)

                      Stop=Position.AvgPrice-5*TickSize;

                      if ((Position.MarketPosition == MarketPosition.Long)&&(Close[0]<=(Stop)));
                      ExitLong();

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by f.saeidi, Today, 11:02 AM
                      1 response
                      1 view
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by geotrades1, Today, 10:02 AM
                      4 responses
                      12 views
                      0 likes
                      Last Post geotrades1  
                      Started by rajendrasubedi2023, Today, 09:50 AM
                      3 responses
                      15 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by lorem, Today, 09:18 AM
                      2 responses
                      11 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by geddyisodin, Today, 05:20 AM
                      4 responses
                      30 views
                      0 likes
                      Last Post geddyisodin  
                      Working...
                      X