Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Selling on the Open, and reactivating NT

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

    Selling on the Open, and reactivating NT

    Hi, this is either a coding problem, or has something to to do with me restarting NT in the middle of the day. I opened a few hundred positions yesterday, and had to restart ninja trader when the e-mail send function kept going. Basically, I was wondering if when I restart, there's anyway of telling the NT program to work with the already open positions without resubmitting the orders.

    Also, what is the best way to sell on the open? I used if BarsSinceEntry==0 then selllong. Is this not going to work? Or is it that I had to restart and it took new positions that threw this off?--Beau

    #2
    beauw,

    When you restart your strategy, especially since it has been running, you need to pay careful attention to syncing issues. Please review this article: http://www.ninjatrader-support.com/v...ead.php?t=4033

    Options available to you are available in Tools->Options->Strategies->NinjaScript.

    if (BarsSinceEntry() == 0) will trigger when you've never traded before. It does not necessarily mean you will trade on the open. There is no order type that will guarantee you a fill at the open. You can place trades on the first tick of the first bar of the session with this condition.
    Code:
    if (Bars.BarsSinceSession && FirstTickOfBar)
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Here's another problem that I just discovered. If both of my entries and my exits are true, then I keep submitting and resubmitting both orders and exits.

      How would I structure my program to ignore the days when I am selling on the open, and ignore the sell condition on the days when I am entering? I seem to have both conditions true for NTAP today.

      I guess what I'm trying to check for is that the day that I do go long, is not the day that I exit. And the day that I exit, is also not going to be a day to attempt to go long. I was trying to work the datetime values out, but I didn't have any success.

      I see the problem of implementing the script. Let's say the script was buy 8% and 10% below the close of yesterday and sell on the open the next day. Well, the basic problem I'm having is that when I get filled on both entries, the minus 8% and the minus 10%, the sell the next day WILL be true even if the entry condition is true the next day, too. So all I've gotten is a bunch of buys and sells one right after the other. There's something in the datatime series that I think would make this possible.

      How do I check if the day that I bought was yesterday? And how do I check if the day I sold was today? I don't get from the date time functions how to check today's date. I just get a lot of hard coded values that aren't of any use to me.

      Comment


        #4
        Hi beauw,

        You can use flags. If your 8% and 10% are true set a flag variable to true. While this flag is true you don't trigger your sell at open. You can do it vice versa also. Afterwards you can just reset the flag and then the system will be ready for another trade.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Sorry, that doesn't help, because I'm calculating on bar update, not at the close.

          What would happen is that I'd have

          if long and boolean sell is true
          sell
          boolean buy is true

          if flat and boolean buy is true
          buy today
          boolean sell is true

          The flag doesn't matter in this case because I have no point of reference for resetting it, because it'll get recalculated on every bar update where the buys are true, and recalculated so that the same problem happens.

          No, I need a flag that checks todays date, and then for the sell checks if the buy date was yesterday. If it does that then I can reset the program. The flags by themselves aren't the problem.

          It's not that I wasn't going to use flags, but that I need to know how to check if the buydate was yesterday. If you can come up with some code for that, I would appreciate. Vice Versa, checking if the sell date was yesterday.

          Is this how you'd check it
          (f[0]!=DateTime.Now

          and setting this in the buy part
          f.Set(DateTime.Now);
          sell=
          true;
          Last edited by beauw; 10-07-2008, 11:28 AM.

          Comment


            #6
            Not sure I follow. You can specify the initial state of the flag in the Variables region of your code. You don't need to be linked down to one flag. You can use as many flags as you need to get it to work.

            If you think using the dates of the trades will work for you, you can definitely check out the Trade objects and access the underlying IExecution to get their time property.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              No, you're not understanding. I set that I bought today, right? I mark the date. If I just use a flag, then it'll be true on the next tick and it'll just go straight to submitting the order. If I mark the date, and I check if that was yesterday as precondition to either buying or selling, THEN, I can reset the flags. The flags aren't an issue. Resetting the flags is the issue, BECAUSE THIS IS NOT CALCULATED ON THE CLOSE. This strategy I assume is calculated on every tick. That means the flags will just cycle through and be true anyway. Come on.

              Comment


                #8
                Just set in the entry condition that the bool had to be false to begin with. If your buy bool is false then you can buy. When you buy your buy bool is true. When it comes around on the next tick the buy bool is true, it wont buy again. Reset to false after you've exited or whenever you deem necessary.

                Code:
                if (buyLong == false)
                {
                     EnterLong();
                     buyLong = true;
                }
                
                if (some exit condition)
                {
                     ExitLong();
                     buyLong = false;
                }
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Josh, listen to me. That's the problem with my conditions. THEY'RE BOTH TRUE TODAY! They get reset, not tomorrow, when the bar closes, but TODAY on the NEXT TICK,because I'm not calculating on the close, but INTRADAY ON EVERY TICK! This means if both conditions are true, then I'll just keep buying and selling on every single tick. Do you get me?

                  I need to know DATE FUNCTIONS. I WANT THE FLAG TO BE DEPENDENT ON TODAY'S DATE.

                  Comment


                    #10
                    Josh, my conditions aren't complicated. They're buyatlimit today, sell on the open tomorrow calculated on each tick, not at the close. I just have one condition on the exit and that is to sell on the open, so the exit condition is simply sell on the open the next day.

                    Basically,

                    Buy today, sell tomorrow. In the case of NTAP today I have buy yesterday, sell today, and buy today, which puts it in an infinite loop of buying and selling when both conditions are true. I only want to do one or the other. That is, preferrably, buy today, sell tomorrow, wait to repeat the buy today, sell tomorrow process. That's all I'm trying to do.

                    The system is basically,
                    buy 8% below the low
                    sell the next day

                    There is nothing fancy about the exit, just that it has to be tomorrow.

                    So, in the case that we have today,
                    buy 8% below the low from yesterday
                    sell the next day and the buy is true again then both conditions are true and I'm stuck in an infinite buy sell loop that keeps repeating on each tick.

                    Comment


                      #11
                      beauw,

                      I am listening to you. Why would your conditions both be true today? You can't submit an order to sell 100 bars into the future. To sell tomorrow you can only submit that order on tomorrow's bar. You have your today's buy condition execute, set your bool to disallow of more entry orders from today, tomorrow comes along, sell condition = true, sell order done, reset bool, can enter long again.

                      Now you bring up DateTimes. This is a completely separate solution. Like I said, you can get DateTime by checking the Trades object for your entry. Then just check against the current Time[0]. If the entry happened yesterday then you know today you can sell.

                      Alternatively, you can simply set a temp variable that takes on Time[0] as you enter today. Tomorrow you check ToDay(Time[0]) against ToDay(temp variable). If it is greater than temp variable's return then you know it is tomorrow and that you can sell.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by beauw View Post

                        ...snip...

                        Buy today, sell tomorrow. In the case of NTAP today I have buy yesterday, sell today, and buy today, which puts it in an infinite loop of buying and selling when both conditions are true. I only want to do one or the other. That is, preferrably, buy today, sell tomorrow, wait to repeat the buy today, sell tomorrow process. That's all I'm trying to do.

                        ... snip ...

                        .
                        beauw,
                        I am wondering, if you have a daily strategy, why are you processing every tick? Why not just use daily bars ?

                        Comment


                          #13
                          Originally posted by NinjaTrader_Josh View Post
                          beauw,

                          When you restart your strategy, especially since it has been running, you need to pay careful attention to syncing issues. Please review this article: http://www.ninjatrader-support.com/v...ead.php?t=4033

                          Options available to you are available in Tools->Options->Strategies->NinjaScript.

                          if (BarsSinceEntry() == 0) will trigger when you've never traded before. It does not necessarily mean you will trade on the open. There is no order type that will guarantee you a fill at the open. You can place trades on the first tick of the first bar of the session with this condition.
                          Code:
                          if (Bars.BarsSinceSession && FirstTickOfBar)
                          This bit of code I did add to the program, and it still kept submitting the orders. Does this method not work when the chart is not calculated on the close?

                          Comment


                            #14
                            Originally posted by twtrader View Post
                            beauw,
                            I am wondering, if you have a daily strategy, why are you processing every tick? Why not just use daily bars ?
                            I am on daily bars, it's just there's ten entries and there's not enough buying power to submit them all. That's why. They have to "get close" to the price before I submit them. The problem is I can't get the program to wait until the bar closes before submitting the exits. And the bit of code that would get the orders price on the open doesn't work.

                            Comment


                              #15
                              beauw,

                              Please use the techniques from my latest post. That code snippet works fine for limiting trades on the first bar of a session and the first tick of that bar. There are no "sessions" when you are using daily bars.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by guillembm, Yesterday, 11:25 AM
                              2 responses
                              9 views
                              0 likes
                              Last Post guillembm  
                              Started by junkone, 04-21-2024, 07:17 AM
                              9 responses
                              68 views
                              0 likes
                              Last Post jeronymite  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              4 responses
                              20 views
                              0 likes
                              Last Post trilliantrader  
                              Started by mgco4you, Yesterday, 09:46 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by wzgy0920, Yesterday, 09:53 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post wzgy0920  
                              Working...
                              X